2021-03-16 13:53:22 +01:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
|
|
|
|
# external imports
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from chainlib.eth.tx import (
|
|
|
|
receipt,
|
|
|
|
transaction,
|
|
|
|
)
|
2021-03-16 15:07:12 +01:00
|
|
|
from chainlib.connection import RPCConnection
|
2021-03-16 13:53:22 +01:00
|
|
|
from chainlib.eth.contract import (
|
|
|
|
ABIContractEncoder,
|
|
|
|
ABIContractType,
|
|
|
|
abi_decode_single,
|
|
|
|
)
|
2021-03-17 11:23:24 +01:00
|
|
|
from chainlib.eth.nonce import RPCNonceOracle
|
2021-03-16 13:53:22 +01:00
|
|
|
from chainlib.eth.address import to_checksum_address
|
|
|
|
from hexathon import (
|
|
|
|
add_0x,
|
|
|
|
strip_0x,
|
|
|
|
)
|
|
|
|
|
|
|
|
# local imports
|
2021-04-30 13:11:22 +02:00
|
|
|
from eth_contract_registry import Registry
|
|
|
|
from eth_contract_registry.registry import ContractRegistry
|
2021-04-30 12:01:08 +02:00
|
|
|
from eth_contract_registry.encoding import from_identifier_hex
|
|
|
|
from eth_contract_registry.pytest.fixtures_registry import valid_identifiers
|
2021-03-16 13:53:22 +01:00
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
valid_identifiers += [
|
|
|
|
'FooContract',
|
|
|
|
]
|
|
|
|
|
|
|
|
def test_set(
|
2021-04-30 12:01:08 +02:00
|
|
|
default_chain_spec,
|
2021-03-16 13:53:22 +01:00
|
|
|
registry,
|
|
|
|
eth_accounts,
|
|
|
|
eth_rpc,
|
|
|
|
eth_signer,
|
2021-04-30 12:01:08 +02:00
|
|
|
roles,
|
2021-03-16 13:53:22 +01:00
|
|
|
):
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
2021-04-30 12:01:08 +02:00
|
|
|
nonce_oracle = RPCNonceOracle(roles['CONTRACT_DEPLOYER'], eth_rpc)
|
2021-04-30 13:11:22 +02:00
|
|
|
builder = ContractRegistry(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
2021-03-16 13:53:22 +01:00
|
|
|
|
|
|
|
o = builder.address_of(registry, 'ContractRegistry', sender_address=eth_accounts[0])
|
|
|
|
r = eth_rpc.do(o)
|
|
|
|
r = abi_decode_single(ABIContractType.ADDRESS, r)
|
2022-02-20 20:46:58 +01:00
|
|
|
assert r == strip_0x(registry)
|
2021-03-16 13:53:22 +01:00
|
|
|
|
2021-11-15 14:33:47 +01:00
|
|
|
(tx_hash_hex, o) = builder.set(registry, roles['CONTRACT_DEPLOYER'], 'ContractRegistry', addr_registry)
|
2021-03-16 13:53:22 +01:00
|
|
|
r = eth_rpc.do(o)
|
|
|
|
o = receipt(r)
|
|
|
|
rcpt = eth_rpc.do(o)
|
|
|
|
assert rcpt['status'] == 0
|
|
|
|
|
2021-11-15 14:33:47 +01:00
|
|
|
(tx_hash_hex, o) = builder.set(registry, roles['CONTRACT_DEPLOYER'], 'FooContract', addr_foo)
|
2021-03-16 13:53:22 +01:00
|
|
|
r = eth_rpc.do(o)
|
|
|
|
o = receipt(r)
|
|
|
|
rcpt = eth_rpc.do(o)
|
|
|
|
assert rcpt['status'] == 1
|
|
|
|
|
2021-04-30 13:11:22 +02:00
|
|
|
builder = Registry(default_chain_spec)
|
2021-03-16 13:53:22 +01:00
|
|
|
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
|
|
|
|
|