chaind-eth

Queue server for ethereum
Log | Files | Refs | README | LICENSE

commit d05cd9f20281aebf543e136e8ee3a23a41df3d35
parent a6420eacfbe3f7fda3094b425d65a6f2fca8dcea
Author: nolash <dev@holbrook.no>
Date:   Sun, 18 Jul 2021 10:59:49 +0200

Include chain interface in tests

Diffstat:
Mchaind_eth/chain.py | 1+
Mtests/chaind_eth_base.py | 5+++++
Atests/test_chain.py | 38++++++++++++++++++++++++++++++++++++++
Mtests/test_filter.py | 13++++++++-----
4 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/chaind_eth/chain.py b/chaind_eth/chain.py @@ -9,6 +9,7 @@ from chainlib.eth.tx import ( Tx, ) + class EthChainInterface(ChainInterface): def __init__(self): diff --git a/tests/chaind_eth_base.py b/tests/chaind_eth_base.py @@ -6,6 +6,9 @@ from chainsyncer.unittest.db import ChainSyncerDb from chainqueue.unittest.db import ChainQueueDb from chainlib.eth.unittest.ethtester import EthTesterCase +# local imports +from chaind_eth.chain import EthChainInterface + class TestBase(EthTesterCase): @@ -17,6 +20,8 @@ class TestBase(EthTesterCase): self.db_chainqueue = ChainQueueDb() self.session_chainqueue = self.db_chainqueue.bind_session() + self.interface = EthChainInterface() + def tearDown(self): self.session_chainsyncer.commit() self.db_chainsyncer.release_session(self.session_chainsyncer) diff --git a/tests/test_chain.py b/tests/test_chain.py @@ -0,0 +1,38 @@ +# standard imports +import unittest + +# external imports +from chainlib.eth.gas import ( + RPCGasOracle, + Gas, + ) +from chainlib.eth.nonce import ( + RPCNonceOracle, + ) +from chainlib.eth.tx import ( + TxFormat, + unpack, + ) +from hexathon import ( + strip_0x, + ) + +# test imports +from tests.chaind_eth_base import TestBase + +class TestChain(TestBase): + + def test_chain_interface(self): + gas_oracle = RPCGasOracle(conn=self.rpc) + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.rpc) + c = Gas(self.chain_spec, signer=self.signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) + (tx_hash, tx_raw_rlp_signed) = c.create(self.accounts[0], self.accounts[1], 1024, tx_format=TxFormat.RLP_SIGNED) + + tx_raw_rlp_signed_bytes = bytes.fromhex(strip_0x(tx_raw_rlp_signed)) + tx_src = unpack(tx_raw_rlp_signed_bytes, self.chain_spec) + tx_src = self.interface.src_normalize(tx_src) + assert tx_src['gas_price'] == tx_src['gasPrice'] + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_filter.py b/tests/test_filter.py @@ -40,10 +40,9 @@ from chainqueue.sql.state import ( set_ready, ) - - # local imports from chaind_eth.filter import StateFilter +from chaind_eth.chain import EthChainInterface # test imports from tests.chaind_eth_base import TestBase @@ -62,12 +61,15 @@ class TestFilter(TestBase): o = raw(tx_raw_rlp_signed) self.rpc.do(o) - o = receipt(tx_hash) + #o = receipt(tx_hash) + o = self.interface.tx_receipt(tx_hash) rcpt = self.rpc.do(o) - o = block_by_hash(rcpt['block_hash']) + #o = block_by_hash(rcpt['block_hash']) + o = self.interface.block_by_number(rcpt['block_number']) block_src = self.rpc.do(o) - block = Block(block_src) + #block = Block(block_src) + block = self.interface.block_from_src(block_src) dsn = dsn_from_config(db_config) backend = SQLBackend(dsn, debug=bool(os.environ.get('DATABASE_DEBUG'))) @@ -81,6 +83,7 @@ class TestFilter(TestBase): set_sent(self.chain_spec, tx_hash, session=self.session_chainqueue) tx_src = unpack(tx_raw_rlp_signed_bytes, self.chain_spec) + tx_src = self.interface.src_normalize(tx_src) tx = Tx(tx_src, block=block, rcpt=rcpt) tx_repr = get_tx(self.chain_spec, tx_hash, session=self.session_chainqueue)