cic-eth: Integrate transaction list queries
This commit is contained in:
@@ -15,12 +15,14 @@ def celery_includes():
|
||||
'cic_eth.eth.token',
|
||||
'cic_eth.eth.request',
|
||||
'cic_eth.eth.tx',
|
||||
'cic_eth.ext.tx',
|
||||
'cic_eth.queue.tx',
|
||||
'cic_eth.admin.ctrl',
|
||||
'cic_eth.admin.nonce',
|
||||
'cic_eth.eth.account',
|
||||
'cic_eth.callbacks.noop',
|
||||
'cic_eth.callbacks.http',
|
||||
'tests.mock.filter',
|
||||
]
|
||||
|
||||
|
||||
|
||||
92
apps/cic-eth/tests/functional/test_list.py
Normal file
92
apps/cic-eth/tests/functional/test_list.py
Normal file
@@ -0,0 +1,92 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
# local imports
|
||||
from cic_eth.api.api_task import Api
|
||||
from cic_eth.eth.token import TokenTxFactory
|
||||
from cic_eth.eth.task import sign_tx
|
||||
from tests.mock.filter import (
|
||||
block_filter,
|
||||
tx_filter,
|
||||
)
|
||||
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_list_tx(
|
||||
default_chain_spec,
|
||||
default_chain_registry,
|
||||
init_database,
|
||||
init_rpc,
|
||||
init_w3,
|
||||
init_eth_tester,
|
||||
dummy_token_gifted,
|
||||
cic_registry,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
tx_hashes = []
|
||||
# external tx
|
||||
init_eth_tester.mine_blocks(13)
|
||||
txf = TokenTxFactory(init_w3.eth.accounts[0], init_rpc)
|
||||
tx = txf.transfer(dummy_token_gifted, init_w3.eth.accounts[1], 3000, default_chain_spec)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx, str(default_chain_spec))
|
||||
tx_hashes.append(tx_hash_hex)
|
||||
init_w3.eth.sendRawTransaction(tx_signed_raw_hex)
|
||||
# add to filter
|
||||
rcpt = init_w3.eth.getTransactionReceipt(tx_hash_hex)
|
||||
a = rcpt['blockNumber']
|
||||
block_filter.add(a.to_bytes(4, 'big'))
|
||||
a = rcpt['blockNumber'] + rcpt['transactionIndex']
|
||||
tx_filter.add(a.to_bytes(4, 'big'))
|
||||
|
||||
# external tx
|
||||
init_eth_tester.mine_blocks(28)
|
||||
txf = TokenTxFactory(init_w3.eth.accounts[0], init_rpc)
|
||||
tx = txf.transfer(dummy_token_gifted, init_w3.eth.accounts[1], 4000, default_chain_spec)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx, str(default_chain_spec))
|
||||
tx_hashes.append(tx_hash_hex)
|
||||
init_w3.eth.sendRawTransaction(tx_signed_raw_hex)
|
||||
# add to filter
|
||||
rcpt = init_w3.eth.getTransactionReceipt(tx_hash_hex)
|
||||
a = rcpt['blockNumber']
|
||||
block_filter.add(a.to_bytes(4, 'big'))
|
||||
a = rcpt['blockNumber'] + rcpt['transactionIndex']
|
||||
tx_filter.add(a.to_bytes(4, 'big'))
|
||||
|
||||
# custodial tx
|
||||
init_eth_tester.mine_blocks(3)
|
||||
txf = TokenTxFactory(init_w3.eth.accounts[0], init_rpc)
|
||||
api = Api(str(default_chain_spec), queue=None)
|
||||
t = api.transfer(init_w3.eth.accounts[0], init_w3.eth.accounts[1], 1000, 'DUM')
|
||||
t.get()
|
||||
tx_hash_hex = None
|
||||
for c in t.collect():
|
||||
tx_hash_hex = c[1]
|
||||
assert t.successful()
|
||||
tx_hashes.append(tx_hash_hex)
|
||||
|
||||
# custodial tx
|
||||
init_eth_tester.mine_blocks(6)
|
||||
api = Api(str(default_chain_spec), queue=None)
|
||||
t = api.transfer(init_w3.eth.accounts[0], init_w3.eth.accounts[1], 2000, 'DUM')
|
||||
t.get()
|
||||
tx_hash_hex = None
|
||||
for c in t.collect():
|
||||
tx_hash_hex = c[1]
|
||||
assert t.successful()
|
||||
tx_hashes.append(tx_hash_hex)
|
||||
|
||||
# test the api
|
||||
t = api.list(init_w3.eth.accounts[1], external_task='tests.mock.filter.filter')
|
||||
r = t.get()
|
||||
for c in t.collect():
|
||||
r = c[1]
|
||||
assert t.successful()
|
||||
|
||||
assert len(r) == 4
|
||||
for tx in r:
|
||||
logg.debug('have tx {}'.format(r))
|
||||
tx_hashes.remove(tx['hash'])
|
||||
assert len(tx_hashes) == 0
|
||||
1
apps/cic-eth/tests/mock/__init__.py
Normal file
1
apps/cic-eth/tests/mock/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .filter import *
|
||||
22
apps/cic-eth/tests/mock/filter.py
Normal file
22
apps/cic-eth/tests/mock/filter.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# third-party imports
|
||||
import celery
|
||||
import moolb
|
||||
|
||||
celery_app = celery.current_app
|
||||
|
||||
block_filter = moolb.Bloom(1024, 3)
|
||||
tx_filter = moolb.Bloom(1024, 3)
|
||||
lo = 0
|
||||
hi = 100
|
||||
|
||||
|
||||
@celery_app.task()
|
||||
def filter(address, offset, limit):
|
||||
return {
|
||||
'alg': 'sha256',
|
||||
'high': hi,
|
||||
'low': lo,
|
||||
'block_filter': block_filter.to_bytes().hex(),
|
||||
'blocktx_filter': tx_filter.to_bytes().hex(),
|
||||
'filter_rounds': 3,
|
||||
}
|
||||
109
apps/cic-eth/tests/unit/ext/test_ext_tx.py
Normal file
109
apps/cic-eth/tests/unit/ext/test_ext_tx.py
Normal file
@@ -0,0 +1,109 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
import celery
|
||||
import moolb
|
||||
|
||||
# local imports
|
||||
from cic_eth.eth.token import TokenTxFactory
|
||||
from cic_eth.eth.task import sign_tx
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
# TODO: This test fails when not run alone. Identify which fixture leaves a dirty state
|
||||
def test_filter_process(
|
||||
init_rpc,
|
||||
default_chain_spec,
|
||||
default_chain_registry,
|
||||
celery_session_worker,
|
||||
init_eth_tester,
|
||||
init_w3,
|
||||
dummy_token_gifted,
|
||||
cic_registry,
|
||||
):
|
||||
|
||||
b = moolb.Bloom(1024, 3)
|
||||
t = moolb.Bloom(1024, 3)
|
||||
|
||||
tx_hashes = []
|
||||
# external tx
|
||||
init_eth_tester.mine_blocks(13)
|
||||
txf = TokenTxFactory(init_w3.eth.accounts[0], init_rpc)
|
||||
tx = txf.transfer(dummy_token_gifted, init_w3.eth.accounts[1], 3000, default_chain_spec)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx, str(default_chain_spec))
|
||||
tx_hashes.append(tx_hash_hex)
|
||||
init_w3.eth.sendRawTransaction(tx_signed_raw_hex)
|
||||
# add to filter
|
||||
rcpt = init_w3.eth.getTransactionReceipt(tx_hash_hex)
|
||||
a = rcpt['blockNumber']
|
||||
b.add(a.to_bytes(4, 'big'))
|
||||
a = rcpt['blockNumber'] + rcpt['transactionIndex']
|
||||
t.add(a.to_bytes(4, 'big'))
|
||||
|
||||
# external tx
|
||||
init_eth_tester.mine_blocks(28)
|
||||
txf = TokenTxFactory(init_w3.eth.accounts[0], init_rpc)
|
||||
tx = txf.transfer(dummy_token_gifted, init_w3.eth.accounts[1], 4000, default_chain_spec)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx, str(default_chain_spec))
|
||||
tx_hashes.append(tx_hash_hex)
|
||||
init_w3.eth.sendRawTransaction(tx_signed_raw_hex)
|
||||
# add to filter
|
||||
rcpt = init_w3.eth.getTransactionReceipt(tx_hash_hex)
|
||||
a = rcpt['blockNumber']
|
||||
b.add(a.to_bytes(4, 'big'))
|
||||
a = rcpt['blockNumber'] + rcpt['transactionIndex']
|
||||
t.add(a.to_bytes(4, 'big'))
|
||||
|
||||
# init_eth_tester.mine_blocks(13)
|
||||
# tx_hash_one = init_w3.eth.sendTransaction({
|
||||
# 'from': init_w3.eth.accounts[2],
|
||||
# 'to': init_w3.eth.accounts[1],
|
||||
# 'value': 1024,
|
||||
# })
|
||||
# rcpt = init_w3.eth.getTransactionReceipt(tx_hash_one)
|
||||
# a = rcpt['blockNumber']
|
||||
# b.add(a.to_bytes(4, 'big'))
|
||||
# a = rcpt['blockNumber'] + rcpt['transactionIndex']
|
||||
# t.add(a.to_bytes(4, 'big'))
|
||||
#
|
||||
# init_eth_tester.mine_blocks(28)
|
||||
# tx_hash_two = init_w3.eth.sendTransaction({
|
||||
# 'from': init_w3.eth.accounts[3],
|
||||
# 'to': init_w3.eth.accounts[1],
|
||||
# 'value': 2048,
|
||||
# })
|
||||
# rcpt = init_w3.eth.getTransactionReceipt(tx_hash_two)
|
||||
# a = rcpt['blockNumber']
|
||||
# b.add(a.to_bytes(4, 'big'))
|
||||
# a = rcpt['blockNumber'] + rcpt['transactionIndex']
|
||||
# t.add(a.to_bytes(4, 'big'))
|
||||
|
||||
init_eth_tester.mine_blocks(10)
|
||||
|
||||
o = {
|
||||
'alg': 'sha256',
|
||||
'filter_rounds': 3,
|
||||
'low': 0,
|
||||
'high': 50,
|
||||
'block_filter': b.to_bytes().hex(),
|
||||
'blocktx_filter': t.to_bytes().hex(),
|
||||
}
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.ext.tx.list_tx_by_bloom',
|
||||
[
|
||||
o,
|
||||
init_w3.eth.accounts[1],
|
||||
str(default_chain_spec),
|
||||
],
|
||||
queue=None
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
assert len(r) == 2
|
||||
for tx_hash in r.keys():
|
||||
tx_hashes.remove(tx_hash)
|
||||
assert len(tx_hashes) == 0
|
||||
Reference in New Issue
Block a user