From 5850186ca03a3832540e19e5e3ce69a223e3e9d5 Mon Sep 17 00:00:00 2001 From: kdeme Date: Tue, 22 Oct 2019 15:14:14 +0200 Subject: [PATCH] Add EIP-8 test + activate rlpx thunk test --- eth.nimble | 1 + tests/p2p/test_rlpx_thunk.json | 3 +++ tests/p2p/test_rlpx_thunk.nim | 30 +++++++++++++++++++----------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/eth.nimble b/eth.nimble index ca33059..fce46c2 100644 --- a/eth.nimble +++ b/eth.nimble @@ -48,6 +48,7 @@ proc runP2pTests() = "test_discovery", "test_ecies", "test_enode", + "test_rlpx_thunk", "test_shh", "test_shh_connect", "test_protocol_handlers", diff --git a/tests/p2p/test_rlpx_thunk.json b/tests/p2p/test_rlpx_thunk.json index a424b1c..5f8851f 100644 --- a/tests/p2p/test_rlpx_thunk.json +++ b/tests/p2p/test_rlpx_thunk.json @@ -48,5 +48,8 @@ "payload": "010a", "error": "RlpTypeMismatch", "description": "listElem to assert on not a list" + }, + "devp2p hello packet version 22 + additional list elements for EIP-8": { + "payload": "00f87137916b6e6574682f76302e39312f706c616e39cdc5836574683dc6846d6f726b1682270fb840fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877c883666f6f836261720304" } } diff --git a/tests/p2p/test_rlpx_thunk.nim b/tests/p2p/test_rlpx_thunk.nim index ad5823a..8955bde 100644 --- a/tests/p2p/test_rlpx_thunk.nim +++ b/tests/p2p/test_rlpx_thunk.nim @@ -16,6 +16,10 @@ node2.startListening() peer = waitFor node1.rlpxConnect(newNode(initENode(node2.keys.pubKey, node2.address))) +proc testThunk(payload: openArray[byte]) = + var (msgId, msgData) = recvMsgMock(payload) + waitFor peer.invokeThunk(msgId.int, msgData) + proc testPayloads(filename: string) = let js = json.parseFile(filename) @@ -29,18 +33,22 @@ proc testPayloads(filename: string) = if payloadHex.isNil or payloadHex.kind != JString: skip() continue - if error.isNil or error.kind != JString: - skip() - continue let payload = hexToSeqByte(payloadHex.str) - # TODO: can I convert the error string to an Exception type at runtime? - expect CatchableError: - try: - var (msgId, msgData) = recvMsgMock(payload) - waitFor peer.invokeThunk(msgId.int, msgData) - except CatchableError as e: - check: e.name == error.str - raise + + if error.isNil: + testThunk(payload) + else: + if error.kind != JString: + skip() + continue + + # TODO: can I convert the error string to an Exception type at runtime? + expect CatchableError: + try: + testThunk(payload) + except CatchableError as e: + check: e.name == error.str + raise testPayloads(sourceDir / "test_rlpx_thunk.json")