mirror of
https://github.com/status-im/nim-eth.git
synced 2025-01-11 06:46:33 +00:00
d2ba753792
* Add metrics related to devp2p peer connections * Avoid reconnecting to peers that just failed connection - Add SeenTable to avoid reconnecting to peers immediately after a failed connect. Depending on the failure, the amount of time is different. This is similar to what is done in nimbus-eth2. - Attempt to rework rlpxConnect at the same time, in order to make sure that errors are properly handled. The current structure is far from ideal, but it is hopefully a small step in the right direction. To many oddities in there right now to really rework rlpxConnect properply. * Fix rlpx thunk fuzzer
60 lines
1.4 KiB
Nim
60 lines
1.4 KiB
Nim
{.used.}
|
|
|
|
import
|
|
std/[json, os],
|
|
unittest2, stint,
|
|
chronos, stew/byteutils,
|
|
../../eth/[p2p, common],
|
|
../stubloglevel,
|
|
./p2p_test_helper,
|
|
./eth_protocol
|
|
|
|
let rng = newRng()
|
|
|
|
var
|
|
node1 = setupTestNode(rng, eth)
|
|
node2 = setupTestNode(rng, eth)
|
|
|
|
node2.startListening()
|
|
let res = waitFor node1.rlpxConnect(newNode(node2.toENode()))
|
|
check res.isOk()
|
|
|
|
let peer = res.get()
|
|
|
|
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)
|
|
|
|
suite extractFilename(filename):
|
|
for testname, testdata in js:
|
|
test testname:
|
|
let
|
|
payloadHex = testdata{"payload"}
|
|
error = testdata{"error"}
|
|
|
|
if payloadHex.isNil or payloadHex.kind != JString:
|
|
skip()
|
|
return
|
|
|
|
let payload = hexToSeqByte(payloadHex.str)
|
|
|
|
if error.isNil:
|
|
testThunk(payload)
|
|
else:
|
|
if error.kind != JString:
|
|
skip()
|
|
return
|
|
|
|
# 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 e
|
|
|
|
testPayloads(sourceDir / "test_rlpx_thunk.json")
|