Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed May 21, 2024
1 parent 193116e commit 8f49d08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 8f49d08

Please sign in to comment.