WIP rehabilitate register account test and task

This commit is contained in:
nolash 2021-03-16 17:16:06 +01:00
parent 6a6b6b59d8
commit 318615751c
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 37 additions and 144 deletions

View File

@ -5,9 +5,9 @@ import logging
import celery import celery
from cic_registry.chain import ChainSpec from cic_registry.chain import ChainSpec
from erc20_single_shot_faucet import Faucet from erc20_single_shot_faucet import Faucet
from cic_registry import zero_address from chainlib.eth.constant import ZERO_ADDRESS
from hexathon import strip_0x from hexathon import strip_0x
from chainlib.eth.connection import RPCConnection from chainlib.connection import RPCConnection
from chainlib.eth.sign import ( from chainlib.eth.sign import (
new_account, new_account,
sign_message, sign_message,
@ -167,7 +167,7 @@ def create(self, password, chain_str):
chain_spec = ChainSpec.from_chain_str(chain_str) chain_spec = ChainSpec.from_chain_str(chain_str)
#c = RpcClient(chain_spec) #c = RpcClient(chain_spec)
a = None a = None
conn = RPCConnection.connect('signer') conn = RPCConnection.connect(chain_spec, 'signer')
o = new_account() o = new_account()
a = conn.do(o) a = conn.do(o)
@ -207,22 +207,22 @@ def register(self, account_address, chain_str, writer_address=None):
session = self.create_session() session = self.create_session()
#session = SessionBase.create_session() #session = SessionBase.create_session()
if writer_address == None: if writer_address == None:
writer_address = AccountRole.get_address('ACCOUNTS_INDEX_WRITER', session=session) writer_address = AccountRole.get_address('ACCOUNT_REGISTRY_WRITER', session=session)
if writer_address == zero_address: if writer_address == ZERO_ADDRESS:
session.close() session.close()
raise RoleMissingError(account_address) raise RoleMissingError(account_address)
logg.debug('adding account address {} to index; writer {}'.format(account_address, writer_address)) logg.debug('adding account address {} to index; writer {}'.format(account_address, writer_address))
queue = self.request.delivery_info['routing_key'] queue = self.request.delivery_info['routing_key']
c = RpcClient(chain_spec, holder_address=writer_address) # c = RpcClient(chain_spec, holder_address=writer_address)
registry = safe_registry(c.w3) # registry = safe_registry(c.w3)
txf = AccountTxFactory(writer_address, c, registry=registry) # txf = AccountTxFactory(writer_address, c, registry=registry)
# tx_add = txf.add(account_address, chain_spec, self.request.root_id, session=session)
# (tx_hash_hex, tx_signed_raw_hex) = sign_and_register_tx(tx_add, chain_str, queue, 'cic_eth.eth.account.cache_account_data', session=session)
tx_add = txf.add(account_address, chain_spec, self.request.root_id, session=session)
(tx_hash_hex, tx_signed_raw_hex) = sign_and_register_tx(tx_add, chain_str, queue, 'cic_eth.eth.account.cache_account_data', session=session)
session.commit() session.commit()
session.close() session.close()
@ -294,9 +294,10 @@ def have(self, account, chain_str):
:returns: Account, or None if not exists :returns: Account, or None if not exists
:rtype: Varies :rtype: Varies
""" """
chain_spec = ChainSpec.from_chain_str(chain_str)
o = sign_message(account, '0x2a') o = sign_message(account, '0x2a')
try: try:
conn = RPCConnection.connect('signer') conn = RPCConnection.connect(chain_spec, 'signer')
conn.do(o) conn.do(o)
return account return account
except Exception as e: except Exception as e:
@ -353,8 +354,8 @@ def cache_gift_data(
tx_hash_hex, tx_hash_hex,
tx['from'], tx['from'],
tx['to'], tx['to'],
zero_address, ZERO_ADDRESS,
zero_address, ZERO_ADDRESS,
0, 0,
0, 0,
session=session, session=session,
@ -398,8 +399,8 @@ def cache_account_data(
tx_hash_hex, tx_hash_hex,
tx['from'], tx['from'],
tx['to'], tx['to'],
zero_address, ZERO_ADDRESS,
zero_address, ZERO_ADDRESS,
0, 0,
0, 0,
session=session, session=session,

View File

@ -4,9 +4,9 @@ import logging
# external imports # external imports
import sha3 import sha3
import celery import celery
from cic_registry.chain import ChainSpec from chainlib.chain import ChainSpec
from chainlib.eth.sign import sign_transaction from chainlib.eth.sign import sign_transaction
from chainlib.eth.connection import RPCConnection from chainlib.connection import RPCConnection
from hexathon import ( from hexathon import (
strip_0x, strip_0x,
add_0x, add_0x,

View File

@ -10,7 +10,7 @@ sys.path.insert(0, root_dir)
from tests.fixtures_config import * 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_role import * from tests.fixtures_role import *
from chainlib.eth.pytest import * from chainlib.eth.pytest import *
from contract_registry.pytest import * from contract_registry.pytest import *
from cic_eth_registry.pytest.fixtures_contracts import *

View File

@ -1,69 +0,0 @@
# standard imports
import logging
import json
import hashlib
# external imports
import pytest
from eth_accounts_index import AccountRegistry
from chainlib.eth.nonce import NodeNonceOracle
from hexathon import add_0x
from chainlib.eth.tx import receipt
# local imports
from contract_registry.registry import Registry
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')
def account_registry(
registry,
eth_signer,
eth_accounts,
eth_rpc,
default_chain_spec,
default_chain_config,
roles,
):
nonce_oracle = NodeNonceOracle(roles['CONTRACT_DEPLOYER'], eth_rpc)
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))
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, 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

View File

@ -6,9 +6,7 @@ import time
# third-party imports # third-party imports
import pytest import pytest
import celery import celery
from chainlib.eth.connection import RPCConnection from chainlib.connection import RPCConnection
import logging_tree
from eth_keys import KeyAPI
# local imports # local imports
from cic_eth.error import OutOfGasError from cic_eth.error import OutOfGasError
@ -25,7 +23,7 @@ logg = logging.getLogger()
def test_create_account( def test_create_account(
default_chain_spec, default_chain_spec,
init_rpc, eth_rpc,
init_database, init_database,
celery_session_worker, celery_session_worker,
caplog, caplog,
@ -60,13 +58,13 @@ def test_create_account(
def test_register_account( def test_register_account(
default_chain_spec, default_chain_spec,
accounts_registry, account_registry,
init_database, init_database,
accounts, eth_accounts,
rpc, eth_rpc,
cic_registry, registry,
celery_session_worker, celery_session_worker,
empty_accounts, eth_empty_accounts,
): ):
logg.debug('chainspec {}'.format(str(default_chain_spec))) logg.debug('chainspec {}'.format(str(default_chain_spec)))
@ -74,8 +72,8 @@ def test_register_account(
s_nonce = celery.signature( s_nonce = celery.signature(
'cic_eth.eth.tx.reserve_nonce', 'cic_eth.eth.tx.reserve_nonce',
[ [
empty_accounts[0], eth_empty_accounts[0],
accounts[0], eth_accounts[0],
], ],
queue=None, queue=None,
) )
@ -83,7 +81,7 @@ def test_register_account(
'cic_eth.eth.account.register', 'cic_eth.eth.account.register',
[ [
str(default_chain_spec), str(default_chain_spec),
init_w3.eth.accounts[0], eth_accounts[0],
], ],
) )
s_nonce.link(s_register) s_nonce.link(s_register)
@ -112,7 +110,7 @@ def test_register_account(
init_eth_tester.mine_block() init_eth_tester.mine_block()
assert accounts_registry.have(eth_empty_accounts[0]) assert account_registry.have(eth_empty_accounts[0])
def test_role_task( def test_role_task(

View File

@ -1,37 +0,0 @@
# 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(
eth_rpc,
eth_signer,
registry,
account_registry,
roles,
eth_empty_accounts,
):
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

View File

@ -55,9 +55,9 @@ cic-eth-tag TRANSFER_AUTHORIZATION_OWNER $DEV_ETH_ACCOUNT_TRANSFER_AUTHORIZATION
#cic-eth-tag FAUCET_GIFTER $DEV_ETH_ACCOUNT_FAUCET_OWNER #cic-eth-tag FAUCET_GIFTER $DEV_ETH_ACCOUNT_FAUCET_OWNER
>&2 echo "create account for accounts index writer" >&2 echo "create account for accounts index writer"
DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=`cic-eth-create $debug --redis-host-callback=$REDIS_HOST --redis-port-callback=$REDIS_PORT --no-register` DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER=`cic-eth-create $debug --redis-host-callback=$REDIS_HOST --redis-port-callback=$REDIS_PORT --no-register`
echo DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=$DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER >> $env_out_file echo DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER=$DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER >> $env_out_file
cic-eth-tag ACCOUNTS_INDEX_WRITER $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER cic-eth-tag ACCOUNT_REGISTRY_WRITER $DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER
# Transfer gas to custodial gas provider adddress # Transfer gas to custodial gas provider adddress
@ -68,7 +68,7 @@ cic-eth-tag ACCOUNTS_INDEX_WRITER $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER
>&2 eth-gas -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_SARAFU_GIFTER $gas_amount >&2 eth-gas -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_SARAFU_GIFTER $gas_amount
>&2 echo gift gas to account index owner >&2 echo gift gas to account index owner
>&2 eth-gas -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER $gas_amount >&2 eth-gas -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER $gas_amount
# Send token to token creator # Send token to token creator
>&2 echo "gift tokens to sarafu owner" >&2 echo "gift tokens to sarafu owner"
@ -100,7 +100,7 @@ export CIC_TRANSFER_AUTHORIZATION_ADDRESS=$CIC_TRANSFER_AUTHORIZATION_ADDRESS
# Deploy one-time token faucet for newly created token # Deploy one-time token faucet for newly created token
>&2 echo "deploy faucet" >&2 echo "deploy faucet"
DEV_ETH_SARAFU_FAUCET_ADDRESS=`sarafu-faucet-deploy -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --token-address $DEV_ETH_SARAFU_TOKEN_ADDRESS --editor $DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER --set-amount $faucet_amount --accounts-index-address $DEV_ETH_ACCOUNTS_INDEX_ADDRESS -w $debug` DEV_ETH_SARAFU_FAUCET_ADDRESS=`sarafu-faucet-deploy -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --token-address $DEV_ETH_SARAFU_TOKEN_ADDRESS --editor $DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER --set-amount $faucet_amount --accounts-index-address $DEV_ETH_ACCOUNT_REGISTRY_ADDRESS -w $debug`
echo DEV_ETH_SARAFU_FAUCET_ADDRESS=$DEV_ETH_SARAFU_FAUCET_ADDRESS >> $env_out_file echo DEV_ETH_SARAFU_FAUCET_ADDRESS=$DEV_ETH_SARAFU_FAUCET_ADDRESS >> $env_out_file
export DEV_ETH_SARAFU_FAUCET_ADDRESS=$DEV_ETH_SARAFU_FAUCET_ADDRESS export DEV_ETH_SARAFU_FAUCET_ADDRESS=$DEV_ETH_SARAFU_FAUCET_ADDRESS
@ -143,7 +143,7 @@ token_description_two=0x54686973206973207468652053617261667520746f6b656e00000000
# Add accounts index writer with key from keystore # Add accounts index writer with key from keystore
>&2 echo "add keystore account $keystore_file to accounts index writers" >&2 echo "add keystore account $keystore_file to accounts index writers"
>&2 eth-accounts-index-add -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -r $CIC_ACCOUNTS_INDEX_ADDRESS --writer $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER -w $debug >&2 eth-accounts-index-add -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -r $CIC_ACCOUNT_REGISTRY_ADDRESS --writer $DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER -w $debug
echo -n 0 > $init_level_file echo -n 0 > $init_level_file