Add EIP-8 test + activate rlpx thunk test

This commit is contained in:
kdeme 2019-10-22 15:14:14 +02:00 committed by zah
parent 17f90920e0
commit 5850186ca0
3 changed files with 23 additions and 11 deletions

View File

@ -48,6 +48,7 @@ proc runP2pTests() =
"test_discovery",
"test_ecies",
"test_enode",
"test_rlpx_thunk",
"test_shh",
"test_shh_connect",
"test_protocol_handlers",

View File

@ -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"
}
}

View File

@ -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,16 +33,20 @@ proc testPayloads(filename: string) =
if payloadHex.isNil or payloadHex.kind != JString:
skip()
continue
if error.isNil or error.kind != JString:
let payload = hexToSeqByte(payloadHex.str)
if error.isNil:
testThunk(payload)
else:
if 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)
testThunk(payload)
except CatchableError as e:
check: e.name == error.str
raise