From 8f49d089f840c76ec5f6e0585f677b38b73e6180 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Wed, 15 May 2024 17:28:50 +0300 Subject: [PATCH] add test --- .../io/libp2p/pubsub/gossip/GossipRouter.kt | 2 +- .../pubsub/gossip/GossipRpcPartsQueueTest.kt | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libp2p/src/main/kotlin/io/libp2p/pubsub/gossip/GossipRouter.kt b/libp2p/src/main/kotlin/io/libp2p/pubsub/gossip/GossipRouter.kt index 01901e85..d548c517 100644 --- a/libp2p/src/main/kotlin/io/libp2p/pubsub/gossip/GossipRouter.kt +++ b/libp2p/src/main/kotlin/io/libp2p/pubsub/gossip/GossipRouter.kt @@ -317,7 +317,7 @@ open class GossipRouter( } private fun handleIHave(msg: Rpc.ControlIHave, peer: PeerHandler) { - // we ignore IHAVE for unknown topics + // we ignore IHAVE gossip for unknown topics if (msg.hasTopicID() && !mesh.containsKey(msg.topicID)) { return } diff --git a/libp2p/src/test/kotlin/io/libp2p/pubsub/gossip/GossipRpcPartsQueueTest.kt b/libp2p/src/test/kotlin/io/libp2p/pubsub/gossip/GossipRpcPartsQueueTest.kt index 636ba52d..843a63f2 100644 --- a/libp2p/src/test/kotlin/io/libp2p/pubsub/gossip/GossipRpcPartsQueueTest.kt +++ b/libp2p/src/test/kotlin/io/libp2p/pubsub/gossip/GossipRpcPartsQueueTest.kt @@ -1,8 +1,10 @@ package io.libp2p.pubsub.gossip import io.libp2p.core.PeerId +import io.libp2p.etc.types.WBytes import io.libp2p.etc.types.toProtobuf import io.libp2p.etc.types.toWBytes +import io.libp2p.pubsub.Topic import io.libp2p.pubsub.gossip.builders.GossipParamsBuilder import io.libp2p.pubsub.gossip.builders.GossipRouterBuilder import org.assertj.core.api.Assertions.assertThat @@ -259,4 +261,17 @@ class GossipRpcPartsQueueTest { assertThat(msgs).hasSize(3) assertThat(msgs.merge()).isEqualTo(single) } + + @Test + fun `check that resulting IHAVE sets the topic ID`() { + val topic: Topic = "topic1" + val partsQueue = TestGossipQueue(gossipParamsWithLimits) + partsQueue.addIHave(WBytes(ByteArray(10)), topic) + val res = partsQueue.takeMerged().first() + assertThat(res.control.ihaveList[0].topicID).isEqualTo(topic) + + val serialized = res.toByteArray() + val desrializedRpc = Rpc.RPC.parseFrom(serialized) + assertThat(desrializedRpc.control.ihaveList[0].topicID).isEqualTo(topic) + } }