Fix tx listing, rehabilitate api and filter tests (hex case problems)
This commit is contained in:
parent
8a9d2ee0be
commit
69d31d202b
@ -9,6 +9,7 @@ import logging
|
|||||||
# external imports
|
# external imports
|
||||||
import celery
|
import celery
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
|
from hexathon import strip_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.api.base import ApiBase
|
from cic_eth.api.base import ApiBase
|
||||||
@ -254,6 +255,8 @@ class Api(ApiBase):
|
|||||||
:returns: uuid of root task
|
:returns: uuid of root task
|
||||||
:rtype: celery.Task
|
:rtype: celery.Task
|
||||||
"""
|
"""
|
||||||
|
#from_address = strip_0x(from_address)
|
||||||
|
#to_address = strip_0x(to_address)
|
||||||
s_check = celery.signature(
|
s_check = celery.signature(
|
||||||
'cic_eth.admin.ctrl.check_lock',
|
'cic_eth.admin.ctrl.check_lock',
|
||||||
[
|
[
|
||||||
|
@ -49,6 +49,7 @@ from cic_eth.queue.tx import (
|
|||||||
from cic_eth.encode import (
|
from cic_eth.encode import (
|
||||||
unpack_normal,
|
unpack_normal,
|
||||||
ZERO_ADDRESS_NORMAL,
|
ZERO_ADDRESS_NORMAL,
|
||||||
|
tx_normalize,
|
||||||
)
|
)
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@ -298,13 +299,15 @@ def cache_gift_data(
|
|||||||
tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex))
|
tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex))
|
||||||
tx = unpack_normal(tx_signed_raw_bytes, chain_spec)
|
tx = unpack_normal(tx_signed_raw_bytes, chain_spec)
|
||||||
tx_data = Faucet.parse_give_to_request(tx['data'])
|
tx_data = Faucet.parse_give_to_request(tx['data'])
|
||||||
|
sender_address = tx_normalize.wallet_address(tx['from'])
|
||||||
|
recipient_address = tx_normalize.wallet_address(tx['to'])
|
||||||
|
|
||||||
session = self.create_session()
|
session = self.create_session()
|
||||||
|
|
||||||
tx_dict = {
|
tx_dict = {
|
||||||
'hash': tx['hash'],
|
'hash': tx['hash'],
|
||||||
'from': tx['from'],
|
'from': sender_address,
|
||||||
'to': tx['to'],
|
'to': recipient_address,
|
||||||
'source_token': ZERO_ADDRESS_NORMAL,
|
'source_token': ZERO_ADDRESS_NORMAL,
|
||||||
'destination_token': ZERO_ADDRESS_NORMAL,
|
'destination_token': ZERO_ADDRESS_NORMAL,
|
||||||
'from_value': 0,
|
'from_value': 0,
|
||||||
@ -338,12 +341,14 @@ def cache_account_data(
|
|||||||
tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex))
|
tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex))
|
||||||
tx = unpack_normal(tx_signed_raw_bytes, chain_spec)
|
tx = unpack_normal(tx_signed_raw_bytes, chain_spec)
|
||||||
tx_data = AccountsIndex.parse_add_request(tx['data'])
|
tx_data = AccountsIndex.parse_add_request(tx['data'])
|
||||||
|
sender_address = tx_normalize.wallet_address(tx['from'])
|
||||||
|
recipient_address = tx_normalize.wallet_address(tx['to'])
|
||||||
|
|
||||||
session = SessionBase.create_session()
|
session = SessionBase.create_session()
|
||||||
tx_dict = {
|
tx_dict = {
|
||||||
'hash': tx['hash'],
|
'hash': tx['hash'],
|
||||||
'from': tx['from'],
|
'from': sender_address,
|
||||||
'to': tx['to'],
|
'to': recipient_address,
|
||||||
'source_token': ZERO_ADDRESS_NORMAL,
|
'source_token': ZERO_ADDRESS_NORMAL,
|
||||||
'destination_token': ZERO_ADDRESS_NORMAL,
|
'destination_token': ZERO_ADDRESS_NORMAL,
|
||||||
'from_value': 0,
|
'from_value': 0,
|
||||||
|
@ -12,7 +12,10 @@ from chainlib.eth.tx import (
|
|||||||
)
|
)
|
||||||
from cic_eth_registry import CICRegistry
|
from cic_eth_registry import CICRegistry
|
||||||
from cic_eth_registry.erc20 import ERC20Token
|
from cic_eth_registry.erc20 import ERC20Token
|
||||||
from hexathon import strip_0x
|
from hexathon import (
|
||||||
|
strip_0x,
|
||||||
|
add_0x,
|
||||||
|
)
|
||||||
from chainqueue.error import NotLocalTxError
|
from chainqueue.error import NotLocalTxError
|
||||||
from eth_erc20 import ERC20
|
from eth_erc20 import ERC20
|
||||||
from chainqueue.sql.tx import cache_tx_dict
|
from chainqueue.sql.tx import cache_tx_dict
|
||||||
@ -38,6 +41,7 @@ from cic_eth.task import (
|
|||||||
CriticalSQLAlchemyAndSignerTask,
|
CriticalSQLAlchemyAndSignerTask,
|
||||||
)
|
)
|
||||||
from cic_eth.eth.nonce import CustodialTaskNonceOracle
|
from cic_eth.eth.nonce import CustodialTaskNonceOracle
|
||||||
|
from cic_eth.encode import tx_normalize
|
||||||
|
|
||||||
celery_app = celery.current_app
|
celery_app = celery.current_app
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@ -62,7 +66,8 @@ def balance(tokens, holder_address, chain_spec_dict):
|
|||||||
|
|
||||||
for t in tokens:
|
for t in tokens:
|
||||||
address = t['address']
|
address = t['address']
|
||||||
token = ERC20Token(chain_spec, rpc, address)
|
logg.debug('address {} {}'.format(address, holder_address))
|
||||||
|
token = ERC20Token(chain_spec, rpc, add_0x(address))
|
||||||
c = ERC20(chain_spec)
|
c = ERC20(chain_spec)
|
||||||
o = c.balance_of(address, holder_address, sender_address=caller_address)
|
o = c.balance_of(address, holder_address, sender_address=caller_address)
|
||||||
r = rpc.do(o)
|
r = rpc.do(o)
|
||||||
@ -371,13 +376,15 @@ def cache_transfer_data(
|
|||||||
tx = unpack(tx_signed_raw_bytes, chain_spec)
|
tx = unpack(tx_signed_raw_bytes, chain_spec)
|
||||||
|
|
||||||
tx_data = ERC20.parse_transfer_request(tx['data'])
|
tx_data = ERC20.parse_transfer_request(tx['data'])
|
||||||
recipient_address = tx_data[0]
|
sender_address = tx_normalize.wallet_address(tx['from'])
|
||||||
|
recipient_address = tx_normalize.wallet_address(tx_data[0])
|
||||||
token_value = tx_data[1]
|
token_value = tx_data[1]
|
||||||
|
|
||||||
|
|
||||||
session = SessionBase.create_session()
|
session = SessionBase.create_session()
|
||||||
tx_dict = {
|
tx_dict = {
|
||||||
'hash': tx_hash_hex,
|
'hash': tx_hash_hex,
|
||||||
'from': tx['from'],
|
'from': sender_address,
|
||||||
'to': recipient_address,
|
'to': recipient_address,
|
||||||
'source_token': tx['to'],
|
'source_token': tx['to'],
|
||||||
'destination_token': tx['to'],
|
'destination_token': tx['to'],
|
||||||
@ -448,13 +455,14 @@ def cache_approve_data(
|
|||||||
tx = unpack(tx_signed_raw_bytes, chain_spec)
|
tx = unpack(tx_signed_raw_bytes, chain_spec)
|
||||||
|
|
||||||
tx_data = ERC20.parse_approve_request(tx['data'])
|
tx_data = ERC20.parse_approve_request(tx['data'])
|
||||||
recipient_address = tx_data[0]
|
sender_address = tx_normalize.wallet_address(tx['from'])
|
||||||
|
recipient_address = tx_normalize.wallet_address(tx_data[0])
|
||||||
token_value = tx_data[1]
|
token_value = tx_data[1]
|
||||||
|
|
||||||
session = SessionBase.create_session()
|
session = SessionBase.create_session()
|
||||||
tx_dict = {
|
tx_dict = {
|
||||||
'hash': tx_hash_hex,
|
'hash': tx_hash_hex,
|
||||||
'from': tx['from'],
|
'from': sender_address,
|
||||||
'to': recipient_address,
|
'to': recipient_address,
|
||||||
'source_token': tx['to'],
|
'source_token': tx['to'],
|
||||||
'destination_token': tx['to'],
|
'destination_token': tx['to'],
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
from chainlib.status import Status as TxStatus
|
from chainlib.status import Status as TxStatus
|
||||||
from cic_eth_registry.erc20 import ERC20Token
|
from cic_eth_registry.erc20 import ERC20Token
|
||||||
|
from hexathon import add_0x
|
||||||
|
|
||||||
# local imports
|
# local impor:ts
|
||||||
from cic_eth.ext.address import translate_address
|
from cic_eth.ext.address import translate_address
|
||||||
|
|
||||||
|
|
||||||
@ -44,8 +45,8 @@ class ExtendedTx:
|
|||||||
destination = source
|
destination = source
|
||||||
if destination_value == None:
|
if destination_value == None:
|
||||||
destination_value = source_value
|
destination_value = source_value
|
||||||
st = ERC20Token(self.chain_spec, self.rpc, source)
|
st = ERC20Token(self.chain_spec, self.rpc, add_0x(source))
|
||||||
dt = ERC20Token(self.chain_spec, self.rpc, destination)
|
dt = ERC20Token(self.chain_spec, self.rpc, add_0x(destination))
|
||||||
self.source_token = source
|
self.source_token = source
|
||||||
self.source_token_symbol = st.symbol
|
self.source_token_symbol = st.symbol
|
||||||
self.source_token_name = st.name
|
self.source_token_name = st.name
|
||||||
|
@ -32,6 +32,7 @@ from potaahto.symbols import snake_and_camel
|
|||||||
from cic_eth.queue.time import tx_times
|
from cic_eth.queue.time import tx_times
|
||||||
from cic_eth.task import BaseTask
|
from cic_eth.task import BaseTask
|
||||||
from cic_eth.db.models.base import SessionBase
|
from cic_eth.db.models.base import SessionBase
|
||||||
|
from cic_eth.encode import tx_normalize
|
||||||
|
|
||||||
celery_app = celery.current_app
|
celery_app = celery.current_app
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@ -134,7 +135,7 @@ def list_tx_by_bloom(self, bloomspec, address, chain_spec_dict):
|
|||||||
tx_address = transfer_data[0]
|
tx_address = transfer_data[0]
|
||||||
tx_token_value = transfer_data[1]
|
tx_token_value = transfer_data[1]
|
||||||
|
|
||||||
if address == tx_address:
|
if tx_normalize.wallet_address(address) == tx_normalize.wallet_address(tx_address):
|
||||||
status = StatusEnum.SENT
|
status = StatusEnum.SENT
|
||||||
try:
|
try:
|
||||||
o = receipt(tx['hash'])
|
o = receipt(tx['hash'])
|
||||||
@ -164,10 +165,10 @@ def list_tx_by_bloom(self, bloomspec, address, chain_spec_dict):
|
|||||||
tx_r['date_created'] = times['queue']
|
tx_r['date_created'] = times['queue']
|
||||||
else:
|
else:
|
||||||
tx_r['date_created'] = times['network']
|
tx_r['date_created'] = times['network']
|
||||||
txs[tx['hash']] = tx_r
|
txs[strip_0x(tx['hash'])] = tx_r
|
||||||
break
|
break
|
||||||
return txs
|
|
||||||
|
|
||||||
|
return txs
|
||||||
|
|
||||||
|
|
||||||
# TODO: Surely it must be possible to optimize this
|
# TODO: Surely it must be possible to optimize this
|
||||||
|
@ -58,6 +58,7 @@ def get_tx_local(chain_spec, tx_hash, session=None):
|
|||||||
|
|
||||||
@celery_app.task(base=CriticalSQLAlchemyTask)
|
@celery_app.task(base=CriticalSQLAlchemyTask)
|
||||||
def get_account_tx(chain_spec_dict, address, as_sender=True, as_recipient=True, counterpart=None):
|
def get_account_tx(chain_spec_dict, address, as_sender=True, as_recipient=True, counterpart=None):
|
||||||
|
address = tx_normalize.wallet_address(address)
|
||||||
chain_spec = ChainSpec.from_dict(chain_spec_dict)
|
chain_spec = ChainSpec.from_dict(chain_spec_dict)
|
||||||
return get_account_tx_local(chain_spec, address, as_sender=as_sender, as_recipient=as_recipient, counterpart=counterpart)
|
return get_account_tx_local(chain_spec, address, as_sender=as_sender, as_recipient=as_recipient, counterpart=counterpart)
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ from hexathon import (
|
|||||||
# local imports
|
# local imports
|
||||||
from .base import SyncFilter
|
from .base import SyncFilter
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
#logg = logging.getLogger(__name__)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
account_registry_add_log_hash = '0x9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c9430'
|
account_registry_add_log_hash = '0x9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c9430'
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
celery==4.4.7
|
celery==4.4.7
|
||||||
chainlib-eth>=0.0.9a14,<0.1.0
|
chainlib-eth>=0.0.9a14,<0.1.0
|
||||||
semver==2.13.0
|
semver==2.13.0
|
||||||
|
crypto-dev-signer>=0.4.15rc2,<0.5.0
|
||||||
|
@ -18,7 +18,10 @@ from eth_erc20 import ERC20
|
|||||||
from sarafu_faucet import MinterFaucet
|
from sarafu_faucet import MinterFaucet
|
||||||
from eth_accounts_index.registry import AccountRegistry
|
from eth_accounts_index.registry import AccountRegistry
|
||||||
from potaahto.symbols import snake_and_camel
|
from potaahto.symbols import snake_and_camel
|
||||||
from hexathon import add_0x
|
from hexathon import (
|
||||||
|
add_0x,
|
||||||
|
strip_0x,
|
||||||
|
)
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.runnable.daemons.filters.callback import CallbackFilter
|
from cic_eth.runnable.daemons.filters.callback import CallbackFilter
|
||||||
@ -160,7 +163,7 @@ def test_faucet_gift_to_tx(
|
|||||||
assert transfer_data['token_address'] == foo_token
|
assert transfer_data['token_address'] == foo_token
|
||||||
|
|
||||||
|
|
||||||
def test_callback_filter(
|
def test_callback_filter_filter(
|
||||||
default_chain_spec,
|
default_chain_spec,
|
||||||
init_database,
|
init_database,
|
||||||
eth_rpc,
|
eth_rpc,
|
||||||
@ -213,6 +216,7 @@ def test_callback_filter(
|
|||||||
|
|
||||||
def call_back(self, transfer_type, result):
|
def call_back(self, transfer_type, result):
|
||||||
self.results[transfer_type] = result
|
self.results[transfer_type] = result
|
||||||
|
logg.debug('result {}'.format(result))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
mock = CallbackMock()
|
mock = CallbackMock()
|
||||||
@ -221,4 +225,4 @@ def test_callback_filter(
|
|||||||
fltr.filter(eth_rpc, mockblock, tx, init_database)
|
fltr.filter(eth_rpc, mockblock, tx, init_database)
|
||||||
|
|
||||||
assert mock.results.get('transfer') != None
|
assert mock.results.get('transfer') != None
|
||||||
assert mock.results['transfer']['destination_token'] == foo_token
|
assert mock.results['transfer']['destination_token'] == strip_0x(foo_token)
|
||||||
|
@ -17,6 +17,9 @@ from chainlib.eth.block import (
|
|||||||
block_by_number,
|
block_by_number,
|
||||||
Block,
|
Block,
|
||||||
)
|
)
|
||||||
|
from chainlib.eth.address import (
|
||||||
|
to_checksum_address,
|
||||||
|
)
|
||||||
from erc20_faucet import Faucet
|
from erc20_faucet import Faucet
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
strip_0x,
|
strip_0x,
|
||||||
@ -25,7 +28,6 @@ from hexathon import (
|
|||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.runnable.daemons.filters.register import RegistrationFilter
|
from cic_eth.runnable.daemons.filters.register import RegistrationFilter
|
||||||
from cic_eth.encode import tx_normalize
|
|
||||||
from cic_eth.queue.query import get_account_tx_local
|
from cic_eth.queue.query import get_account_tx_local
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@ -70,12 +72,13 @@ def test_register_filter(
|
|||||||
tx = Tx(tx_src, block=block, rcpt=rcpt)
|
tx = Tx(tx_src, block=block, rcpt=rcpt)
|
||||||
tx.apply_receipt(rcpt)
|
tx.apply_receipt(rcpt)
|
||||||
|
|
||||||
fltr = RegistrationFilter(default_chain_spec, add_0x(os.urandom(20).hex()), queue=None)
|
fltr = RegistrationFilter(default_chain_spec, to_checksum_address(os.urandom(20).hex()), queue=None)
|
||||||
t = fltr.filter(eth_rpc, block, tx, db_session=init_database)
|
t = fltr.filter(eth_rpc, block, tx, db_session=init_database)
|
||||||
assert t == None
|
assert t == None
|
||||||
|
|
||||||
fltr = RegistrationFilter(default_chain_spec, account_registry, queue=None)
|
fltr = RegistrationFilter(default_chain_spec, to_checksum_address(account_registry), queue=None)
|
||||||
t = fltr.filter(eth_rpc, block, tx, db_session=init_database)
|
t = fltr.filter(eth_rpc, block, tx, db_session=init_database)
|
||||||
|
logg.debug('t {}'.format(t))
|
||||||
|
|
||||||
t.get_leaf()
|
t.get_leaf()
|
||||||
assert t.successful()
|
assert t.successful()
|
||||||
@ -89,4 +92,4 @@ def test_register_filter(
|
|||||||
gift_tx = unpack(tx_raw_signed_bytes, default_chain_spec)
|
gift_tx = unpack(tx_raw_signed_bytes, default_chain_spec)
|
||||||
|
|
||||||
gift = Faucet.parse_give_to_request(gift_tx['data'])
|
gift = Faucet.parse_give_to_request(gift_tx['data'])
|
||||||
assert gift[0] == agent_roles['ALICE']
|
assert add_0x(gift[0]) == agent_roles['ALICE']
|
||||||
|
@ -19,6 +19,7 @@ from chainqueue.sql.query import get_account_tx
|
|||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.runnable.daemons.filters.transferauth import TransferAuthFilter
|
from cic_eth.runnable.daemons.filters.transferauth import TransferAuthFilter
|
||||||
|
from cic_eth.encode import tx_normalize
|
||||||
|
|
||||||
|
|
||||||
def test_filter_transferauth(
|
def test_filter_transferauth(
|
||||||
@ -66,7 +67,8 @@ def test_filter_transferauth(
|
|||||||
t.get_leaf()
|
t.get_leaf()
|
||||||
assert t.successful()
|
assert t.successful()
|
||||||
|
|
||||||
approve_txs = get_account_tx(default_chain_spec.asdict(), agent_roles['ALICE'], as_sender=True, session=init_database)
|
#approve_txs = get_account_tx(default_chain_spec.asdict(), agent_roles['ALICE'], as_sender=True, session=init_database)
|
||||||
|
approve_txs = get_account_tx(default_chain_spec.asdict(), tx_normalize.wallet_address(agent_roles['ALICE']), as_sender=True, session=init_database)
|
||||||
ks = list(approve_txs.keys())
|
ks = list(approve_txs.keys())
|
||||||
assert len(ks) == 1
|
assert len(ks) == 1
|
||||||
|
|
||||||
@ -76,4 +78,4 @@ def test_filter_transferauth(
|
|||||||
|
|
||||||
c = ERC20(default_chain_spec)
|
c = ERC20(default_chain_spec)
|
||||||
approve = c.parse_approve_request(approve_tx['data'])
|
approve = c.parse_approve_request(approve_tx['data'])
|
||||||
assert approve[0] == agent_roles['BOB']
|
assert approve[0] == strip_0x(agent_roles['BOB'])
|
||||||
|
@ -10,6 +10,7 @@ from cic_eth_registry.erc20 import ERC20Token
|
|||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from eth_accounts_index import AccountsIndex
|
from eth_accounts_index import AccountsIndex
|
||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
|
receipt,
|
||||||
transaction,
|
transaction,
|
||||||
)
|
)
|
||||||
from chainqueue.sql.state import (
|
from chainqueue.sql.state import (
|
||||||
@ -29,6 +30,7 @@ def test_account_api(
|
|||||||
init_database,
|
init_database,
|
||||||
init_eth_rpc,
|
init_eth_rpc,
|
||||||
account_registry,
|
account_registry,
|
||||||
|
cic_registry,
|
||||||
custodial_roles,
|
custodial_roles,
|
||||||
celery_session_worker,
|
celery_session_worker,
|
||||||
):
|
):
|
||||||
@ -49,6 +51,7 @@ def test_account_api_register(
|
|||||||
eth_rpc,
|
eth_rpc,
|
||||||
celery_session_worker,
|
celery_session_worker,
|
||||||
):
|
):
|
||||||
|
|
||||||
api = Api(str(default_chain_spec), callback_param='accounts', callback_task='cic_eth.callbacks.noop.noop', queue=None)
|
api = Api(str(default_chain_spec), callback_param='accounts', callback_task='cic_eth.callbacks.noop.noop', queue=None)
|
||||||
t = api.create_account('')
|
t = api.create_account('')
|
||||||
register_tx_hash = t.get_leaf()
|
register_tx_hash = t.get_leaf()
|
||||||
@ -69,12 +72,18 @@ def test_account_api_register(
|
|||||||
r = t.get_leaf()
|
r = t.get_leaf()
|
||||||
assert t.successful()
|
assert t.successful()
|
||||||
|
|
||||||
|
o = receipt(register_tx_hash)
|
||||||
|
r = eth_rpc.do(o)
|
||||||
|
assert r['status'] == 1
|
||||||
|
|
||||||
o = transaction(register_tx_hash)
|
o = transaction(register_tx_hash)
|
||||||
tx_src = eth_rpc.do(o)
|
tx_src = eth_rpc.do(o)
|
||||||
|
|
||||||
c = AccountsIndex(default_chain_spec)
|
c = AccountsIndex(default_chain_spec)
|
||||||
address = c.parse_add_request(tx_src['data'])
|
address = c.parse_add_request(tx_src['data'])
|
||||||
|
logg.debug('address {} '.format(address))
|
||||||
o = c.have(account_registry, address[0], sender_address=custodial_roles['CONTRACT_DEPLOYER'])
|
o = c.have(account_registry, address[0], sender_address=custodial_roles['CONTRACT_DEPLOYER'])
|
||||||
|
logg.debug('o {}'.format(o))
|
||||||
r = eth_rpc.do(o)
|
r = eth_rpc.do(o)
|
||||||
assert c.parse_have(r)
|
assert c.parse_have(r)
|
||||||
|
|
||||||
|
@ -3,18 +3,22 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
|
import pytest
|
||||||
from chainlib.eth.address import to_checksum_address
|
from chainlib.eth.address import to_checksum_address
|
||||||
|
from hexathon import add_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.api.api_task import Api
|
from cic_eth.api.api_task import Api
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def test_balance_simple_api(
|
def test_balance_simple_api(
|
||||||
default_chain_spec,
|
default_chain_spec,
|
||||||
init_database,
|
init_database,
|
||||||
cic_registry,
|
cic_registry,
|
||||||
foo_token,
|
foo_token,
|
||||||
|
register_lookups,
|
||||||
register_tokens,
|
register_tokens,
|
||||||
api,
|
api,
|
||||||
celery_session_worker,
|
celery_session_worker,
|
||||||
@ -22,7 +26,7 @@ def test_balance_simple_api(
|
|||||||
|
|
||||||
chain_str = str(default_chain_spec)
|
chain_str = str(default_chain_spec)
|
||||||
|
|
||||||
a = to_checksum_address('0x' + os.urandom(20).hex())
|
a = add_0x(to_checksum_address(os.urandom(20).hex()))
|
||||||
t = api.balance(a, 'FOO', include_pending=False)
|
t = api.balance(a, 'FOO', include_pending=False)
|
||||||
r = t.get_leaf()
|
r = t.get_leaf()
|
||||||
assert t.successful()
|
assert t.successful()
|
||||||
@ -36,6 +40,7 @@ def test_balance_complex_api(
|
|||||||
init_database,
|
init_database,
|
||||||
cic_registry,
|
cic_registry,
|
||||||
foo_token,
|
foo_token,
|
||||||
|
register_lookups,
|
||||||
register_tokens,
|
register_tokens,
|
||||||
api,
|
api,
|
||||||
celery_session_worker,
|
celery_session_worker,
|
||||||
@ -43,7 +48,7 @@ def test_balance_complex_api(
|
|||||||
|
|
||||||
chain_str = str(default_chain_spec)
|
chain_str = str(default_chain_spec)
|
||||||
|
|
||||||
a = to_checksum_address('0x' + os.urandom(20).hex())
|
a = add_0x(to_checksum_address(os.urandom(20).hex()))
|
||||||
t = api.balance(a, 'FOO', include_pending=True)
|
t = api.balance(a, 'FOO', include_pending=True)
|
||||||
r = t.get_leaf()
|
r = t.get_leaf()
|
||||||
assert t.successful()
|
assert t.successful()
|
||||||
|
@ -6,6 +6,7 @@ import pytest
|
|||||||
from chainlib.eth.nonce import RPCNonceOracle
|
from chainlib.eth.nonce import RPCNonceOracle
|
||||||
from eth_erc20 import ERC20
|
from eth_erc20 import ERC20
|
||||||
from chainlib.eth.tx import receipt
|
from chainlib.eth.tx import receipt
|
||||||
|
from hexathon import strip_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.api.api_task import Api
|
from cic_eth.api.api_task import Api
|
||||||
@ -23,7 +24,6 @@ from cic_eth.pytest.mock.filter import (
|
|||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail()
|
|
||||||
def test_list_tx(
|
def test_list_tx(
|
||||||
default_chain_spec,
|
default_chain_spec,
|
||||||
init_database,
|
init_database,
|
||||||
@ -34,8 +34,10 @@ def test_list_tx(
|
|||||||
agent_roles,
|
agent_roles,
|
||||||
foo_token,
|
foo_token,
|
||||||
register_tokens,
|
register_tokens,
|
||||||
|
register_lookups,
|
||||||
init_eth_tester,
|
init_eth_tester,
|
||||||
celery_session_worker,
|
celery_session_worker,
|
||||||
|
init_celery_tasks,
|
||||||
):
|
):
|
||||||
|
|
||||||
tx_hashes = []
|
tx_hashes = []
|
||||||
@ -63,13 +65,16 @@ def test_list_tx(
|
|||||||
o = receipt(tx_hash_hex)
|
o = receipt(tx_hash_hex)
|
||||||
r = eth_rpc.do(o)
|
r = eth_rpc.do(o)
|
||||||
assert r['status'] == 1
|
assert r['status'] == 1
|
||||||
|
|
||||||
a = r['block_number']
|
a = r['block_number']
|
||||||
block_filter.add(a.to_bytes(4, 'big'))
|
ab = a.to_bytes(4, 'big')
|
||||||
|
block_filter.add(ab)
|
||||||
|
|
||||||
a = r['block_number'] + r['transaction_index']
|
bb = r['transaction_index'].to_bytes(4, 'big')
|
||||||
tx_filter.add(a.to_bytes(4, 'big'))
|
cb = ab + bb
|
||||||
|
tx_filter.add(cb)
|
||||||
|
|
||||||
tx_hashes.append(tx_hash_hex)
|
tx_hashes.append(strip_0x(tx_hash_hex))
|
||||||
|
|
||||||
# external tx two
|
# external tx two
|
||||||
Nonce.next(agent_roles['ALICE'], 'foo', session=init_database)
|
Nonce.next(agent_roles['ALICE'], 'foo', session=init_database)
|
||||||
@ -83,26 +88,29 @@ def test_list_tx(
|
|||||||
o = receipt(tx_hash_hex)
|
o = receipt(tx_hash_hex)
|
||||||
r = eth_rpc.do(o)
|
r = eth_rpc.do(o)
|
||||||
assert r['status'] == 1
|
assert r['status'] == 1
|
||||||
|
|
||||||
a = r['block_number']
|
a = r['block_number']
|
||||||
block_filter.add(a.to_bytes(4, 'big'))
|
ab = a.to_bytes(4, 'big')
|
||||||
|
block_filter.add(ab)
|
||||||
|
|
||||||
a = r['block_number'] + r['transaction_index']
|
bb = r['transaction_index'].to_bytes(4, 'big')
|
||||||
tx_filter.add(a.to_bytes(4, 'big'))
|
cb = ab + bb
|
||||||
|
tx_filter.add(cb)
|
||||||
|
|
||||||
tx_hashes.append(tx_hash_hex)
|
tx_hashes.append(strip_0x(tx_hash_hex))
|
||||||
|
|
||||||
init_eth_tester.mine_blocks(28)
|
init_eth_tester.mine_blocks(28)
|
||||||
|
|
||||||
# custodial tx 1
|
# custodial tx 1
|
||||||
api = Api(str(default_chain_spec), queue=None)
|
api = Api(str(default_chain_spec), queue=None)
|
||||||
t = api.transfer(agent_roles['ALICE'], agent_roles['CAROL'], 64, 'FOO') #, 'blinky')
|
t = api.transfer(agent_roles['ALICE'], agent_roles['CAROL'], 64, 'FOO')
|
||||||
r = t.get_leaf()
|
r = t.get_leaf()
|
||||||
assert t.successful()
|
assert t.successful()
|
||||||
tx_hashes.append(r)
|
tx_hashes.append(r)
|
||||||
|
|
||||||
# custodial tx 2
|
# custodial tx 2
|
||||||
api = Api(str(default_chain_spec), queue=None)
|
api = Api(str(default_chain_spec), queue=None)
|
||||||
t = api.transfer(agent_roles['ALICE'], agent_roles['DAVE'], 16, 'FOO') #, 'blinky')
|
t = api.transfer(agent_roles['ALICE'], agent_roles['DAVE'], 16, 'FOO')
|
||||||
r = t.get_leaf()
|
r = t.get_leaf()
|
||||||
assert t.successful()
|
assert t.successful()
|
||||||
tx_hashes.append(r)
|
tx_hashes.append(r)
|
||||||
@ -117,7 +125,8 @@ def test_list_tx(
|
|||||||
assert len(r) == 3
|
assert len(r) == 3
|
||||||
logg.debug('rrrr {}'.format(r))
|
logg.debug('rrrr {}'.format(r))
|
||||||
|
|
||||||
|
logg.debug('testing against hashes {}'.format(tx_hashes))
|
||||||
for tx in r:
|
for tx in r:
|
||||||
logg.debug('have tx {}'.format(tx))
|
logg.debug('have tx {}'.format(tx))
|
||||||
tx_hashes.remove(tx['hash'])
|
tx_hashes.remove(strip_0x(tx['hash']))
|
||||||
assert len(tx_hashes) == 1
|
assert len(tx_hashes) == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user