Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix flaky test for dos topic #1747

Merged
merged 1 commit into from
May 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions tests/wakunode2/test_validators.nim
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ suite "WakuNode2 - Validators":
for node in nodes: node.wakuRelay.subscribe(spamProtectedTopic, handler)
await sleepAsync(500.millis)

# Each node sends 10 messages, signed but with a non-whitelisted key (total = 50)
# Each node sends 5 messages, signed but with a non-whitelisted key (total = 25)
for i in 0..<5:
for j in 0..<10:
for j in 0..<5:
var msg = WakuMessage(
payload: urandom(1*(10^3)), contentTopic: spamProtectedTopic,
version: 2, timestamp: now(), ephemeral: true)
Expand All @@ -148,34 +148,34 @@ suite "WakuNode2 - Validators":

await nodes[i].publish(spamProtectedTopic, msg)

# Each node sends 10 messages that are not signed (total = 50)
# Each node sends 5 messages that are not signed (total = 25)
for i in 0..<5:
for j in 0..<10:
for j in 0..<5:
let unsignedMessage = WakuMessage(
payload: urandom(1*(10^3)), contentTopic: spamProtectedTopic,
version: 2, timestamp: now(), ephemeral: true)
await nodes[i].publish(spamProtectedTopic, unsignedMessage)

# Each node sends 10 messages that dont contain timestamp (total = 50)
# Each node sends 5 messages that dont contain timestamp (total = 25)
for i in 0..<5:
for j in 0..<10:
for j in 0..<5:
let unsignedMessage = WakuMessage(
payload: urandom(1*(10^3)), contentTopic: spamProtectedTopic,
version: 2, timestamp: 0, ephemeral: true)
await nodes[i].publish(spamProtectedTopic, unsignedMessage)

# Each node sends 10 messages way BEFORE than the current timestmap (total = 50)
# Each node sends 5 messages way BEFORE than the current timestmap (total = 25)
for i in 0..<5:
for j in 0..<10:
for j in 0..<5:
let beforeTimestamp = now() - getNanosecondTime(6*60)
let unsignedMessage = WakuMessage(
payload: urandom(1*(10^3)), contentTopic: spamProtectedTopic,
version: 2, timestamp: beforeTimestamp, ephemeral: true)
await nodes[i].publish(spamProtectedTopic, unsignedMessage)

# Each node sends 10 messages way LATER than the current timestmap (total = 50)
# Each node sends 5 messages way LATER than the current timestmap (total = 25)
for i in 0..<5:
for j in 0..<10:
for j in 0..<5:
let afterTimestamp = now() - getNanosecondTime(6*60)
let unsignedMessage = WakuMessage(
payload: urandom(1*(10^3)), contentTopic: spamProtectedTopic,
Expand All @@ -185,20 +185,20 @@ suite "WakuNode2 - Validators":
# Wait for gossip
await sleepAsync(2.seconds)

# Since we have a full mesh with 5 nodes and each one publishes 50+50+50+50+50 msgs
# there are 1250 messages being sent.
# 250 are received ok in the handler (first hop)
# 1000 are are wrong so rejected (rejected not relayed)
# Since we have a full mesh with 5 nodes and each one publishes 25+25+25+25+25 msgs
# there are 625 messages being sent.
# 125 are received ok in the handler (first hop)
# 500 are are wrong so rejected (rejected not relayed)
check:
msgReceived == 250
msgReceived == 125

var msgRejected = 0
for i in 0..<5:
for k, v in nodes[i].wakuRelay.peerStats.mpairs:
msgRejected += v.topicInfos[spamProtectedTopic].invalidMessageDeliveries.int

check:
msgRejected == 1000
msgRejected == 500

await allFutures(nodes.mapIt(it.stop()))

Expand Down