contract-registry

Ethereum Smart Contract key-value registry
Info | Log | Files | Refs

fixtures_registry.py (1950B)


      1 # standard imports
      2 import json
      3 import logging
      4 import hashlib
      5 
      6 # external imports
      7 from hexathon import add_0x
      8 import pytest
      9 from chainlib.connection import RPCConnection
     10 from chainlib.eth.tx import receipt
     11 from chainlib.eth.nonce import RPCNonceOracle
     12 
     13 # local imports
     14 from eth_contract_registry.registry import ContractRegistry
     15 from eth_contract_registry.encoding import to_identifier
     16 
     17 #logg = logging.getLogger(__name__)
     18 logg = logging.getLogger()
     19 
     20 valid_identifiers = [
     21         'ContractRegistry',
     22         ]
     23 
     24 
     25 @pytest.fixture(scope='function')
     26 def roles(
     27     eth_accounts,
     28     ):
     29     return {
     30         'DEFAULT': eth_accounts[0],
     31         'CONTRACT_DEPLOYER': eth_accounts[1],
     32         }
     33 
     34 
     35 @pytest.fixture(scope='function')
     36 def registry(
     37     default_chain_spec,
     38     default_chain_config,
     39     init_eth_tester,
     40     eth_rpc,
     41     eth_accounts,
     42     eth_signer,
     43     roles,
     44         ):
     45   
     46     nonce_oracle = RPCNonceOracle(roles['CONTRACT_DEPLOYER'], eth_rpc)
     47 
     48     builder = ContractRegistry(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
     49     logg.info('registering identifiers {} in contract registry'.format(valid_identifiers))
     50     (tx_hash_hex, o) = builder.constructor(roles['CONTRACT_DEPLOYER'], valid_identifiers)
     51     r = eth_rpc.do(o)
     52     
     53     o = receipt(r)
     54     rcpt = eth_rpc.do(o)
     55     assert rcpt['status'] == 1
     56 
     57     registry_address = rcpt['contract_address'] 
     58 
     59     c = ContractRegistry(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
     60 
     61     chain_spec_identifier = to_identifier(str(default_chain_spec))
     62 
     63     h = hashlib.new('sha256')
     64     j = json.dumps(default_chain_config)
     65     h.update(j.encode('utf-8'))
     66     z = h.digest()
     67     chain_config_digest = add_0x(z.hex())
     68     (tx_hash_hex, o) = c.set(registry_address, roles['CONTRACT_DEPLOYER'], 'ContractRegistry', registry_address)
     69     r = eth_rpc.do(o)
     70     o = receipt(tx_hash_hex)
     71     r = eth_rpc.do(o)
     72     assert r['status'] == 1
     73 
     74     return registry_address