Move nonce, gas tasks to respective modules, chainspec instead of chainid for chainlib tx
This commit is contained in:
@@ -30,9 +30,7 @@ from cic_eth.api import AdminApi
|
||||
from cic_eth.db.models.role import AccountRole
|
||||
from cic_eth.db.enum import LockEnum
|
||||
from cic_eth.error import InitializationError
|
||||
from cic_eth.eth.tx import (
|
||||
cache_gas_data,
|
||||
)
|
||||
from cic_eth.eth.gas import cache_gas_data
|
||||
from cic_eth.queue.tx import queue_create
|
||||
|
||||
logg = logging.getLogger()
|
||||
@@ -53,7 +51,7 @@ logg = logging.getLogger()
|
||||
# gas_provider = c.gas_provider()
|
||||
#
|
||||
# s_nonce = celery.signature(
|
||||
# 'cic_eth.eth.tx.reserve_nonce',
|
||||
# 'cic_eth.eth.nonce.reserve_nonce',
|
||||
# [
|
||||
# init_w3.eth.accounts[0],
|
||||
# gas_provider,
|
||||
@@ -61,7 +59,7 @@ logg = logging.getLogger()
|
||||
# queue=None,
|
||||
# )
|
||||
# s_refill = celery.signature(
|
||||
# 'cic_eth.eth.tx.refill_gas',
|
||||
# 'cic_eth.eth.gas.refill_gas',
|
||||
# [
|
||||
# chain_str,
|
||||
# ],
|
||||
@@ -80,7 +78,7 @@ logg = logging.getLogger()
|
||||
# o = q.first()
|
||||
# tx_raw = o.signed_tx
|
||||
#
|
||||
# tx_dict = unpack_signed_raw_tx(bytes.fromhex(tx_raw[2:]), default_chain_spec.chain_id())
|
||||
# tx_dict = unpack(bytes.fromhex(tx_raw), default_chain_spec)
|
||||
# gas_price_before = tx_dict['gasPrice']
|
||||
#
|
||||
# s = celery.signature(
|
||||
@@ -106,7 +104,7 @@ logg = logging.getLogger()
|
||||
#
|
||||
# tx_raw_new = get_tx(tx_hash_new_hex)
|
||||
# logg.debug('get {}'.format(tx_raw_new))
|
||||
# tx_dict_new = unpack_signed_raw_tx(bytes.fromhex(tx_raw_new['signed_tx'][2:]), default_chain_spec.chain_id())
|
||||
# tx_dict_new = unpack(bytes.fromhex(tx_raw_new['signed_tx']), default_chain_spec)
|
||||
# assert tx_hash_new_hex != tx_dict['hash']
|
||||
# assert tx_dict_new['gasPrice'] > gas_price_before
|
||||
#
|
||||
@@ -130,7 +128,7 @@ logg = logging.getLogger()
|
||||
# sigs = []
|
||||
# for i in range(5):
|
||||
# s = celery.signature(
|
||||
# 'cic_eth.eth.tx.refill_gas',
|
||||
# 'cic_eth.eth.gas.refill_gas',
|
||||
# [
|
||||
# eth_empty_accounts[i],
|
||||
# chain_str,
|
||||
@@ -278,11 +276,10 @@ def test_tx(
|
||||
celery_worker,
|
||||
):
|
||||
|
||||
chain_id = default_chain_spec.chain_id()
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 1024, tx_format=TxFormat.RLP_SIGNED)
|
||||
tx = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), chain_id)
|
||||
tx = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), default_chain_spec)
|
||||
queue_create(default_chain_spec, tx['nonce'], agent_roles['ALICE'], tx_hash_hex, tx_signed_raw_hex)
|
||||
cache_gas_data(tx_hash_hex, tx_signed_raw_hex, default_chain_spec.asdict())
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ def test_list_tx(
|
||||
celery_worker,
|
||||
):
|
||||
|
||||
chain_id = default_chain_spec.chain_id()
|
||||
|
||||
tx_hashes = []
|
||||
|
||||
# external tx
|
||||
@@ -59,7 +57,7 @@ def test_list_tx(
|
||||
init_database.commit()
|
||||
|
||||
init_eth_tester.mine_blocks(13)
|
||||
c = ERC20(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
c = ERC20(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.transfer(foo_token, custodial_roles['FOO_TOKEN_GIFTER'], agent_roles['ALICE'], 1024)
|
||||
eth_rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
@@ -79,7 +77,7 @@ def test_list_tx(
|
||||
|
||||
init_eth_tester.mine_blocks(13)
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
c = ERC20(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
c = ERC20(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.transfer(foo_token, agent_roles['ALICE'], agent_roles['BOB'], 256)
|
||||
eth_rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
|
||||
@@ -73,7 +73,7 @@ def test_register_account(
|
||||
):
|
||||
|
||||
s_nonce = celery.signature(
|
||||
'cic_eth.eth.tx.reserve_nonce',
|
||||
'cic_eth.eth.nonce.reserve_nonce',
|
||||
[
|
||||
eth_empty_accounts[0],
|
||||
default_chain_spec.asdict(),
|
||||
@@ -160,7 +160,7 @@ def test_gift(
|
||||
):
|
||||
|
||||
nonce_oracle = RPCNonceOracle(contract_roles['ACCOUNT_REGISTRY_WRITER'], eth_rpc)
|
||||
c = AccountRegistry(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=default_chain_spec.chain_id())
|
||||
c = AccountRegistry(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.add(account_registry, contract_roles['ACCOUNT_REGISTRY_WRITER'], agent_roles['ALICE'])
|
||||
eth_rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
@@ -168,7 +168,7 @@ def test_gift(
|
||||
assert r['status'] == 1
|
||||
|
||||
s_nonce = celery.signature(
|
||||
'cic_eth.eth.tx.reserve_nonce',
|
||||
'cic_eth.eth.nonce.reserve_nonce',
|
||||
[
|
||||
agent_roles['ALICE'],
|
||||
default_chain_spec.asdict(),
|
||||
|
||||
@@ -28,7 +28,7 @@ def test_otx_cache_transfer(
|
||||
celery_session_worker,
|
||||
):
|
||||
nonce_oracle = RPCNonceOracle(token_roles['FOO_TOKEN_OWNER'], eth_rpc)
|
||||
c = ERC20(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=default_chain_spec.chain_id())
|
||||
c = ERC20(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
transfer_value = 100 * (10**6)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = c.transfer(foo_token, token_roles['FOO_TOKEN_OWNER'], agent_roles['ALICE'], transfer_value, tx_format=TxFormat.RLP_SIGNED)
|
||||
register_tx(tx_hash_hex, tx_signed_raw_hex, default_chain_spec, None, session=init_database)
|
||||
@@ -59,7 +59,7 @@ def test_erc20_balance_task(
|
||||
):
|
||||
|
||||
nonce_oracle = RPCNonceOracle(token_roles['FOO_TOKEN_OWNER'], eth_rpc)
|
||||
c = ERC20(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=default_chain_spec.chain_id())
|
||||
c = ERC20(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
transfer_value = 100 * (10**6)
|
||||
(tx_hash_hex, o) = c.transfer(foo_token, token_roles['FOO_TOKEN_OWNER'], agent_roles['ALICE'], transfer_value)
|
||||
eth_rpc.do(o)
|
||||
@@ -102,7 +102,7 @@ def test_erc20_transfer_task(
|
||||
transfer_value = 100 * (10 ** 6)
|
||||
|
||||
s_nonce = celery.signature(
|
||||
'cic_eth.eth.tx.reserve_nonce',
|
||||
'cic_eth.eth.nonce.reserve_nonce',
|
||||
[
|
||||
[token_object],
|
||||
default_chain_spec.asdict(),
|
||||
@@ -144,7 +144,7 @@ def test_erc20_approve_task(
|
||||
transfer_value = 100 * (10 ** 6)
|
||||
|
||||
s_nonce = celery.signature(
|
||||
'cic_eth.eth.tx.reserve_nonce',
|
||||
'cic_eth.eth.nonce.reserve_nonce',
|
||||
[
|
||||
[token_object],
|
||||
default_chain_spec.asdict(),
|
||||
|
||||
@@ -17,7 +17,7 @@ from chainqueue.db.models.otx import Otx
|
||||
|
||||
# local imports
|
||||
from cic_eth.queue.tx import register_tx
|
||||
from cic_eth.eth.tx import cache_gas_data
|
||||
from cic_eth.eth.gas import cache_gas_data
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
@@ -32,11 +32,9 @@ def test_tx_send(
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
chain_id = default_chain_spec.chain_id()
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 1024, tx_format=TxFormat.RLP_SIGNED)
|
||||
#unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), chain_id)
|
||||
register_tx(tx_hash_hex, tx_signed_raw_hex, default_chain_spec, None, session=init_database)
|
||||
cache_gas_data(tx_hash_hex, tx_signed_raw_hex, default_chain_spec.asdict())
|
||||
|
||||
@@ -79,17 +77,15 @@ def test_resend_with_higher_gas(
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
chain_id = default_chain_spec.chain_id()
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 1024, tx_format=TxFormat.RLP_SIGNED)
|
||||
#unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), chain_id)
|
||||
register_tx(tx_hash_hex, tx_signed_raw_hex, default_chain_spec, None, session=init_database)
|
||||
cache_gas_data(tx_hash_hex, tx_signed_raw_hex, default_chain_spec.asdict())
|
||||
tx_before = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), default_chain_spec.chain_id())
|
||||
tx_before = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), default_chain_spec)
|
||||
|
||||
s = celery.signature(
|
||||
'cic_eth.eth.tx.resend_with_higher_gas',
|
||||
'cic_eth.eth.gas.resend_with_higher_gas',
|
||||
[
|
||||
tx_hash_hex,
|
||||
default_chain_spec.asdict(),
|
||||
@@ -105,7 +101,7 @@ def test_resend_with_higher_gas(
|
||||
if otx == None:
|
||||
raise NotLocalTxError(r)
|
||||
|
||||
tx_after = unpack(bytes.fromhex(strip_0x(otx.signed_tx)), default_chain_spec.chain_id())
|
||||
tx_after = unpack(bytes.fromhex(strip_0x(otx.signed_tx)), default_chain_spec)
|
||||
logg.debug('gasprices before {} after {}'.format(tx_before['gasPrice'], tx_after['gasPrice']))
|
||||
assert tx_after['gasPrice'] > tx_before['gasPrice']
|
||||
|
||||
|
||||
@@ -33,14 +33,13 @@ def test_set(
|
||||
agent_roles,
|
||||
):
|
||||
|
||||
chain_id = default_chain_spec.chain_id()
|
||||
rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
gas_oracle = RPCGasOracle(eth_rpc)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_id=chain_id)
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
|
||||
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
|
||||
tx = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), chain_id)
|
||||
tx = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), default_chain_spec)
|
||||
|
||||
otx = Otx(
|
||||
tx['nonce'],
|
||||
@@ -87,18 +86,17 @@ def test_clone(
|
||||
agent_roles,
|
||||
):
|
||||
|
||||
chain_id = default_chain_spec.chain_id()
|
||||
rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
gas_oracle = StaticGasOracle(2 * (10 ** 9), 21000)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_id=chain_id)
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
|
||||
txs_rpc = [
|
||||
c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED),
|
||||
]
|
||||
|
||||
gas_oracle = StaticGasOracle(4 * (10 ** 9), 21000)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_id=chain_id)
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
txs_rpc += [
|
||||
c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED),
|
||||
]
|
||||
@@ -107,7 +105,7 @@ def test_clone(
|
||||
for tx_rpc in txs_rpc:
|
||||
tx_hash_hex = tx_rpc[0]
|
||||
tx_signed_raw_hex = tx_rpc[1]
|
||||
tx_dict = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), chain_id)
|
||||
tx_dict = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), default_chain_spec)
|
||||
otx = Otx(
|
||||
tx_dict['nonce'],
|
||||
tx_hash_hex,
|
||||
|
||||
@@ -18,13 +18,12 @@ def test_unpack(
|
||||
agent_roles,
|
||||
):
|
||||
|
||||
chain_id = default_chain_spec.chain_id()
|
||||
rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
gas_oracle = RPCGasOracle(eth_rpc)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_id=default_chain_spec.chain_id())
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
|
||||
|
||||
tx = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), chain_id=chain_id)
|
||||
tx = unpack(bytes.fromhex(strip_0x(tx_signed_raw_hex)), default_chain_spec)
|
||||
|
||||
assert tx_hash_hex == tx['hash']
|
||||
|
||||
@@ -23,7 +23,7 @@ def test_translate(
|
||||
|
||||
nonce_oracle = RPCNonceOracle(contract_roles['CONTRACT_DEPLOYER'], eth_rpc)
|
||||
|
||||
c = AddressDeclarator(signer=eth_signer, nonce_oracle=nonce_oracle, chain_id=default_chain_spec.chain_id())
|
||||
c = AddressDeclarator(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
|
||||
description = 'alice'.encode('utf-8').ljust(32, b'\x00').hex()
|
||||
(tx_hash_hex, o) = c.add_declaration(address_declarator, contract_roles['CONTRACT_DEPLOYER'], agent_roles['ALICE'], add_0x(description))
|
||||
|
||||
@@ -15,7 +15,7 @@ from cic_eth.db.enum import LockEnum
|
||||
from cic_eth.db.models.lock import Lock
|
||||
from cic_eth.queue.query import get_upcoming_tx
|
||||
from cic_eth.queue.tx import register_tx
|
||||
from cic_eth.eth.tx import cache_gas_data
|
||||
from cic_eth.eth.gas import cache_gas_data
|
||||
|
||||
# test imports
|
||||
from tests.util.nonce import StaticNonceOracle
|
||||
@@ -32,7 +32,7 @@ def test_upcoming_with_lock(
|
||||
rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
nonce_oracle = StaticNonceOracle(42)
|
||||
gas_oracle = RPCGasOracle(eth_rpc)
|
||||
c = Gas(signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_id=default_chain_spec.chain_id())
|
||||
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
|
||||
(tx_hash_hex, tx_rpc) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6))
|
||||
tx_signed_raw_hex = tx_rpc['params'][0]
|
||||
|
||||
Reference in New Issue
Block a user