diff --git a/apps/cic-eth/.coveragerc b/apps/cic-eth/.coveragerc index 63f983d6..377171da 100644 --- a/apps/cic-eth/.coveragerc +++ b/apps/cic-eth/.coveragerc @@ -5,3 +5,4 @@ omit = cic_eth/db/migrations/* cic_eth/sync/head.py cic_eth/sync/mempool.py + *redis*.py diff --git a/apps/cic-eth/cic_eth/registry.py b/apps/cic-eth/cic_eth/registry.py index 2b5e2b94..b46b2008 100644 --- a/apps/cic-eth/cic_eth/registry.py +++ b/apps/cic-eth/cic_eth/registry.py @@ -5,29 +5,30 @@ import logging from cic_eth_registry import CICRegistry from cic_eth_registry.lookup.declarator import AddressDeclaratorLookup from cic_eth_registry.lookup.tokenindex import TokenIndexLookup +from chainlib.eth.constant import ZERO_ADDRESS logg = logging.getLogger() -def connect_token_registry(rpc, chain_spec): +def connect_token_registry(rpc, chain_spec, sender_address=ZERO_ADDRESS): registry = CICRegistry(chain_spec, rpc) - token_registry_address = registry.by_name('TokenRegistry') + token_registry_address = registry.by_name('TokenRegistry', sender_address=sender_address) logg.debug('using token registry address {}'.format(token_registry_address)) lookup = TokenIndexLookup(chain_spec, token_registry_address) CICRegistry.add_lookup(lookup) -def connect_declarator(rpc, chain_spec, trusted_addresses): +def connect_declarator(rpc, chain_spec, trusted_addresses, sender_address=ZERO_ADDRESS): registry = CICRegistry(chain_spec, rpc) - declarator_address = registry.by_name('AddressDeclarator') + declarator_address = registry.by_name('AddressDeclarator', sender_address=sender_address) logg.debug('using declarator address {}'.format(declarator_address)) lookup = AddressDeclaratorLookup(chain_spec, declarator_address, trusted_addresses) CICRegistry.add_lookup(lookup) -def connect(rpc, chain_spec, registry_address): +def connect(rpc, chain_spec, registry_address, sender_address=ZERO_ADDRESS): CICRegistry.address = registry_address registry = CICRegistry(chain_spec, rpc) - registry_address = registry.by_name('ContractRegistry') + registry_address = registry.by_name('ContractRegistry', sender_address=sender_address) return registry diff --git a/apps/cic-eth/cic_eth/stat.py b/apps/cic-eth/cic_eth/stat.py index d3a07fdb..e674e120 100644 --- a/apps/cic-eth/cic_eth/stat.py +++ b/apps/cic-eth/cic_eth/stat.py @@ -20,7 +20,11 @@ def init_chain_stat(rpc, block_start=0): if block_start == 0: o = block_latest() r = rpc.do(o) - block_start = int(r, 16) + try: + block_start = int(r, 16) + except TypeError: + block_start = int(r) + logg.debug('blockstart {}'.format(block_start)) for i in range(BLOCK_SAMPLES): o = block_by_number(block_start-10+i) diff --git a/apps/cic-eth/tests/unit/test_registry_connect.py b/apps/cic-eth/tests/unit/test_registry_connect.py new file mode 100644 index 00000000..baf23375 --- /dev/null +++ b/apps/cic-eth/tests/unit/test_registry_connect.py @@ -0,0 +1,21 @@ +# local imports +from cic_eth.registry import * + +def test_registry_connect( + eth_rpc, + default_chain_spec, + address_declarator, + token_registry, + contract_roles, + registry, + agent_roles, + ): + + r = connect(eth_rpc, default_chain_spec, registry, sender_address=contract_roles['CONTRACT_DEPLOYER']) + + connect_declarator(eth_rpc, default_chain_spec, [agent_roles['ALICE']], sender_address=contract_roles['CONTRACT_DEPLOYER']) + r.by_name('AddressDeclarator', sender_address=contract_roles['CONTRACT_DEPLOYER']) + + connect_token_registry(eth_rpc, default_chain_spec, sender_address=contract_roles['CONTRACT_DEPLOYER']) + r.by_name('TokenRegistry', sender_address=contract_roles['CONTRACT_DEPLOYER']) + diff --git a/apps/cic-eth/tests/unit/test_stat.py b/apps/cic-eth/tests/unit/test_stat.py new file mode 100644 index 00000000..5da49fdc --- /dev/null +++ b/apps/cic-eth/tests/unit/test_stat.py @@ -0,0 +1,18 @@ +# standard imports +import datetime + +# local imports +from cic_eth.stat import init_chain_stat + + +def test_chain_stat( + eth_rpc, + init_eth_tester, + ): + + now = int(datetime.datetime.now().timestamp()) + 1 + for i in range(11): + init_eth_tester.time_travel(now + (i * 2)) + + s = init_chain_stat(eth_rpc, block_start=0) + assert s.block_average() == 2