chaind-eth

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

commit c35957275c6533c3244b3a41bb310bea57f06315
parent 1929050e97631b09382ffbf5d3334d8a3f93375e
Author: nolash <dev@holbrook.no>
Date:   Fri, 16 Jul 2021 21:48:30 +0200

add filter test

Diffstat:
Mtest_requirements.txt | 3+++
Mtests/chaind_eth_base.py | 5++++-
Atests/test_filter.py | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/test_requirements.txt b/test_requirements.txt @@ -0,0 +1,3 @@ +eth_tester==0.5.0b3 +py-evm==0.3.0a20 +rlp==2.0.1 diff --git a/tests/chaind_eth_base.py b/tests/chaind_eth_base.py @@ -4,11 +4,13 @@ import unittest # external imports from chainsyncer.unittest.db import ChainSyncerDb from chainqueue.unittest.db import ChainQueueDb +from chainlib.eth.unittest.ethtester import EthTesterCase -class TestBase(unittest.TestCase): +class TestBase(EthTesterCase): def setUp(self): + super(TestBase, self).setUp() self.db_chainsyncer = ChainSyncerDb() self.session_chainsyncer = self.db_chainsyncer.bind_session() @@ -20,3 +22,4 @@ class TestBase(unittest.TestCase): self.db_chainsyncer.release_session(self.session_chainsyncer) self.session_chainqueue.commit() self.db_chainqueue.release_session(self.session_chainqueue) + super(TestBase, self).tearDown() diff --git a/tests/test_filter.py b/tests/test_filter.py @@ -0,0 +1,97 @@ +# standard imports +import unittest +import logging +import os + +# external imports +from potaahto.symbols import snake_and_camel +from hexathon import ( + strip_0x, + ) +from chainqueue.adapters.eth import EthAdapter +from chainqueue.unittest.db import ( + db_config, + dsn_from_config, + ) +from chainqueue.sql.backend import SQLBackend +from chainqueue.enum import is_alive +from chainqueue.sql.query import get_tx +from chainlib.eth.gas import ( + RPCGasOracle, + Gas, + ) +from chainlib.eth.nonce import ( + RPCNonceOracle, + ) +from chainlib.eth.tx import ( + TxFormat, + raw, + unpack, + receipt, + Tx, + ) +from chainlib.eth.block import ( + block_by_hash, + Block, + ) +from chainqueue.sql.state import ( + set_sent, + set_reserved, + set_ready, + ) + + + +# local imports +from chaind_eth.filter import StateFilter + +# test imports +from tests.chaind_eth_base import TestBase + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + + +class TestFilter(TestBase): + + def test_filter(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) + o = raw(tx_raw_rlp_signed) + self.rpc.do(o) + + o = receipt(tx_hash) + rcpt = self.rpc.do(o) + + o = block_by_hash(rcpt['block_hash']) + block_src = self.rpc.do(o) + block = Block(block_src) + + dsn = dsn_from_config(db_config) + backend = SQLBackend(dsn, debug=bool(os.environ.get('DATABASE_DEBUG'))) + adapter = EthAdapter(backend) + + tx_raw_rlp_signed_bytes = bytes.fromhex(strip_0x(tx_raw_rlp_signed)) + adapter.add(self.chain_spec, tx_raw_rlp_signed_bytes, session=self.session_chainqueue) + + set_ready(self.chain_spec, tx_hash, session=self.session_chainqueue) + set_reserved(self.chain_spec, tx_hash, session=self.session_chainqueue) + set_sent(self.chain_spec, tx_hash, session=self.session_chainqueue) + + tx_src = unpack(tx_raw_rlp_signed_bytes, self.chain_spec) + tx = Tx(tx_src, block=block, rcpt=rcpt) + + tx_repr = get_tx(self.chain_spec, tx_hash, session=self.session_chainqueue) + assert is_alive(tx_repr['status']) + + fltr = StateFilter(self.chain_spec) + fltr.filter(self.rpc, block, tx, session=self.session_chainqueue) + + tx_repr = get_tx(self.chain_spec, tx_hash, session=self.session_chainqueue) + assert not is_alive(tx_repr['status']) + + +if __name__ == '__main__': + unittest.main()