eth-contract-registry/python/eth_contract_registry/pytest/fixtures_registry.py

75 lines
1.9 KiB
Python
Raw Permalink Normal View History

# standard imports
import json
import logging
import hashlib
# external imports
from hexathon import add_0x
import pytest
2021-03-16 15:07:12 +01:00
from chainlib.connection import RPCConnection
from chainlib.eth.tx import receipt
2021-03-17 11:23:24 +01:00
from chainlib.eth.nonce import RPCNonceOracle
# local imports
2021-04-30 13:11:22 +02:00
from eth_contract_registry.registry import ContractRegistry
2021-03-25 19:16:36 +01:00
from eth_contract_registry.encoding import to_identifier
2021-03-21 14:02:39 +01:00
#logg = logging.getLogger(__name__)
logg = logging.getLogger()
valid_identifiers = [
'ContractRegistry',
]
@pytest.fixture(scope='function')
def roles(
eth_accounts,
):
return {
2021-03-21 14:02:39 +01:00
'DEFAULT': eth_accounts[0],
'CONTRACT_DEPLOYER': eth_accounts[1],
}
2021-03-21 14:02:39 +01:00
@pytest.fixture(scope='function')
def registry(
2021-03-16 15:07:12 +01:00
default_chain_spec,
default_chain_config,
init_eth_tester,
eth_rpc,
eth_accounts,
eth_signer,
roles,
):
2021-03-17 11:23:24 +01: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-21 14:02:39 +01:00
logg.info('registering identifiers {} in contract registry'.format(valid_identifiers))
(tx_hash_hex, o) = builder.constructor(roles['CONTRACT_DEPLOYER'], valid_identifiers)
r = eth_rpc.do(o)
o = receipt(r)
rcpt = eth_rpc.do(o)
assert rcpt['status'] == 1
registry_address = rcpt['contract_address']
2021-04-30 13:11:22 +02:00
c = ContractRegistry(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
chain_spec_identifier = to_identifier(str(default_chain_spec))
h = hashlib.new('sha256')
j = json.dumps(default_chain_config)
h.update(j.encode('utf-8'))
z = h.digest()
chain_config_digest = add_0x(z.hex())
(tx_hash_hex, o) = c.set(registry_address, roles['CONTRACT_DEPLOYER'], 'ContractRegistry', registry_address)
r = eth_rpc.do(o)
o = receipt(tx_hash_hex)
r = eth_rpc.do(o)
assert r['status'] == 1
return registry_address