From cba5212872f91543bf6a7a3e02057429906b88fc Mon Sep 17 00:00:00 2001 From: Franck R Date: Wed, 19 Jan 2022 15:43:45 +1100 Subject: [PATCH] Upgrade nim-waku to v0.7 (#417) --- .github/workflows/ci.yml | 5 ++- CHANGELOG.md | 4 +++ nim-waku | 2 +- src/lib/waku.ts | 8 +++-- src/lib/waku_light_push/index.node.spec.ts | 12 ++----- src/lib/waku_relay/index.node.spec.ts | 16 +++------ src/lib/waku_store/index.node.spec.ts | 39 +++++----------------- src/test_utils/nim_waku.ts | 13 ++++---- 8 files changed, 35 insertions(+), 64 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11ab36c6e2..0c6f5226e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: build_and_test: env: BUF_VERSION: '0.56.0' - NIM_WAKU_VERSION: 'v0.6' + NIM_WAKU_VERSION: 'v0.7' strategy: matrix: node: [16] @@ -27,8 +27,7 @@ jobs: run: | mkdir -p nim-waku/build cd nim-waku - wget "https://github.com/status-im/nim-waku/releases/download/${NIM_WAKU_VERSION}/nim-waku-ubuntu-latest.tar.gz.1.zip" - unzip nim-waku-ubuntu-latest.tar.gz.1.zip + wget "https://github.com/status-im/nim-waku/releases/download/${NIM_WAKU_VERSION}/nim-waku-ubuntu-latest.tar.gz" tar xavf nim-waku-ubuntu-latest.tar.gz - name: Install NodeJS diff --git a/CHANGELOG.md b/CHANGELOG.md index 2515dd3a44..e3d7f09bec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Test: Upgrade nim-waku node to v0.7. + ## [0.15.0] - 2022-01-17 ### Added diff --git a/nim-waku b/nim-waku index ea14823daf..dba82b6c9c 160000 --- a/nim-waku +++ b/nim-waku @@ -1 +1 @@ -Subproject commit ea14823dafcbabd4ac5457b3f1311f2ed62a2d68 +Subproject commit dba82b6c9c9a8982608f52955356a2df8efcaf9e diff --git a/src/lib/waku.ts b/src/lib/waku.ts index d812abb131..25ac55bf4a 100644 --- a/src/lib/waku.ts +++ b/src/lib/waku.ts @@ -309,8 +309,12 @@ export class Waku { * with [[Waku.create]]. The Promise resolves only once we are connected to a * Store peer, Relay peer and Light Push peer. */ - async waitForConnectedPeer(): Promise { - const desiredProtocols = [[StoreCodec], [LightPushCodec], RelayCodecs]; + async waitForConnectedPeer(protocols?: string[][]): Promise { + const desiredProtocols = protocols ?? [ + [StoreCodec], + [LightPushCodec], + RelayCodecs, + ]; await Promise.all( desiredProtocols.map((desiredProtocolVersions) => { diff --git a/src/lib/waku_light_push/index.node.spec.ts b/src/lib/waku_light_push/index.node.spec.ts index 5ff779e960..ef6d7b5276 100644 --- a/src/lib/waku_light_push/index.node.spec.ts +++ b/src/lib/waku_light_push/index.node.spec.ts @@ -30,11 +30,7 @@ describe('Waku Light Push [node only]', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer(); const messageText = 'Light Push works!'; const message = await WakuMessage.fromUtf8String( @@ -71,11 +67,7 @@ describe('Waku Light Push [node only]', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer(); const nimPeerId = await nimWaku.getPeerId(); diff --git a/src/lib/waku_relay/index.node.spec.ts b/src/lib/waku_relay/index.node.spec.ts index 7c1a9ba3bd..e2e94feb05 100644 --- a/src/lib/waku_relay/index.node.spec.ts +++ b/src/lib/waku_relay/index.node.spec.ts @@ -19,6 +19,8 @@ import { getPublicKey, } from '../waku_message/version_1'; +import { RelayCodecs } from './constants'; + const log = debug('waku:test'); const TestContentTopic = '/test/1/waku-relay/utf8'; @@ -427,11 +429,7 @@ describe('Waku Relay [node only]', () => { await nimWaku.start(); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer([RelayCodecs]); // Wait for one heartbeat to ensure mesh is updated await new Promise((resolve) => { @@ -542,12 +540,8 @@ describe('Waku Relay [node only]', () => { // Wait for identify protocol to finish await Promise.all([ - new Promise((resolve) => - waku1.libp2p.peerStore.once('change:protocols', resolve) - ), - new Promise((resolve) => - waku2.libp2p.peerStore.once('change:protocols', resolve) - ), + waku1.waitForConnectedPeer([RelayCodecs]), + waku2.waitForConnectedPeer([RelayCodecs]), ]); await Promise.all([ diff --git a/src/lib/waku_store/index.node.spec.ts b/src/lib/waku_store/index.node.spec.ts index 30c334a42d..38124db7cb 100644 --- a/src/lib/waku_store/index.node.spec.ts +++ b/src/lib/waku_store/index.node.spec.ts @@ -21,6 +21,8 @@ import { import { PageDirection } from './history_rpc'; +import { StoreCodec } from './index'; + const dbg = debug('waku:test:store'); const TestContentTopic = '/test/1/waku-store/utf8'; @@ -53,12 +55,7 @@ describe('Waku Store', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); - + await waku.waitForConnectedPeer([[StoreCodec]]); const messages = await waku.store.queryHistory([]); expect(messages?.length).eq(2); @@ -89,11 +86,7 @@ describe('Waku Store', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer([[StoreCodec]]); let messages: WakuMessage[] = []; @@ -131,11 +124,7 @@ describe('Waku Store', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer([[StoreCodec]]); let messages: WakuMessage[] = []; const desiredMsgs = 14; @@ -170,11 +159,7 @@ describe('Waku Store', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer([[StoreCodec]]); const messages = await waku.store.queryHistory([], { pageDirection: PageDirection.FORWARD, @@ -212,11 +197,7 @@ describe('Waku Store', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer([[StoreCodec]]); const nimPeerId = await nimWaku.getPeerId(); @@ -485,11 +466,7 @@ describe('Waku Store', () => { libp2p: { modules: { transport: [TCP] } }, }); await waku.dial(await nimWaku.getMultiaddrWithId()); - - // Wait for identify protocol to finish - await new Promise((resolve) => { - waku.libp2p.peerStore.once('change:protocols', resolve); - }); + await waku.waitForConnectedPeer([[StoreCodec]]); const nimPeerId = await nimWaku.getPeerId(); diff --git a/src/test_utils/nim_waku.ts b/src/test_utils/nim_waku.ts index d2ce6cd424..04d66c0bc8 100644 --- a/src/test_utils/nim_waku.ts +++ b/src/test_utils/nim_waku.ts @@ -303,14 +303,14 @@ export class NimWaku { } async getPeerId(): Promise { - return await this.setPeerId().then((res) => res.peerId); + return await this._getPeerId().then((res) => res.peerId); } async getMultiaddrWithId(): Promise { - return await this.setPeerId().then((res) => res.multiaddrWithId); + return await this._getPeerId().then((res) => res.multiaddrWithId); } - private async setPeerId(): Promise<{ + private async _getPeerId(): Promise<{ peerId: PeerId; multiaddrWithId: Multiaddr; }> { @@ -318,7 +318,8 @@ export class NimWaku { return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId }; } const res = await this.info(); - this.multiaddrWithId = multiaddr(res.listenStr); + this.multiaddrWithId = res.listenAddresses.map((ma) => multiaddr(ma))[0]; + if (!this.multiaddrWithId) throw 'Nim-waku did not return a multiaddr'; const peerIdStr = this.multiaddrWithId.getPeerId(); if (!peerIdStr) throw 'Nim-waku multiaddr does not contain peerId'; this.peerId = PeerId.createFromB58String(peerIdStr); @@ -411,6 +412,6 @@ export function bufToHex(buffer: Uint8Array): string { } interface RpcInfoResponse { - // multiaddr including id. - listenStr: string; + // multiaddrs including peer id. + listenAddresses: string[]; }