From 3cd8172e6546eaaef522df8658dd0a7905f1c176 Mon Sep 17 00:00:00 2001 From: kdeme Date: Thu, 11 Apr 2019 15:08:32 +0200 Subject: [PATCH] Add test for failing connection handler --- eth.nimble | 2 +- ...handler.nim => test_protocol_handlers.nim} | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) rename tests/p2p/{test_failing_handler.nim => test_protocol_handlers.nim} (69%) diff --git a/eth.nimble b/eth.nimble index bcd0e75..7563c92 100644 --- a/eth.nimble +++ b/eth.nimble @@ -51,7 +51,7 @@ proc runP2pTests() = "test_enode", "test_shh", "test_shh_connect", - "test_failing_handler", + "test_protocol_handlers", ]: runTest("tests/p2p/" & filename) diff --git a/tests/p2p/test_failing_handler.nim b/tests/p2p/test_protocol_handlers.nim similarity index 69% rename from tests/p2p/test_failing_handler.nim rename to tests/p2p/test_protocol_handlers.nim index 8694bbd..3b14f68 100644 --- a/tests/p2p/test_failing_handler.nim +++ b/tests/p2p/test_protocol_handlers.nim @@ -39,8 +39,20 @@ p2pProtocol xyz(version = 1, if true: raise newException(CatchableError, "Fake xyz exception") +p2pProtocol hah(version = 1, + shortName = "hah", + networkState = network): + + onPeerConnected do (peer: Peer): + if true: + raise newException(UselessPeerError, "Fake hah exception") + peer.networkState.count += 1 + + onPeerDisconnected do (peer: Peer, reason: DisconnectionReason) {.gcsafe.}: + peer.networkState.count -= 1 + suite "Testing protocol handlers": - asyncTest "Failing disconnect handler": + asyncTest "Failing disconnection handler": let bootENode = waitFor setupBootNode() var node1 = setupTestNode(abc, xyz) var node2 = setupTestNode(abc, xyz) @@ -60,3 +72,14 @@ suite "Testing protocol handlers": # handlers, each handler still ran node1.protocolState(abc).count == 0 node1.protocolState(xyz).count == 0 + + asyncTest "Failing connection handler": + var node1 = setupTestNode(hah) + var node2 = setupTestNode(hah) + node2.startListening() + let peer = waitFor node1.rlpxConnect(newNode(initENode(node2.keys.pubKey, + node2.address))) + check: + peer.isNil == true + # To check if the disconnection handler did not run + node1.protocolState(hah).count == 0