diff --git a/chaind_eth/chain.py b/chaind_eth/chain.py index d9171cd..687a802 100644 --- 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 index 33a9a09..e83cd0d 100644 --- 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 new file mode 100644 index 0000000..0d13820 --- /dev/null +++ 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 index 6e6e0ae..a78de29 100644 --- 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)