From ea4b30752d946bb09fb397cb9855aa90a08dc75a Mon Sep 17 00:00:00 2001 From: Sasha <118575614+weboko@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:05:35 +0100 Subject: [PATCH] chore: fix nwaku interop test failures (#1792) * chore: investigate interop test failures * try some fixes * remove only * remove comment * use getConnections for waku node --- packages/core/src/lib/filter/index.ts | 4 +++ .../single_node/multiple_pubsub.node.spec.ts | 12 +++++--- packages/tests/tests/filter/utils.ts | 22 ++++++++++---- .../tests/tests/store/multiple_pubsub.spec.ts | 30 ++++++++----------- packages/tests/tests/store/utils.ts | 17 +++++++++-- 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/packages/core/src/lib/filter/index.ts b/packages/core/src/lib/filter/index.ts index 0ef013ea07..5d89322321 100644 --- a/packages/core/src/lib/filter/index.ts +++ b/packages/core/src/lib/filter/index.ts @@ -309,6 +309,10 @@ class Filter extends BaseProtocol implements IReceiver { }) )[0]; + if (!peer) { + throw new Error("No peer found to initiate subscription."); + } + const subscription = this.getActiveSubscription(pubsubTopic, peer.id.toString()) ?? this.setActiveSubscription( diff --git a/packages/tests/tests/filter/single_node/multiple_pubsub.node.spec.ts b/packages/tests/tests/filter/single_node/multiple_pubsub.node.spec.ts index b695229d38..f7f17bb0bc 100644 --- a/packages/tests/tests/filter/single_node/multiple_pubsub.node.spec.ts +++ b/packages/tests/tests/filter/single_node/multiple_pubsub.node.spec.ts @@ -386,10 +386,14 @@ describe("Waku Filter V2 (Named sharding): Multiple PubsubTopics", function () { this.beforeEach(async function () { this.timeout(15000); - [nwaku, waku] = await runNodes(this, [ - customPubsubTopic1, - customPubsubTopic2 - ]); + [nwaku, waku] = await runNodes( + this, + [customPubsubTopic1, customPubsubTopic2], + { + clusterId: 3, + shards: [1, 2] + } + ); subscription = await waku.filter.createSubscription(customPubsubTopic1); messageCollector = new MessageCollector(); }); diff --git a/packages/tests/tests/filter/utils.ts b/packages/tests/tests/filter/utils.ts index 64bed3f379..06ed3950d3 100644 --- a/packages/tests/tests/filter/utils.ts +++ b/packages/tests/tests/filter/utils.ts @@ -79,12 +79,22 @@ export async function runNodes( log.error("jswaku node failed to start:", error); } - if (waku) { - await waku.dial(await nwaku.getMultiaddrWithId()); - await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]); - await nwaku.ensureSubscriptions(pubsubTopics); - return [nwaku, waku]; - } else { + if (!waku) { throw new Error("Failed to initialize waku"); } + + await waku.dial(await nwaku.getMultiaddrWithId()); + await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]); + await nwaku.ensureSubscriptions(pubsubTopics); + + const wakuConnections = waku.libp2p.getConnections(); + const nwakuPeers = await nwaku.peers(); + + if (wakuConnections.length < 1 || nwakuPeers.length < 1) { + throw new Error( + `Expected at least 1 peer in each node. Got waku connections: ${wakuConnections.length} and nwaku: ${nwakuPeers.length}` + ); + } + + return [nwaku, waku]; } diff --git a/packages/tests/tests/store/multiple_pubsub.spec.ts b/packages/tests/tests/store/multiple_pubsub.spec.ts index a3477beb17..a41597e065 100644 --- a/packages/tests/tests/store/multiple_pubsub.spec.ts +++ b/packages/tests/tests/store/multiple_pubsub.spec.ts @@ -342,13 +342,22 @@ describe("Waku Store (named sharding), custom pubsub topic", function () { nwaku = new ServiceNode(makeLogFileName(this)); await nwaku.start({ store: true, - pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2], - relay: true + relay: true, + pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2] }); await nwaku.ensureSubscriptions([ customShardedPubsubTopic1, customShardedPubsubTopic2 ]); + + waku = await startAndConnectLightNode( + nwaku, + [customShardedPubsubTopic1, customShardedPubsubTopic2], + { + clusterId: 3, + shards: [1, 2] + } + ); }); afterEach(async function () { @@ -363,10 +372,7 @@ describe("Waku Store (named sharding), custom pubsub topic", function () { customContentTopic1, customShardedPubsubTopic1 ); - waku = await startAndConnectLightNode(nwaku, [ - customShardedPubsubTopic1, - customShardedPubsubTopic2 - ]); + const messages = await processQueriedMessages( waku, [customDecoder1], @@ -397,11 +403,6 @@ describe("Waku Store (named sharding), custom pubsub topic", function () { customShardedPubsubTopic2 ); - waku = await startAndConnectLightNode(nwaku, [ - customShardedPubsubTopic1, - customShardedPubsubTopic2 - ]); - const customMessages = await processQueriedMessages( waku, [customDecoder1], @@ -451,13 +452,6 @@ describe("Waku Store (named sharding), custom pubsub topic", function () { customShardedPubsubTopic2 ); - waku = await createLightNode({ - staticNoiseKey: NOISE_KEY_1, - pubsubTopics: [customShardedPubsubTopic1, customShardedPubsubTopic2] - }); - await waku.start(); - - await waku.dial(await nwaku.getMultiaddrWithId()); await waku.dial(await nwaku2.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); diff --git a/packages/tests/tests/store/utils.ts b/packages/tests/tests/store/utils.ts index 3390311355..994a39c4ca 100644 --- a/packages/tests/tests/store/utils.ts +++ b/packages/tests/tests/store/utils.ts @@ -107,16 +107,27 @@ export async function startAndConnectLightNode( shardInfo?: ShardingParams ): Promise { const waku = await createLightNode({ + pubsubTopics: shardInfo ? undefined : pubsubTopics, + staticNoiseKey: NOISE_KEY_1, + libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }, ...((pubsubTopics.length !== 1 || pubsubTopics[0] !== DefaultPubsubTopic) && { shardInfo: shardInfo - }), - pubsubTopics: shardInfo ? undefined : pubsubTopics, - staticNoiseKey: NOISE_KEY_1 + }) }); await waku.start(); await waku.dial(await instance.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Store]); + + const wakuConnections = waku.libp2p.getConnections(); + const nwakuPeers = await instance.peers(); + + if (wakuConnections.length < 1 || nwakuPeers.length < 1) { + throw new Error( + `Expected at least 1 peer in each node. Got waku connections: ${wakuConnections.length} and nwaku: ${nwakuPeers.length}` + ); + } + log.info("Waku node created"); return waku; }