adding cic-eth as sub dir
This commit is contained in:
128
apps/cic-eth/tests/tasks/test_account.py
Normal file
128
apps/cic-eth/tests/tasks/test_account.py
Normal file
@@ -0,0 +1,128 @@
|
||||
# standard imports
|
||||
import os
|
||||
import logging
|
||||
import time
|
||||
|
||||
# third-party imports
|
||||
import pytest
|
||||
import web3
|
||||
import celery
|
||||
|
||||
# local imports
|
||||
from cic_eth.error import OutOfGasError
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from cic_eth.db.models.base import SessionBase
|
||||
from cic_eth.db.enum import StatusEnum
|
||||
from cic_eth.db.enum import StatusEnum
|
||||
from cic_eth.db.models.nonce import Nonce
|
||||
from cic_eth.db.models.role import AccountRole
|
||||
from cic_eth.eth.account import AccountTxFactory
|
||||
|
||||
logg = logging.getLogger() #__name__)
|
||||
|
||||
|
||||
def test_create_account(
|
||||
default_chain_spec,
|
||||
init_w3,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.account.create',
|
||||
[
|
||||
'foo',
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
logg.debug('got account {}'.format(r))
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Nonce).filter(Nonce.address_hex==r)
|
||||
o = q.first()
|
||||
logg.debug('oooo s {}'.format(o))
|
||||
session.close()
|
||||
assert o != None
|
||||
assert o.nonce == 0
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.account.have',
|
||||
[
|
||||
r,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
assert r == t.get()
|
||||
|
||||
|
||||
def test_register_account(
|
||||
default_chain_spec,
|
||||
accounts_registry,
|
||||
init_database,
|
||||
init_eth_tester,
|
||||
init_w3,
|
||||
cic_registry,
|
||||
celery_session_worker,
|
||||
eth_empty_accounts,
|
||||
):
|
||||
|
||||
logg.debug('chainspec {}'.format(str(default_chain_spec)))
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.account.register',
|
||||
[
|
||||
eth_empty_accounts[0],
|
||||
str(default_chain_spec),
|
||||
init_w3.eth.accounts[0],
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
address = t.get()
|
||||
r = t.collect()
|
||||
t.successful()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
o = session.query(Otx).first()
|
||||
tx_signed_hex = o.signed_tx
|
||||
session.close()
|
||||
|
||||
s_send = celery.signature(
|
||||
'cic_eth.eth.tx.send',
|
||||
[
|
||||
[tx_signed_hex],
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s_send.apply_async()
|
||||
address = t.get()
|
||||
r = t.collect()
|
||||
t.successful()
|
||||
|
||||
init_eth_tester.mine_block()
|
||||
|
||||
assert accounts_registry.have(eth_empty_accounts[0])
|
||||
|
||||
|
||||
def test_role_task(
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
default_chain_spec,
|
||||
):
|
||||
|
||||
address = '0x' + os.urandom(20).hex()
|
||||
role = AccountRole.set('foo', address)
|
||||
init_database.add(role)
|
||||
init_database.commit()
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.account.role',
|
||||
[
|
||||
address,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
assert r == 'foo'
|
||||
45
apps/cic-eth/tests/tasks/test_convert.py
Normal file
45
apps/cic-eth/tests/tasks/test_convert.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import celery
|
||||
|
||||
from cic_eth.db import TxConvertTransfer
|
||||
from cic_eth.eth.bancor import BancorTxFactory
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_transfer_after_convert(
|
||||
init_w3,
|
||||
init_database,
|
||||
cic_registry,
|
||||
bancor_tokens,
|
||||
bancor_registry,
|
||||
default_chain_spec,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
tx_hash = os.urandom(32).hex()
|
||||
txct = TxConvertTransfer(tx_hash, init_w3.eth.accounts[1], default_chain_spec)
|
||||
init_database.add(txct)
|
||||
init_database.commit()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.bancor.transfer_converted',
|
||||
[
|
||||
[
|
||||
{
|
||||
'address': bancor_tokens[0],
|
||||
},
|
||||
],
|
||||
init_w3.eth.accounts[0],
|
||||
init_w3.eth.accounts[1],
|
||||
1024,
|
||||
tx_hash,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
t.collect()
|
||||
assert t.successful()
|
||||
66
apps/cic-eth/tests/tasks/test_faucet.py
Normal file
66
apps/cic-eth/tests/tasks/test_faucet.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# standard imports
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
import celery
|
||||
|
||||
# local imports
|
||||
from cic_eth.eth.account import unpack_gift
|
||||
from cic_eth.eth.factory import TxFactory
|
||||
from cic_eth.eth.util import unpack_signed_raw_tx
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
script_dir = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def test_faucet(
|
||||
default_chain_spec,
|
||||
faucet_amount,
|
||||
faucet,
|
||||
eth_empty_accounts,
|
||||
bancor_tokens,
|
||||
w3_account_roles,
|
||||
w3_account_token_owners,
|
||||
init_w3,
|
||||
solidity_abis,
|
||||
init_eth_tester,
|
||||
cic_registry,
|
||||
celery_session_worker,
|
||||
init_database,
|
||||
):
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.account.gift',
|
||||
[
|
||||
init_w3.eth.accounts[7],
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
s_send = celery.signature(
|
||||
'cic_eth.eth.tx.send',
|
||||
[
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
s.link(s_send)
|
||||
t = s.apply_async()
|
||||
signed_tx = t.get()
|
||||
for r in t.collect():
|
||||
logg.debug('result {}'.format(r))
|
||||
|
||||
assert t.successful()
|
||||
|
||||
tx = unpack_signed_raw_tx(bytes.fromhex(signed_tx[0][2:]), default_chain_spec.chain_id())
|
||||
giveto = unpack_gift(tx['data'])
|
||||
assert giveto['to'] == init_w3.eth.accounts[7]
|
||||
|
||||
init_eth_tester.mine_block()
|
||||
|
||||
token = init_w3.eth.contract(abi=solidity_abis['ERC20'], address=bancor_tokens[0])
|
||||
|
||||
balance = token.functions.balanceOf(init_w3.eth.accounts[7]).call()
|
||||
|
||||
assert balance == faucet_amount
|
||||
246
apps/cic-eth/tests/tasks/test_gas_tasks.py
Normal file
246
apps/cic-eth/tests/tasks/test_gas_tasks.py
Normal file
@@ -0,0 +1,246 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import time
|
||||
|
||||
# third-party imports
|
||||
import pytest
|
||||
import celery
|
||||
from web3.exceptions import ValidationError
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.enum import StatusEnum
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from cic_eth.db.models.tx import TxCache
|
||||
from cic_eth.db.models.base import SessionBase
|
||||
from cic_eth.eth.task import sign_and_register_tx
|
||||
from cic_eth.eth.task import sign_tx
|
||||
from cic_eth.eth.token import TokenTxFactory
|
||||
from cic_eth.eth.token import TxFactory
|
||||
from cic_eth.eth.token import cache_transfer_data
|
||||
from cic_eth.eth.rpc import RpcClient
|
||||
from cic_eth.queue.tx import create as queue_create
|
||||
from cic_eth.error import OutOfGasError
|
||||
from cic_eth.db.models.role import AccountRole
|
||||
from cic_eth.error import AlreadyFillingGasError
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_refill_gas(
|
||||
default_chain_spec,
|
||||
init_eth_tester,
|
||||
init_rpc,
|
||||
init_database,
|
||||
cic_registry,
|
||||
init_eth_account_roles,
|
||||
celery_session_worker,
|
||||
eth_empty_accounts,
|
||||
):
|
||||
|
||||
provider_address = AccountRole.get_address('GAS_GIFTER')
|
||||
receiver_address = eth_empty_accounts[0]
|
||||
|
||||
c = init_rpc
|
||||
refill_amount = c.refill_amount()
|
||||
|
||||
balance = init_rpc.w3.eth.getBalance(receiver_address)
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.refill_gas',
|
||||
[
|
||||
receiver_address,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
t.collect()
|
||||
assert t.successful()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.send',
|
||||
[
|
||||
[r],
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
t.collect()
|
||||
assert t.successful()
|
||||
|
||||
init_eth_tester.mine_block()
|
||||
balance_new = init_rpc.w3.eth.getBalance(receiver_address)
|
||||
assert balance_new == (balance + refill_amount)
|
||||
|
||||
# Verify that entry is added in TxCache
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Otx)
|
||||
q = q.join(TxCache)
|
||||
q = q.filter(TxCache.recipient==receiver_address)
|
||||
r = q.first()
|
||||
|
||||
assert r.status == StatusEnum.SENT
|
||||
|
||||
|
||||
def test_refill_deduplication(
|
||||
default_chain_spec,
|
||||
init_rpc,
|
||||
init_database,
|
||||
init_eth_account_roles,
|
||||
cic_registry,
|
||||
celery_session_worker,
|
||||
eth_empty_accounts,
|
||||
):
|
||||
|
||||
provider_address = AccountRole.get_address('ETH_GAS_PROVIDER_ADDRESS')
|
||||
receiver_address = eth_empty_accounts[0]
|
||||
|
||||
c = init_rpc
|
||||
refill_amount = c.refill_amount()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.refill_gas',
|
||||
[
|
||||
receiver_address,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
for e in t.collect():
|
||||
pass
|
||||
assert t.successful()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.refill_gas',
|
||||
[
|
||||
receiver_address,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
|
||||
t = s.apply_async()
|
||||
with pytest.raises(AlreadyFillingGasError):
|
||||
t.get()
|
||||
|
||||
|
||||
def test_check_gas(
|
||||
default_chain_spec,
|
||||
init_eth_tester,
|
||||
init_w3,
|
||||
init_rpc,
|
||||
eth_empty_accounts,
|
||||
init_database,
|
||||
cic_registry,
|
||||
celery_session_worker,
|
||||
bancor_registry,
|
||||
bancor_tokens,
|
||||
):
|
||||
|
||||
provider_address = init_w3.eth.accounts[0]
|
||||
gas_receiver_address = eth_empty_accounts[0]
|
||||
token_receiver_address = init_w3.eth.accounts[1]
|
||||
|
||||
c = init_rpc
|
||||
txf = TokenTxFactory(gas_receiver_address, c)
|
||||
tx_transfer = txf.transfer(bancor_tokens[0], token_receiver_address, 42, default_chain_spec)
|
||||
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_and_register_tx(tx_transfer, str(default_chain_spec), None)
|
||||
|
||||
gas_price = c.gas_price()
|
||||
gas_limit = tx_transfer['gas']
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.check_gas',
|
||||
[
|
||||
[tx_hash_hex],
|
||||
str(default_chain_spec),
|
||||
[],
|
||||
gas_receiver_address,
|
||||
gas_limit * gas_price,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
with pytest.raises(OutOfGasError):
|
||||
r = t.get()
|
||||
#assert len(r) == 0
|
||||
|
||||
time.sleep(1)
|
||||
t.collect()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Otx)
|
||||
q = q.filter(Otx.tx_hash==tx_hash_hex)
|
||||
r = q.first()
|
||||
session.close()
|
||||
assert r.status == StatusEnum.WAITFORGAS
|
||||
|
||||
|
||||
def test_resend_with_higher_gas(
|
||||
default_chain_spec,
|
||||
init_eth_tester,
|
||||
init_w3,
|
||||
init_rpc,
|
||||
init_database,
|
||||
cic_registry,
|
||||
celery_session_worker,
|
||||
bancor_registry,
|
||||
bancor_tokens,
|
||||
):
|
||||
|
||||
c = init_rpc
|
||||
txf = TokenTxFactory(init_w3.eth.accounts[0], c)
|
||||
|
||||
tx_transfer = txf.transfer(bancor_tokens[0], init_w3.eth.accounts[1], 1024, default_chain_spec)
|
||||
logg.debug('txtransfer {}'.format(tx_transfer))
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx_transfer, str(default_chain_spec))
|
||||
logg.debug('signed raw {}'.format(tx_signed_raw_hex))
|
||||
queue_create(
|
||||
tx_transfer['nonce'],
|
||||
tx_transfer['from'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
str(default_chain_spec),
|
||||
)
|
||||
logg.debug('create {}'.format(tx_transfer['from']))
|
||||
cache_transfer_data(
|
||||
tx_hash_hex,
|
||||
tx_transfer, #_signed_raw_hex,
|
||||
)
|
||||
|
||||
s_resend = celery.signature(
|
||||
'cic_eth.eth.tx.resend_with_higher_gas',
|
||||
[
|
||||
tx_hash_hex,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s_resend.apply_async()
|
||||
|
||||
i = 0
|
||||
for r in t.collect():
|
||||
logg.debug('{} {}'.format(i, r[0].get()))
|
||||
i += 1
|
||||
|
||||
assert t.successful()
|
||||
|
||||
#
|
||||
#def test_resume(
|
||||
# default_chain_spec,
|
||||
# init_eth_tester,
|
||||
# w3,
|
||||
# w3_account_roles,
|
||||
# init_database,
|
||||
# bancor_tokens,
|
||||
# celery_session_worker,
|
||||
# eth_empty_accounts,
|
||||
# ):
|
||||
#
|
||||
# txf = TokenTxFactory()
|
||||
#
|
||||
# tx_transfer = txf.transfer(bancor_tokens[0], eth_empty_accounts[1], 1024)
|
||||
# (tx_hash_hex, tx_signed_raw_hex) = sign_and_register_tx(tx_transfer)
|
||||
#
|
||||
# resume_tx()
|
||||
355
apps/cic-eth/tests/tasks/test_lock_tasks.py
Normal file
355
apps/cic-eth/tests/tasks/test_lock_tasks.py
Normal file
@@ -0,0 +1,355 @@
|
||||
# standard imports
|
||||
import os
|
||||
|
||||
# third-party imports
|
||||
import celery
|
||||
import pytest
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.lock import Lock
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from cic_eth.db.enum import LockEnum
|
||||
from cic_eth.error import LockedError
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'task_postfix,flag_enum',
|
||||
[
|
||||
('send', LockEnum.SEND),
|
||||
('queue', LockEnum.QUEUE),
|
||||
],
|
||||
)
|
||||
def test_lock_task(
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
default_chain_spec,
|
||||
task_postfix,
|
||||
flag_enum,
|
||||
):
|
||||
|
||||
chain_str = str(default_chain_spec)
|
||||
address = '0x' + os.urandom(20).hex()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.lock_{}'.format(task_postfix),
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
assert t.successful()
|
||||
assert r == 'foo'
|
||||
|
||||
q = init_database.query(Lock)
|
||||
q = q.filter(Lock.address==address)
|
||||
lock = q.first()
|
||||
assert lock != None
|
||||
assert lock.flags == flag_enum
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.unlock_{}'.format(task_postfix),
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
assert t.successful()
|
||||
assert r == 'foo'
|
||||
|
||||
q = init_database.query(Lock)
|
||||
q = q.filter(Lock.address==address)
|
||||
lock = q.first()
|
||||
assert lock == None
|
||||
|
||||
|
||||
def test_lock_check_task(
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
default_chain_spec,
|
||||
):
|
||||
|
||||
chain_str = str(default_chain_spec)
|
||||
address = '0x' + os.urandom(20).hex()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.lock_send',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.lock_queue',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.check_lock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
LockEnum.SEND,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
|
||||
with pytest.raises(LockedError):
|
||||
r = t.get()
|
||||
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.check_lock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
LockEnum.CREATE,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
assert r == 'foo'
|
||||
|
||||
|
||||
def test_lock_arbitrary_task(
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
default_chain_spec,
|
||||
):
|
||||
|
||||
chain_str = str(default_chain_spec)
|
||||
address = '0x' + os.urandom(20).hex()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.lock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address,
|
||||
LockEnum.SEND | LockEnum.QUEUE,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
assert r == 'foo'
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.check_lock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
LockEnum.SEND | LockEnum.QUEUE,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
with pytest.raises(LockedError):
|
||||
r = t.get()
|
||||
assert r == 'foo'
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.unlock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address,
|
||||
LockEnum.SEND,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
assert r == 'foo'
|
||||
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.check_lock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
LockEnum.SEND,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.unlock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
assert r == 'foo'
|
||||
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.check_lock',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
LockEnum.QUEUE,
|
||||
address,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
|
||||
def test_lock_list(
|
||||
default_chain_spec,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
chain_str = str(default_chain_spec)
|
||||
|
||||
# Empty list of no lock set
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.get_lock',
|
||||
[],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
assert len(r) == 0
|
||||
|
||||
# One element if lock set and no link with otx
|
||||
tx_hash = '0x' + os.urandom(32).hex()
|
||||
address_foo = '0x' + os.urandom(20).hex()
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.lock_send',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address_foo,
|
||||
tx_hash,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.get_lock',
|
||||
[],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
assert len(r) == 1
|
||||
assert r[0]['tx_hash'] == None
|
||||
assert r[0]['address'] == address_foo
|
||||
assert r[0]['flags'] == LockEnum.SEND
|
||||
|
||||
# One element if lock set and link with otx, tx_hash now available
|
||||
signed_tx = '0x' + os.urandom(128).hex()
|
||||
otx = Otx.add(
|
||||
0,
|
||||
address_foo,
|
||||
tx_hash,
|
||||
signed_tx,
|
||||
)
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.unlock_send',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address_foo,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.lock_send',
|
||||
[
|
||||
'foo',
|
||||
chain_str,
|
||||
address_foo,
|
||||
tx_hash,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.get_lock',
|
||||
[],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
assert r[0]['tx_hash'] == tx_hash
|
||||
|
||||
|
||||
# Two elements if two locks in place
|
||||
address_bar = '0x' + os.urandom(20).hex()
|
||||
tx_hash = '0x' + os.urandom(32).hex()
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.ctrl.lock_queue',
|
||||
[
|
||||
'bar',
|
||||
chain_str,
|
||||
address_bar,
|
||||
tx_hash,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.get_lock',
|
||||
[],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
assert len(r) == 2
|
||||
|
||||
# One element if filtered by address
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.get_lock',
|
||||
[
|
||||
address_bar,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
assert len(r) == 1
|
||||
assert r[0]['tx_hash'] == None
|
||||
assert r[0]['address'] == address_bar
|
||||
assert r[0]['flags'] == LockEnum.QUEUE
|
||||
|
||||
address_bogus = '0x' + os.urandom(20).hex()
|
||||
# No elements if filtered by non-existent address
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.get_lock',
|
||||
[
|
||||
address_bogus,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
49
apps/cic-eth/tests/tasks/test_nonce_tasks.py
Normal file
49
apps/cic-eth/tests/tasks/test_nonce_tasks.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# third-party imports
|
||||
import celery
|
||||
|
||||
# local imports
|
||||
from cic_eth.admin.nonce import shift_nonce
|
||||
from cic_eth.queue.tx import create as queue_create
|
||||
from cic_eth.eth.tx import otx_cache_parse_tx
|
||||
from cic_eth.eth.task import sign_tx
|
||||
|
||||
def test_shift_nonce(
|
||||
default_chain_spec,
|
||||
init_database,
|
||||
init_w3,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
chain_str = str(default_chain_spec)
|
||||
|
||||
tx_hashes = []
|
||||
for i in range(5):
|
||||
tx = {
|
||||
'from': init_w3.eth.accounts[0],
|
||||
'to': init_w3.eth.accounts[i],
|
||||
'nonce': i,
|
||||
'gas': 21000,
|
||||
'gasPrice': 1000000,
|
||||
'value': 128,
|
||||
'chainId': default_chain_spec.chain_id(),
|
||||
'data': '',
|
||||
}
|
||||
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx, chain_str)
|
||||
queue_create(tx['nonce'], init_w3.eth.accounts[0], tx_hash_hex, tx_signed_raw_hex, chain_str)
|
||||
otx_cache_parse_tx(tx_hash_hex, tx_signed_raw_hex, chain_str)
|
||||
tx_hashes.append(tx_hash_hex)
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.admin.nonce.shift_nonce',
|
||||
[
|
||||
chain_str,
|
||||
tx_hashes[2],
|
||||
],
|
||||
queue=None,
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
for _ in t.collect():
|
||||
pass
|
||||
assert t.successful()
|
||||
174
apps/cic-eth/tests/tasks/test_otx_tasks.py
Normal file
174
apps/cic-eth/tests/tasks/test_otx_tasks.py
Normal file
@@ -0,0 +1,174 @@
|
||||
# standard imports
|
||||
import os
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
import pytest
|
||||
import celery
|
||||
from cic_registry import zero_address
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from cic_eth.db.models.tx import TxCache
|
||||
from cic_eth.db.enum import StatusEnum
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
# TODO: Refactor to use test vector decorator
|
||||
def test_status_success(
|
||||
init_w3,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
tx_hash = '0x' + os.urandom(32).hex()
|
||||
signed_tx = '0x' + os.urandom(128).hex()
|
||||
account = '0x' + os.urandom(20).hex()
|
||||
|
||||
otx = Otx(0, init_w3.eth.accounts[0], tx_hash, signed_tx)
|
||||
init_database.add(otx)
|
||||
init_database.commit()
|
||||
assert otx.status == StatusEnum.PENDING
|
||||
|
||||
txc = TxCache(tx_hash, account, init_w3.eth.accounts[0], zero_address, zero_address, 13, 13)
|
||||
init_database.add(txc)
|
||||
init_database.commit()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_sent_status',
|
||||
[tx_hash],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.SENT
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_final_status',
|
||||
[tx_hash, 13],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.SUCCESS
|
||||
|
||||
|
||||
def test_status_tempfail_resend(
|
||||
init_w3,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
tx_hash = '0x' + os.urandom(32).hex()
|
||||
signed_tx = '0x' + os.urandom(128).hex()
|
||||
account = '0x' + os.urandom(20).hex()
|
||||
|
||||
otx = Otx(0, init_w3.eth.accounts[0], tx_hash, signed_tx)
|
||||
init_database.add(otx)
|
||||
init_database.commit()
|
||||
|
||||
txc = TxCache(tx_hash, account, init_w3.eth.accounts[0], zero_address, zero_address, 13, 13)
|
||||
init_database.add(txc)
|
||||
init_database.commit()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_sent_status',
|
||||
[tx_hash, True],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.SENDFAIL
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_sent_status',
|
||||
[tx_hash],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.SENT
|
||||
|
||||
|
||||
|
||||
def test_status_fail(
|
||||
init_w3,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
tx_hash = '0x' + os.urandom(32).hex()
|
||||
signed_tx = '0x' + os.urandom(128).hex()
|
||||
account = '0x' + os.urandom(20).hex()
|
||||
|
||||
otx = Otx(0, init_w3.eth.accounts[0], tx_hash, signed_tx)
|
||||
init_database.add(otx)
|
||||
init_database.commit()
|
||||
|
||||
txc = TxCache(tx_hash, account, init_w3.eth.accounts[0], zero_address, zero_address, 13, 13)
|
||||
init_database.add(txc)
|
||||
init_database.commit()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_sent_status',
|
||||
[tx_hash],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.SENT
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_final_status',
|
||||
[tx_hash, 13, True],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.REVERTED
|
||||
|
||||
|
||||
|
||||
def test_status_fubar(
|
||||
init_w3,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
tx_hash = '0x' + os.urandom(32).hex()
|
||||
signed_tx = '0x' + os.urandom(128).hex()
|
||||
account = '0x' + os.urandom(20).hex()
|
||||
|
||||
otx = Otx(0, init_w3.eth.accounts[0], tx_hash, signed_tx)
|
||||
init_database.add(otx)
|
||||
init_database.commit()
|
||||
|
||||
txc = TxCache(tx_hash, account, init_w3.eth.accounts[0], zero_address, zero_address, 13, 13)
|
||||
init_database.add(txc)
|
||||
init_database.commit()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_sent_status',
|
||||
[tx_hash],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.SENT
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.queue.tx.set_fubar',
|
||||
[tx_hash],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
assert t.successful()
|
||||
init_database.refresh(otx)
|
||||
assert otx.status == StatusEnum.FUBAR
|
||||
125
apps/cic-eth/tests/tasks/test_states.py
Normal file
125
apps/cic-eth/tests/tasks/test_states.py
Normal file
@@ -0,0 +1,125 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import time
|
||||
|
||||
# third-party imports
|
||||
import celery
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.base import SessionBase
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from cic_eth.db.enum import StatusEnum
|
||||
from cic_eth.eth.task import sign_and_register_tx
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_states_initial(
|
||||
init_w3,
|
||||
init_database,
|
||||
init_eth_account_roles,
|
||||
celery_session_worker,
|
||||
):
|
||||
tx = {
|
||||
'from': init_w3.eth.accounts[0],
|
||||
'to': init_w3.eth.accounts[1],
|
||||
'nonce': 42,
|
||||
'gas': 21000,
|
||||
'gasPrice': 1000000,
|
||||
'value': 128,
|
||||
'chainId': 666,
|
||||
'data': '',
|
||||
}
|
||||
(tx_hash_hex, tx_raw_signed_hex) = sign_and_register_tx(tx, 'Foo:666', None)
|
||||
|
||||
otx = init_database.query(Otx).filter(Otx.tx_hash==tx_hash_hex).first()
|
||||
assert otx.status == StatusEnum.PENDING.value
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.check_gas',
|
||||
[
|
||||
[tx_hash_hex],
|
||||
'Foo:666',
|
||||
[tx_raw_signed_hex],
|
||||
init_w3.eth.accounts[0],
|
||||
8000000,
|
||||
],
|
||||
queue=None,
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
for c in t.collect():
|
||||
pass
|
||||
assert t.successful()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
otx = session.query(Otx).filter(Otx.tx_hash==tx_hash_hex).first()
|
||||
assert otx.status == StatusEnum.READYSEND.value
|
||||
|
||||
otx.waitforgas(session=session)
|
||||
session.commit()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.check_gas',
|
||||
[
|
||||
[tx_hash_hex],
|
||||
'Foo:666',
|
||||
[tx_raw_signed_hex],
|
||||
init_w3.eth.accounts[0],
|
||||
8000000,
|
||||
],
|
||||
queue=None,
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
for c in t.collect():
|
||||
pass
|
||||
assert t.successful()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
otx = session.query(Otx).filter(Otx.tx_hash==tx_hash_hex).first()
|
||||
assert otx.status == StatusEnum.READYSEND.value
|
||||
|
||||
|
||||
def test_states_failed(
|
||||
init_w3,
|
||||
init_database,
|
||||
init_eth_account_roles,
|
||||
celery_session_worker,
|
||||
):
|
||||
tx = {
|
||||
'from': init_w3.eth.accounts[0],
|
||||
'to': init_w3.eth.accounts[1],
|
||||
'nonce': 42,
|
||||
'gas': 21000,
|
||||
'gasPrice': 1000000,
|
||||
'value': 128,
|
||||
'chainId': 666,
|
||||
'data': '',
|
||||
}
|
||||
(tx_hash_hex, tx_raw_signed_hex) = sign_and_register_tx(tx, 'Foo:666', None)
|
||||
|
||||
otx = init_database.query(Otx).filter(Otx.tx_hash==tx_hash_hex).first()
|
||||
otx.sendfail(session=init_database)
|
||||
init_database.add(otx)
|
||||
init_database.commit()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.check_gas',
|
||||
[
|
||||
[tx_hash_hex],
|
||||
'Foo:666',
|
||||
[tx_raw_signed_hex],
|
||||
init_w3.eth.accounts[0],
|
||||
8000000,
|
||||
],
|
||||
queue=None,
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
for c in t.collect():
|
||||
pass
|
||||
assert t.successful()
|
||||
|
||||
otx = init_database.query(Otx).filter(Otx.tx_hash==tx_hash_hex).first()
|
||||
assert otx.status == StatusEnum.RETRY.value
|
||||
42
apps/cic-eth/tests/tasks/test_token_tasks.py
Normal file
42
apps/cic-eth/tests/tasks/test_token_tasks.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
import celery
|
||||
|
||||
# local imports
|
||||
from cic_eth.eth.token import TokenTxFactory
|
||||
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_approve(
|
||||
init_rpc,
|
||||
default_chain_spec,
|
||||
celery_session_worker,
|
||||
bancor_tokens,
|
||||
bancor_registry,
|
||||
cic_registry,
|
||||
):
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.token.approve',
|
||||
[
|
||||
[
|
||||
{
|
||||
'address': bancor_tokens[0],
|
||||
},
|
||||
],
|
||||
init_rpc.w3.eth.accounts[0],
|
||||
init_rpc.w3.eth.accounts[1],
|
||||
1024,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
for r in t.collect():
|
||||
logg.debug('result {}'.format(r))
|
||||
|
||||
assert t.successful()
|
||||
76
apps/cic-eth/tests/tasks/test_transfer_approval.py
Normal file
76
apps/cic-eth/tests/tasks/test_transfer_approval.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import time
|
||||
|
||||
# third-party imports
|
||||
from erc20_approval_escrow import TransferApproval
|
||||
import celery
|
||||
import sha3
|
||||
|
||||
# local imports
|
||||
from cic_eth.eth.token import TokenTxFactory
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
# BUG: transaction receipt only found sometimes
|
||||
def test_transfer_approval(
|
||||
default_chain_spec,
|
||||
transfer_approval,
|
||||
bancor_tokens,
|
||||
w3_account_roles,
|
||||
eth_empty_accounts,
|
||||
cic_registry,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
init_eth_tester,
|
||||
init_w3,
|
||||
):
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.request.transfer_approval_request',
|
||||
[
|
||||
[
|
||||
{
|
||||
'address': bancor_tokens[0],
|
||||
},
|
||||
],
|
||||
w3_account_roles['eth_account_sarafu_owner'],
|
||||
eth_empty_accounts[0],
|
||||
1024,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
|
||||
s_send = celery.signature(
|
||||
'cic_eth.eth.tx.send',
|
||||
[
|
||||
str(default_chain_spec),
|
||||
],
|
||||
|
||||
)
|
||||
s.link(s_send)
|
||||
t = s.apply_async()
|
||||
|
||||
tx_signed_raws = t.get()
|
||||
for r in t.collect():
|
||||
logg.debug('result {}'.format(r))
|
||||
|
||||
assert t.successful()
|
||||
|
||||
init_eth_tester.mine_block()
|
||||
|
||||
h = sha3.keccak_256()
|
||||
tx_signed_raw = tx_signed_raws[0]
|
||||
tx_signed_raw_bytes = bytes.fromhex(tx_signed_raw[2:])
|
||||
h.update(tx_signed_raw_bytes)
|
||||
tx_hash = h.digest()
|
||||
rcpt = init_w3.eth.getTransactionReceipt(tx_hash)
|
||||
|
||||
assert rcpt.status == 1
|
||||
|
||||
a = TransferApproval(init_w3, transfer_approval)
|
||||
assert a.last_serial() == 1
|
||||
|
||||
logg.debug('requests {}'.format(a.requests(1)['serial']))
|
||||
|
||||
168
apps/cic-eth/tests/tasks/test_tx_tasks.py
Normal file
168
apps/cic-eth/tests/tasks/test_tx_tasks.py
Normal file
@@ -0,0 +1,168 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import os
|
||||
|
||||
# third-party imports
|
||||
import celery
|
||||
import pytest
|
||||
|
||||
# local imports
|
||||
import cic_eth
|
||||
from cic_eth.db.models.lock import Lock
|
||||
from cic_eth.db.enum import StatusEnum
|
||||
from cic_eth.db.enum import LockEnum
|
||||
from cic_eth.error import LockedError
|
||||
from cic_eth.queue.tx import create as queue_create
|
||||
from cic_eth.queue.tx import set_sent_status
|
||||
from cic_eth.eth.tx import cache_gas_refill_data
|
||||
from cic_eth.error import PermanentTxError
|
||||
from cic_eth.queue.tx import get_tx
|
||||
from cic_eth.eth.task import sign_tx
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
# TODO: There is no
|
||||
def test_send_reject(
|
||||
default_chain_spec,
|
||||
init_w3,
|
||||
mocker,
|
||||
init_database,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
nonce = init_w3.eth.getTransactionCount(init_w3.eth.accounts[0], 'pending')
|
||||
tx = {
|
||||
'from': init_w3.eth.accounts[0],
|
||||
'to': init_w3.eth.accounts[1],
|
||||
'nonce': nonce,
|
||||
'gas': 21000,
|
||||
'gasPrice': 1000000,
|
||||
'value': 128,
|
||||
'chainId': default_chain_spec.chain_id(),
|
||||
'data': '',
|
||||
}
|
||||
|
||||
chain_str = str(default_chain_spec)
|
||||
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx, chain_str)
|
||||
queue_create(tx['nonce'], tx['from'], tx_hash_hex, tx_signed_raw_hex, str(default_chain_spec))
|
||||
cache_gas_refill_data(tx_hash_hex, tx)
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.send',
|
||||
[
|
||||
[tx_signed_raw_hex],
|
||||
chain_str,
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
|
||||
|
||||
def test_sync_tx(
|
||||
default_chain_spec,
|
||||
init_database,
|
||||
init_w3,
|
||||
init_wallet_extension,
|
||||
init_eth_tester,
|
||||
celery_session_worker,
|
||||
eth_empty_accounts,
|
||||
):
|
||||
|
||||
nonce = init_w3.eth.getTransactionCount(init_w3.eth.accounts[0], 'pending')
|
||||
tx = {
|
||||
'from': init_w3.eth.accounts[0],
|
||||
'to': init_w3.eth.accounts[1],
|
||||
'nonce': nonce,
|
||||
'gas': 21000,
|
||||
'gasPrice': 1000000,
|
||||
'value': 128,
|
||||
'chainId': default_chain_spec.chain_id(),
|
||||
'data': '',
|
||||
}
|
||||
|
||||
chain_str = str(default_chain_spec)
|
||||
|
||||
(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx, chain_str)
|
||||
queue_create(tx['nonce'], tx['from'], tx_hash_hex, tx_signed_raw_hex, str(default_chain_spec))
|
||||
cache_gas_refill_data(tx_hash_hex, tx)
|
||||
|
||||
init_w3.eth.send_raw_transaction(tx_signed_raw_hex)
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.sync_tx',
|
||||
[
|
||||
tx_hash_hex,
|
||||
chain_str,
|
||||
],
|
||||
queue=None
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
for _ in t.collect():
|
||||
pass
|
||||
assert t.successful()
|
||||
|
||||
tx_dict = get_tx(tx_hash_hex)
|
||||
assert tx_dict['status'] == StatusEnum.SENT
|
||||
|
||||
init_eth_tester.mine_block()
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.sync_tx',
|
||||
[
|
||||
tx_hash_hex,
|
||||
chain_str,
|
||||
],
|
||||
queue=None
|
||||
)
|
||||
t = s.apply_async()
|
||||
r = t.get()
|
||||
for _ in t.collect():
|
||||
pass
|
||||
assert t.successful()
|
||||
|
||||
tx_dict = get_tx(tx_hash_hex)
|
||||
assert tx_dict['status'] == StatusEnum.SUCCESS
|
||||
|
||||
|
||||
|
||||
def test_resume_tx(
|
||||
default_chain_spec,
|
||||
init_database,
|
||||
init_w3,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
tx = {
|
||||
'from': init_w3.eth.accounts[0],
|
||||
'to': init_w3.eth.accounts[1],
|
||||
'nonce': 42 ,
|
||||
'gas': 21000,
|
||||
'gasPrice': 1000000,
|
||||
'value': 128,
|
||||
'chainId': default_chain_spec.chain_id(),
|
||||
'data': '',
|
||||
}
|
||||
tx_signed = init_w3.eth.sign_transaction(tx)
|
||||
tx_hash = init_w3.keccak(hexstr=tx_signed['raw'])
|
||||
tx_hash_hex = tx_hash.hex()
|
||||
queue_create(tx['nonce'], tx['from'], tx_hash_hex, tx_signed['raw'], str(default_chain_spec))
|
||||
cache_gas_refill_data(tx_hash_hex, tx)
|
||||
|
||||
set_sent_status(tx_hash_hex, True)
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.resume_tx',
|
||||
[
|
||||
tx_hash_hex,
|
||||
str(default_chain_spec),
|
||||
],
|
||||
)
|
||||
t = s.apply_async()
|
||||
t.get()
|
||||
for r in t.collect():
|
||||
logg.debug('collect {}'.format(r))
|
||||
assert t.successful()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user