Assimilate agnostic rpc in base tests
This commit is contained in:
parent
be3a2e7b2d
commit
6a6b6b59d8
@ -11,5 +11,6 @@ from tests.fixtures_config import *
|
|||||||
from tests.fixtures_celery import *
|
from tests.fixtures_celery import *
|
||||||
from tests.fixtures_database import *
|
from tests.fixtures_database import *
|
||||||
from tests.fixtures_contracts import *
|
from tests.fixtures_contracts import *
|
||||||
|
from tests.fixtures_role import *
|
||||||
from chainlib.eth.pytest import *
|
from chainlib.eth.pytest import *
|
||||||
from cic_registry.pytest import *
|
from contract_registry.pytest import *
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
@ -7,23 +8,48 @@ import pytest
|
|||||||
from eth_accounts_index import AccountRegistry
|
from eth_accounts_index import AccountRegistry
|
||||||
from chainlib.eth.nonce import NodeNonceOracle
|
from chainlib.eth.nonce import NodeNonceOracle
|
||||||
from hexathon import add_0x
|
from hexathon import add_0x
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_registry.registry import Registry
|
from contract_registry.registry import Registry
|
||||||
from cic_registry.encoding import to_identifier
|
from contract_registry.encoding import to_identifier
|
||||||
|
from contract_registry.pytest.fixtures_registry import valid_identifiers
|
||||||
|
|
||||||
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
valid_identifiers += [
|
||||||
|
'AccountRegistry',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def accounts_registry(
|
def account_registry(
|
||||||
registry,
|
registry,
|
||||||
eth_signer,
|
eth_signer,
|
||||||
|
eth_accounts,
|
||||||
eth_rpc,
|
eth_rpc,
|
||||||
accounts,
|
|
||||||
default_chain_spec,
|
default_chain_spec,
|
||||||
default_chain_config,
|
default_chain_config,
|
||||||
|
roles,
|
||||||
):
|
):
|
||||||
|
|
||||||
nonce_oracle = NodeNonceOracle(accounts[0], eth_rpc)
|
nonce_oracle = NodeNonceOracle(roles['CONTRACT_DEPLOYER'], eth_rpc)
|
||||||
c = Registry(signer=eth_rpc.signer, nonce_oracle=nonce_oracle)
|
|
||||||
|
c = AccountRegistry(signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.constructor(roles['CONTRACT_DEPLOYER'])
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
assert r['status'] == 1
|
||||||
|
account_registry_address = r['contract_address']
|
||||||
|
|
||||||
|
(tx_hash_hex, o) = c.add_writer(account_registry_address, roles['CONTRACT_DEPLOYER'], roles['ACCOUNT_REGISTRY_WRITER'])
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
assert r['status'] == 1
|
||||||
|
|
||||||
|
c = Registry(signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
chain_spec_identifier = to_identifier(str(default_chain_spec))
|
chain_spec_identifier = to_identifier(str(default_chain_spec))
|
||||||
|
|
||||||
@ -32,4 +58,12 @@ def accounts_registry(
|
|||||||
h.update(j.encode('utf-8'))
|
h.update(j.encode('utf-8'))
|
||||||
z = h.digest()
|
z = h.digest()
|
||||||
chain_config_digest = add_0x(z.hex())
|
chain_config_digest = add_0x(z.hex())
|
||||||
o = c.set(registry, accounts[0], 'AccountsRegistry', accounts[1], chain_spec_identifier, chain_config_digest)
|
(tx_hash_hex, o) = c.set(registry, roles['CONTRACT_DEPLOYER'], 'AccountRegistry', account_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
|
||||||
|
|
||||||
|
logg.info('accounts registry deployed: {}'.format(account_registry_address))
|
||||||
|
return account_registry_address
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
# external imports
|
|
||||||
import pytest
|
|
||||||
from cic_registry import CICRegistry
|
|
||||||
from chainlib.chain import ChainSpec
|
|
||||||
from eth_accounts_index import AccountRegistry
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
|
||||||
def default_chain_spec():
|
|
||||||
return ChainSpec('evm', 'bloxberg', 8996)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
|
||||||
def accounts_registry(
|
|
||||||
default_chain_spec,
|
|
||||||
cic_registry,
|
|
||||||
):
|
|
||||||
#abi = AccountRegistry.abi()
|
|
||||||
#constructor = w3.eth.contract(abi=abi, bytecode=AccountRegistry.bytecode())
|
|
||||||
#tx_hash = constructor.constructor().transact()
|
|
||||||
r = w3.eth.getTransactionReceipt(tx_hash)
|
|
||||||
logg.debug('accounts registry deployed {}'.format(r.contractAddress))
|
|
||||||
account_registry = AccountRegistry(w3, r.contractAddress)
|
|
||||||
|
|
||||||
c = w3.eth.contract(abi=abi, address=r.contractAddress)
|
|
||||||
c.functions.addWriter(w3.eth.accounts[0]).transact()
|
|
||||||
|
|
||||||
CICRegistry.add_contract(default_chain_spec, c, 'AccountRegistry')
|
|
||||||
|
|
||||||
return account_registry
|
|
@ -2,7 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from chainlib.eth.connection import RPCConnection
|
from chainlib.connection import RPCConnection
|
||||||
from chainlib.eth.gas import (
|
from chainlib.eth.gas import (
|
||||||
balance,
|
balance,
|
||||||
price,
|
price,
|
||||||
@ -19,31 +19,33 @@ logg = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def test_init_eth_tester(
|
def test_init_eth_tester(
|
||||||
accounts,
|
default_chain_spec,
|
||||||
|
eth_accounts,
|
||||||
init_eth_tester,
|
init_eth_tester,
|
||||||
init_rpc,
|
eth_rpc,
|
||||||
):
|
):
|
||||||
|
|
||||||
conn = RPCConnection.connect()
|
conn = RPCConnection.connect(default_chain_spec, 'default')
|
||||||
o = balance(accounts[0])
|
o = balance(eth_accounts[0])
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
|
|
||||||
o = price()
|
o = price()
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
|
|
||||||
o = count_pending(accounts[0])
|
o = count_pending(eth_accounts[0])
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
|
|
||||||
o = count_confirmed(accounts[0])
|
o = count_confirmed(eth_accounts[0])
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
|
|
||||||
|
|
||||||
def test_signer(
|
def test_signer(
|
||||||
|
default_chain_spec,
|
||||||
init_eth_tester,
|
init_eth_tester,
|
||||||
init_rpc,
|
eth_rpc,
|
||||||
accounts,
|
eth_accounts,
|
||||||
):
|
):
|
||||||
|
|
||||||
o = sign_message(accounts[0], '0x2a')
|
o = sign_message(eth_accounts[0], '0x2a')
|
||||||
conn = RPCConnection.connect('signer')
|
conn = RPCConnection.connect(default_chain_spec, 'signer')
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
|
@ -1,4 +1,37 @@
|
|||||||
|
# standard imports
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from chainlib.eth.nonce import NodeNonceOracle
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
from eth_accounts_index import AccountRegistry
|
||||||
|
from contract_registry.registry import (
|
||||||
|
Registry,
|
||||||
|
)
|
||||||
|
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def test_registry(
|
def test_registry(
|
||||||
accounts_registry,
|
eth_rpc,
|
||||||
|
eth_signer,
|
||||||
|
registry,
|
||||||
|
account_registry,
|
||||||
|
roles,
|
||||||
|
eth_empty_accounts,
|
||||||
):
|
):
|
||||||
pass
|
|
||||||
|
nonce_oracle = NodeNonceOracle(roles['DEFAULT'], eth_rpc)
|
||||||
|
c = Registry(signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||||
|
o = c.address_of(registry, 'AccountRegistry', roles['DEFAULT'])
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
r = c.parse_address_of(r)
|
||||||
|
assert account_registry == r
|
||||||
|
|
||||||
|
nonce_oracle = NodeNonceOracle(roles['ACCOUNT_REGISTRY_WRITER'], eth_rpc)
|
||||||
|
c = AccountRegistry(signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.add(account_registry, roles['ACCOUNT_REGISTRY_WRITER'], eth_empty_accounts[0])
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
assert r['status'] == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user