ethereum / ethereum/populus

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

Open
#423 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
319
Forks
110
PR merge metrics
No merged PRs in 30d

Description

* 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](https://user-images.githubusercontent.com/18537398/34373872-d64326ac-eaee-11e7-9ff5-0d76b01ead45.jpg)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.