WIP Add check gas test

This commit is contained in:
nolash 2021-05-31 12:45:03 +02:00
parent b88c290683
commit ae711b0727
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 457 additions and 260 deletions

View File

@ -57,10 +57,12 @@ celery_app = celery.current_app
logg = logging.getLogger() logg = logging.getLogger()
MAXIMUM_FEE_UNITS = 8000000
class MaxGasOracle: class MaxGasOracle:
def gas(code=None): def gas(code=None):
return 8000000 return MAXIMUM_FEE_UNITS
def create_check_gas_task(tx_signed_raws_hex, chain_spec, holder_address, gas=None, tx_hashes_hex=None, queue=None): def create_check_gas_task(tx_signed_raws_hex, chain_spec, holder_address, gas=None, tx_hashes_hex=None, queue=None):
@ -150,7 +152,7 @@ def cache_gas_data(
@celery_app.task(bind=True, throws=(OutOfGasError), base=CriticalSQLAlchemyAndWeb3Task) @celery_app.task(bind=True, throws=(OutOfGasError), base=CriticalSQLAlchemyAndWeb3Task)
def check_gas(self, tx_hashes, chain_spec_dict, txs=[], address=None, gas_required=None): def check_gas(self, tx_hashes, chain_spec_dict, txs=[], address=None, gas_required=MAXIMUM_FEE_UNITS):
"""Check the gas level of the sender address of a transaction. """Check the gas level of the sender address of a transaction.
If the account balance is not sufficient for the required gas, gas refill is requested and OutOfGasError raiser. If the account balance is not sufficient for the required gas, gas refill is requested and OutOfGasError raiser.
@ -170,18 +172,23 @@ def check_gas(self, tx_hashes, chain_spec_dict, txs=[], address=None, gas_requir
:return: Signed raw transaction data list :return: Signed raw transaction data list
:rtype: param txs, unchanged :rtype: param txs, unchanged
""" """
chain_spec = ChainSpec.from_dict(chain_spec_dict)
addresses = []
if len(txs) == 0: if len(txs) == 0:
for i in range(len(tx_hashes)): for i in range(len(tx_hashes)):
o = get_tx(tx_hashes[i]) o = get_tx(chain_spec_dict, tx_hashes[i])
txs.append(o['signed_tx']) txs.append(o['signed_tx'])
logg.debug('sender {}'.format(o))
tx = unpack(bytes.fromhex(strip_0x(o['signed_tx'])), chain_spec)
if address == None: if address == None:
address = o['address'] address = tx['from']
elif address != tx['from']:
raise ValueError('txs passed to check gas must all have same sender')
if not is_checksum_address(address): if not is_checksum_address(address):
raise ValueError('invalid address {}'.format(address)) raise ValueError('invalid address {}'.format(address))
chain_spec = ChainSpec.from_dict(chain_spec_dict)
queue = self.request.delivery_info.get('routing_key') queue = self.request.delivery_info.get('routing_key')
conn = RPCConnection.connect(chain_spec) conn = RPCConnection.connect(chain_spec)

View File

@ -1,4 +1,4 @@
cic-base~=0.1.2b13 cic-base~=0.1.2b14
celery==4.4.7 celery==4.4.7
crypto-dev-signer~=0.4.14b3 crypto-dev-signer~=0.4.14b3
confini~=0.3.6rc3 confini~=0.3.6rc3

View File

@ -51,7 +51,7 @@ def test_admin_api_tx(
agent_roles, agent_roles,
contract_roles, contract_roles,
custodial_roles, custodial_roles,
celery_worker, celery_session_worker,
foo_token, foo_token,
address_declarator, address_declarator,
cic_registry, cic_registry,
@ -119,255 +119,255 @@ def test_admin_api_tx(
assert tx['tx_hash'] == tx_hash_hex assert tx['tx_hash'] == tx_hash_hex
#def test_admin_api_account( def test_admin_api_account(
# default_chain_spec, default_chain_spec,
# init_database, init_database,
# eth_rpc, eth_rpc,
# eth_signer, eth_signer,
# agent_roles, agent_roles,
# contract_roles, contract_roles,
# celery_session_worker, celery_session_worker,
# caplog, caplog,
# ): ):
#
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
# gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc) gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
#
# tx_hashes_alice = [] tx_hashes_alice = []
# txs_alice = [] txs_alice = []
#
# for i in range(3): for i in range(3):
# c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) 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_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
# queue_create( queue_create(
# default_chain_spec, default_chain_spec,
# 42+i, 42+i,
# agent_roles['ALICE'], agent_roles['ALICE'],
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# session=init_database, session=init_database,
# ) )
# cache_gas_data( cache_gas_data(
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# default_chain_spec.asdict(), default_chain_spec.asdict(),
# ) )
# tx_hashes_alice.append(tx_hash_hex) tx_hashes_alice.append(tx_hash_hex)
# txs_alice.append(tx_signed_raw_hex) txs_alice.append(tx_signed_raw_hex)
#
# init_database.commit() init_database.commit()
#
# nonce_oracle = OverrideNonceOracle(agent_roles['BOB'], 13) nonce_oracle = OverrideNonceOracle(agent_roles['BOB'], 13)
# tx_hashes_bob = [] tx_hashes_bob = []
# txs_bob = [] txs_bob = []
#
# for i in range(2): for i in range(2):
# c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) 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) (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( queue_create(
# default_chain_spec, default_chain_spec,
# 13+i, 13+i,
# agent_roles['BOB'], agent_roles['BOB'],
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# session=init_database, session=init_database,
# ) )
# cache_gas_data( cache_gas_data(
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# default_chain_spec.asdict(), default_chain_spec.asdict(),
# ) )
# tx_hashes_bob.append(tx_hash_hex) tx_hashes_bob.append(tx_hash_hex)
# txs_bob.append(tx_signed_raw_hex) txs_bob.append(tx_signed_raw_hex)
#
# init_database.commit() init_database.commit()
#
#
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
# r = api.account(default_chain_spec, agent_roles['ALICE']) r = api.account(default_chain_spec, agent_roles['ALICE'])
# assert len(r) == 5 assert len(r) == 5
#
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
# r = api.account(default_chain_spec, agent_roles['ALICE'], include_sender=False) r = api.account(default_chain_spec, agent_roles['ALICE'], include_sender=False)
# assert len(r) == 2 assert len(r) == 2
#
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
# r = api.account(default_chain_spec, agent_roles['ALICE'], include_recipient=False) r = api.account(default_chain_spec, agent_roles['ALICE'], include_recipient=False)
# assert len(r) == 3 assert len(r) == 3
#
#
#def test_admin_api_account_writer( def test_admin_api_account_writer(
# default_chain_spec, default_chain_spec,
# init_database, init_database,
# eth_rpc, eth_rpc,
# eth_signer, eth_signer,
# agent_roles, agent_roles,
# contract_roles, contract_roles,
# celery_session_worker, celery_session_worker,
# caplog, caplog,
# ): ):
#
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
# gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc) gas_oracle = OverrideGasOracle(limit=21000, conn=eth_rpc)
#
# c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) 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_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
# queue_create( queue_create(
# default_chain_spec, default_chain_spec,
# 42, 42,
# agent_roles['ALICE'], agent_roles['ALICE'],
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# session=init_database, session=init_database,
# ) )
# cache_gas_data( cache_gas_data(
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# default_chain_spec.asdict(), default_chain_spec.asdict(),
# ) )
#
# init_database.commit() init_database.commit()
#
# buf = io.StringIO() buf = io.StringIO()
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) 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) api.account(default_chain_spec, agent_roles['ALICE'], renderer=json.dumps, w=buf)
#
# # TODO: improve eval # TODO: improve eval
# tx = json.loads(buf.getvalue()) tx = json.loads(buf.getvalue())
# assert tx['tx_hash'] == tx_hash_hex assert tx['tx_hash'] == tx_hash_hex
#
#
#def test_registry( def test_registry(
# eth_rpc, eth_rpc,
# cic_registry, cic_registry,
# contract_roles, contract_roles,
# celery_session_worker, celery_session_worker,
# ): ):
#
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
# t = api.registry() t = api.registry()
# r = t.get_leaf() r = t.get_leaf()
# assert r == cic_registry assert r == cic_registry
#
#
#def test_proxy_do( def test_proxy_do(
# default_chain_spec, default_chain_spec,
# eth_rpc, eth_rpc,
# contract_roles, contract_roles,
# celery_session_worker, celery_session_worker,
# ): ):
#
# o = block_latest() o = block_latest()
# r = eth_rpc.do(o) r = eth_rpc.do(o)
#
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
# t = api.proxy_do(default_chain_spec, o) t = api.proxy_do(default_chain_spec, o)
# rr = t.get_leaf() rr = t.get_leaf()
#
# assert r == rr assert r == rr
#
#
#def test_resend_inplace( def test_resend_inplace(
# init_database, init_database,
# default_chain_spec, default_chain_spec,
# eth_rpc, eth_rpc,
# eth_signer, eth_signer,
# agent_roles, agent_roles,
# contract_roles, contract_roles,
# celery_session_worker, celery_session_worker,
# ): ):
#
# rpc = RPCConnection.connect(default_chain_spec, 'default') rpc = RPCConnection.connect(default_chain_spec, 'default')
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
# gas_oracle = OverrideGasOracle(price=1000000000, limit=21000) gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
# c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) 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_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
#
# queue_create( queue_create(
# default_chain_spec, default_chain_spec,
# 42, 42,
# agent_roles['ALICE'], agent_roles['ALICE'],
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# session=init_database, session=init_database,
# ) )
# cache_gas_data( cache_gas_data(
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# default_chain_spec.asdict(), default_chain_spec.asdict(),
# ) )
#
# set_ready(default_chain_spec, tx_hash_hex, session=init_database) set_ready(default_chain_spec, tx_hash_hex, session=init_database)
# set_reserved(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) set_sent(default_chain_spec, tx_hash_hex, session=init_database)
#
# init_database.commit() init_database.commit()
#
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
# t = api.resend(tx_hash_hex, default_chain_spec, unlock=True) t = api.resend(tx_hash_hex, default_chain_spec, unlock=True)
# r = t.get_leaf() r = t.get_leaf()
# assert t.successful() assert t.successful()
#
#
# otx = Otx.load(tx_hash_hex, session=init_database) otx = Otx.load(tx_hash_hex, session=init_database)
# assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
#
# txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database) txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
# assert len(txs) == 2 assert len(txs) == 2
#
#
#
#@pytest.mark.xfail() @pytest.mark.xfail()
#def test_resend_clone( def test_resend_clone(
# init_database, init_database,
# default_chain_spec, default_chain_spec,
# eth_rpc, eth_rpc,
# eth_signer, eth_signer,
# agent_roles, agent_roles,
# contract_roles, contract_roles,
# celery_session_worker, celery_session_worker,
# ): ):
#
# rpc = RPCConnection.connect(default_chain_spec, 'default') rpc = RPCConnection.connect(default_chain_spec, 'default')
# nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42)
# gas_oracle = OverrideGasOracle(price=1000000000, limit=21000) gas_oracle = OverrideGasOracle(price=1000000000, limit=21000)
# c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) 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_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
#
# queue_create( queue_create(
# default_chain_spec, default_chain_spec,
# 42, 42,
# agent_roles['ALICE'], agent_roles['ALICE'],
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# session=init_database, session=init_database,
# ) )
# cache_gas_data( cache_gas_data(
# tx_hash_hex, tx_hash_hex,
# tx_signed_raw_hex, tx_signed_raw_hex,
# default_chain_spec.asdict(), default_chain_spec.asdict(),
# ) )
#
# set_ready(default_chain_spec, tx_hash_hex, session=init_database) set_ready(default_chain_spec, tx_hash_hex, session=init_database)
# set_reserved(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) set_sent(default_chain_spec, tx_hash_hex, session=init_database)
#
# init_database.commit() init_database.commit()
#
# api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER'])
# t = api.resend(tx_hash_hex, default_chain_spec, in_place=False) t = api.resend(tx_hash_hex, default_chain_spec, in_place=False)
# r = t.get_leaf() r = t.get_leaf()
# assert t.successful() assert t.successful()
#
# otx = Otx.load(tx_hash_hex, session=init_database) otx = Otx.load(tx_hash_hex, session=init_database)
# assert otx.status & StatusBits.IN_NETWORK == StatusBits.IN_NETWORK assert otx.status & StatusBits.IN_NETWORK == StatusBits.IN_NETWORK
# assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE
#
# txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database) txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database)
# assert len(txs) == 1 assert len(txs) == 1
#
# txs = get_nonce_tx_cache(default_chain_spec, otx.nonce + 1, agent_roles['ALICE'], session=init_database) txs = get_nonce_tx_cache(default_chain_spec, otx.nonce + 1, agent_roles['ALICE'], session=init_database)
# assert len(txs) == 1 assert len(txs) == 1
#
# otx = Otx.load(txs[0], session=init_database) otx = Otx.load(txs[0], session=init_database)
# assert otx.status == 0 assert otx.status == 0

View File

@ -0,0 +1,190 @@
# external imports
import celery
from chainlib.connection import RPCConnection
from chainlib.eth.nonce import (
OverrideNonceOracle,
RPCNonceOracle,
)
from chainlib.eth.gas import (
OverrideGasOracle,
Gas,
)
from chainlib.eth.tx import (
TxFormat,
)
from chainlib.eth.constant import (
MINIMUM_FEE_UNITS,
MINIMUM_FEE_PRICE,
)
from chainqueue.tx import create as queue_create
from chainqueue.query import get_tx
from chainqueue.db.enum import StatusBits
# local imports
from cic_eth.eth.gas import cache_gas_data
from cic_eth.error import OutOfGasError
def test_task_check_gas_ok(
default_chain_spec,
eth_rpc,
eth_signer,
init_database,
agent_roles,
custodial_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(),
)
init_database.commit()
s = celery.signature(
'cic_eth.eth.gas.check_gas',
[
[
tx_hash_hex,
],
default_chain_spec.asdict(),
],
queue=None
)
t = s.apply_async()
r = t.get_leaf()
assert t.successful()
init_database.commit()
tx = get_tx(default_chain_spec, tx_hash_hex, session=init_database)
assert tx['status'] & StatusBits.QUEUED == StatusBits.QUEUED
def test_task_check_gas_insufficient(
default_chain_spec,
eth_rpc,
eth_signer,
init_database,
agent_roles,
custodial_roles,
celery_session_worker,
whoever,
):
rpc = RPCConnection.connect(default_chain_spec, 'default')
nonce_oracle = OverrideNonceOracle(whoever, 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(whoever, agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
queue_create(
default_chain_spec,
42,
whoever,
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()
s = celery.signature(
'cic_eth.eth.gas.check_gas',
[
[
tx_hash_hex,
],
default_chain_spec.asdict(),
],
queue=None
)
t = s.apply_async()
try:
r = t.get_leaf()
except OutOfGasError:
pass
init_database.commit()
tx = get_tx(default_chain_spec, tx_hash_hex, session=init_database)
assert tx['status'] & StatusBits.GAS_ISSUES == StatusBits.GAS_ISSUES
def test_task_check_gas_low(
default_chain_spec,
eth_rpc,
eth_signer,
init_database,
agent_roles,
custodial_roles,
celery_session_worker,
whoever,
):
gas_oracle = OverrideGasOracle(price=MINIMUM_FEE_PRICE, limit=MINIMUM_FEE_UNITS)
nonce_oracle = RPCNonceOracle(custodial_roles['GAS_GIFTER'], conn=eth_rpc)
c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash_hex, o) = c.create(custodial_roles['GAS_GIFTER'], whoever, 100 * (10 ** 6))
r = eth_rpc.do(o)
rpc = RPCConnection.connect(default_chain_spec, 'default')
nonce_oracle = OverrideNonceOracle(whoever, 42)
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(whoever, agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED)
queue_create(
default_chain_spec,
42,
whoever,
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()
s = celery.signature(
'cic_eth.eth.gas.check_gas',
[
[
tx_hash_hex,
],
default_chain_spec.asdict(),
],
queue=None
)
t = s.apply_async()
r = t.get_leaf()
assert t.successful()
init_database.commit()
tx = get_tx(default_chain_spec, tx_hash_hex, session=init_database)
assert tx['status'] & StatusBits.QUEUED == StatusBits.QUEUED