Add GRAFT on direct peers test.

This commit is contained in:
Alejandro Cabeza Romero 2024-09-30 17:42:45 +02:00
parent 7549d95a8e
commit 151ef3c0e7
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
1 changed files with 42 additions and 1 deletions

View File

@ -1872,7 +1872,7 @@ suite "Gossipsub Parameters":
)
# Unsubscribe from the topic
nodes[1].unsubscribe(topic, handler)
nodes[1].unsubscribe(topic, voidTopicHandler)
# Then verify what nodes receive the PX
check:
@ -1892,3 +1892,44 @@ suite "Gossipsub Parameters":
)
await allFuturesThrowing(nodesFut.concat())
asyncTest "GRAFT on direct peers are rejected":
# Given 2 nodes
let
topic = "foo"
nodes = generateNodes(2, gossip = true)
nodesFut = await allFinished(nodes.mapIt(it.switch.start()))
n0 = nodes[0]
n1 = nodes[1]
g0 = GossipSub(n0)
g1 = GossipSub(n1)
# Connect them
await subscribeNodes(nodes)
# Set them as direct peers
await g0.addDirectPeer(n1.switch.peerInfo.peerId, n1.switch.peerInfo.addrs)
await g1.addDirectPeer(n0.switch.peerInfo.peerId, n0.switch.peerInfo.addrs)
# Get peers to check their behaviour penalty
let
p0 = g0.getOrCreatePeer(n1.switch.peerInfo.peerId, @[GossipSubCodec_12])
p1 = g1.getOrCreatePeer(n0.switch.peerInfo.peerId, @[GossipSubCodec_12])
check:
p0.behaviourPenalty == 0
p1.behaviourPenalty == 0
# When node 0 sends a GRAFT message to node 1
let controlMessage = ControlMessage(graft: @[ControlGraft(topicID: topic)])
g0.broadcast(@[p1], RPCMsg(control: some(controlMessage)), isHighPriority = true)
await sleepAsync(DURATION_TIMEOUT)
echo p0.behaviourPenalty
# Then the peer should be penalized
check:
p0.behaviourPenalty >= 0.09 and p0.behaviourPenalty <= 0.1
p1.behaviourPenalty == 0
# Cleanup
await allFuturesThrowing(nodes.mapIt(allFutures(it.switch.stop())))
await allFuturesThrowing(nodesFut)