Skip to content

Commit

Permalink
merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko committed Oct 5, 2024
2 parents d1e2ba1 + d37e024 commit 0c2e7e9
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 32 deletions.
18 changes: 10 additions & 8 deletions packages/sdk/src/waku/wait_for_remote_peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export async function waitForRemotePeer(
protocols?: Protocols[],
timeoutMs?: number
): Promise<void> {
// if no protocols or empty array passed - try to derive from mounted
protocols = protocols?.length ? protocols : getEnabledProtocols(waku);
// if no protocols or empty array passed - try to derive from mounted
protocols = protocols?.length ? protocols : getEnabledProtocols(waku);
const connections = waku.libp2p.getConnections();
Expand Down Expand Up @@ -153,14 +155,6 @@ async function waitForMetadata(
}

for (const peerId of connectedPeers) {
const confirmedAllCodecs = Array.from(enabledCodes.values()).every(
(v) => v
);

if (confirmedAllCodecs) {
return true;
}

try {
const peer = await waku.libp2p.peerStore.get(peerId);
const hasSomeCodes = peer.protocols.some((c) => enabledCodes.has(c));
Expand All @@ -175,6 +169,14 @@ async function waitForMetadata(
enabledCodes.set(c, true);
}
});

const confirmedAllCodecs = Array.from(enabledCodes.values()).every(
(v) => v
);

if (confirmedAllCodecs) {
return true;
}
}
}
} catch (e) {
Expand Down
9 changes: 2 additions & 7 deletions packages/tests/src/utils/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Protocols
} from "@waku/interfaces";
import { createLightNode } from "@waku/sdk";
import { derivePubsubTopicsFromNetworkConfig, isDefined } from "@waku/utils";
import { derivePubsubTopicsFromNetworkConfig } from "@waku/utils";
import { Context } from "mocha";
import pRetry from "p-retry";

Expand Down Expand Up @@ -52,12 +52,7 @@ export async function runMultipleNodes(

for (const node of serviceNodes.nodes) {
await waku.dial(await node.getMultiaddrWithId());
await waku.waitForPeer(
[
!customArgs?.filter ? undefined : Protocols.Filter,
!customArgs?.lightpush ? undefined : Protocols.LightPush
].filter(isDefined)
);
await waku.waitForPeer([Protocols.Filter, Protocols.LightPush]);
await node.ensureSubscriptions(
derivePubsubTopicsFromNetworkConfig(networkConfig)
);
Expand Down
6 changes: 1 addition & 5 deletions packages/tests/tests/ephemeral.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ describe("Waku Message Ephemeral field", function () {
await waku.start();
await waku.dial(await nwaku.getMultiaddrWithId());

await waku.waitForPeer([
Protocols.Filter,
Protocols.LightPush,
Protocols.Store
]);
await waku.waitForPeer([Protocols.Filter, Protocols.LightPush]);
});

it("Ephemeral messages are not stored", async function () {
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/tests/filter/peer_management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("Waku Filter: Peer Management: E2E", function () {
[serviceNodes, waku] = await runMultipleNodes(
this.ctx,
DefaultTestShardInfo,
undefined,
{ lightpush: true, filter: true },
undefined,
5
);
Expand Down Expand Up @@ -222,7 +222,7 @@ describe("Waku Filter: Peer Management: E2E", function () {
const [serviceNodes, waku] = await runMultipleNodes(
this.ctx,
DefaultTestShardInfo,
undefined,
{ lightpush: true, filter: true },
undefined,
2
);
Expand Down
5 changes: 4 additions & 1 deletion packages/tests/tests/filter/ping.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const runTests = (strictCheckNodes: boolean): void => {

beforeEachCustom(this, async () => {
try {
[serviceNodes, waku] = await runMultipleNodes(this.ctx, TestShardInfo);
[serviceNodes, waku] = await runMultipleNodes(this.ctx, TestShardInfo, {
lightpush: true,
filter: true
});
} catch (error) {
console.error(error);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/tests/tests/filter/push.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const runTests = (strictCheckNodes: boolean): void => {
let serviceNodes: ServiceNodesFleet;

beforeEachCustom(this, async () => {
[serviceNodes, waku] = await runMultipleNodes(this.ctx, TestShardInfo);
[serviceNodes, waku] = await runMultipleNodes(this.ctx, TestShardInfo, {
lightpush: true,
filter: true
});
});

afterEachCustom(this, async () => {
Expand Down
12 changes: 8 additions & 4 deletions packages/tests/tests/filter/unsubscribe.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ const runTests = (strictCheckNodes: boolean): void => {
let serviceNodes: ServiceNodesFleet;

beforeEachCustom(this, async () => {
[serviceNodes, waku] = await runMultipleNodes(this.ctx, {
contentTopics: [TestContentTopic],
clusterId: ClusterId
});
[serviceNodes, waku] = await runMultipleNodes(
this.ctx,
{
contentTopics: [TestContentTopic],
clusterId: ClusterId
},
{ filter: true, lightpush: true }
);
});

afterEachCustom(this, async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/tests/health-manager/protocols.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("Health Manager", function () {
[serviceNodes, waku] = await runMultipleNodes(
this.ctx,
TestShardInfo,
undefined,
{ lightpush: true, filter: true },
undefined,
num
);
Expand All @@ -62,7 +62,7 @@ describe("Health Manager", function () {
[serviceNodes, waku] = await runMultipleNodes(
this.ctx,
TestShardInfo,
undefined,
{ filter: true, lightpush: true },
undefined,
num
);
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/light-push/index.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const runTests = (strictNodeCheck: boolean): void => {
[serviceNodes, waku] = await runMultipleNodes(
this.ctx,
TestShardInfo,
undefined,
{ lightpush: true, filter: true },
strictNodeCheck,
numServiceNodes,
true
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/light-push/peer_management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("Waku Light Push: Connection Management: E2E", function () {
[serviceNodes, waku] = await runMultipleNodes(
this.ctx,
DefaultTestShardInfo,
undefined,
{ lightpush: true, filter: true },
undefined,
5
);
Expand Down

0 comments on commit 0c2e7e9

Please sign in to comment.