Rehabilitate address translate test
This commit is contained in:
parent
0ab8675d19
commit
431ee11f4f
@ -3,25 +3,36 @@ import logging
|
|||||||
|
|
||||||
# third-party imports
|
# third-party imports
|
||||||
import celery
|
import celery
|
||||||
from cic_registry.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
|
from chainlib.connection import RPCConnection
|
||||||
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
|
from cic_eth_registry import CICRegistry
|
||||||
|
from eth_address_declarator import AddressDeclarator
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.eth import RpcClient
|
from cic_eth.eth import RpcClient
|
||||||
from cic_eth.registry import safe_registry
|
from cic_eth.registry import safe_registry
|
||||||
|
from cic_eth.task import BaseTask
|
||||||
|
|
||||||
celery_app = celery.current_app
|
celery_app = celery.current_app
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def translate_address(address, trusted_addresses, chain_spec):
|
def translate_address(address, trusted_addresses, chain_spec, sender_address=ZERO_ADDRESS):
|
||||||
c = RpcClient(chain_spec)
|
|
||||||
registry = safe_registry(c.w3)
|
rpc = RPCConnection.connect(chain_spec, 'default')
|
||||||
|
registry = CICRegistry(chain_spec, rpc)
|
||||||
|
|
||||||
|
declarator_address = registry.by_name('AddressDeclarator', sender_address=sender_address)
|
||||||
|
c = AddressDeclarator()
|
||||||
|
|
||||||
for trusted_address in trusted_addresses:
|
for trusted_address in trusted_addresses:
|
||||||
o = registry.get_contract(chain_spec, 'AddressDeclarator', 'Declarator')
|
o = c.declaration(declarator_address, trusted_address, address, sender_address=sender_address)
|
||||||
fn = o.function('declaration')
|
r = rpc.do(o)
|
||||||
declaration_hex = fn(trusted_address, address).call()
|
declaration_hex = AddressDeclarator.parse_declaration(r)
|
||||||
declaration_bytes = declaration_hex[0].rstrip(b'\x00')
|
declaration_hex = declaration_hex[0].rstrip('0')
|
||||||
|
declaration_bytes = bytes.fromhex(declaration_hex)
|
||||||
declaration = None
|
declaration = None
|
||||||
try:
|
try:
|
||||||
declaration = declaration_bytes.decode('utf-8', errors='strict')
|
declaration = declaration_bytes.decode('utf-8', errors='strict')
|
||||||
@ -30,19 +41,19 @@ def translate_address(address, trusted_addresses, chain_spec):
|
|||||||
return declaration
|
return declaration
|
||||||
|
|
||||||
|
|
||||||
@celery_app.task()
|
@celery_app.task(bind=True, base=BaseTask)
|
||||||
def translate_tx_addresses(tx, trusted_addresses, chain_str):
|
def translate_tx_addresses(self, tx, trusted_addresses, chain_spec_dict):
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(chain_str)
|
chain_spec = ChainSpec.from_dict(chain_spec_dict)
|
||||||
|
|
||||||
declaration = None
|
declaration = None
|
||||||
if tx['sender_label'] == None:
|
if tx['sender_label'] == None:
|
||||||
declaration = translate_address(tx['sender'], trusted_addresses, chain_spec)
|
declaration = translate_address(tx['sender'], trusted_addresses, chain_spec, self.call_address)
|
||||||
tx['sender_label'] = declaration
|
tx['sender_label'] = declaration
|
||||||
|
|
||||||
declaration = None
|
declaration = None
|
||||||
if tx['recipient_label'] == None:
|
if tx['recipient_label'] == None:
|
||||||
declaration = translate_address(tx['recipient'], trusted_addresses, chain_spec)
|
declaration = translate_address(tx['recipient'], trusted_addresses, chain_spec, self.call_address)
|
||||||
tx['recipient_label'] = declaration
|
tx['recipient_label'] = declaration
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
|
@ -1,16 +1,28 @@
|
|||||||
# third-party imports
|
# external imports
|
||||||
import pytest
|
import pytest
|
||||||
import tempfile
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
# local impors
|
||||||
|
from cic_eth.task import BaseTask
|
||||||
|
|
||||||
#logg = logging.getLogger(__name__)
|
#logg = logging.getLogger(__name__)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def init_celery_tasks(
|
||||||
|
contract_roles,
|
||||||
|
):
|
||||||
|
BaseTask.call_address = contract_roles['DEFAULT']
|
||||||
|
|
||||||
|
|
||||||
# celery fixtures
|
# celery fixtures
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def celery_includes():
|
def celery_includes(
|
||||||
|
contract_roles,
|
||||||
|
):
|
||||||
return [
|
return [
|
||||||
# 'cic_eth.eth.bancor',
|
# 'cic_eth.eth.bancor',
|
||||||
'cic_eth.eth.erc20',
|
'cic_eth.eth.erc20',
|
||||||
|
@ -29,7 +29,7 @@ def test_list_tx(
|
|||||||
foo_token,
|
foo_token,
|
||||||
register_tokens,
|
register_tokens,
|
||||||
init_eth_tester,
|
init_eth_tester,
|
||||||
celery_worker,
|
celery_session_worker,
|
||||||
):
|
):
|
||||||
|
|
||||||
chain_id = default_chain_spec.chain_id()
|
chain_id = default_chain_spec.chain_id()
|
||||||
|
@ -69,7 +69,7 @@ def test_register_account(
|
|||||||
eth_empty_accounts,
|
eth_empty_accounts,
|
||||||
custodial_roles,
|
custodial_roles,
|
||||||
call_sender,
|
call_sender,
|
||||||
celery_worker,
|
celery_session_worker,
|
||||||
):
|
):
|
||||||
|
|
||||||
s_nonce = celery.signature(
|
s_nonce = celery.signature(
|
||||||
@ -123,9 +123,9 @@ def test_register_account(
|
|||||||
|
|
||||||
@pytest.mark.skip()
|
@pytest.mark.skip()
|
||||||
def test_role_task(
|
def test_role_task(
|
||||||
|
default_chain_spec,
|
||||||
init_database,
|
init_database,
|
||||||
celery_session_worker,
|
celery_session_worker,
|
||||||
default_chain_spec,
|
|
||||||
):
|
):
|
||||||
|
|
||||||
address = '0x' + os.urandom(20).hex()
|
address = '0x' + os.urandom(20).hex()
|
||||||
|
Loading…
Reference in New Issue
Block a user