Skip to content

Conversation

@rlve
Copy link
Contributor

@rlve rlve commented Jul 1, 2025

Changes:

  • add tests for different combinations of signature flags: sign, verifySignature and anonymize
  • also I noticed testgossipsubskipmcache tests from PR were not working and were not included to run in CI

@rlve rlve marked this pull request as ready for review July 1, 2025 15:20
@rlve rlve requested a review from a team as a code owner July 1, 2025 15:20
Comment on lines 92 to 126
type NodeConfig = tuple[sign: bool, verify: bool, anonymize: bool]
let scenarios =
@[
# (sender_config, receiver_config, should_work)

# valid combos
# S default, R default
((true, true, false), (true, true, false), true),
# S default, R anonymous
((true, true, false), (false, false, true), true),
# S anonymous, R anonymous
((false, false, true), (false, false, true), true),
# S only sign, R only verify
((true, false, false), (false, true, false), true),
# S only verify, R only sign
((true, true, true), (false, false, false), true),
# S anonymous (not signed despite the flag), R minimal
((false, true, true), (true, false, false), true),
# S unsigned, R unsigned
((false, false, false), (false, false, false), true),

# invalid combos
# S anonymous, R default
((false, false, true), (true, true, false), false),
# S unsigned, R anonymous but verify
((false, false, false), (true, true, true), false),
# S unsigned, R default
((false, false, false), (true, true, false), false),
]

for scenario in scenarios:
let title = "Compatibility matrix: " & $scenario
asyncTest title:
let
(senderConfig, receiverConfig, shouldWork) = scenario
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be better if scenarios is seq[Scenario], then type Scenario has senderConfig receiverConfig and shouldWork properties. senderConfig and receiverConfig are i guess NodeConfig ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 0c2b351, but I don't love how verbose it is now.

Comment on lines 129 to 139
gossip = true,
sign = senderConfig[0],
verifySignature = senderConfig[1],
anonymize = senderConfig[2],
)[0]
receiver = generateNodes(
1,
gossip = true,
sign = receiverConfig[0],
verifySignature = receiverConfig[1],
anonymize = receiverConfig[2],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sign = senderConfig.sign,
verifySignature = senderConfig.verifySignature,
anonymize = senderConfig.anonymize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 0c2b351

Comment on lines 146 to 148
var messageReceived = false
proc handler(topic: string, data: seq[byte]) {.async.} =
messageReceived = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess we had some utility for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 0c2b351

Comment on lines 85 to 90
check:
receivedMessages[0].data == testData
receivedMessages[0].fromPeer.data.len == 0
receivedMessages[0].seqno.len == 0
receivedMessages[0].signature.len == 0
receivedMessages[0].key.len == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check isAnonymusMessage(receivedMessages[0])
proc isAnonymusMessage(msg): bool =
  return msg.fromPeer.data.len == 0 and msg.seqno.len == 0 ......

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code like this is much more self explanatory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree here, adding proc isAnonymusMessage would be redundant if I were to use it in only one place. The test case is clear, it shows sending an anonymous message and asserts it's properties.

Comment on lines -2 to -5
const
libp2p_pubsub_sign {.booldefine.} = true
libp2p_pubsub_verify {.booldefine.} = true
libp2p_pubsub_anonymize {.booldefine.} = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we had opened issue to remove these consts or we just discussed for removing them? anyway if there is issue let's close it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about it and I created this issue: #1434, which is linked.

@github-project-automation github-project-automation bot moved this from new to In Progress in nim-libp2p Jul 2, 2025
@rlve rlve merged commit 4f85976 into master Jul 2, 2025
23 checks passed
@rlve rlve deleted the test-gossipsub-compatibility-2 branch July 2, 2025 12:09
@github-project-automation github-project-automation bot moved this from In Progress to done in nim-libp2p Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

test(gossipsub): add specific tests around verifySignature, anonymize and sign

4 participants