mirror of
git://holbrook.no/eth-contract-registry
synced 2024-11-16 14:36:46 +01:00
83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
# standard imports
|
|
import os
|
|
|
|
# external imports
|
|
import logging
|
|
import pytest
|
|
from chainlib.eth.tx import (
|
|
receipt,
|
|
transaction,
|
|
)
|
|
from chainlib.eth.connection import RPCConnection
|
|
from chainlib.eth.contract import (
|
|
ABIContractEncoder,
|
|
ABIContractType,
|
|
abi_decode_single,
|
|
)
|
|
from chainlib.eth.nonce import NodeNonceOracle
|
|
from chainlib.eth.address import to_checksum_address
|
|
from hexathon import (
|
|
add_0x,
|
|
strip_0x,
|
|
)
|
|
|
|
# local imports
|
|
from contract_registry.registry import Registry
|
|
from contract_registry.encoding import from_identifier_hex
|
|
from contract_registry.pytest.fixtures_registry import valid_identifiers
|
|
|
|
logg = logging.getLogger()
|
|
|
|
valid_identifiers += [
|
|
'FooContract',
|
|
]
|
|
|
|
def test_set(
|
|
registry,
|
|
eth_accounts,
|
|
eth_rpc,
|
|
eth_signer,
|
|
):
|
|
|
|
addr_registry = to_checksum_address(os.urandom(20).hex())
|
|
addr_foo = to_checksum_address(os.urandom(20).hex())
|
|
bogus_hash = add_0x(os.urandom(32).hex())
|
|
|
|
#conn = RPCConnection.connect('default')
|
|
nonce_oracle = NodeNonceOracle(eth_accounts[0], eth_rpc)
|
|
builder = Registry(signer=eth_signer, nonce_oracle=nonce_oracle)
|
|
(tx_hash_hex, o) = builder.set(registry, eth_accounts[0], 'ContractRegistry', addr_registry, bogus_hash, bogus_hash)
|
|
r = eth_rpc.do(o)
|
|
|
|
o = receipt(r)
|
|
rcpt = eth_rpc.do(o)
|
|
assert rcpt['status'] == 1
|
|
|
|
o = builder.identifier(registry, 0, sender_address=eth_accounts[0])
|
|
r = eth_rpc.do(o)
|
|
r = from_identifier_hex(r)
|
|
assert r == 'ContractRegistry'
|
|
|
|
o = builder.address_of(registry, 'ContractRegistry', sender_address=eth_accounts[0])
|
|
r = eth_rpc.do(o)
|
|
r = abi_decode_single(ABIContractType.ADDRESS, r)
|
|
assert r == addr_registry
|
|
|
|
(tx_hash_hex, o) = builder.set(registry, eth_accounts[0], 'ContractRegistry', addr_registry, bogus_hash, bogus_hash)
|
|
r = eth_rpc.do(o)
|
|
o = receipt(r)
|
|
rcpt = eth_rpc.do(o)
|
|
assert rcpt['status'] == 0
|
|
|
|
(tx_hash_hex, o) = builder.set(registry, eth_accounts[0], 'FooContract', addr_foo, bogus_hash, bogus_hash)
|
|
r = eth_rpc.do(o)
|
|
o = receipt(r)
|
|
rcpt = eth_rpc.do(o)
|
|
assert rcpt['status'] == 1
|
|
|
|
o = builder.address_of(registry, 'FooContract', sender_address=eth_accounts[0])
|
|
r = eth_rpc.do(o)
|
|
r = abi_decode_single(ABIContractType.ADDRESS, r)
|
|
assert r == addr_foo
|
|
|