ethereum / pytest-ethereum

MIT License
19 stars 12 forks source link

Ad-Hoc Compiled Contract Address not in Canonical Form #20

Open fubuloubu opened 5 years ago

fubuloubu commented 5 years ago

What was wrong?

Got yelled at doing something that doesn't fail when using web3py directly

Code that produced the error

from vyper.compiler import compile as vyc
from vyper.compiler import mk_full_signature as vya

@pytest.fixture
def AdHocContract(w3):
    VYPER_CONTRACT = """
a: address
    """
    interface = {
        'abi': vya(VYPER_CONTRACT),
        'bytecode': vyc(VYPER_CONTRACT),
        'bytecode_runtime': vyc(VYPER_CONTRACT, bytecode_runtime=True)
    }
    txn_hash = w3.eth.contract(**interface).constructor().transact()
    address = w3.eth.waitForTransactionReceipt(txn_hash)['contractAddress']
    return w3.eth.contract(address, **interface)

Full error output

    txn_hash = w3.eth.contract(**interface).constructor().transact()
    address = w3.eth.waitForTransactionReceipt(txn_hash)['contractAddress']
>   return w3.eth.contract(address, **interface)

E   ethpm.exceptions.ValidationError: Py-EthPM library only accepts canonicalized addresses.
    0xDe09E74d4888Bc4e65F589e8c13Bce9F71DdF4c7 is not in the accepted format.

How can it be fixed?

pytest-ethereum should convert address to canonical form before passing to ethPM for ad-hoc compiled contracts.

fubuloubu commented 5 years ago

See https://github.com/GunClear/PlasmaRifle/commit/9c3abc3da2b04ce2162c5ffccd6932b3b18da7e0 for real setup (issue is patched in commit)