commit 441cb0040471331154ef5cdb0ba00d1ea5086783
parent b96542715d07674ebd0d024f9d1ba46bad5e1c77
Author: lash <dev@holbrook.no>
Date: Tue, 15 Mar 2022 09:32:20 +0000
Add dispatch, test
Diffstat:
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/chaind/eth/cache.py b/chaind/eth/cache.py
@@ -39,3 +39,4 @@ class EthCacheTx(CacheTx):
self.recipient = eth_normalizer.address(tx['to'])
self.nonce = eth_normalizer.value(tx['nonce'])
self.value = eth_normalizer.value(tx['value'])
+ self.src = signed_tx
diff --git a/chaind/eth/dispatch.py b/chaind/eth/dispatch.py
@@ -0,0 +1,13 @@
+# external imports
+from chainlib.eth.tx import raw
+
+
+class EthDispatcher:
+
+ def __init__(self, conn):
+ self.conn = conn
+
+
+ def send(self, payload):
+ o = raw(payload)
+ self.conn.do(o)
diff --git a/tests/test_tx.py b/tests/test_tx.py
@@ -15,27 +15,59 @@ from chaind.unittest.common import TestChaindFsBase
from chaind.driver import QueueDriver
from chaind.filter import StateFilter
from chainlib.eth.gas import Gas
+from jsonrpc_std.parse import jsonrpc_validate_dict
+from hexathon import strip_0x
# local imports
from chaind.eth.cache import EthCacheTx
+from chaind.eth.dispatch import EthDispatcher
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
+class MockConn:
+
+ def __init__(self):
+ self.fails = []
+ self.last = None
+
+
+ def add_fail(self, v):
+ self.fails.append(v)
+
+
+ def do(self, v):
+ if v in self.fails:
+ raise RuntimeError(v)
+ v = jsonrpc_validate_dict(v)
+ if v['method'] != 'eth_sendRawTransaction':
+ raise ValueError('unsupported method {}'.format(v['method']))
+ self.last = v['params'][0]
+
+
class TestEthChaindFs(TestChaindFsBase):
def setUp(self):
self.cache_adapter = EthCacheTx
+ self.conn = MockConn()
+ self.dispatcher = EthDispatcher(self.conn)
super(TestEthChaindFs, self).setUp()
def test_deserialize(self):
- data = "f8610d2a82520894eb3907ecad74a0013c259d5874ae7f22dcbcc95c8204008078a0ddbebd76701f6531e5ea42599f890268716e2bb38e3e125874f47595c2338049a00f5648d17b20efac8cb7ff275a510ebef6815e1599e29067821372b83eb1d28c"
+ data = "f8610d2a82520894eb3907ecad74a0013c259d5874ae7f22dcbcc95c8204008078a0ddbebd76701f6531e5ea42599f890268716e2bb38e3e125874f47595c2338049a00f5648d17b20efac8cb7ff275a510ebef6815e1599e29067821372b83eb1d28c" # valid RLP example data
hsh = self.adapter.put(data)
v = self.adapter.get(hsh)
self.assertEqual(data, v)
+ def test_dispatch(self):
+ data = "f8610d2a82520894eb3907ecad74a0013c259d5874ae7f22dcbcc95c8204008078a0ddbebd76701f6531e5ea42599f890268716e2bb38e3e125874f47595c2338049a00f5648d17b20efac8cb7ff275a510ebef6815e1599e29067821372b83eb1d28c" # valid RLP example data
+ hsh = self.adapter.put(data)
+ self.adapter.dispatch(hsh)
+ self.assertEqual(strip_0x(self.conn.last), strip_0x(data))
+
+
if __name__ == '__main__':
unittest.main()