Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On pytest how could I transfer byte array as an input to the smart-contract like in solidity browser? #423

Open
avatar-lavventura opened this issue Dec 27, 2017 · 0 comments

Comments

@avatar-lavventura
Copy link

avatar-lavventura commented Dec 27, 2017

  • Populus Version: 2.2.0
  • OS: osx
solc --version
solc, the solidity compiler commandline interface
Version: 0.4.18-develop.2017.9.23+commit.ccb68970.Linux.g++

Please note that I couldn't solve this problem for months, I have tried everything :(

I have following contract; I can call set()with following byte array on solidity browser. The smart contract accepts the input as bytes32. I assume if geth and solidity browser sees a string starting with 0x, it converts it to byte format.

Following transaction call works without having any problem.

myContract.set("0x15CEF23823A9410D60CB6E6CC56046EC6035A9353100476EA28C94752AF104CD")

--

myContract.get()
Returns: "0x15CEF23823A9410D60CB6E6CC56046EC6035A9353100476EA28C94752AF104CD

My contract:

contract Contract {
  bytes32 public hash;
  function set(bytes32 hash_) returns (bool success)
  {
        hash = hash_;
  }
  function get() constant returns bytes32 {
     return hash;
   }
}

I want to do same operation on Populus.
When I try to call it as on test_greeter.py:

def test_greeter(web3, accounts, chain):
    myContract, _ = chain.provider.get_or_deploy_contract('Lottery')
    set_txn_hash = myContract.transact().set("0x15CEF23823A9410D60CB6E6CC56046EC6035A9353100476EA28C94752AF104CD")

It gives following error, I assume python sees the input given to set() as string instead of bytes. And the string version of the input exceeds the byte32.

   @classmethod
    def _encode_abi(cls, abi, arguments, data=None):
        argument_types = get_abi_input_types(abi)

        if not check_if_arguments_can_be_encoded(abi, arguments, {}):
            raise TypeError(
                "One or more arguments could not be encoded to the necessary "
                "ABI type.  Expected types are: {0}".format(
>                   ', '.join(argument_types),
                )
            )
E           TypeError: One or more arguments could not be encoded to the necessary ABI type.  Expected types are: bytes32

[Q] While using Populus on pytest how could I transfer byte array as an input to the contract like in solidity browser?

Thank you for your valuable time and help.

animal-197161_960_720

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant