mirror of
git://holbrook.no/eth-contract-registry
synced 2024-12-22 20:27:32 +01:00
Add test role, register registry to registry
This commit is contained in:
parent
19de2bface
commit
2b3575f5a3
@ -1,13 +1,18 @@
|
||||
# standard imports
|
||||
import json
|
||||
import logging
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from hexathon import add_0x
|
||||
import pytest
|
||||
from chainlib.connection import RPCConnection
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.nonce import NodeNonceOracle
|
||||
|
||||
# local imports
|
||||
from contract_registry.registry import Registry
|
||||
from contract_registry.encoding import to_identifier
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
@ -15,23 +20,53 @@ valid_identifiers = [
|
||||
'ContractRegistry',
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def roles(
|
||||
eth_accounts,
|
||||
):
|
||||
return {
|
||||
'CONTRACT_DEPLOYER': eth_accounts[0],
|
||||
}
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def registry(
|
||||
default_chain_spec,
|
||||
default_chain_config,
|
||||
init_eth_tester,
|
||||
init_eth_rpc,
|
||||
eth_rpc,
|
||||
eth_accounts,
|
||||
eth_signer,
|
||||
roles,
|
||||
):
|
||||
|
||||
conn = RPCConnection.connect(default_chain_spec, 'default')
|
||||
builder = Registry(signer=conn.signer)
|
||||
(tx_hash_hex, o) = builder.constructor(eth_accounts[0], valid_identifiers)
|
||||
r = conn.do(o)
|
||||
nonce_oracle = NodeNonceOracle(roles['CONTRACT_DEPLOYER'], eth_rpc)
|
||||
|
||||
builder = Registry(signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = builder.constructor(roles['CONTRACT_DEPLOYER'], valid_identifiers)
|
||||
r = eth_rpc.do(o)
|
||||
logg.debug('r {}'.format(r))
|
||||
|
||||
o = receipt(r)
|
||||
rcpt = conn.do(o)
|
||||
rcpt = eth_rpc.do(o)
|
||||
|
||||
assert rcpt['status'] == 1
|
||||
return rcpt['contract_address']
|
||||
|
||||
registry_address = rcpt['contract_address']
|
||||
|
||||
c = Registry(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, chain_spec_identifier, chain_config_digest)
|
||||
r = eth_rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = eth_rpc.do(o)
|
||||
assert r['status'] == 1
|
||||
|
||||
return registry_address
|
||||
|
Loading…
Reference in New Issue
Block a user