diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60ff4cdc93..0b029c3f32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: pull_request: env: - NWAKU_VERSION: "v0.11" + NWAKU_VERSION: "v0.13.0" NODE_JS: "16" jobs: diff --git a/nwaku b/nwaku index fec1397483..9debd44e2a 160000 --- a/nwaku +++ b/nwaku @@ -1 +1 @@ -Subproject commit fec13974836149c2b81cab8d4178dee7bfc56db1 +Subproject commit 9debd44e2aebf07eaf96b4525a4497c69aaf4445 diff --git a/packages/core/src/lib/waku.ts b/packages/core/src/lib/waku.ts index f792eb6c56..ba1bdd6c9e 100644 --- a/packages/core/src/lib/waku.ts +++ b/packages/core/src/lib/waku.ts @@ -13,8 +13,8 @@ import { FilterCodec, WakuFilter } from "./waku_filter"; import { LightPushCodec, WakuLightPush } from "./waku_light_push"; import { EncoderV0 } from "./waku_message/version_0"; import { WakuRelay } from "./waku_relay"; -import { RelayCodecs, RelayPingContentTopic } from "./waku_relay/constants"; import * as relayConstants from "./waku_relay/constants"; +import { RelayCodecs, RelayPingContentTopic } from "./waku_relay/constants"; import { StoreCodec, WakuStore } from "./waku_store"; export const DefaultPingKeepAliveValueSecs = 0; @@ -109,13 +109,20 @@ export class WakuNode implements Waku { * Dials to the provided peer. * * @param peer The peer to dial - * @param protocols Waku protocols we expect from the peer; Default to Relay + * @param protocols Waku protocols we expect from the peer; Defaults to mounted protocols */ async dial( peer: PeerId | Multiaddr, protocols?: Protocols[] ): Promise { - const _protocols = protocols ?? [Protocols.Relay]; + const _protocols = protocols ?? []; + + if (typeof protocols === "undefined") { + this.relay && _protocols.push(Protocols.Relay); + this.store && _protocols.push(Protocols.Store); + this.filter && _protocols.push(Protocols.Filter); + this.lightPush && _protocols.push(Protocols.LightPush); + } const codecs: string[] = []; if (_protocols.includes(Protocols.Relay)) { @@ -131,8 +138,6 @@ export class WakuNode implements Waku { codecs.push(FilterCodec); } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore: new Multiaddr is not backward compatible return this.libp2p.dialProtocol(peer, codecs); } diff --git a/packages/core/src/lib/waku_store/index.ts b/packages/core/src/lib/waku_store/index.ts index 6bef492059..efcbf10b72 100644 --- a/packages/core/src/lib/waku_store/index.ts +++ b/packages/core/src/lib/waku_store/index.ts @@ -227,8 +227,8 @@ export class WakuStore { ); log("Querying history with the following options", { - peerId: options?.peerId?.toString(), ...options, + peerId: options?.peerId?.toString(), }); const res = await selectPeerForProtocol( diff --git a/packages/tests/package.json b/packages/tests/package.json index 5b4ce611c2..f2eaabaade 100644 --- a/packages/tests/package.json +++ b/packages/tests/package.json @@ -48,7 +48,7 @@ "check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"", "check:tsc": "tsc -p tsconfig.dev.json", "test": "run-s test:*", - "test:node": "TS_NODE_PROJECT=./tsconfig.json mocha", + "test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha", "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build" }, "engines": { diff --git a/packages/tests/src/nwaku.ts b/packages/tests/src/nwaku.ts index 036196446e..1a240e6dff 100644 --- a/packages/tests/src/nwaku.ts +++ b/packages/tests/src/nwaku.ts @@ -44,10 +44,10 @@ export interface Args { nodekey?: string; portsShift?: number; logLevel?: LogLevel; - persistMessages?: boolean; lightpush?: boolean; filter?: boolean; store?: boolean; + storeMessageDbUrl?: string; topics?: string; rpcPrivate?: boolean; websocketSupport?: boolean; @@ -407,7 +407,7 @@ export class Nwaku { headers: new Headers({ "Content-Type": "application/json" }), }); const json = await res.json(); - log(`RPC Response: `, res, JSON.stringify(json)); + log(`RPC Response: `, JSON.stringify(json)); return json.result; } @@ -423,7 +423,7 @@ export function argsToArray(args: Args): Array { for (const [key, value] of Object.entries(args)) { // Change the key from camelCase to kebab-case - const kebabKey = key.replace(/([A-Z])/, (_, capital) => { + const kebabKey = key.replace(/([A-Z])/g, (_, capital) => { return "-" + capital.toLowerCase(); }); @@ -442,6 +442,7 @@ export function defaultArgs(): Args { rpc: true, rpcAdmin: true, websocketSupport: true, + storeMessageDbUrl: "sqlite://:memory:", logLevel: LogLevel.Debug, }; } diff --git a/packages/tests/tests/nwaku.node.spec.ts b/packages/tests/tests/nwaku.node.spec.ts index 5299aab3f6..b1602bb2da 100644 --- a/packages/tests/tests/nwaku.node.spec.ts +++ b/packages/tests/tests/nwaku.node.spec.ts @@ -16,6 +16,7 @@ describe("nwaku", () => { "--rpc=true", "--rpc-admin=true", "--websocket-support=true", + "--store-message-db-url=sqlite://:memory:", "--log-level=DEBUG", "--ports-shift=42", ]; diff --git a/packages/tests/tests/store.node.spec.ts b/packages/tests/tests/store.node.spec.ts index da6deeece3..b7ff8c5076 100644 --- a/packages/tests/tests/store.node.spec.ts +++ b/packages/tests/tests/store.node.spec.ts @@ -32,7 +32,7 @@ describe("Waku Store", () => { beforeEach(async function () { this.timeout(15_000); nwaku = new Nwaku(makeLogFileName(this)); - await nwaku.start({ persistMessages: true, store: true, lightpush: true }); + await nwaku.start({ store: true, lightpush: true }); }); afterEach(async function () { @@ -48,7 +48,7 @@ describe("Waku Store", () => { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, }) ) @@ -78,7 +78,7 @@ describe("Waku Store", () => { expect(messages?.length).eq(totalMsgs); const result = messages?.findIndex((msg) => { - return bytesToUtf8(msg.payload!) === "Message 0"; + return msg.payload![0]! === 0; }); expect(result).to.not.eq(-1); }); @@ -119,7 +119,7 @@ describe("Waku Store", () => { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, }) ) @@ -146,7 +146,7 @@ describe("Waku Store", () => { expect(messages?.length).eq(totalMsgs); const result = messages?.findIndex((msg) => { - return bytesToUtf8(msg.payload!) === "Message 0"; + return msg.payload![0]! === 0; }); expect(result).to.not.eq(-1); }); @@ -160,7 +160,7 @@ describe("Waku Store", () => { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, }) ) @@ -199,7 +199,7 @@ describe("Waku Store", () => { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, }) ) @@ -225,13 +225,8 @@ describe("Waku Store", () => { ); expect(messages?.length).eq(totalMsgs); - for (let index = 0; index < totalMsgs; index++) { - expect( - messages?.findIndex((msg) => { - return bytesToUtf8(msg.payload!) === `Message ${index}`; - }) - ).to.eq(index); - } + const payloads = messages.map((msg) => msg.payload![0]!); + expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys())); }); it("Ordered Callback - Backward", async function () { @@ -242,7 +237,7 @@ describe("Waku Store", () => { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, }) ) @@ -270,13 +265,8 @@ describe("Waku Store", () => { messages = messages.reverse(); expect(messages?.length).eq(totalMsgs); - for (let index = 0; index < totalMsgs; index++) { - expect( - messages?.findIndex((msg) => { - return bytesToUtf8(msg.payload!) === `Message ${index}`; - }) - ).to.eq(index); - } + const payloads = messages.map((msg) => msg.payload![0]!); + expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys())); }); it("Generator, with asymmetric & symmetric encrypted messages", async function () { @@ -385,27 +375,27 @@ describe("Waku Store", () => { const now = new Date(); const startTime = new Date(); - // Set start time 5 minutes in the past - startTime.setTime(now.getTime() - 5 * 60 * 1000); + // Set start time 15 seconds in the past + startTime.setTime(now.getTime() - 15 * 1000); const message1Timestamp = new Date(); - // Set first message was 4 minutes in the past - message1Timestamp.setTime(now.getTime() - 4 * 60 * 1000); + // Set first message was 10 seconds in the past + message1Timestamp.setTime(now.getTime() - 10 * 1000); const message2Timestamp = new Date(); - // Set second message 2 minutes in the past - message2Timestamp.setTime(now.getTime() - 2 * 60 * 1000); + // Set second message 2 seconds in the past + message2Timestamp.setTime(now.getTime() - 2 * 1000); const messageTimestamps = [message1Timestamp, message2Timestamp]; const endTime = new Date(); - // Set end time 1 minute in the past - endTime.setTime(now.getTime() - 60 * 1000); + // Set end time 1 second in the past + endTime.setTime(now.getTime() - 1000); for (let i = 0; i < 2; i++) { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, timestamp: messageTimestamps[i], }) @@ -453,7 +443,7 @@ describe("Waku Store", () => { expect(firstMessages?.length).eq(1); - expect(bytesToUtf8(firstMessages[0].payload!)).eq("Message 0"); + expect(firstMessages[0].payload![0]!).eq(0); expect(bothMessages?.length).eq(2); }); @@ -467,7 +457,7 @@ describe("Waku Store", () => { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, }) ) @@ -505,7 +495,6 @@ describe("Waku Store, custom pubsub topic", () => { this.timeout(15_000); nwaku = new Nwaku(makeLogFileName(this)); await nwaku.start({ - persistMessages: true, store: true, topics: customPubSubTopic, }); @@ -524,7 +513,7 @@ describe("Waku Store, custom pubsub topic", () => { expect( await nwaku.sendMessage( Nwaku.toMessageRpcQuery({ - payload: utf8ToBytes(`Message ${i}`), + payload: new Uint8Array([i]), contentTopic: TestContentTopic, }), customPubSubTopic @@ -556,7 +545,7 @@ describe("Waku Store, custom pubsub topic", () => { expect(messages?.length).eq(totalMsgs); const result = messages?.findIndex((msg) => { - return bytesToUtf8(msg.payload!) === "Message 0"; + return msg.payload![0]! === 0; }); expect(result).to.not.eq(-1); }); diff --git a/packages/tests/tests/wait_for_remote_peer.node.spec.ts b/packages/tests/tests/wait_for_remote_peer.node.spec.ts index 96aeba1ed3..08bbb4da5c 100644 --- a/packages/tests/tests/wait_for_remote_peer.node.spec.ts +++ b/packages/tests/tests/wait_for_remote_peer.node.spec.ts @@ -101,7 +101,6 @@ describe("Wait for remote peer", function () { relay: false, lightpush: false, filter: false, - persistMessages: true, }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); @@ -128,7 +127,6 @@ describe("Wait for remote peer", function () { relay: false, lightpush: false, filter: false, - persistMessages: true, }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); @@ -213,7 +211,6 @@ describe("Wait for remote peer", function () { lightpush: true, relay: false, store: true, - persistMessages: true, }); const multiAddrWithId = await nwaku.getMultiaddrWithId(); diff --git a/packages/tests/tests/waku.node.spec.ts b/packages/tests/tests/waku.node.spec.ts index 587f6ab808..4d8def7b4d 100644 --- a/packages/tests/tests/waku.node.spec.ts +++ b/packages/tests/tests/waku.node.spec.ts @@ -38,7 +38,6 @@ describe("Waku Dial [node only]", function () { filter: true, store: true, lightpush: true, - persistMessages: true, }); const multiAddrWithId = await nwaku.getMultiaddrWithId();