test_tx.py (2207B)
1 # standard imports 2 import os 3 import tempfile 4 import unittest 5 import shutil 6 import logging 7 import hashlib 8 9 # external imports 10 from chainlib.chain import ChainSpec 11 from chainqueue.cache import CacheTokenTx 12 from chainlib.error import RPCException 13 from chainlib.status import Status as TxStatus 14 from chaind.unittest.fs import TestChaindFsBase 15 from chaind.driver import QueueDriver 16 from chaind.filter import StateFilter 17 from chainlib.eth.gas import Gas 18 from jsonrpc_std.parse import jsonrpc_validate_dict 19 from hexathon import strip_0x 20 21 # local imports 22 from chaind.eth.cache import EthCacheTx 23 from chaind.eth.dispatch import EthDispatcher 24 25 logging.basicConfig(level=logging.DEBUG) 26 logg = logging.getLogger() 27 28 29 class MockConn: 30 31 def __init__(self): 32 self.fails = [] 33 self.last = None 34 35 36 def add_fail(self, v): 37 self.fails.append(v) 38 39 40 def do(self, v): 41 if v in self.fails: 42 raise RuntimeError(v) 43 v = jsonrpc_validate_dict(v) 44 if v['method'] != 'eth_sendRawTransaction': 45 raise ValueError('unsupported method {}'.format(v['method'])) 46 self.last = v['params'][0] 47 48 49 class TestEthChaindFs(TestChaindFsBase): 50 51 def setUp(self): 52 self.cache_adapter = EthCacheTx 53 self.conn = MockConn() 54 self.dispatcher = EthDispatcher(self.conn) 55 super(TestEthChaindFs, self).setUp() 56 57 58 def test_deserialize(self): 59 data = "f8610d2a82520894eb3907ecad74a0013c259d5874ae7f22dcbcc95c8204008078a0ddbebd76701f6531e5ea42599f890268716e2bb38e3e125874f47595c2338049a00f5648d17b20efac8cb7ff275a510ebef6815e1599e29067821372b83eb1d28c" # valid RLP example data 60 hsh = self.adapter.put(data) 61 v = self.adapter.get(hsh) 62 self.assertEqual(data, v) 63 64 65 def test_dispatch(self): 66 data = "f8610d2a82520894eb3907ecad74a0013c259d5874ae7f22dcbcc95c8204008078a0ddbebd76701f6531e5ea42599f890268716e2bb38e3e125874f47595c2338049a00f5648d17b20efac8cb7ff275a510ebef6815e1599e29067821372b83eb1d28c" # valid RLP example data 67 hsh = self.adapter.put(data) 68 self.adapter.dispatch(hsh) 69 self.assertEqual(strip_0x(self.conn.last), strip_0x(data)) 70 71 72 if __name__ == '__main__': 73 unittest.main()