Use external chain queue engine
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.otx import OtxSync
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_db_block_sync(
|
||||
init_database,
|
||||
):
|
||||
|
||||
s = OtxSync('eip155:8995:bloxberg')
|
||||
|
||||
s.head(666, 12)
|
||||
assert s.head() == (666, 12)
|
||||
|
||||
s.session(42, 13)
|
||||
assert s.session() == (42, 13)
|
||||
|
||||
s.backlog(13, 2)
|
||||
assert s.backlog() == (13, 2)
|
||||
|
||||
assert not s.synced
|
||||
|
||||
s.backlog(42, 13)
|
||||
assert s.backlog() == (42, 13)
|
||||
assert s.synced
|
||||
@@ -3,7 +3,7 @@ import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from cic_eth.db import TxConvertTransfer
|
||||
from cic_eth.db.models.convert import TxConvertTransfer
|
||||
from cic_eth.db.error import UnknownConvertError
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
# standard imports
|
||||
import os
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
import pytest
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.base import SessionBase
|
||||
from cic_eth.db.models.otx import OtxStateLog
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from cic_eth.db.enum import (
|
||||
StatusEnum,
|
||||
StatusBits,
|
||||
is_alive,
|
||||
)
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
#def test_get(
|
||||
# rpc_eth,
|
||||
# rpc_signer,
|
||||
# agent_roles,
|
||||
# init_database,
|
||||
# ):
|
||||
#
|
||||
# rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
# nonce_oracle = RPCNonceOracle(agent_roles['ALICE'])
|
||||
# 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())
|
||||
#
|
||||
# for i in range(10):
|
||||
#
|
||||
# (tx_hash_hex, tx_rpc) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6)),
|
||||
#
|
||||
# tx_def = {
|
||||
# 'from': init_w3.eth.accounts[0],
|
||||
# 'to': init_w3.eth.accounts[1],
|
||||
# 'nonce': 0,
|
||||
# 'value': 101,
|
||||
# 'gasPrice': 2000000000,
|
||||
# 'gas': 21000,
|
||||
# 'data': '',
|
||||
# 'chainId': 1,
|
||||
# }
|
||||
#
|
||||
# session = init_database
|
||||
# txs = []
|
||||
# for i in range(10):
|
||||
# nonce = init_w3.eth.getTransactionCount(init_w3.eth.accounts[0], 'pending')
|
||||
# tx_def['nonce'] = nonce
|
||||
# tx = init_w3.eth.sign_transaction(tx_def)
|
||||
# tx_hash = init_w3.eth.send_raw_transaction(tx['raw'])
|
||||
# logg.debug('tx {}'.format(tx))
|
||||
#
|
||||
# address = init_w3.eth.accounts[i%3]
|
||||
# otx = Otx(int((i/3)+1), address, '0x'+tx_hash.hex(), tx['raw'])
|
||||
# txs.append(otx)
|
||||
# session.add(otx)
|
||||
# session.flush()
|
||||
#
|
||||
# logg.debug(txs)
|
||||
# session.commit()
|
||||
#
|
||||
# txs[0].status = 0
|
||||
# session.add(txs[0])
|
||||
# session.commit()
|
||||
# session.close()
|
||||
#
|
||||
# get_txs = Otx.get()
|
||||
# logg.debug(get_txs)
|
||||
|
||||
|
||||
def test_state_log(
|
||||
init_database,
|
||||
):
|
||||
|
||||
Otx.tracing = True
|
||||
|
||||
address = '0x' + os.urandom(20).hex()
|
||||
tx_hash = '0x' + os.urandom(32).hex()
|
||||
signed_tx = '0x' + os.urandom(128).hex()
|
||||
otx = Otx.add(0, address, tx_hash, signed_tx, session=init_database)
|
||||
|
||||
otx.waitforgas(session=init_database)
|
||||
init_database.commit()
|
||||
|
||||
otx.readysend(session=init_database)
|
||||
init_database.commit()
|
||||
|
||||
otx.sent(session=init_database)
|
||||
init_database.commit()
|
||||
|
||||
otx.success(1024, session=init_database)
|
||||
init_database.commit()
|
||||
|
||||
q = init_database.query(OtxStateLog)
|
||||
q = q.filter(OtxStateLog.otx_id==otx.id)
|
||||
q = q.order_by(OtxStateLog.date.asc())
|
||||
logs = q.all()
|
||||
|
||||
assert logs[0].status == StatusEnum.PENDING
|
||||
assert logs[1].status == StatusEnum.WAITFORGAS
|
||||
assert logs[2].status & StatusBits.QUEUED
|
||||
assert logs[3].status & StatusBits.IN_NETWORK
|
||||
assert not is_alive(logs[4].status)
|
||||
@@ -1,97 +0,0 @@
|
||||
# standard imports
|
||||
import os
|
||||
|
||||
# third-party imports
|
||||
import pytest
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from cic_eth.db.enum import (
|
||||
StatusEnum,
|
||||
StatusBits,
|
||||
is_alive,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def otx(
|
||||
init_database,
|
||||
):
|
||||
|
||||
bogus_hash = '0x' + os.urandom(32).hex()
|
||||
bogus_address = '0x' + os.urandom(20).hex()
|
||||
bogus_tx_raw = '0x' + os.urandom(128).hex()
|
||||
return Otx(0, bogus_address, bogus_hash, bogus_tx_raw)
|
||||
|
||||
|
||||
def test_status_chain_gas(
|
||||
init_database,
|
||||
otx,
|
||||
):
|
||||
|
||||
otx.waitforgas(init_database)
|
||||
otx.readysend(init_database)
|
||||
otx.sent(init_database)
|
||||
otx.success(1024, init_database)
|
||||
assert not is_alive(otx.status)
|
||||
|
||||
|
||||
def test_status_chain_straight_success(
|
||||
init_database,
|
||||
otx,
|
||||
):
|
||||
|
||||
otx.readysend(init_database)
|
||||
otx.sent(init_database)
|
||||
otx.success(1024, init_database)
|
||||
assert not is_alive(otx.status)
|
||||
|
||||
|
||||
def test_status_chain_straight_revert(
|
||||
init_database,
|
||||
otx,
|
||||
):
|
||||
|
||||
otx.readysend(init_database)
|
||||
otx.sent(init_database)
|
||||
otx.minefail(1024, init_database)
|
||||
assert not is_alive(otx.status)
|
||||
|
||||
|
||||
def test_status_chain_nodeerror(
|
||||
init_database,
|
||||
otx,
|
||||
):
|
||||
|
||||
otx.readysend(init_database)
|
||||
otx.sendfail(init_database)
|
||||
otx.retry(init_database)
|
||||
otx.sent(init_database)
|
||||
otx.success(1024, init_database)
|
||||
assert not is_alive(otx.status)
|
||||
|
||||
|
||||
|
||||
def test_status_chain_nodeerror_multiple(
|
||||
init_database,
|
||||
otx,
|
||||
):
|
||||
|
||||
otx.readysend(init_database)
|
||||
otx.sendfail(init_database)
|
||||
otx.retry(init_database)
|
||||
otx.sendfail(init_database)
|
||||
otx.retry(init_database)
|
||||
otx.sent(init_database)
|
||||
otx.success(1024, init_database)
|
||||
assert not is_alive(otx.status)
|
||||
|
||||
|
||||
def test_status_chain_nodeerror(
|
||||
init_database,
|
||||
otx,
|
||||
):
|
||||
|
||||
otx.readysend(init_database)
|
||||
otx.reject(init_database)
|
||||
assert not is_alive(otx.status)
|
||||
@@ -18,10 +18,8 @@ from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.tx import TxCache
|
||||
from cic_eth.db.models.otx import Otx
|
||||
from chainqueue.db.models.tx import TxCache
|
||||
from chainqueue.db.models.otx import Otx
|
||||
|
||||
# test imports
|
||||
from tests.util.gas import StaticGasOracle
|
||||
@@ -35,18 +33,16 @@ 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'],
|
||||
tx['from'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
)
|
||||
@@ -66,6 +62,7 @@ def test_set(
|
||||
to_value,
|
||||
666,
|
||||
13,
|
||||
session=init_database,
|
||||
)
|
||||
init_database.add(txc)
|
||||
init_database.commit()
|
||||
@@ -89,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),
|
||||
]
|
||||
@@ -109,10 +105,9 @@ 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_dict['from'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
)
|
||||
@@ -130,15 +125,16 @@ def test_clone(
|
||||
ZERO_ADDRESS,
|
||||
txs[0]['value'],
|
||||
txs[0]['value'],
|
||||
session=init_database,
|
||||
)
|
||||
init_database.add(txc)
|
||||
init_database.commit()
|
||||
|
||||
TxCache.clone(txs[0]['hash'], txs[1]['hash'])
|
||||
TxCache.clone(txs[0]['hash'], txs[1]['hash'], session=init_database)
|
||||
|
||||
q = init_database.query(TxCache)
|
||||
q = q.join(Otx)
|
||||
q = q.filter(Otx.tx_hash==txs[1]['hash'])
|
||||
q = q.filter(Otx.tx_hash==strip_0x(txs[1]['hash']))
|
||||
txc_clone = q.first()
|
||||
|
||||
assert txc_clone != None
|
||||
|
||||
Reference in New Issue
Block a user