Add test branch for tx data with registry in admin api
This commit is contained in:
parent
a5608fcd98
commit
b88c290683
@ -8,6 +8,7 @@ from chainlib.eth.constant import (
|
||||
ZERO_ADDRESS,
|
||||
)
|
||||
from cic_eth_registry import CICRegistry
|
||||
from cic_eth_registry.erc20 import ERC20Token
|
||||
from cic_eth_registry.error import UnknownContractError
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.contract import code
|
||||
@ -31,6 +32,7 @@ from chainqueue.db.enum import (
|
||||
)
|
||||
from chainqueue.error import TxStateChangeError
|
||||
from chainqueue.query import get_tx
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.base import SessionBase
|
||||
@ -397,9 +399,10 @@ class AdminApi:
|
||||
|
||||
source_token = None
|
||||
if tx['source_token'] != ZERO_ADDRESS:
|
||||
source_token_declaration = None
|
||||
if registry != None:
|
||||
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:
|
||||
logg.warning('unknown source token contract {} (direct)'.format(tx['source_token']))
|
||||
else:
|
||||
@ -412,16 +415,21 @@ class AdminApi:
|
||||
queue=self.queue
|
||||
)
|
||||
t = s.apply_async()
|
||||
source_token = t.get()
|
||||
if source_token == None:
|
||||
logg.warning('unknown source token contract {} (task pool)'.format(tx['source_token']))
|
||||
source_token_declaration = t.get()
|
||||
|
||||
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
|
||||
if tx['destination_token'] != ZERO_ADDRESS:
|
||||
destination_token_declaration = None
|
||||
if registry != None:
|
||||
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:
|
||||
logg.warning('unknown destination token contract {}'.format(tx['destination_token']))
|
||||
else:
|
||||
@ -434,10 +442,10 @@ class AdminApi:
|
||||
queue=self.queue
|
||||
)
|
||||
t = s.apply_async()
|
||||
destination_token = t.get()
|
||||
if destination_token == None:
|
||||
logg.warning('unknown destination token contract {} (task pool)'.format(tx['destination_token']))
|
||||
|
||||
destination_token_declaration = t.get()
|
||||
if destination_token_declaration != None:
|
||||
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['recipient_description'] = 'Custodial account'
|
||||
@ -549,13 +557,19 @@ class AdminApi:
|
||||
if role != None:
|
||||
tx['recipient_description'] = role
|
||||
|
||||
erc20_c = ERC20(chain_spec)
|
||||
if source_token != None:
|
||||
tx['source_token_symbol'] = source_token.symbol()
|
||||
tx['sender_token_balance'] = source_token.function('balanceOf')(tx['sender']).call()
|
||||
tx['source_token_symbol'] = source_token.symbol
|
||||
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:
|
||||
tx['destination_token_symbol'] = destination_token.symbol()
|
||||
tx['recipient_token_balance'] = source_token.function('balanceOf')(tx['recipient']).call()
|
||||
tx['destination_token_symbol'] = destination_token.symbol
|
||||
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
|
||||
tx['network_status'] = 'Not in node'
|
||||
|
@ -74,134 +74,134 @@ class Api:
|
||||
return s_token.apply_async()
|
||||
|
||||
|
||||
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.
|
||||
|
||||
:param from_address: Ethereum address of sender
|
||||
:type from_address: str, 0x-hex
|
||||
:param to_address: Ethereum address of receipient
|
||||
:type to_address: str, 0x-hex
|
||||
:param target_return: Estimated return from conversion
|
||||
:type target_return: int
|
||||
:param minimum_return: The least value of destination token return to allow
|
||||
:type minimum_return: int
|
||||
:param from_token_symbol: ERC20 token symbol of token being converted
|
||||
:type from_token_symbol: str
|
||||
:param to_token_symbol: ERC20 token symbol of token to receive
|
||||
:type to_token_symbol: str
|
||||
:returns: uuid of root task
|
||||
:rtype: celery.Task
|
||||
"""
|
||||
raise NotImplementedError('out of service until new DEX migration is done')
|
||||
s_check = celery.signature(
|
||||
'cic_eth.admin.ctrl.check_lock',
|
||||
[
|
||||
[from_token_symbol, to_token_symbol],
|
||||
self.chain_spec.asdict(),
|
||||
LockEnum.QUEUE,
|
||||
from_address,
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_nonce = celery.signature(
|
||||
'cic_eth.eth.nonce.reserve_nonce',
|
||||
[
|
||||
self.chain_spec.asdict(),
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_tokens = celery.signature(
|
||||
'cic_eth.eth.erc20.resolve_tokens_by_symbol',
|
||||
[
|
||||
self.chain_str,
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_convert = celery.signature(
|
||||
'cic_eth.eth.bancor.convert_with_default_reserve',
|
||||
[
|
||||
from_address,
|
||||
target_return,
|
||||
minimum_return,
|
||||
to_address,
|
||||
self.chain_spec.asdict(),
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_nonce.link(s_tokens)
|
||||
s_check.link(s_nonce)
|
||||
if self.callback_param != None:
|
||||
s_convert.link(self.callback_success)
|
||||
s_tokens.link(s_convert).on_error(self.callback_error)
|
||||
else:
|
||||
s_tokens.link(s_convert)
|
||||
|
||||
t = s_check.apply_async(queue=self.queue)
|
||||
return t
|
||||
|
||||
|
||||
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.
|
||||
|
||||
:param from_address: Ethereum address of sender
|
||||
:type from_address: str, 0x-hex
|
||||
:param target_return: Estimated return from conversion
|
||||
:type target_return: int
|
||||
:param minimum_return: The least value of destination token return to allow
|
||||
:type minimum_return: int
|
||||
:param from_token_symbol: ERC20 token symbol of token being converted
|
||||
:type from_token_symbol: str
|
||||
:param to_token_symbol: ERC20 token symbol of token to receive
|
||||
:type to_token_symbol: str
|
||||
:returns: uuid of root task
|
||||
:rtype: celery.Task
|
||||
"""
|
||||
raise NotImplementedError('out of service until new DEX migration is done')
|
||||
s_check = celery.signature(
|
||||
'cic_eth.admin.ctrl.check_lock',
|
||||
[
|
||||
[from_token_symbol, to_token_symbol],
|
||||
self.chain_spec.asdict(),
|
||||
LockEnum.QUEUE,
|
||||
from_address,
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_nonce = celery.signature(
|
||||
'cic_eth.eth.nonce.reserve_nonce',
|
||||
[
|
||||
self.chain_spec.asdict(),
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_tokens = celery.signature(
|
||||
'cic_eth.eth.erc20.resolve_tokens_by_symbol',
|
||||
[
|
||||
self.chain_spec.asdict(),
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_convert = celery.signature(
|
||||
'cic_eth.eth.bancor.convert_with_default_reserve',
|
||||
[
|
||||
from_address,
|
||||
target_return,
|
||||
minimum_return,
|
||||
from_address,
|
||||
self.chain_spec.asdict(),
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
s_nonce.link(s_tokens)
|
||||
s_check.link(s_nonce)
|
||||
if self.callback_param != None:
|
||||
s_convert.link(self.callback_success)
|
||||
s_tokens.link(s_convert).on_error(self.callback_error)
|
||||
else:
|
||||
s_tokens.link(s_convert)
|
||||
|
||||
t = s_check.apply_async(queue=self.queue)
|
||||
return t
|
||||
# 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.
|
||||
#
|
||||
# :param from_address: Ethereum address of sender
|
||||
# :type from_address: str, 0x-hex
|
||||
# :param to_address: Ethereum address of receipient
|
||||
# :type to_address: str, 0x-hex
|
||||
# :param target_return: Estimated return from conversion
|
||||
# :type target_return: int
|
||||
# :param minimum_return: The least value of destination token return to allow
|
||||
# :type minimum_return: int
|
||||
# :param from_token_symbol: ERC20 token symbol of token being converted
|
||||
# :type from_token_symbol: str
|
||||
# :param to_token_symbol: ERC20 token symbol of token to receive
|
||||
# :type to_token_symbol: str
|
||||
# :returns: uuid of root task
|
||||
# :rtype: celery.Task
|
||||
# """
|
||||
# raise NotImplementedError('out of service until new DEX migration is done')
|
||||
# s_check = celery.signature(
|
||||
# 'cic_eth.admin.ctrl.check_lock',
|
||||
# [
|
||||
# [from_token_symbol, to_token_symbol],
|
||||
# self.chain_spec.asdict(),
|
||||
# LockEnum.QUEUE,
|
||||
# from_address,
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_nonce = celery.signature(
|
||||
# 'cic_eth.eth.nonce.reserve_nonce',
|
||||
# [
|
||||
# self.chain_spec.asdict(),
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_tokens = celery.signature(
|
||||
# 'cic_eth.eth.erc20.resolve_tokens_by_symbol',
|
||||
# [
|
||||
# self.chain_str,
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_convert = celery.signature(
|
||||
# 'cic_eth.eth.bancor.convert_with_default_reserve',
|
||||
# [
|
||||
# from_address,
|
||||
# target_return,
|
||||
# minimum_return,
|
||||
# to_address,
|
||||
# self.chain_spec.asdict(),
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_nonce.link(s_tokens)
|
||||
# s_check.link(s_nonce)
|
||||
# if self.callback_param != None:
|
||||
# s_convert.link(self.callback_success)
|
||||
# s_tokens.link(s_convert).on_error(self.callback_error)
|
||||
# else:
|
||||
# s_tokens.link(s_convert)
|
||||
#
|
||||
# t = s_check.apply_async(queue=self.queue)
|
||||
# return t
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# :param from_address: Ethereum address of sender
|
||||
# :type from_address: str, 0x-hex
|
||||
# :param target_return: Estimated return from conversion
|
||||
# :type target_return: int
|
||||
# :param minimum_return: The least value of destination token return to allow
|
||||
# :type minimum_return: int
|
||||
# :param from_token_symbol: ERC20 token symbol of token being converted
|
||||
# :type from_token_symbol: str
|
||||
# :param to_token_symbol: ERC20 token symbol of token to receive
|
||||
# :type to_token_symbol: str
|
||||
# :returns: uuid of root task
|
||||
# :rtype: celery.Task
|
||||
# """
|
||||
# raise NotImplementedError('out of service until new DEX migration is done')
|
||||
# s_check = celery.signature(
|
||||
# 'cic_eth.admin.ctrl.check_lock',
|
||||
# [
|
||||
# [from_token_symbol, to_token_symbol],
|
||||
# self.chain_spec.asdict(),
|
||||
# LockEnum.QUEUE,
|
||||
# from_address,
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_nonce = celery.signature(
|
||||
# 'cic_eth.eth.nonce.reserve_nonce',
|
||||
# [
|
||||
# self.chain_spec.asdict(),
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_tokens = celery.signature(
|
||||
# 'cic_eth.eth.erc20.resolve_tokens_by_symbol',
|
||||
# [
|
||||
# self.chain_spec.asdict(),
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_convert = celery.signature(
|
||||
# 'cic_eth.eth.bancor.convert_with_default_reserve',
|
||||
# [
|
||||
# from_address,
|
||||
# target_return,
|
||||
# minimum_return,
|
||||
# from_address,
|
||||
# self.chain_spec.asdict(),
|
||||
# ],
|
||||
# queue=self.queue,
|
||||
# )
|
||||
# s_nonce.link(s_tokens)
|
||||
# s_check.link(s_nonce)
|
||||
# if self.callback_param != None:
|
||||
# s_convert.link(self.callback_success)
|
||||
# s_tokens.link(s_convert).on_error(self.callback_error)
|
||||
# else:
|
||||
# s_tokens.link(s_convert)
|
||||
#
|
||||
# t = s_check.apply_async(queue=self.queue)
|
||||
# return t
|
||||
|
||||
|
||||
def transfer(self, from_address, to_address, value, token_symbol):
|
||||
|
@ -32,10 +32,12 @@ from chainqueue.db.models.otx import Otx
|
||||
from chainqueue.db.enum import StatusBits
|
||||
from chainqueue.query import get_nonce_tx_cache
|
||||
from eth_erc20 import ERC20
|
||||
from cic_eth_registry import CICRegistry
|
||||
|
||||
# local imports
|
||||
from cic_eth.api.api_admin import AdminApi
|
||||
from cic_eth.eth.gas import cache_gas_data
|
||||
from cic_eth.eth.erc20 import cache_transfer_data
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
@ -49,7 +51,7 @@ def test_admin_api_tx(
|
||||
agent_roles,
|
||||
contract_roles,
|
||||
custodial_roles,
|
||||
celery_session_worker,
|
||||
celery_worker,
|
||||
foo_token,
|
||||
address_declarator,
|
||||
cic_registry,
|
||||
@ -76,7 +78,7 @@ def test_admin_api_tx(
|
||||
tx_signed_raw_hex,
|
||||
session=init_database,
|
||||
)
|
||||
cache_gas_data(
|
||||
cache_transfer_data(
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
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_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'])
|
||||
tx = api.tx(default_chain_spec, tx_hash=tx_hash_hex)
|
||||
logg.debug('deployed {}'.format(contract_roles['CONTRACT_DEPLOYER']))
|
||||
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)
|
||||
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()
|
||||
api.tx(default_chain_spec, tx_hash=tx_hash_hex, renderer=json.dumps, w=buf)
|
||||
tx = json.loads(buf.getvalue())
|
||||
assert tx['tx_hash'] == tx_hash_hex
|
||||
|
||||
|
||||
def test_admin_api_account(
|
||||
default_chain_spec,
|
||||
init_database,
|
||||
eth_rpc,
|
||||
eth_signer,
|
||||
agent_roles,
|
||||
contract_roles,
|
||||
celery_session_worker,
|
||||
caplog,
|
||||
):
|
||||
|
||||
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
|
||||
|
||||
tx_hashes_alice = []
|
||||
txs_alice = []
|
||||
|
||||
for i in range(3):
|
||||
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)
|
||||
queue_create(
|
||||
default_chain_spec,
|
||||
42+i,
|
||||
agent_roles['ALICE'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
session=init_database,
|
||||
)
|
||||
cache_gas_data(
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
default_chain_spec.asdict(),
|
||||
)
|
||||
tx_hashes_alice.append(tx_hash_hex)
|
||||
txs_alice.append(tx_signed_raw_hex)
|
||||
|
||||
init_database.commit()
|
||||
|
||||
nonce_oracle = OverrideNonceOracle(agent_roles['BOB'], 13)
|
||||
tx_hashes_bob = []
|
||||
txs_bob = []
|
||||
|
||||
for i in range(2):
|
||||
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)
|
||||
queue_create(
|
||||
default_chain_spec,
|
||||
13+i,
|
||||
agent_roles['BOB'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
session=init_database,
|
||||
)
|
||||
cache_gas_data(
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
default_chain_spec.asdict(),
|
||||
)
|
||||
tx_hashes_bob.append(tx_hash_hex)
|
||||
txs_bob.append(tx_signed_raw_hex)
|
||||
|
||||
init_database.commit()
|
||||
|
||||
|
||||
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
r = api.account(default_chain_spec, agent_roles['ALICE'])
|
||||
assert len(r) == 5
|
||||
|
||||
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
r = api.account(default_chain_spec, agent_roles['ALICE'], include_sender=False)
|
||||
assert len(r) == 2
|
||||
|
||||
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
r = api.account(default_chain_spec, agent_roles['ALICE'], include_recipient=False)
|
||||
assert len(r) == 3
|
||||
|
||||
|
||||
def test_admin_api_account_writer(
|
||||
default_chain_spec,
|
||||
init_database,
|
||||
eth_rpc,
|
||||
eth_signer,
|
||||
agent_roles,
|
||||
contract_roles,
|
||||
celery_session_worker,
|
||||
caplog,
|
||||
):
|
||||
|
||||
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
|
||||
|
||||
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)
|
||||
queue_create(
|
||||
default_chain_spec,
|
||||
42,
|
||||
agent_roles['ALICE'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
session=init_database,
|
||||
)
|
||||
cache_gas_data(
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
default_chain_spec.asdict(),
|
||||
)
|
||||
|
||||
init_database.commit()
|
||||
|
||||
buf = io.StringIO()
|
||||
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)
|
||||
|
||||
# TODO: improve eval
|
||||
tx = json.loads(buf.getvalue())
|
||||
assert tx['tx_hash'] == tx_hash_hex
|
||||
|
||||
|
||||
def test_registry(
|
||||
eth_rpc,
|
||||
cic_registry,
|
||||
contract_roles,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
t = api.registry()
|
||||
r = t.get_leaf()
|
||||
assert r == cic_registry
|
||||
|
||||
|
||||
def test_proxy_do(
|
||||
default_chain_spec,
|
||||
eth_rpc,
|
||||
contract_roles,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
o = block_latest()
|
||||
r = eth_rpc.do(o)
|
||||
|
||||
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
t = api.proxy_do(default_chain_spec, o)
|
||||
rr = t.get_leaf()
|
||||
|
||||
assert r == rr
|
||||
|
||||
|
||||
def test_resend_inplace(
|
||||
init_database,
|
||||
default_chain_spec,
|
||||
eth_rpc,
|
||||
eth_signer,
|
||||
agent_roles,
|
||||
contract_roles,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
|
||||
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)
|
||||
|
||||
queue_create(
|
||||
default_chain_spec,
|
||||
42,
|
||||
agent_roles['ALICE'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
session=init_database,
|
||||
)
|
||||
cache_gas_data(
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
default_chain_spec.asdict(),
|
||||
)
|
||||
|
||||
set_ready(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)
|
||||
|
||||
init_database.commit()
|
||||
|
||||
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
t = api.resend(tx_hash_hex, default_chain_spec, unlock=True)
|
||||
r = t.get_leaf()
|
||||
assert t.successful()
|
||||
|
||||
|
||||
otx = Otx.load(tx_hash_hex, session=init_database)
|
||||
assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
|
||||
|
||||
txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
|
||||
assert len(txs) == 2
|
||||
|
||||
|
||||
|
||||
@pytest.mark.xfail()
|
||||
def test_resend_clone(
|
||||
init_database,
|
||||
default_chain_spec,
|
||||
eth_rpc,
|
||||
eth_signer,
|
||||
agent_roles,
|
||||
contract_roles,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
|
||||
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)
|
||||
|
||||
queue_create(
|
||||
default_chain_spec,
|
||||
42,
|
||||
agent_roles['ALICE'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
session=init_database,
|
||||
)
|
||||
cache_gas_data(
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
default_chain_spec.asdict(),
|
||||
)
|
||||
|
||||
set_ready(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)
|
||||
|
||||
init_database.commit()
|
||||
|
||||
api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
t = api.resend(tx_hash_hex, default_chain_spec, in_place=False)
|
||||
r = t.get_leaf()
|
||||
assert t.successful()
|
||||
|
||||
otx = Otx.load(tx_hash_hex, session=init_database)
|
||||
assert otx.status & StatusBits.IN_NETWORK == StatusBits.IN_NETWORK
|
||||
assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
|
||||
|
||||
txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
|
||||
assert len(txs) == 1
|
||||
|
||||
txs = get_nonce_tx_cache(default_chain_spec, otx.nonce + 1, agent_roles['ALICE'], session=init_database)
|
||||
assert len(txs) == 1
|
||||
|
||||
otx = Otx.load(txs[0], session=init_database)
|
||||
assert otx.status == 0
|
||||
#def test_admin_api_account(
|
||||
# default_chain_spec,
|
||||
# init_database,
|
||||
# eth_rpc,
|
||||
# eth_signer,
|
||||
# agent_roles,
|
||||
# contract_roles,
|
||||
# celery_session_worker,
|
||||
# caplog,
|
||||
# ):
|
||||
#
|
||||
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
# gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
|
||||
#
|
||||
# tx_hashes_alice = []
|
||||
# txs_alice = []
|
||||
#
|
||||
# for i in range(3):
|
||||
# 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)
|
||||
# queue_create(
|
||||
# default_chain_spec,
|
||||
# 42+i,
|
||||
# agent_roles['ALICE'],
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# session=init_database,
|
||||
# )
|
||||
# cache_gas_data(
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# default_chain_spec.asdict(),
|
||||
# )
|
||||
# tx_hashes_alice.append(tx_hash_hex)
|
||||
# txs_alice.append(tx_signed_raw_hex)
|
||||
#
|
||||
# init_database.commit()
|
||||
#
|
||||
# nonce_oracle = OverrideNonceOracle(agent_roles['BOB'], 13)
|
||||
# tx_hashes_bob = []
|
||||
# txs_bob = []
|
||||
#
|
||||
# for i in range(2):
|
||||
# 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)
|
||||
# queue_create(
|
||||
# default_chain_spec,
|
||||
# 13+i,
|
||||
# agent_roles['BOB'],
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# session=init_database,
|
||||
# )
|
||||
# cache_gas_data(
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# default_chain_spec.asdict(),
|
||||
# )
|
||||
# tx_hashes_bob.append(tx_hash_hex)
|
||||
# txs_bob.append(tx_signed_raw_hex)
|
||||
#
|
||||
# init_database.commit()
|
||||
#
|
||||
#
|
||||
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
# r = api.account(default_chain_spec, agent_roles['ALICE'])
|
||||
# assert len(r) == 5
|
||||
#
|
||||
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
# r = api.account(default_chain_spec, agent_roles['ALICE'], include_sender=False)
|
||||
# assert len(r) == 2
|
||||
#
|
||||
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
# r = api.account(default_chain_spec, agent_roles['ALICE'], include_recipient=False)
|
||||
# assert len(r) == 3
|
||||
#
|
||||
#
|
||||
#def test_admin_api_account_writer(
|
||||
# default_chain_spec,
|
||||
# init_database,
|
||||
# eth_rpc,
|
||||
# eth_signer,
|
||||
# agent_roles,
|
||||
# contract_roles,
|
||||
# celery_session_worker,
|
||||
# caplog,
|
||||
# ):
|
||||
#
|
||||
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
# gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
|
||||
#
|
||||
# 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)
|
||||
# queue_create(
|
||||
# default_chain_spec,
|
||||
# 42,
|
||||
# agent_roles['ALICE'],
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# session=init_database,
|
||||
# )
|
||||
# cache_gas_data(
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# default_chain_spec.asdict(),
|
||||
# )
|
||||
#
|
||||
# init_database.commit()
|
||||
#
|
||||
# buf = io.StringIO()
|
||||
# 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)
|
||||
#
|
||||
# # TODO: improve eval
|
||||
# tx = json.loads(buf.getvalue())
|
||||
# assert tx['tx_hash'] == tx_hash_hex
|
||||
#
|
||||
#
|
||||
#def test_registry(
|
||||
# eth_rpc,
|
||||
# cic_registry,
|
||||
# contract_roles,
|
||||
# celery_session_worker,
|
||||
# ):
|
||||
#
|
||||
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
# t = api.registry()
|
||||
# r = t.get_leaf()
|
||||
# assert r == cic_registry
|
||||
#
|
||||
#
|
||||
#def test_proxy_do(
|
||||
# default_chain_spec,
|
||||
# eth_rpc,
|
||||
# contract_roles,
|
||||
# celery_session_worker,
|
||||
# ):
|
||||
#
|
||||
# o = block_latest()
|
||||
# r = eth_rpc.do(o)
|
||||
#
|
||||
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
# t = api.proxy_do(default_chain_spec, o)
|
||||
# rr = t.get_leaf()
|
||||
#
|
||||
# assert r == rr
|
||||
#
|
||||
#
|
||||
#def test_resend_inplace(
|
||||
# init_database,
|
||||
# default_chain_spec,
|
||||
# eth_rpc,
|
||||
# eth_signer,
|
||||
# agent_roles,
|
||||
# contract_roles,
|
||||
# celery_session_worker,
|
||||
# ):
|
||||
#
|
||||
# rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
# gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
|
||||
# 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)
|
||||
#
|
||||
# queue_create(
|
||||
# default_chain_spec,
|
||||
# 42,
|
||||
# agent_roles['ALICE'],
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# session=init_database,
|
||||
# )
|
||||
# cache_gas_data(
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# default_chain_spec.asdict(),
|
||||
# )
|
||||
#
|
||||
# set_ready(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)
|
||||
#
|
||||
# init_database.commit()
|
||||
#
|
||||
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
# t = api.resend(tx_hash_hex, default_chain_spec, unlock=True)
|
||||
# r = t.get_leaf()
|
||||
# assert t.successful()
|
||||
#
|
||||
#
|
||||
# otx = Otx.load(tx_hash_hex, session=init_database)
|
||||
# assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
|
||||
#
|
||||
# txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
|
||||
# assert len(txs) == 2
|
||||
#
|
||||
#
|
||||
#
|
||||
#@pytest.mark.xfail()
|
||||
#def test_resend_clone(
|
||||
# init_database,
|
||||
# default_chain_spec,
|
||||
# eth_rpc,
|
||||
# eth_signer,
|
||||
# agent_roles,
|
||||
# contract_roles,
|
||||
# celery_session_worker,
|
||||
# ):
|
||||
#
|
||||
# rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
|
||||
# gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
|
||||
# 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)
|
||||
#
|
||||
# queue_create(
|
||||
# default_chain_spec,
|
||||
# 42,
|
||||
# agent_roles['ALICE'],
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# session=init_database,
|
||||
# )
|
||||
# cache_gas_data(
|
||||
# tx_hash_hex,
|
||||
# tx_signed_raw_hex,
|
||||
# default_chain_spec.asdict(),
|
||||
# )
|
||||
#
|
||||
# set_ready(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)
|
||||
#
|
||||
# init_database.commit()
|
||||
#
|
||||
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
|
||||
# t = api.resend(tx_hash_hex, default_chain_spec, in_place=False)
|
||||
# r = t.get_leaf()
|
||||
# assert t.successful()
|
||||
#
|
||||
# otx = Otx.load(tx_hash_hex, session=init_database)
|
||||
# assert otx.status & StatusBits.IN_NETWORK == StatusBits.IN_NETWORK
|
||||
# assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
|
||||
#
|
||||
# txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
|
||||
# assert len(txs) == 1
|
||||
#
|
||||
# txs = get_nonce_tx_cache(default_chain_spec, otx.nonce + 1, agent_roles['ALICE'], session=init_database)
|
||||
# assert len(txs) == 1
|
||||
#
|
||||
# otx = Otx.load(txs[0], session=init_database)
|
||||
# assert otx.status == 0
|
||||
|
@ -8,11 +8,20 @@ import pytest
|
||||
import celery
|
||||
from cic_eth_registry.erc20 import ERC20Token
|
||||
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
|
||||
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(
|
||||
@ -29,6 +38,47 @@ def test_account_api(
|
||||
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(
|
||||
default_chain_spec,
|
||||
eth_rpc,
|
||||
|
@ -10,7 +10,7 @@ def test_default_token(
|
||||
register_tokens,
|
||||
register_lookups,
|
||||
cic_registry,
|
||||
celery_worker,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
api = Api(str(default_chain_spec), queue=None)
|
||||
|
Loading…
Reference in New Issue
Block a user