Add test branch for tx data with registry in admin api

This commit is contained in:
nolash 2021-05-31 11:29:04 +02:00
parent a5608fcd98
commit b88c290683
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 472 additions and 398 deletions

View File

@ -8,6 +8,7 @@ from chainlib.eth.constant import (
ZERO_ADDRESS, ZERO_ADDRESS,
) )
from cic_eth_registry import CICRegistry from cic_eth_registry import CICRegistry
from cic_eth_registry.erc20 import ERC20Token
from cic_eth_registry.error import UnknownContractError from cic_eth_registry.error import UnknownContractError
from chainlib.eth.address import to_checksum_address from chainlib.eth.address import to_checksum_address
from chainlib.eth.contract import code from chainlib.eth.contract import code
@ -31,6 +32,7 @@ from chainqueue.db.enum import (
) )
from chainqueue.error import TxStateChangeError from chainqueue.error import TxStateChangeError
from chainqueue.query import get_tx from chainqueue.query import get_tx
from eth_erc20 import ERC20
# local imports # local imports
from cic_eth.db.models.base import SessionBase from cic_eth.db.models.base import SessionBase
@ -397,9 +399,10 @@ class AdminApi:
source_token = None source_token = None
if tx['source_token'] != ZERO_ADDRESS: if tx['source_token'] != ZERO_ADDRESS:
source_token_declaration = None
if registry != None: if registry != None:
try: try:
source_token = registry.by_address(tx['source_token']) source_token_declaration = registry.by_address(tx['source_token'], sender_address=self.call_address)
except UnknownContractError: except UnknownContractError:
logg.warning('unknown source token contract {} (direct)'.format(tx['source_token'])) logg.warning('unknown source token contract {} (direct)'.format(tx['source_token']))
else: else:
@ -412,16 +415,21 @@ class AdminApi:
queue=self.queue queue=self.queue
) )
t = s.apply_async() t = s.apply_async()
source_token = t.get() source_token_declaration = t.get()
if source_token == None:
logg.warning('unknown source token contract {} (task pool)'.format(tx['source_token'])) if source_token_declaration != None:
logg.warning('found declarator record for source token {} but not checking validity'.format(tx['source_token']))
source_token = ERC20Token(chain_spec, self.rpc, tx['source_token'])
logg.debug('source token set tup {}'.format(source_token))
destination_token = None destination_token = None
if tx['destination_token'] != ZERO_ADDRESS: if tx['destination_token'] != ZERO_ADDRESS:
destination_token_declaration = None
if registry != None: if registry != None:
try: try:
destination_token = registry.by_address(tx['destination_token']) destination_token_declaration = registry.by_address(tx['destination_token'], sender_address=self.call_address)
except UnknownContractError: except UnknownContractError:
logg.warning('unknown destination token contract {}'.format(tx['destination_token'])) logg.warning('unknown destination token contract {}'.format(tx['destination_token']))
else: else:
@ -434,10 +442,10 @@ class AdminApi:
queue=self.queue queue=self.queue
) )
t = s.apply_async() t = s.apply_async()
destination_token = t.get() destination_token_declaration = t.get()
if destination_token == None: if destination_token_declaration != None:
logg.warning('unknown destination token contract {} (task pool)'.format(tx['destination_token'])) logg.warning('found declarator record for destination token {} but not checking validity'.format(tx['destination_token']))
destination_token = ERC20Token(chain_spec, self.rpc, tx['destination_token'])
tx['sender_description'] = 'Custodial account' tx['sender_description'] = 'Custodial account'
tx['recipient_description'] = 'Custodial account' tx['recipient_description'] = 'Custodial account'
@ -549,13 +557,19 @@ class AdminApi:
if role != None: if role != None:
tx['recipient_description'] = role tx['recipient_description'] = role
erc20_c = ERC20(chain_spec)
if source_token != None: if source_token != None:
tx['source_token_symbol'] = source_token.symbol() tx['source_token_symbol'] = source_token.symbol
tx['sender_token_balance'] = source_token.function('balanceOf')(tx['sender']).call() o = erc20_c.balance_of(tx['source_token'], tx['sender'], sender_address=self.call_address)
r = self.rpc.do(o)
tx['sender_token_balance'] = erc20_c.parse_balance_of(r)
if destination_token != None: if destination_token != None:
tx['destination_token_symbol'] = destination_token.symbol() tx['destination_token_symbol'] = destination_token.symbol
tx['recipient_token_balance'] = source_token.function('balanceOf')(tx['recipient']).call() o = erc20_c.balance_of(tx['destination_token'], tx['recipient'], sender_address=self.call_address)
r = self.rpc.do(o)
tx['recipient_token_balance'] = erc20_c.parse_balance_of(r)
#tx['recipient_token_balance'] = destination_token.function('balanceOf')(tx['recipient']).call()
# TODO: this can mean either not subitted or culled, need to check other txs with same nonce to determine which # TODO: this can mean either not subitted or culled, need to check other txs with same nonce to determine which
tx['network_status'] = 'Not in node' tx['network_status'] = 'Not in node'

