From 74770592dc7b450ac889a560699469135f91c07c Mon Sep 17 00:00:00 2001 From: aya Date: Mon, 30 Sep 2024 08:06:46 +0300 Subject: [PATCH 1/6] adding block5 protobuf 1-4 test cases --- tests/pubsub/testgossipinternal.nim | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 777b479789..bfba99c7c3 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -662,6 +662,50 @@ suite "GossipSub internal": await allFuturesThrowing(conns.mapIt(it.close())) await gossipSub.switch.stop() + # test cases for block 5 gossibsub test plan + # tests 1 -4 for checking the formatting of objects + # have - want - graft - prune + + asyncTest "Check ControlIHave formatting": + let topic = "dummytopic" + + let msgID = @[0'u8, 1, 2, 3] + let msg = ControlIHave(topicID: topic, messageIDs: @[msgID]) + check: + msg.topicID == topic + msg.messageIDs == @[msgID] + + asyncTest "Check ControlIWant formatting": + let msgID = @[0'u8, 1, 2, 3] + let msg = ControlIWant(messageIDs: @[msgID]) + check: + msg.messageIDs == @[msgID] + + asyncTest "Check ControGraft formatting": + let topic = "dummytopic" + let msg = ControlGraft(topicID: topic) + check: + msg.topicID == topic + + asyncTest "Check ControPrune": + let topic = "foobar" + #var peerecord:seq[bytes] + var + peerecord: seq[byte] = @[1, 2, 3] + peerData: seq[byte] = @[4, 5] + backoff: uint64 = 123 + peerInfo = PeerInfoMsg( + peerId: PeerId(data: @['e'.byte]), # 1 byte + signedPeerRecord: @['f'.byte, 'g'.byte] # 2 bytes + , + ) + + let msg = ControlPrune(topicID: topic, peers: @[peerInfo], backoff: backoff) + check: + msg.topicID == topic + msg.peers.contains(peerInfo) + msg.backoff == backoff + asyncTest "handleIHave/Iwant tests": let gossipSub = TestGossipSub.init(newStandardSwitch()) From 4f96d1bc3794caefeed995dd497a1035035d2b63 Mon Sep 17 00:00:00 2001 From: aya Date: Tue, 1 Oct 2024 15:05:12 +0300 Subject: [PATCH 2/6] Test cases of block5[1,2,7] --- tests/pubsub/testgossipinternal.nim | 62 ++++++++++------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index bfba99c7c3..90f8930bfa 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -663,49 +663,29 @@ suite "GossipSub internal": await gossipSub.switch.stop() # test cases for block 5 gossibsub test plan - # tests 1 -4 for checking the formatting of objects - # have - want - graft - prune - - asyncTest "Check ControlIHave formatting": - let topic = "dummytopic" - - let msgID = @[0'u8, 1, 2, 3] - let msg = ControlIHave(topicID: topic, messageIDs: @[msgID]) - check: - msg.topicID == topic - msg.messageIDs == @[msgID] - - asyncTest "Check ControlIWant formatting": - let msgID = @[0'u8, 1, 2, 3] - let msg = ControlIWant(messageIDs: @[msgID]) - check: - msg.messageIDs == @[msgID] - - asyncTest "Check ControGraft formatting": - let topic = "dummytopic" - let msg = ControlGraft(topicID: topic) - check: - msg.topicID == topic - - asyncTest "Check ControPrune": - let topic = "foobar" - #var peerecord:seq[bytes] - var - peerecord: seq[byte] = @[1, 2, 3] - peerData: seq[byte] = @[4, 5] - backoff: uint64 = 123 - peerInfo = PeerInfoMsg( - peerId: PeerId(data: @['e'.byte]), # 1 byte - signedPeerRecord: @['f'.byte, 'g'.byte] # 2 bytes - , + #check correctly parsed ihave/iwant messages + # check value before & after decoding equal " round trip testing + # check encoding / decoding time less than 1 millisecond + asyncTest "Check encoding/decoding roundtrip ": + let id = @[0'u8, 1, 2, 3] + let msg = Message(topic: "topic", data: id) + let rpcMsg = RPCMsg( + control: some( + ControlMessage(ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])], + iwant: @[ControlIWant(messageIDs: @[@[0'u8,1,2]])]) ) - - let msg = ControlPrune(topicID: topic, peers: @[peerInfo], backoff: backoff) + ) + let encodeTimeout = Moment.now() + 1.milliseconds + let encoded = encodeRpcMsg(rpcMsg, true) + let timeout2 = Moment.now() + let decoded = decodeRpcMsg(encoded) + echo encoded + let decodeTime = Moment.now() check: - msg.topicID == topic - msg.peers.contains(peerInfo) - msg.backoff == backoff - + rpcMsg == decoded.value + encodeTimeout > timeout2 + timeout2+1.milliseconds > decodeTime + asyncTest "handleIHave/Iwant tests": let gossipSub = TestGossipSub.init(newStandardSwitch()) From f545a870b09af310bec0a05204eb6a30174881c8 Mon Sep 17 00:00:00 2001 From: aya Date: Thu, 3 Oct 2024 14:21:54 +0300 Subject: [PATCH 3/6] adding test cases [1-4 ,7] for block 5 --- tests/pubsub/testgossipinternal.nim | 57 ++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 90f8930bfa..9be5e0d860 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -664,28 +664,59 @@ suite "GossipSub internal": # test cases for block 5 gossibsub test plan #check correctly parsed ihave/iwant messages - # check value before & after decoding equal " round trip testing + # check value before & after decoding equal using protoc cmd tool for reference # check encoding / decoding time less than 1 millisecond - asyncTest "Check encoding/decoding roundtrip ": - let id = @[0'u8, 1, 2, 3] - let msg = Message(topic: "topic", data: id) + asyncTest "Check RPCMsg encoding": + let backofftime = 10.uint64 + var id: seq[byte] = @[123] let rpcMsg = RPCMsg( control: some( - ControlMessage(ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])], - iwant: @[ControlIWant(messageIDs: @[@[0'u8,1,2]])]) + ControlMessage( + ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])], + iwant: @[ControlIWant(messageIDs: @[id])], + graft: @[ControlGraft(topicID: "foobar")], + prune: @[ControlPrune(topicID: "foobar", backoff: backofftime)], + ) ) ) + let encodedExpected: seq[byte] = + @[ + 26, 44, 10, 10, 6, 102, 111, 111, 98, 97, 114, 18, 3, 49, 50, 51, 18, 5, 10, 3, + 49, 50, 51, 26, 8, 10, 6, 102, 111, 111, 98, 97, 114, 34, 10, 10, 6, 102, 111, + 111, 98, 97, 114, 16, + ] #encoded using protoc cmd tool + let encodeTimeout = Moment.now() + 1.milliseconds - let encoded = encodeRpcMsg(rpcMsg, true) + let encodedMsg = encodeRpcMsg(rpcMsg, true) let timeout2 = Moment.now() - let decoded = decodeRpcMsg(encoded) - echo encoded - let decodeTime = Moment.now() check: - rpcMsg == decoded.value encodeTimeout > timeout2 - timeout2+1.milliseconds > decodeTime - + encodedExpected == encodedMsg + + asyncTest "Check RPCMsg decoding": + let id: seq[byte] = @[1] + let originMessage = RPCMsg( + control: some( + ControlMessage( + ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])], + graft: @[ControlGraft(topicID: "foobar")], + ) + ) + ) + #data encoded using protoc cmd tool + let encodedMsg: seq[byte] = + @[ + 26, 23, 10, 11, 10, 6, 102, 111, 111, 98, 97, 114, 18, 1, 49, 26, 8, 10, 6, 102, + 111, 111, 98, 97, 114, + ] + + let decodeTimeout = Moment.now() + 1.milliseconds + var rpcMsg = decodeRpcMsg(encodedMsg).value + let timeout2 = Moment.now() + check: + decodeTimeout > timeout2 + rpcMsg == originMessage + asyncTest "handleIHave/Iwant tests": let gossipSub = TestGossipSub.init(newStandardSwitch()) From 96459cc47c9dca13ec2315e84628b8edbaab8eea Mon Sep 17 00:00:00 2001 From: aya Date: Thu, 3 Oct 2024 16:45:23 +0300 Subject: [PATCH 4/6] fixing florin's comments --- tests/pubsub/testgossipinternal.nim | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 9be5e0d860..8a6712469e 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -662,10 +662,10 @@ suite "GossipSub internal": await allFuturesThrowing(conns.mapIt(it.close())) await gossipSub.switch.stop() - # test cases for block 5 gossibsub test plan - #check correctly parsed ihave/iwant messages - # check value before & after decoding equal using protoc cmd tool for reference - # check encoding / decoding time less than 1 millisecond + # test cases for block 5 gossibsub test plan + # check correctly parsed ihave/iwant/graft/prune/idontwant messages + # check value before & after decoding equal using protoc cmd tool for reference + # check encoding / decoding time less than 1 millisecond asyncTest "Check RPCMsg encoding": let backofftime = 10.uint64 var id: seq[byte] = @[123] @@ -676,14 +676,15 @@ suite "GossipSub internal": iwant: @[ControlIWant(messageIDs: @[id])], graft: @[ControlGraft(topicID: "foobar")], prune: @[ControlPrune(topicID: "foobar", backoff: backofftime)], + idontwant: @[ControlIWant(messageIDs: @[id])], ) ) ) let encodedExpected: seq[byte] = @[ - 26, 44, 10, 10, 6, 102, 111, 111, 98, 97, 114, 18, 3, 49, 50, 51, 18, 5, 10, 3, + 26, 51, 10, 10, 6, 102, 111, 111, 98, 97, 114, 18, 3, 49, 50, 51, 18, 5, 10, 3, 49, 50, 51, 26, 8, 10, 6, 102, 111, 111, 98, 97, 114, 34, 10, 10, 6, 102, 111, - 111, 98, 97, 114, 16, + 111, 98, 97, 114, 16, 10, 42, 5, 10, 3, 49, 50, 51, ] #encoded using protoc cmd tool let encodeTimeout = Moment.now() + 1.milliseconds @@ -694,20 +695,25 @@ suite "GossipSub internal": encodedExpected == encodedMsg asyncTest "Check RPCMsg decoding": + let backofftime = 12.uint64 let id: seq[byte] = @[1] let originMessage = RPCMsg( control: some( ControlMessage( ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])], - graft: @[ControlGraft(topicID: "foobar")], + iwant: @[ControlIWant(messageIDs: @[id])], + graft: @[ControlGraft(topicID: "topic")], + prune: @[ControlPrune(topicID: "new", backoff: backofftime)], + idontwant: @[ControlIWant(messageIDs: @[id])], ) ) ) #data encoded using protoc cmd tool let encodedMsg: seq[byte] = @[ - 26, 23, 10, 11, 10, 6, 102, 111, 111, 98, 97, 114, 18, 1, 49, 26, 8, 10, 6, 102, - 111, 111, 98, 97, 114, + 26, 41, 10, 11, 10, 6, 102, 111, 111, 98, 97, 114, 18, 1, 49, 18, 3, 10, 1, 49, + 26, 7, 10, 5, 116, 111, 112, 105, 99, 34, 7, 10, 3, 110, 101, 119, 16, 12, 42, + 3, 10, 1, 49, ] let decodeTimeout = Moment.now() + 1.milliseconds From 1d5baca63c899afc9a726ffcf1898aa008aef643 Mon Sep 17 00:00:00 2001 From: aya Date: Thu, 3 Oct 2024 17:12:32 +0300 Subject: [PATCH 5/6] fixing review comments --- tests/pubsub/testgossipinternal.nim | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 8a6712469e..1d03f1d036 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -665,7 +665,6 @@ suite "GossipSub internal": # test cases for block 5 gossibsub test plan # check correctly parsed ihave/iwant/graft/prune/idontwant messages # check value before & after decoding equal using protoc cmd tool for reference - # check encoding / decoding time less than 1 millisecond asyncTest "Check RPCMsg encoding": let backofftime = 10.uint64 var id: seq[byte] = @[123] @@ -687,11 +686,9 @@ suite "GossipSub internal": 111, 98, 97, 114, 16, 10, 42, 5, 10, 3, 49, 50, 51, ] #encoded using protoc cmd tool - let encodeTimeout = Moment.now() + 1.milliseconds - let encodedMsg = encodeRpcMsg(rpcMsg, true) - let timeout2 = Moment.now() + check: - encodeTimeout > timeout2 + encodedExpected == encodedMsg asyncTest "Check RPCMsg decoding": @@ -716,11 +713,9 @@ suite "GossipSub internal": 3, 10, 1, 49, ] - let decodeTimeout = Moment.now() + 1.milliseconds - var rpcMsg = decodeRpcMsg(encodedMsg).value - let timeout2 = Moment.now() + check: - decodeTimeout > timeout2 + rpcMsg == originMessage asyncTest "handleIHave/Iwant tests": From 422c4dafb329c52fa97a30adc1b580b89cb404c7 Mon Sep 17 00:00:00 2001 From: aya Date: Thu, 3 Oct 2024 17:18:40 +0300 Subject: [PATCH 6/6] fixing review comments & linters --- tests/pubsub/testgossipinternal.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 1d03f1d036..79a6f4eff3 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -686,9 +686,8 @@ suite "GossipSub internal": 111, 98, 97, 114, 16, 10, 42, 5, 10, 3, 49, 50, 51, ] #encoded using protoc cmd tool - + let encodedMsg = encodeRpcMsg(rpcMsg, true) check: - encodedExpected == encodedMsg asyncTest "Check RPCMsg decoding": @@ -713,9 +712,8 @@ suite "GossipSub internal": 3, 10, 1, 49, ] - + var rpcMsg = decodeRpcMsg(encodedMsg).value check: - rpcMsg == originMessage asyncTest "handleIHave/Iwant tests":