-
Notifications
You must be signed in to change notification settings - Fork 71
test(gossipsub): Signature flags tests #1496
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0a8ea4
test: add tests signature flags
rlve 65e5fba
Merge branch 'master' into test-gossipsub-compatibility-2
rlve bcd8ab7
Merge branch 'master' into test-gossipsub-compatibility-2
rlve 6a0767a
test: include file
rlve c86a8f2
test: fix and include testgossipsubskipmcache
rlve fb13b2d
Merge branch 'test-gossipsub-compatibility-2' of github.com:vacp2p/ni…
rlve 9d24abd
test: fix
rlve 0c2b351
test: refactor
rlve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
217 changes: 217 additions & 0 deletions
217
tests/pubsub/integration/testgossipsubsignatureflags.nim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| # Nim-LibP2P | ||
| # Copyright (c) 2023-2025 Status Research & Development GmbH | ||
| # Licensed under either of | ||
| # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) | ||
| # * MIT license ([LICENSE-MIT](LICENSE-MIT)) | ||
| # at your option. | ||
| # This file may not be copied, modified, or distributed except according to | ||
| # those terms. | ||
|
|
||
| {.used.} | ||
|
|
||
| import unittest2 | ||
| import chronos | ||
| import stew/byteutils | ||
| import ../utils | ||
| import ../../../libp2p/protocols/pubsub/[gossipsub, pubsub] | ||
| import ../../../libp2p/protocols/pubsub/rpc/[messages] | ||
| import ../../helpers | ||
| import ../../utils/futures | ||
|
|
||
| suite "GossipSub Integration - Signature Flags": | ||
| const | ||
| topic = "foobar" | ||
| testData = "test message".toBytes() | ||
|
|
||
| teardown: | ||
| checkTrackers() | ||
|
|
||
| asyncTest "Default - messages are signed when sign=true and contain fromPeer and seqno when anonymize=false": | ||
| let nodes = generateNodes( | ||
| 2, gossip = true, sign = true, verifySignature = true, anonymize = false | ||
| ) | ||
|
|
||
| startNodesAndDeferStop(nodes) | ||
| await connectNodesStar(nodes) | ||
|
|
||
| nodes.subscribeAllNodes(topic, voidTopicHandler) | ||
|
|
||
| var (receivedMessages, checkForMessage) = createCheckForMessages() | ||
| nodes[1].addOnRecvObserver(checkForMessage) | ||
|
|
||
| tryPublish await nodes[0].publish(topic, testData), 1 | ||
|
|
||
| checkUntilTimeout: | ||
| receivedMessages[].len > 0 | ||
|
|
||
| let receivedMessage = receivedMessages[][0] | ||
| check: | ||
| receivedMessage.data == testData | ||
| receivedMessage.fromPeer.data.len > 0 | ||
| receivedMessage.seqno.len > 0 | ||
| receivedMessage.signature.len > 0 | ||
| receivedMessage.key.len > 0 | ||
|
|
||
| asyncTest "Sign flag - messages are not signed when sign=false": | ||
| let nodes = generateNodes( | ||
| 2, gossip = true, sign = false, verifySignature = false, anonymize = false | ||
| ) | ||
|
|
||
| startNodesAndDeferStop(nodes) | ||
| await connectNodesStar(nodes) | ||
|
|
||
| nodes.subscribeAllNodes(topic, voidTopicHandler) | ||
|
|
||
| var (receivedMessages, checkForMessage) = createCheckForMessages() | ||
| nodes[1].addOnRecvObserver(checkForMessage) | ||
|
|
||
| tryPublish await nodes[0].publish(topic, testData), 1 | ||
|
|
||
| checkUntilTimeout: | ||
| receivedMessages[].len > 0 | ||
|
|
||
| let receivedMessage = receivedMessages[][0] | ||
| check: | ||
| receivedMessage.data == testData | ||
| receivedMessage.signature.len == 0 | ||
| receivedMessage.key.len == 0 | ||
|
|
||
| asyncTest "Anonymize flag - messages are anonymous when anonymize=true": | ||
| let nodes = generateNodes( | ||
| 2, gossip = true, sign = true, verifySignature = true, anonymize = true | ||
| ) # anonymize = true takes precedence | ||
| startNodesAndDeferStop(nodes) | ||
| await connectNodesStar(nodes) | ||
|
|
||
| nodes.subscribeAllNodes(topic, voidTopicHandler) | ||
|
|
||
| var (receivedMessages, checkForMessage) = createCheckForMessages() | ||
| nodes[1].addOnRecvObserver(checkForMessage) | ||
|
|
||
| let testData = "anonymous message".toBytes() | ||
| tryPublish await nodes[0].publish(topic, testData), 1 | ||
|
|
||
| checkUntilTimeout: | ||
| receivedMessages[].len > 0 | ||
|
|
||
| let receivedMessage = receivedMessages[][0] | ||
| check: | ||
| receivedMessage.data == testData | ||
| receivedMessage.fromPeer.data.len == 0 | ||
| receivedMessage.seqno.len == 0 | ||
| receivedMessage.signature.len == 0 | ||
| receivedMessage.key.len == 0 | ||
|
|
||
| type NodeConfig = object | ||
| sign: bool | ||
| verify: bool | ||
| anonymize: bool | ||
|
|
||
| type Scenario = object | ||
| senderConfig: NodeConfig | ||
| receiverConfig: NodeConfig | ||
| shouldWork: bool | ||
|
|
||
| let scenarios: seq[Scenario] = | ||
| @[ | ||
| # valid combos | ||
| # S default, R default | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: true, verify: true, anonymize: false), | ||
| receiverConfig: NodeConfig(sign: true, verify: true, anonymize: false), | ||
| shouldWork: true, | ||
| ), | ||
| # S default, R anonymous | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: true, verify: true, anonymize: false), | ||
| receiverConfig: NodeConfig(sign: false, verify: false, anonymize: true), | ||
| shouldWork: true, | ||
| ), | ||
| # S anonymous, R anonymous | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: false, verify: false, anonymize: true), | ||
| receiverConfig: NodeConfig(sign: false, verify: false, anonymize: true), | ||
| shouldWork: true, | ||
| ), | ||
| # S only sign, R only verify | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: true, verify: false, anonymize: false), | ||
| receiverConfig: NodeConfig(sign: false, verify: true, anonymize: false), | ||
| shouldWork: true, | ||
| ), | ||
| # S only verify, R only sign | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: true, verify: true, anonymize: true), | ||
| receiverConfig: NodeConfig(sign: false, verify: false, anonymize: false), | ||
| shouldWork: true, | ||
| ), | ||
| # S anonymous (not signed despite the flag), R minimal | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: false, verify: true, anonymize: true), | ||
| receiverConfig: NodeConfig(sign: true, verify: false, anonymize: false), | ||
| shouldWork: true, | ||
| ), | ||
| # S unsigned, R unsigned | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: false, verify: false, anonymize: false), | ||
| receiverConfig: NodeConfig(sign: false, verify: false, anonymize: false), | ||
| shouldWork: true, | ||
| ), | ||
|
|
||
| # invalid combos | ||
| # S anonymous, R default | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: false, verify: false, anonymize: true), | ||
| receiverConfig: NodeConfig(sign: true, verify: true, anonymize: false), | ||
| shouldWork: false, | ||
| ), | ||
| # S unsigned, R anonymous but verify | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: false, verify: false, anonymize: false), | ||
| receiverConfig: NodeConfig(sign: true, verify: true, anonymize: true), | ||
| shouldWork: false, | ||
| ), | ||
| # S unsigned, R default | ||
| Scenario( | ||
| senderConfig: NodeConfig(sign: false, verify: false, anonymize: false), | ||
| receiverConfig: NodeConfig(sign: true, verify: true, anonymize: false), | ||
| shouldWork: false, | ||
| ), | ||
| ] | ||
|
|
||
| for scenario in scenarios: | ||
| let title = "Compatibility matrix: " & $scenario | ||
| asyncTest title: | ||
| let | ||
| sender = generateNodes( | ||
| 1, | ||
| gossip = true, | ||
| sign = scenario.senderConfig.sign, | ||
| verifySignature = scenario.senderConfig.verify, | ||
| anonymize = scenario.senderConfig.anonymize, | ||
| )[0] | ||
| receiver = generateNodes( | ||
| 1, | ||
| gossip = true, | ||
| sign = scenario.receiverConfig.sign, | ||
| verifySignature = scenario.receiverConfig.verify, | ||
| anonymize = scenario.receiverConfig.anonymize, | ||
| )[0] | ||
| nodes = @[sender, receiver] | ||
|
|
||
| startNodesAndDeferStop(nodes) | ||
| await connectNodesStar(nodes) | ||
|
|
||
| let (messageReceivedFut, handler) = createCompleteHandler() | ||
|
|
||
| nodes.subscribeAllNodes(topic, handler) | ||
| await waitForHeartbeat() | ||
|
|
||
| discard await sender.publish(topic, testData) | ||
|
|
||
| let messageReceived = await waitForState(messageReceivedFut, HEARTBEAT_TIMEOUT) | ||
| check: | ||
| if scenario.shouldWork: | ||
| messageReceived.isCompleted(true) | ||
| else: | ||
| messageReceived.isCancelled() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.