View File

@ -74,134 +74,134 @@ class Api:
return s_token.apply_async() return s_token.apply_async()
def convert_transfer(self, from_address, to_address, target_return, minimum_return, from_token_symbol, to_token_symbol): # def convert_transfer(self, from_address, to_address, target_return, minimum_return, from_token_symbol, to_token_symbol):
"""Executes a chain of celery tasks that performs conversion between two ERC20 tokens, and transfers to a specified receipient after convert has completed. # """Executes a chain of celery tasks that performs conversion between two ERC20 tokens, and transfers to a specified receipient after convert has completed.
#
:param from_address: Ethereum address of sender # :param from_address: Ethereum address of sender
:type from_address: str, 0x-hex # :type from_address: str, 0x-hex
:param to_address: Ethereum address of receipient # :param to_address: Ethereum address of receipient
:type to_address: str, 0x-hex # :type to_address: str, 0x-hex
:param target_return: Estimated return from conversion # :param target_return: Estimated return from conversion
:type target_return: int # :type target_return: int
:param minimum_return: The least value of destination token return to allow # :param minimum_return: The least value of destination token return to allow
:type minimum_return: int # :type minimum_return: int
:param from_token_symbol: ERC20 token symbol of token being converted # :param from_token_symbol: ERC20 token symbol of token being converted
:type from_token_symbol: str # :type from_token_symbol: str
:param to_token_symbol: ERC20 token symbol of token to receive # :param to_token_symbol: ERC20 token symbol of token to receive
:type to_token_symbol: str # :type to_token_symbol: str
:returns: uuid of root task # :returns: uuid of root task
:rtype: celery.Task # :rtype: celery.Task
""" # """
raise NotImplementedError('out of service until new DEX migration is done') # raise NotImplementedError('out of service until new DEX migration is done')
s_check = celery.signature( # s_check = celery.signature(
'cic_eth.admin.ctrl.check_lock', # 'cic_eth.admin.ctrl.check_lock',
[ # [
[from_token_symbol, to_token_symbol], # [from_token_symbol, to_token_symbol],
self.chain_spec.asdict(), # self.chain_spec.asdict(),
LockEnum.QUEUE, # LockEnum.QUEUE,
from_address, # from_address,
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_nonce = celery.signature( # s_nonce = celery.signature(
'cic_eth.eth.nonce.reserve_nonce', # 'cic_eth.eth.nonce.reserve_nonce',
[ # [
self.chain_spec.asdict(), # self.chain_spec.asdict(),
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_tokens = celery.signature( # s_tokens = celery.signature(
'cic_eth.eth.erc20.resolve_tokens_by_symbol', # 'cic_eth.eth.erc20.resolve_tokens_by_symbol',
[ # [
self.chain_str, # self.chain_str,
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_convert = celery.signature( # s_convert = celery.signature(
'cic_eth.eth.bancor.convert_with_default_reserve', # 'cic_eth.eth.bancor.convert_with_default_reserve',
[ # [
from_address, # from_address,
target_return, # target_return,
minimum_return, # minimum_return,
to_address, # to_address,
self.chain_spec.asdict(), # self.chain_spec.asdict(),
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_nonce.link(s_tokens) # s_nonce.link(s_tokens)
s_check.link(s_nonce) # s_check.link(s_nonce)
if self.callback_param != None: # if self.callback_param != None:
s_convert.link(self.callback_success) # s_convert.link(self.callback_success)
s_tokens.link(s_convert).on_error(self.callback_error) # s_tokens.link(s_convert).on_error(self.callback_error)
else: # else:
s_tokens.link(s_convert) # s_tokens.link(s_convert)
#
t = s_check.apply_async(queue=self.queue) # t = s_check.apply_async(queue=self.queue)
return t # return t
#
#
def convert(self, from_address, target_return, minimum_return, from_token_symbol, to_token_symbol): # def convert(self, from_address, target_return, minimum_return, from_token_symbol, to_token_symbol):
"""Executes a chain of celery tasks that performs conversion between two ERC20 tokens. # """Executes a chain of celery tasks that performs conversion between two ERC20 tokens.
#
:param from_address: Ethereum address of sender # :param from_address: Ethereum address of sender
:type from_address: str, 0x-hex # :type from_address: str, 0x-hex
:param target_return: Estimated return from conversion # :param target_return: Estimated return from conversion
:type target_return: int # :type target_return: int
:param minimum_return: The least value of destination token return to allow # :param minimum_return: The least value of destination token return to allow
:type minimum_return: int # :type minimum_return: int
:param from_token_symbol: ERC20 token symbol of token being converted # :param from_token_symbol: ERC20 token symbol of token being converted
:type from_token_symbol: str # :type from_token_symbol: str
:param to_token_symbol: ERC20 token symbol of token to receive # :param to_token_symbol: ERC20 token symbol of token to receive
:type to_token_symbol: str # :type to_token_symbol: str
:returns: uuid of root task # :returns: uuid of root task
:rtype: celery.Task # :rtype: celery.Task
""" # """
raise NotImplementedError('out of service until new DEX migration is done') # raise NotImplementedError('out of service until new DEX migration is done')
s_check = celery.signature( # s_check = celery.signature(
'cic_eth.admin.ctrl.check_lock', # 'cic_eth.admin.ctrl.check_lock',
[ # [
[from_token_symbol, to_token_symbol], # [from_token_symbol, to_token_symbol],
self.chain_spec.asdict(), # self.chain_spec.asdict(),
LockEnum.QUEUE, # LockEnum.QUEUE,
from_address, # from_address,
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_nonce = celery.signature( # s_nonce = celery.signature(
'cic_eth.eth.nonce.reserve_nonce', # 'cic_eth.eth.nonce.reserve_nonce',
[ # [
self.chain_spec.asdict(), # self.chain_spec.asdict(),
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_tokens = celery.signature( # s_tokens = celery.signature(
'cic_eth.eth.erc20.resolve_tokens_by_symbol', # 'cic_eth.eth.erc20.resolve_tokens_by_symbol',
[ # [
self.chain_spec.asdict(), # self.chain_spec.asdict(),
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_convert = celery.signature( # s_convert = celery.signature(
'cic_eth.eth.bancor.convert_with_default_reserve', # 'cic_eth.eth.bancor.convert_with_default_reserve',
[ # [
from_address, # from_address,
target_return, # target_return,
minimum_return, # minimum_return,
from_address, # from_address,
self.chain_spec.asdict(), # self.chain_spec.asdict(),
], # ],
queue=self.queue, # queue=self.queue,
) # )
s_nonce.link(s_tokens) # s_nonce.link(s_tokens)
s_check.link(s_nonce) # s_check.link(s_nonce)
if self.callback_param != None: # if self.callback_param != None:
s_convert.link(self.callback_success) # s_convert.link(self.callback_success)
s_tokens.link(s_convert).on_error(self.callback_error) # s_tokens.link(s_convert).on_error(self.callback_error)
else: # else:
s_tokens.link(s_convert) # s_tokens.link(s_convert)
#
t = s_check.apply_async(queue=self.queue) # t = s_check.apply_async(queue=self.queue)
return t # return t
def transfer(self, from_address, to_address, value, token_symbol): def transfer(self, from_address, to_address, value, token_symbol):

View File

@ -32,10 +32,12 @@ from chainqueue.db.models.otx import Otx
from chainqueue.db.enum import StatusBits from chainqueue.db.enum import StatusBits
from chainqueue.query import get_nonce_tx_cache from chainqueue.query import get_nonce_tx_cache
from eth_erc20 import ERC20 from eth_erc20 import ERC20
from cic_eth_registry import CICRegistry
# local imports # local imports
from cic_eth.api.api_admin import AdminApi from cic_eth.api.api_admin import AdminApi
from cic_eth.eth.gas import cache_gas_data from cic_eth.eth.gas import cache_gas_data
from cic_eth.eth.erc20 import cache_transfer_data
logg = logging.getLogger() logg = logging.getLogger()
@ -49,7 +51,7 @@ def test_admin_api_tx(
agent_roles, agent_roles,
contract_roles, contract_roles,
custodial_roles, custodial_roles,
celery_session_worker, celery_worker,
foo_token, foo_token,
address_declarator, address_declarator,
cic_registry, cic_registry,
@ -76,7 +78,7 @@ def test_admin_api_tx(
tx_signed_raw_hex, tx_signed_raw_hex,
session=init_database, session=init_database,
) )
cache_gas_data( cache_transfer_data(
tx_hash_hex, tx_hash_hex,
tx_signed_raw_hex, tx_signed_raw_hex,
default_chain_spec.asdict(), default_chain_spec.asdict(),
@ -95,269 +97,277 @@ def test_admin_api_tx(
set_reserved(default_chain_spec, tx_hash_hex, session=init_database) set_reserved(default_chain_spec, tx_hash_hex, session=init_database)
set_sent(default_chain_spec, tx_hash_hex, session=init_database) set_sent(default_chain_spec, tx_hash_hex, session=init_database)
# lookup by transaction hash, without registry
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
tx = api.tx(default_chain_spec, tx_hash=tx_hash_hex) tx = api.tx(default_chain_spec, tx_hash=tx_hash_hex)
logg.debug('deployed {}'.format(contract_roles['CONTRACT_DEPLOYER'])) logg.debug('deployed {}'.format(contract_roles['CONTRACT_DEPLOYER']))
assert tx['tx_hash'] == tx_hash_hex assert tx['tx_hash'] == tx_hash_hex
# lookup by RLP transaction, without registry
tx = api.tx(default_chain_spec, tx_raw=tx_signed_raw_hex) tx = api.tx(default_chain_spec, tx_raw=tx_signed_raw_hex)
assert tx['tx_hash'] == tx_hash_hex assert tx['tx_hash'] == tx_hash_hex
# lookup by transaction hash, with registry
registry = CICRegistry(default_chain_spec, eth_rpc)
tx = api.tx(default_chain_spec, tx_hash=tx_hash_hex, registry=registry)
assert tx['tx_hash'] == tx_hash_hex
# lookup by transaction hash, using writer
buf = io.StringIO() buf = io.StringIO()
api.tx(default_chain_spec, tx_hash=tx_hash_hex, renderer=json.dumps, w=buf) api.tx(default_chain_spec, tx_hash=tx_hash_hex, renderer=json.dumps, w=buf)
tx = json.loads(buf.getvalue()) tx = json.loads(buf.getvalue())
assert tx['tx_hash'] == tx_hash_hex assert tx['tx_hash'] == tx_hash_hex
def test_admin_api_account( #def test_admin_api_account(
default_chain_spec, # default_chain_spec,
init_database, # init_database,
eth_rpc, # eth_rpc,
eth_signer, # eth_signer,
agent_roles, # agent_roles,
contract_roles, # contract_roles,
celery_session_worker, # celery_session_worker,
caplog, # caplog,
): # ):
#
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) # nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc) # gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
#
tx_hashes_alice = [] # tx_hashes_alice = []
txs_alice = [] # txs_alice = []
#
for i in range(3): # for i in range(3):
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) # c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED) # (tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
queue_create( # queue_create(
default_chain_spec, # default_chain_spec,
42+i, # 42+i,
agent_roles['ALICE'], # agent_roles['ALICE'],
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
session=init_database, # session=init_database,
) # )
cache_gas_data( # cache_gas_data(
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
default_chain_spec.asdict(), # default_chain_spec.asdict(),
) # )
tx_hashes_alice.append(tx_hash_hex) # tx_hashes_alice.append(tx_hash_hex)
txs_alice.append(tx_signed_raw_hex) # txs_alice.append(tx_signed_raw_hex)
#
init_database.commit() # init_database.commit()
#
nonce_oracle = OverrideNonceOracle(agent_roles['BOB'], 13) # nonce_oracle = OverrideNonceOracle(agent_roles['BOB'], 13)
tx_hashes_bob = [] # tx_hashes_bob = []
txs_bob = [] # txs_bob = []
#
for i in range(2): # for i in range(2):
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) # c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['BOB'], agent_roles['ALICE'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED) # (tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['BOB'], agent_roles['ALICE'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
queue_create( # queue_create(
default_chain_spec, # default_chain_spec,
13+i, # 13+i,
agent_roles['BOB'], # agent_roles['BOB'],
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
session=init_database, # session=init_database,
) # )
cache_gas_data( # cache_gas_data(
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
default_chain_spec.asdict(), # default_chain_spec.asdict(),
) # )
tx_hashes_bob.append(tx_hash_hex) # tx_hashes_bob.append(tx_hash_hex)
txs_bob.append(tx_signed_raw_hex) # txs_bob.append(tx_signed_raw_hex)
#
init_database.commit() # init_database.commit()
#
#
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
r = api.account(default_chain_spec, agent_roles['ALICE']) # r = api.account(default_chain_spec, agent_roles['ALICE'])
assert len(r) == 5 # assert len(r) == 5
#
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
r = api.account(default_chain_spec, agent_roles['ALICE'], include_sender=False) # r = api.account(default_chain_spec, agent_roles['ALICE'], include_sender=False)
assert len(r) == 2 # assert len(r) == 2
#
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
r = api.account(default_chain_spec, agent_roles['ALICE'], include_recipient=False) # r = api.account(default_chain_spec, agent_roles['ALICE'], include_recipient=False)
assert len(r) == 3 # assert len(r) == 3
#
#
def test_admin_api_account_writer( #def test_admin_api_account_writer(
default_chain_spec, # default_chain_spec,
init_database, # init_database,
eth_rpc, # eth_rpc,
eth_signer, # eth_signer,
agent_roles, # agent_roles,
contract_roles, # contract_roles,
celery_session_worker, # celery_session_worker,
caplog, # caplog,
): # ):
#
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) # nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc) # gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
#
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) # c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED) # (tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
queue_create( # queue_create(
default_chain_spec, # default_chain_spec,
42, # 42,
agent_roles['ALICE'], # agent_roles['ALICE'],
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
session=init_database, # session=init_database,
) # )
cache_gas_data( # cache_gas_data(
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
default_chain_spec.asdict(), # default_chain_spec.asdict(),
) # )
#
init_database.commit() # init_database.commit()
#
buf = io.StringIO() # buf = io.StringIO()
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
api.account(default_chain_spec, agent_roles['ALICE'], renderer=json.dumps, w=buf) # api.account(default_chain_spec, agent_roles['ALICE'], renderer=json.dumps, w=buf)
#
# TODO: improve eval # # TODO: improve eval
tx = json.loads(buf.getvalue()) # tx = json.loads(buf.getvalue())
assert tx['tx_hash'] == tx_hash_hex # assert tx['tx_hash'] == tx_hash_hex
#
#
def test_registry( #def test_registry(
eth_rpc, # eth_rpc,
cic_registry, # cic_registry,
contract_roles, # contract_roles,
celery_session_worker, # celery_session_worker,
): # ):
#
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
t = api.registry() # t = api.registry()
r = t.get_leaf() # r = t.get_leaf()
assert r == cic_registry # assert r == cic_registry
#
#
def test_proxy_do( #def test_proxy_do(
default_chain_spec, # default_chain_spec,
eth_rpc, # eth_rpc,
contract_roles, # contract_roles,
celery_session_worker, # celery_session_worker,
): # ):
#
o = block_latest() # o = block_latest()
r = eth_rpc.do(o) # r = eth_rpc.do(o)
#
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
t = api.proxy_do(default_chain_spec, o) # t = api.proxy_do(default_chain_spec, o)
rr = t.get_leaf() # rr = t.get_leaf()
#
assert r == rr # assert r == rr
#
#
def test_resend_inplace( #def test_resend_inplace(
init_database, # init_database,
default_chain_spec, # default_chain_spec,
eth_rpc, # eth_rpc,
eth_signer, # eth_signer,
agent_roles, # agent_roles,
contract_roles, # contract_roles,
celery_session_worker, # celery_session_worker,
): # ):
#
rpc = RPCConnection.connect(default_chain_spec, 'default') # rpc = RPCConnection.connect(default_chain_spec, 'default')
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) # nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
gas_oracle = OverrideGasOracle(price=1000000000, limit=21000) # gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) # c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED) # (tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
#
queue_create( # queue_create(
default_chain_spec, # default_chain_spec,
42, # 42,
agent_roles['ALICE'], # agent_roles['ALICE'],
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
session=init_database, # session=init_database,
) # )
cache_gas_data( # cache_gas_data(
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
default_chain_spec.asdict(), # default_chain_spec.asdict(),
) # )
#
set_ready(default_chain_spec, tx_hash_hex, session=init_database) # set_ready(default_chain_spec, tx_hash_hex, session=init_database)
set_reserved(default_chain_spec, tx_hash_hex, session=init_database) # set_reserved(default_chain_spec, tx_hash_hex, session=init_database)
set_sent(default_chain_spec, tx_hash_hex, session=init_database) # set_sent(default_chain_spec, tx_hash_hex, session=init_database)
#
init_database.commit() # init_database.commit()
#
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
t = api.resend(tx_hash_hex, default_chain_spec, unlock=True) # t = api.resend(tx_hash_hex, default_chain_spec, unlock=True)
r = t.get_leaf() # r = t.get_leaf()
assert t.successful() # assert t.successful()
#
#
otx = Otx.load(tx_hash_hex, session=init_database) # otx = Otx.load(tx_hash_hex, session=init_database)
assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE # assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
#
txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database) # txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
assert len(txs) == 2 # assert len(txs) == 2
#
#
#
@pytest.mark.xfail() #@pytest.mark.xfail()
def test_resend_clone( #def test_resend_clone(
init_database, # init_database,
default_chain_spec, # default_chain_spec,
eth_rpc, # eth_rpc,
eth_signer, # eth_signer,
agent_roles, # agent_roles,
contract_roles, # contract_roles,
celery_session_worker, # celery_session_worker,
): # ):
#
rpc = RPCConnection.connect(default_chain_spec, 'default') # rpc = RPCConnection.connect(default_chain_spec, 'default')
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) # nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
gas_oracle = OverrideGasOracle(price=1000000000, limit=21000) # gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) # c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED) # (tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
#
queue_create( # queue_create(
default_chain_spec, # default_chain_spec,
42, # 42,
agent_roles['ALICE'], # agent_roles['ALICE'],
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
session=init_database, # session=init_database,
) # )
cache_gas_data( # cache_gas_data(
tx_hash_hex, # tx_hash_hex,
tx_signed_raw_hex, # tx_signed_raw_hex,
default_chain_spec.asdict(), # default_chain_spec.asdict(),
) # )
#
set_ready(default_chain_spec, tx_hash_hex, session=init_database) # set_ready(default_chain_spec, tx_hash_hex, session=init_database)
set_reserved(default_chain_spec, tx_hash_hex, session=init_database) # set_reserved(default_chain_spec, tx_hash_hex, session=init_database)
set_sent(default_chain_spec, tx_hash_hex, session=init_database) # set_sent(default_chain_spec, tx_hash_hex, session=init_database)
#
init_database.commit() # init_database.commit()
#
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) # api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
t = api.resend(tx_hash_hex, default_chain_spec, in_place=False) # t = api.resend(tx_hash_hex, default_chain_spec, in_place=False)
r = t.get_leaf() # r = t.get_leaf()
assert t.successful() # assert t.successful()
#
otx = Otx.load(tx_hash_hex, session=init_database) # otx = Otx.load(tx_hash_hex, session=init_database)
assert otx.status & StatusBits.IN_NETWORK == StatusBits.IN_NETWORK # assert otx.status & StatusBits.IN_NETWORK == StatusBits.IN_NETWORK
assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE # assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
#
txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database) # txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
assert len(txs) == 1 # assert len(txs) == 1
#
txs = get_nonce_tx_cache(default_chain_spec, otx.nonce + 1, agent_roles['ALICE'], session=init_database) # txs = get_nonce_tx_cache(default_chain_spec, otx.nonce + 1, agent_roles['ALICE'], session=init_database)
assert len(txs) == 1 # assert len(txs) == 1
#
otx = Otx.load(txs[0], session=init_database) # otx = Otx.load(txs[0], session=init_database)
assert otx.status == 0 # assert otx.status == 0

View File

@ -8,11 +8,20 @@ import pytest
import celery import celery
from cic_eth_registry.erc20 import ERC20Token from cic_eth_registry.erc20 import ERC20Token
from chainlib.chain import ChainSpec from chainlib.chain import ChainSpec
from eth_accounts_index import AccountsIndex
from chainlib.eth.tx import (
transaction,
)
from chainqueue.state import (
set_reserved,
)
# local imports # local imports
from cic_eth.api import Api from cic_eth.api import Api
from cic_eth.queue.query import get_tx
logg = logging.getLogger(__name__) #logg = logging.getLogger(__name__)
logg = logging.getLogger()
def test_account_api( def test_account_api(
@ -29,6 +38,47 @@ def test_account_api(
assert t.successful() assert t.successful()
def test_account_api_register(
default_chain_spec,
init_database,
account_registry,
faucet,
custodial_roles,
cic_registry,
register_lookups,
eth_rpc,
celery_session_worker,
):
api = Api(str(default_chain_spec), callback_param='accounts', callback_task='cic_eth.callbacks.noop.noop', queue=None)
t = api.create_account('')
register_tx_hash = t.get_leaf()
assert t.successful()
set_reserved(default_chain_spec, register_tx_hash, session=init_database)
tx = get_tx(default_chain_spec.asdict(), register_tx_hash)
s = celery.signature(
'cic_eth.eth.tx.send',
[
[tx['signed_tx']],
default_chain_spec.asdict(),
],
queue=None
)
t = s.apply_async()
r = t.get_leaf()
assert t.successful()
o = transaction(register_tx_hash)
tx_src = eth_rpc.do(o)
c = AccountsIndex(default_chain_spec)
address = c.parse_add_request(tx_src['data'])
o = c.have(account_registry, address[0], sender_address=custodial_roles['CONTRACT_DEPLOYER'])
r = eth_rpc.do(o)
assert c.parse_have(r)
def test_transfer_api( def test_transfer_api(
default_chain_spec, default_chain_spec,
eth_rpc, eth_rpc,

View File

@ -10,7 +10,7 @@ def test_default_token(
register_tokens, register_tokens,
register_lookups, register_lookups,
cic_registry, cic_registry,
celery_worker, celery_session_worker,
): ):
api = Api(str(default_chain_spec), queue=None) api = Api(str(default_chain_spec), queue=None)