From 136a749af4cb00efce2c11c84ca2987895ff9aad Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Thu, 26 Sep 2024 17:48:12 +0200 Subject: [PATCH] Add docs for test. --- tests/pubsub/testgossipinternal.nim | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 777b479789..2352fc6f78 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -677,55 +677,76 @@ suite "GossipSub internal": gossipSub.mesh[topic] = initHashSet[PubSubPeer]() gossipSub.subscribe(topic, handler2) + # Instantiates 30 peers and connects all of them to the previously defined `gossipSub` for i in 0 ..< 30: + # Define a new connection let conn = TestBufferStream.new(noop) conns &= conn let peerId = randomPeerId() conn.peerId = peerId let peer = gossipSub.getPubSubPeer(peerId) peer.handler = handler + # Add the connection to `gossipSub`, to their `gossipSub.gossipsub` and `gossipSub.mesh` tables gossipSub.grafted(peer, topic) gossipSub.mesh[topic].incl(peer) + # Peers with no budget should not request messages block: - # should ignore no budget peer + # Define a new connection let conn = TestBufferStream.new(noop) conns &= conn let peerId = randomPeerId() conn.peerId = peerId let peer = gossipSub.getPubSubPeer(peerId) + # Add message to `gossipSub`'s message cache let id = @[0'u8, 1, 2, 3] + gossipSub.mcache.put(id, Message()) + peer.sentIHaves[^1].incl(id) + # Build an IHAVE message that contains the same message ID three times let msg = ControlIHave(topicID: topic, messageIDs: @[id, id, id]) + # Given the peer has no budget to request messages peer.iHaveBudget = 0 + # When a peer makes an IHAVE request for the a message that `gossipSub` has let iwants = gossipSub.handleIHave(peer, @[msg]) + # Then `gossipSub` should not generate an IWant message for the message, check: iwants.messageIDs.len == 0 + # Peers with budget should request messages. If ids are repeated, only one request should be generated block: - # given duplicate ihave should generate only one iwant + # Define a new connection let conn = TestBufferStream.new(noop) conns &= conn let peerId = randomPeerId() conn.peerId = peerId let peer = gossipSub.getPubSubPeer(peerId) let id = @[0'u8, 1, 2, 3] + # Build an IHAVE message that contains the same message ID three times let msg = ControlIHave(topicID: topic, messageIDs: @[id, id, id]) + # Given the budget is not 0 (because it's not been overridden) + # When a peer makes an IHAVE request for the a message that `gossipSub` does not have let iwants = gossipSub.handleIHave(peer, @[msg]) + # Then `gossipSub` should generate an IWant message for the message check: iwants.messageIDs.len == 1 + # Peers with budget should request messages. If ids are repeated, only one request should be generated block: - # given duplicate iwant should generate only one message + # Define a new connection let conn = TestBufferStream.new(noop) conns &= conn let peerId = randomPeerId() conn.peerId = peerId let peer = gossipSub.getPubSubPeer(peerId) + # Add message to `gossipSub`'s message cache let id = @[0'u8, 1, 2, 3] gossipSub.mcache.put(id, Message()) peer.sentIHaves[^1].incl(id) + # Build an IWANT message that contains the same message ID three times let msg = ControlIWant(messageIDs: @[id, id, id]) + # When a peer makes an IWANT request for the a message that `gossipSub` has let genmsg = gossipSub.handleIWant(peer, @[msg]) + # Then `gossipSub` should return the message check: genmsg.len == 1