-
Notifications
You must be signed in to change notification settings - Fork 43
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(tests): peer-exchange interop #1773
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ab3d58
fix(tests): px interop
danisharora099 dca2f6e
optimize waitFor utility
danisharora099 ab29a15
Merge branch 'master' into fix/peer-exchange-interop-test
danisharora099 0cd283a
address minor comments
danisharora099 7a6e0a9
Merge branch 'master' into fix/peer-exchange-interop-test
danisharora099 079ccb6
fix: test refactoring
danisharora099 96127e2
Merge branch 'master' into fix/peer-exchange-interop-test
danisharora099 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
This file contains 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 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,39 @@ | ||
import type { IdentifyResult } from "@libp2p/interface"; | ||
import type { PeerId } from "@libp2p/interface/peer-id"; | ||
import type { LightNode } from "@waku/interfaces"; | ||
|
||
/** | ||
* Wait for a remote peer to be identified with a given codec | ||
* @param waku - Waku node | ||
* @param codec - Codec to wait for | ||
* @returns Promise that resolves when the peer is identified | ||
* @internal | ||
* This function is introduced as `core/waitForRemotePeer` only accounts for core protocols like Filter, LightPush & Store | ||
* While this (currently) is not required by the SDK, it is required for the tests | ||
*/ | ||
export async function waitForRemotePeerWithCodec( | ||
waku: LightNode, | ||
codec: string, | ||
nodePeerId: PeerId | ||
): Promise<void> { | ||
const connectedPeers = waku.libp2p | ||
.getConnections() | ||
.map((conn) => conn.remotePeer); | ||
if ( | ||
connectedPeers.find((connectedPeer) => connectedPeer.equals(nodePeerId)) | ||
) { | ||
return; | ||
} | ||
|
||
await new Promise<void>((resolve) => { | ||
const cb = (evt: CustomEvent<IdentifyResult>): void => { | ||
if (evt.detail.protocols.includes(codec)) { | ||
waku.libp2p.removeEventListener("peer:identify", cb); | ||
resolve(); | ||
} | ||
}; | ||
waku.libp2p.addEventListener("peer:identify", cb); | ||
}); | ||
|
||
return; | ||
} |
This file contains 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.
these values never get set, so that it will always
throw
at:87
and if not it willdial
emptymaddrs
arrayThere 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.
haha, you're right which is why the test failed as well. this caught in during the refactor from
find
tosome
-- addressed this -- thanks! :)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.
merging this PR now, let me know if you want to suggest any other change & I can follow up