Skip to content

Commit

Permalink
test reproducing the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Jun 5, 2024
1 parent 443015f commit 2956971
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
41 changes: 41 additions & 0 deletions tests/pubsub/testgossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1075,3 +1075,44 @@ suite "GossipSub":
check currentRateLimitHits() == rateLimitHits + 2

await stopNodes(nodes)

asyncTest "Peer must send right gosspipsub version":
func dumbMsgIdProvider(m: Message): Result[MessageId, ValidationResult] =
ok(newSeq[byte](10))
let node0 = generateNodes(
1,
gossip = true,
msgIdProvider = dumbMsgIdProvider
)[0]
let node1 = generateNodes(
1,
gossip = true,
msgIdProvider = dumbMsgIdProvider,
gossipSubVersion = GossipSubCodec_10
)[0]

let nodesFut = await allFinished(
node0.switch.start(),
node1.switch.start(),
)

await node0.switch.connect(node1.switch.peerInfo.peerId, node1.switch.peerInfo.addrs)

proc handler(topic: string, data: seq[byte]) {.async.} = discard

node0.subscribe("foobar", handler)
node1.subscribe("foobar", handler)
await waitSubGraph(@[node0, node1], "foobar")

var gossip0: GossipSub = GossipSub(node0)
var gossip1: GossipSub = GossipSub(node1)

checkUntilTimeout: gossip0.mesh.getOrDefault("foobar").toSeq[0].codec == GossipSubCodec_10
checkUntilTimeout: gossip1.mesh.getOrDefault("foobar").toSeq[0].codec == GossipSubCodec_10

await allFuturesThrowing(
node0.switch.stop(),
node1.switch.stop(),
)

await allFuturesThrowing(nodesFut.concat())
5 changes: 4 additions & 1 deletion tests/pubsub/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ proc generateNodes*(
unsubscribeBackoff = 1.seconds,
maxMessageSize: int = 1024 * 1024,
enablePX: bool = false,
overheadRateLimit: Opt[tuple[bytes: int, interval: Duration]] = Opt.none(tuple[bytes: int, interval: Duration])): seq[PubSub] =
overheadRateLimit: Opt[tuple[bytes: int, interval: Duration]] = Opt.none(tuple[bytes: int, interval: Duration]),
gossipSubVersion: string = ""): seq[PubSub] =

for i in 0..<num:
let switch = newStandardSwitch(secureManagers = secureManagers, sendSignedPeerRecord = sendSignedPeerRecord)
Expand All @@ -87,6 +88,8 @@ proc generateNodes*(
g.topicParams.mgetOrPut("foobar", TopicParams.init()).topicWeight = 1.0
g.topicParams.mgetOrPut("foo", TopicParams.init()).topicWeight = 1.0
g.topicParams.mgetOrPut("bar", TopicParams.init()).topicWeight = 1.0
if gossipSubVersion != "":
g.codecs = @[gossipSubVersion]
g.PubSub
else:
FloodSub.init(
Expand Down

0 comments on commit 2956971

Please sign in to comment.