Add blockstat, registryconnect tests

This commit is contained in:
nolash 2021-05-27 15:27:38 +02:00
parent ec58ef3414
commit 7ce708196c
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 52 additions and 7 deletions

View File

@ -5,3 +5,4 @@ omit =
cic_eth/db/migrations/*
cic_eth/sync/head.py
cic_eth/sync/mempool.py
*redis*.py

View File

@ -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

View File

@ -20,7 +20,11 @@ def init_chain_stat(rpc, block_start=0):
if block_start == 0:
o = block_latest()
r = rpc.do(o)
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)

View File

@ -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'])

View File

@ -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