Rename nim-waku to nwaku

This commit is contained in:
Franck 2022-04-01 12:19:51 +11:00
parent ecd2445bf9
commit dc90279905
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
11 changed files with 157 additions and 158 deletions

View File

@ -61,6 +61,7 @@
"muxer", "muxer",
"mvps", "mvps",
"nodekey", "nodekey",
"nwaku",
"opendns", "opendns",
"peerhave", "peerhave",
"portfinder", "portfinder",

View File

@ -12,7 +12,7 @@ export enum Fleet {
/** /**
* Return list of pre-defined (hardcoded) bootstrap nodes. * Return list of pre-defined (hardcoded) bootstrap nodes.
* *
* Default behavior is to return nodes of the nim-waku Status Prod fleet. * Default behavior is to return nodes of the nwaku Status Prod fleet.
* *
* @param fleet The fleet to be returned. Defaults to production fleet. * @param fleet The fleet to be returned. Defaults to production fleet.
* @param wantedNumber The number of connections desired. Defaults to [[DefaultWantedNumber]]. * @param wantedNumber The number of connections desired. Defaults to [[DefaultWantedNumber]].

View File

@ -4,9 +4,9 @@ import PeerId from "peer-id";
import { import {
makeLogFileName, makeLogFileName,
NimWaku,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
Nwaku,
} from "../test_utils/"; } from "../test_utils/";
import { Protocols, Waku } from "./waku"; import { Protocols, Waku } from "./waku";
@ -18,20 +18,20 @@ const dbg = debug("waku:test");
const TestContentTopic = "/test/1/waku/utf8"; const TestContentTopic = "/test/1/waku/utf8";
describe("Waku Dial [node only]", function () { describe("Waku Dial [node only]", function () {
describe("Interop: Nim", function () { describe("Interop: nwaku", function () {
let waku: Waku; let waku: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("js connects to nim", async function () { it("connects to nwaku", async function () {
this.timeout(20_000); this.timeout(20_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start(); await nwaku.start();
const multiAddrWithId = await nimWaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
@ -39,26 +39,26 @@ describe("Waku Dial [node only]", function () {
await waku.dial(multiAddrWithId); await waku.dial(multiAddrWithId);
await waku.waitForRemotePeer([Protocols.Relay]); await waku.waitForRemotePeer([Protocols.Relay]);
const nimPeerId = await nimWaku.getPeerId(); const nimPeerId = await nwaku.getPeerId();
expect(await waku.libp2p.peerStore.has(nimPeerId)).to.be.true; expect(await waku.libp2p.peerStore.has(nimPeerId)).to.be.true;
}); });
}); });
describe("Bootstrap", function () { describe("Bootstrap", function () {
let waku: Waku; let waku: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("Passing an array", async function () { it("Passing an array", async function () {
this.timeout(10_000); this.timeout(10_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start(); await nwaku.start();
const multiAddrWithId = await nimWaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
@ -77,14 +77,14 @@ describe("Waku Dial [node only]", function () {
it("Passing a function", async function () { it("Passing a function", async function () {
this.timeout(10_000); this.timeout(10_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start(); await nwaku.start();
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
bootstrap: { bootstrap: {
getPeers: async () => { getPeers: async () => {
return [await nimWaku.getMultiaddrWithId()]; return [await nwaku.getMultiaddrWithId()];
}, },
}, },
}); });
@ -95,7 +95,7 @@ describe("Waku Dial [node only]", function () {
}); });
}); });
const multiAddrWithId = await nimWaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
expect(connectedPeerID.toB58String()).to.eq(multiAddrWithId.getPeerId()); expect(connectedPeerID.toB58String()).to.eq(multiAddrWithId.getPeerId());
}); });
}); });
@ -168,18 +168,18 @@ describe("Decryption Keys", () => {
describe("Wait for remote peer / get peers", function () { describe("Wait for remote peer / get peers", function () {
let waku: Waku; let waku: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("Relay", async function () { it("Relay", async function () {
this.timeout(20_000); this.timeout(20_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start(); await nwaku.start();
const multiAddrWithId = await nimWaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
dbg("Create"); dbg("Create");
waku = await Waku.create({ waku = await Waku.create({
@ -199,9 +199,9 @@ describe("Wait for remote peer / get peers", function () {
it("Store", async function () { it("Store", async function () {
this.timeout(20_000); this.timeout(20_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true }); await nwaku.start({ persistMessages: true });
const multiAddrWithId = await nimWaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
@ -222,9 +222,9 @@ describe("Wait for remote peer / get peers", function () {
it("LightPush", async function () { it("LightPush", async function () {
this.timeout(20_000); this.timeout(20_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ lightpush: true }); await nwaku.start({ lightpush: true });
const multiAddrWithId = await nimWaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,

View File

@ -1,7 +1,7 @@
import { expect } from "chai"; import { expect } from "chai";
import debug from "debug"; import debug from "debug";
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from "../../test_utils"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../../test_utils";
import { delay } from "../../test_utils/delay"; import { delay } from "../../test_utils/delay";
import { Protocols, Waku } from "../waku"; import { Protocols, Waku } from "../waku";
import { WakuMessage } from "../waku_message"; import { WakuMessage } from "../waku_message";
@ -12,23 +12,23 @@ const TestContentTopic = "/test/1/waku-light-push/utf8";
describe("Waku Light Push [node only]", () => { describe("Waku Light Push [node only]", () => {
let waku: Waku; let waku: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("Push successfully", async function () { it("Push successfully", async function () {
this.timeout(5_000); this.timeout(5_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ lightpush: true }); await nwaku.start({ lightpush: true });
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.LightPush]); await waku.waitForRemotePeer([Protocols.LightPush]);
const messageText = "Light Push works!"; const messageText = "Light Push works!";
@ -44,7 +44,7 @@ describe("Waku Light Push [node only]", () => {
while (msgs.length === 0) { while (msgs.length === 0) {
await delay(200); await delay(200);
msgs = await nimWaku.messages(); msgs = await nwaku.messages();
} }
expect(msgs[0].contentTopic).to.equal(message.contentTopic); expect(msgs[0].contentTopic).to.equal(message.contentTopic);
@ -57,17 +57,17 @@ describe("Waku Light Push [node only]", () => {
const customPubSubTopic = "/waku/2/custom-dapp/proto"; const customPubSubTopic = "/waku/2/custom-dapp/proto";
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ lightpush: true, topics: customPubSubTopic }); await nwaku.start({ lightpush: true, topics: customPubSubTopic });
waku = await Waku.create({ waku = await Waku.create({
pubSubTopic: customPubSubTopic, pubSubTopic: customPubSubTopic,
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.LightPush]); await waku.waitForRemotePeer([Protocols.LightPush]);
const nimPeerId = await nimWaku.getPeerId(); const nimPeerId = await nwaku.getPeerId();
const messageText = "Light Push works!"; const messageText = "Light Push works!";
const message = await WakuMessage.fromUtf8String( const message = await WakuMessage.fromUtf8String(
@ -84,10 +84,10 @@ describe("Waku Light Push [node only]", () => {
let msgs: WakuMessage[] = []; let msgs: WakuMessage[] = [];
dbg("Waiting for message to show on nim-waku side"); dbg("Waiting for message to show in nwaku");
while (msgs.length === 0) { while (msgs.length === 0) {
await delay(200); await delay(200);
msgs = await nimWaku.messages(); msgs = await nwaku.messages();
} }
expect(msgs[0].contentTopic).to.equal(message.contentTopic); expect(msgs[0].contentTopic).to.equal(message.contentTopic);

View File

@ -3,8 +3,8 @@ import debug from "debug";
import { import {
makeLogFileName, makeLogFileName,
NimWaku,
NOISE_KEY_1, NOISE_KEY_1,
Nwaku,
WakuRelayMessage, WakuRelayMessage,
} from "../../test_utils"; } from "../../test_utils";
import { delay } from "../../test_utils/delay"; import { delay } from "../../test_utils/delay";
@ -24,9 +24,9 @@ const dbg = debug("waku:test:message");
const TestContentTopic = "/test/1/waku-message/utf8"; const TestContentTopic = "/test/1/waku-message/utf8";
describe("Waku Message [node only]", function () { describe("Waku Message [node only]", function () {
describe("Interop: Nim", function () { describe("Interop: nwaku", function () {
let waku: Waku; let waku: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
beforeEach(async function () { beforeEach(async function () {
this.timeout(30_000); this.timeout(30_000);
@ -34,27 +34,27 @@ describe("Waku Message [node only]", function () {
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
dbg("Starting nim-waku node"); dbg("Starting nwaku node");
await nimWaku.start({ rpcPrivate: true }); await nwaku.start({ rpcPrivate: true });
dbg("Dialing to nim-waku node"); dbg("Dialing to nwaku node");
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
dbg("Wait for remote peer"); dbg("Wait for remote peer");
await waku.waitForRemotePeer([Protocols.Relay]); await waku.waitForRemotePeer([Protocols.Relay]);
dbg("Remote peer ready"); dbg("Remote peer ready");
// As this test uses the nim-waku RPC API, we somehow often face // As this test uses the nwaku RPC API, we somehow often face
// Race conditions where the nim-waku node does not have the js-waku // Race conditions where the nwaku node does not have the js-waku
// Node in its relay mesh just yet. // Node in its relay mesh just yet.
await delay(500); await delay(500);
}); });
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("JS decrypts nim message [asymmetric, no signature]", async function () { it("Decrypts nwaku message [asymmetric, no signature]", async function () {
this.timeout(5000); this.timeout(5000);
const messageText = "Here is an encrypted message."; const messageText = "Here is an encrypted message.";
@ -77,7 +77,7 @@ describe("Waku Message [node only]", function () {
const publicKey = getPublicKey(privateKey); const publicKey = getPublicKey(privateKey);
dbg("Post message"); dbg("Post message");
const res = await nimWaku.postAsymmetricMessage(message, publicKey); const res = await nwaku.postAsymmetricMessage(message, publicKey);
expect(res).to.be.true; expect(res).to.be.true;
const receivedMsg = await receivedMsgPromise; const receivedMsg = await receivedMsgPromise;
@ -87,11 +87,11 @@ describe("Waku Message [node only]", function () {
expect(receivedMsg.payloadAsUtf8).to.eq(messageText); expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
}); });
it("Js encrypts message for nim [asymmetric, no signature]", async function () { it("Encrypts message for nwaku [asymmetric, no signature]", async function () {
this.timeout(5000); this.timeout(5000);
dbg("Ask nim-waku to generate asymmetric key pair"); dbg("Ask nwaku to generate asymmetric key pair");
const keyPair = await nimWaku.getAsymmetricKeyPair(); const keyPair = await nwaku.getAsymmetricKeyPair();
const privateKey = hexToBytes(keyPair.privateKey); const privateKey = hexToBytes(keyPair.privateKey);
const publicKey = hexToBytes(keyPair.publicKey); const publicKey = hexToBytes(keyPair.publicKey);
@ -111,9 +111,9 @@ describe("Waku Message [node only]", function () {
let msgs: WakuRelayMessage[] = []; let msgs: WakuRelayMessage[] = [];
while (msgs.length === 0) { while (msgs.length === 0) {
dbg("Wait for message to be seen by nim-waku"); dbg("Wait for message to be seen by nwaku");
await delay(200); await delay(200);
msgs = await nimWaku.getAsymmetricMessages(privateKey); msgs = await nwaku.getAsymmetricMessages(privateKey);
} }
dbg("Check message content"); dbg("Check message content");
@ -121,7 +121,7 @@ describe("Waku Message [node only]", function () {
expect(bytesToUtf8(hexToBytes(msgs[0].payload))).to.equal(messageText); expect(bytesToUtf8(hexToBytes(msgs[0].payload))).to.equal(messageText);
}); });
it("JS decrypts nim message [symmetric, no signature]", async function () { it("Decrypts nwaku message [symmetric, no signature]", async function () {
this.timeout(5000); this.timeout(5000);
const messageText = "Here is a message encrypted in a symmetric manner."; const messageText = "Here is a message encrypted in a symmetric manner.";
@ -143,8 +143,8 @@ describe("Waku Message [node only]", function () {
} }
); );
dbg("Post message using nim-waku"); dbg("Post message using nwaku");
await nimWaku.postSymmetricMessage(message, symKey); await nwaku.postSymmetricMessage(message, symKey);
dbg("Wait for message to be received by js-waku"); dbg("Wait for message to be received by js-waku");
const receivedMsg = await receivedMsgPromise; const receivedMsg = await receivedMsgPromise;
dbg("Message received by js-waku"); dbg("Message received by js-waku");
@ -154,11 +154,11 @@ describe("Waku Message [node only]", function () {
expect(receivedMsg.payloadAsUtf8).to.eq(messageText); expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
}); });
it("Js encrypts message for nim [symmetric, no signature]", async function () { it("Encrypts message for nwaku [symmetric, no signature]", async function () {
this.timeout(5000); this.timeout(5000);
dbg("Getting symmetric key from nim-waku"); dbg("Getting symmetric key from nwaku");
const symKey = await nimWaku.getSymmetricKey(); const symKey = await nwaku.getSymmetricKey();
dbg("Encrypting message with js-waku"); dbg("Encrypting message with js-waku");
const messageText = const messageText =
"This is a message I am going to encrypt with a symmetric key"; "This is a message I am going to encrypt with a symmetric key";
@ -176,8 +176,8 @@ describe("Waku Message [node only]", function () {
while (msgs.length === 0) { while (msgs.length === 0) {
await delay(200); await delay(200);
dbg("Getting messages from nim-waku"); dbg("Getting messages from nwaku");
msgs = await nimWaku.getSymmetricMessages(symKey); msgs = await nwaku.getSymmetricMessages(symKey);
} }
expect(msgs[0].contentTopic).to.equal(message.contentTopic); expect(msgs[0].contentTopic).to.equal(message.contentTopic);

View File

@ -3,9 +3,9 @@ import debug from "debug";
import { import {
makeLogFileName, makeLogFileName,
NimWaku,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
Nwaku,
} from "../../test_utils"; } from "../../test_utils";
import { delay } from "../../test_utils/delay"; import { delay } from "../../test_utils/delay";
import { DefaultPubSubTopic, Protocols, Waku } from "../waku"; import { DefaultPubSubTopic, Protocols, Waku } from "../waku";
@ -306,9 +306,9 @@ describe("Waku Relay [node only]", () => {
}); });
}); });
describe("Interop: Nim", function () { describe("Interop: nwaku", function () {
let waku: Waku; let waku: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
beforeEach(async function () { beforeEach(async function () {
this.timeout(30_000); this.timeout(30_000);
@ -316,19 +316,19 @@ describe("Waku Relay [node only]", () => {
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + ""); nwaku = new Nwaku(this.test?.ctx?.currentTest?.title + "");
await nimWaku.start(); await nwaku.start();
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.Relay]); await waku.waitForRemotePeer([Protocols.Relay]);
}); });
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("nim subscribes to js", async function () { it("nwaku subscribes", async function () {
let subscribers: string[] = []; let subscribers: string[] = [];
while (subscribers.length === 0) { while (subscribers.length === 0) {
@ -336,11 +336,11 @@ describe("Waku Relay [node only]", () => {
subscribers = waku.libp2p.pubsub.getSubscribers(DefaultPubSubTopic); subscribers = waku.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
} }
const nimPeerId = await nimWaku.getPeerId(); const nimPeerId = await nwaku.getPeerId();
expect(subscribers).to.contain(nimPeerId.toB58String()); expect(subscribers).to.contain(nimPeerId.toB58String());
}); });
it("Js publishes to nim", async function () { it("Publishes to nwaku", async function () {
this.timeout(30000); this.timeout(30000);
const messageText = "This is a message"; const messageText = "This is a message";
@ -356,7 +356,7 @@ describe("Waku Relay [node only]", () => {
while (msgs.length === 0) { while (msgs.length === 0) {
console.log("Waiting for messages"); console.log("Waiting for messages");
await delay(200); await delay(200);
msgs = await nimWaku.messages(); msgs = await nwaku.messages();
} }
expect(msgs[0].contentTopic).to.equal(message.contentTopic); expect(msgs[0].contentTopic).to.equal(message.contentTopic);
@ -364,7 +364,7 @@ describe("Waku Relay [node only]", () => {
expect(msgs[0].payloadAsUtf8).to.equal(messageText); expect(msgs[0].payloadAsUtf8).to.equal(messageText);
}); });
it("Nim publishes to js", async function () { it("Nwaku publishes", async function () {
await delay(200); await delay(200);
const messageText = "Here is another message."; const messageText = "Here is another message.";
@ -379,7 +379,7 @@ describe("Waku Relay [node only]", () => {
} }
); );
await nimWaku.sendMessage(NimWaku.toWakuRelayMessage(message)); await nwaku.sendMessage(Nwaku.toWakuRelayMessage(message));
const receivedMsg = await receivedMsgPromise; const receivedMsg = await receivedMsgPromise;
@ -388,13 +388,13 @@ describe("Waku Relay [node only]", () => {
expect(receivedMsg.payloadAsUtf8).to.eq(messageText); expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
}); });
describe.skip("js to nim to js", function () { describe.skip("Two nodes connected to nwaku", function () {
let waku1: Waku; let waku1: Waku;
let waku2: Waku; let waku2: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku1 && !!waku1 &&
waku1.stop().catch((e) => console.log("Waku failed to stop", e)); waku1.stop().catch((e) => console.log("Waku failed to stop", e));
!!waku2 && !!waku2 &&
@ -412,13 +412,13 @@ describe("Waku Relay [node only]", () => {
}), }),
]); ]);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start(); await nwaku.start();
const nimWakuMultiaddr = await nimWaku.getMultiaddrWithId(); const nwakuMultiaddr = await nwaku.getMultiaddrWithId();
await Promise.all([ await Promise.all([
waku1.dial(nimWakuMultiaddr), waku1.dial(nwakuMultiaddr),
waku2.dial(nimWakuMultiaddr), waku2.dial(nwakuMultiaddr),
]); ]);
// Wait for identify protocol to finish // Wait for identify protocol to finish

View File

@ -3,9 +3,9 @@ import debug from "debug";
import { import {
makeLogFileName, makeLogFileName,
NimWaku,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
Nwaku,
} from "../../test_utils"; } from "../../test_utils";
import { delay } from "../../test_utils/delay"; import { delay } from "../../test_utils/delay";
import { Protocols, Waku } from "../waku"; import { Protocols, Waku } from "../waku";
@ -24,23 +24,23 @@ const TestContentTopic = "/test/1/waku-store/utf8";
describe("Waku Store", () => { describe("Waku Store", () => {
let waku: Waku; let waku: Waku;
let nimWaku: NimWaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
!!nimWaku && nimWaku.stop(); !!nwaku && nwaku.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("Retrieves history", async function () { it("Retrieves history", async function () {
this.timeout(5_000); this.timeout(5_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true }); await nwaku.start({ persistMessages: true });
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
expect( expect(
await nimWaku.sendMessage( await nwaku.sendMessage(
NimWaku.toWakuRelayMessage( Nwaku.toWakuRelayMessage(
await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic) await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic)
) )
) )
@ -50,7 +50,7 @@ describe("Waku Store", () => {
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.Store]); await waku.waitForRemotePeer([Protocols.Store]);
const messages = await waku.store.queryHistory([]); const messages = await waku.store.queryHistory([]);
@ -64,15 +64,15 @@ describe("Waku Store", () => {
it("Retrieves history using callback", async function () { it("Retrieves history using callback", async function () {
this.timeout(10_000); this.timeout(10_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true }); await nwaku.start({ persistMessages: true });
const totalMsgs = 20; const totalMsgs = 20;
for (let i = 0; i < totalMsgs; i++) { for (let i = 0; i < totalMsgs; i++) {
expect( expect(
await nimWaku.sendMessage( await nwaku.sendMessage(
NimWaku.toWakuRelayMessage( Nwaku.toWakuRelayMessage(
await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic) await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic)
) )
) )
@ -82,7 +82,7 @@ describe("Waku Store", () => {
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.Store]); await waku.waitForRemotePeer([Protocols.Store]);
let messages: WakuMessage[] = []; let messages: WakuMessage[] = [];
@ -103,15 +103,15 @@ describe("Waku Store", () => {
it("Retrieval aborts when callback returns true", async function () { it("Retrieval aborts when callback returns true", async function () {
this.timeout(5_000); this.timeout(5_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true }); await nwaku.start({ persistMessages: true });
const availMsgs = 20; const availMsgs = 20;
for (let i = 0; i < availMsgs; i++) { for (let i = 0; i < availMsgs; i++) {
expect( expect(
await nimWaku.sendMessage( await nwaku.sendMessage(
NimWaku.toWakuRelayMessage( Nwaku.toWakuRelayMessage(
await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic) await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic)
) )
) )
@ -121,7 +121,7 @@ describe("Waku Store", () => {
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.Store]); await waku.waitForRemotePeer([Protocols.Store]);
let messages: WakuMessage[] = []; let messages: WakuMessage[] = [];
@ -141,13 +141,13 @@ describe("Waku Store", () => {
it("Retrieves all historical elements in chronological order through paging", async function () { it("Retrieves all historical elements in chronological order through paging", async function () {
this.timeout(5_000); this.timeout(5_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true }); await nwaku.start({ persistMessages: true });
for (let i = 0; i < 15; i++) { for (let i = 0; i < 15; i++) {
expect( expect(
await nimWaku.sendMessage( await nwaku.sendMessage(
NimWaku.toWakuRelayMessage( Nwaku.toWakuRelayMessage(
await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic) await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic)
) )
) )
@ -157,7 +157,7 @@ describe("Waku Store", () => {
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.Store]); await waku.waitForRemotePeer([Protocols.Store]);
const messages = await waku.store.queryHistory([], { const messages = await waku.store.queryHistory([], {
@ -178,13 +178,13 @@ describe("Waku Store", () => {
this.timeout(5_000); this.timeout(5_000);
const customPubSubTopic = "/waku/2/custom-dapp/proto"; const customPubSubTopic = "/waku/2/custom-dapp/proto";
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true, topics: customPubSubTopic }); await nwaku.start({ persistMessages: true, topics: customPubSubTopic });
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
expect( expect(
await nimWaku.sendMessage( await nwaku.sendMessage(
NimWaku.toWakuRelayMessage( Nwaku.toWakuRelayMessage(
await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic) await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic)
), ),
customPubSubTopic customPubSubTopic
@ -196,10 +196,10 @@ describe("Waku Store", () => {
pubSubTopic: customPubSubTopic, pubSubTopic: customPubSubTopic,
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.Store]); await waku.waitForRemotePeer([Protocols.Store]);
const nimPeerId = await nimWaku.getPeerId(); const nimPeerId = await nwaku.getPeerId();
const messages = await waku.store.queryHistory([], { const messages = await waku.store.queryHistory([], {
peerId: nimPeerId, peerId: nimPeerId,
@ -215,8 +215,8 @@ describe("Waku Store", () => {
it("Retrieves history with asymmetric & symmetric encrypted messages", async function () { it("Retrieves history with asymmetric & symmetric encrypted messages", async function () {
this.timeout(10_000); this.timeout(10_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true, lightpush: true }); await nwaku.start({ persistMessages: true, lightpush: true });
const encryptedAsymmetricMessageText = const encryptedAsymmetricMessageText =
"This message is encrypted for me using asymmetric"; "This message is encrypted for me using asymmetric";
@ -266,7 +266,7 @@ describe("Waku Store", () => {
Waku.create({ Waku.create({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
}), }),
nimWaku.getMultiaddrWithId(), nwaku.getMultiaddrWithId(),
]); ]);
dbg("Waku nodes created"); dbg("Waku nodes created");
@ -276,7 +276,7 @@ describe("Waku Store", () => {
waku2.dial(nimWakuMultiaddr), waku2.dial(nimWakuMultiaddr),
]); ]);
dbg("Waku nodes connected to nim Waku"); dbg("Waku nodes connected to nwaku");
let lightPushPeerFound = false; let lightPushPeerFound = false;
while (!lightPushPeerFound) { while (!lightPushPeerFound) {
@ -324,8 +324,8 @@ describe("Waku Store", () => {
it("Retrieves history with asymmetric & symmetric encrypted messages on different content topics", async function () { it("Retrieves history with asymmetric & symmetric encrypted messages on different content topics", async function () {
this.timeout(10_000); this.timeout(10_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true, lightpush: true }); await nwaku.start({ persistMessages: true, lightpush: true });
const encryptedAsymmetricMessageText = const encryptedAsymmetricMessageText =
"This message is encrypted for me using asymmetric"; "This message is encrypted for me using asymmetric";
@ -384,7 +384,7 @@ describe("Waku Store", () => {
Waku.create({ Waku.create({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
}), }),
nimWaku.getMultiaddrWithId(), nwaku.getMultiaddrWithId(),
]); ]);
dbg("Waku nodes created"); dbg("Waku nodes created");
@ -394,7 +394,7 @@ describe("Waku Store", () => {
waku2.dial(nimWakuMultiaddr), waku2.dial(nimWakuMultiaddr),
]); ]);
dbg("Waku nodes connected to nim Waku"); dbg("Waku nodes connected to nwaku");
let lightPushPeerFound = false; let lightPushPeerFound = false;
while (!lightPushPeerFound) { while (!lightPushPeerFound) {
@ -445,8 +445,8 @@ describe("Waku Store", () => {
it("Retrieves history using start and end time", async function () { it("Retrieves history using start and end time", async function () {
this.timeout(5_000); this.timeout(5_000);
nimWaku = new NimWaku(makeLogFileName(this)); nwaku = new Nwaku(makeLogFileName(this));
await nimWaku.start({ persistMessages: true }); await nwaku.start({ persistMessages: true });
const now = new Date(); const now = new Date();
@ -469,8 +469,8 @@ describe("Waku Store", () => {
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
expect( expect(
await nimWaku.sendMessage( await nwaku.sendMessage(
NimWaku.toWakuRelayMessage( Nwaku.toWakuRelayMessage(
await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic, { await WakuMessage.fromUtf8String(`Message ${i}`, TestContentTopic, {
timestamp: messageTimestamps[i], timestamp: messageTimestamps[i],
}) })
@ -482,18 +482,18 @@ describe("Waku Store", () => {
waku = await Waku.create({ waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
await waku.waitForRemotePeer([Protocols.Store]); await waku.waitForRemotePeer([Protocols.Store]);
const nimPeerId = await nimWaku.getPeerId(); const nwakuPeerId = await nwaku.getPeerId();
const firstMessage = await waku.store.queryHistory([], { const firstMessage = await waku.store.queryHistory([], {
peerId: nimPeerId, peerId: nwakuPeerId,
timeFilter: { startTime, endTime: message1Timestamp }, timeFilter: { startTime, endTime: message1Timestamp },
}); });
const bothMessages = await waku.store.queryHistory([], { const bothMessages = await waku.store.queryHistory([], {
peerId: nimPeerId, peerId: nwakuPeerId,
timeFilter: { timeFilter: {
startTime, startTime,
endTime, endTime,

View File

@ -8,4 +8,4 @@
export * from "./async_fs"; export * from "./async_fs";
export * from "./constants"; export * from "./constants";
export * from "./log_file"; export * from "./log_file";
export * from "./nim_waku"; export * from "./nwaku";

View File

@ -1,5 +1,5 @@
/** /**
* Utilities to make it help check nim-waku logs. * Utilities to make it help check nwaku logs.
* *
* @hidden * @hidden
* @module * @module

View File

@ -1,8 +1,8 @@
import { expect } from "chai"; import { expect } from "chai";
import { argsToArray, bytesToHex, defaultArgs, strToHex } from "./nim_waku"; import { argsToArray, bytesToHex, defaultArgs, strToHex } from "./nwaku";
describe("nim_waku", () => { describe("nwaku", () => {
it("Correctly serialized arguments", function () { it("Correctly serialized arguments", function () {
const args = defaultArgs(); const args = defaultArgs();
Object.assign(args, { portsShift: 42 }); Object.assign(args, { portsShift: 42 });

View File

@ -19,7 +19,7 @@ import * as proto from "../proto/waku/v2/message";
import { existsAsync, mkdirAsync, openAsync } from "./async_fs"; import { existsAsync, mkdirAsync, openAsync } from "./async_fs";
import waitForLine from "./log_file"; import waitForLine from "./log_file";
const dbg = debug("waku:nim-waku"); const dbg = debug("waku:nwaku");
const NIM_WAKU_DIR = appRoot + "/nim-waku"; const NIM_WAKU_DIR = appRoot + "/nim-waku";
const NIM_WAKU_BIN = NIM_WAKU_DIR + "/build/wakunode2"; const NIM_WAKU_BIN = NIM_WAKU_DIR + "/build/wakunode2";
@ -67,7 +67,7 @@ export interface WakuRelayMessage {
timestamp?: number; // Unix epoch time in nanoseconds as a 64-bits integer value. timestamp?: number; // Unix epoch time in nanoseconds as a 64-bits integer value.
} }
export class NimWaku { export class Nwaku {
private process?: ChildProcess; private process?: ChildProcess;
private pid?: number; private pid?: number;
private peerId?: PeerId; private peerId?: PeerId;
@ -97,7 +97,7 @@ export class NimWaku {
} }
constructor(logName: string) { constructor(logName: string) {
this.logPath = `${LOG_DIR}/nim-waku_${logName}.log`; this.logPath = `${LOG_DIR}/nwaku_${logName}.log`;
} }
async start(args?: Args): Promise<void> { async start(args?: Args): Promise<void> {
@ -138,7 +138,7 @@ export class NimWaku {
); );
const argsArray = argsToArray(mergedArgs); const argsArray = argsToArray(mergedArgs);
dbg(`nim-waku args: ${argsArray.join(" ")}`); dbg(`nwaku args: ${argsArray.join(" ")}`);
this.process = spawn(NIM_WAKU_BIN, argsArray, { this.process = spawn(NIM_WAKU_BIN, argsArray, {
cwd: NIM_WAKU_DIR, cwd: NIM_WAKU_DIR,
stdio: [ stdio: [
@ -149,14 +149,12 @@ export class NimWaku {
}); });
this.pid = this.process.pid; this.pid = this.process.pid;
dbg( dbg(
`nim-waku ${ `nwaku ${this.process.pid} started at ${new Date().toLocaleTimeString()}`
this.process.pid
} started at ${new Date().toLocaleTimeString()}`
); );
this.process.on("exit", (signal) => { this.process.on("exit", (signal) => {
dbg( dbg(
`nim-waku ${ `nwaku ${
this.process ? this.process.pid : this.pid this.process ? this.process.pid : this.pid
} process exited with ${signal} at ${new Date().toLocaleTimeString()}` } process exited with ${signal} at ${new Date().toLocaleTimeString()}`
); );
@ -164,23 +162,23 @@ export class NimWaku {
this.process.on("error", (err) => { this.process.on("error", (err) => {
console.log( console.log(
`nim-waku ${ `nwaku ${
this.process ? this.process.pid : this.pid this.process ? this.process.pid : this.pid
} process encountered an error: ${err} at ${new Date().toLocaleTimeString()}` } process encountered an error: ${err} at ${new Date().toLocaleTimeString()}`
); );
}); });
dbg("Waiting to see 'Node setup complete' in nim-waku logs"); dbg("Waiting to see 'Node setup complete' in nwaku logs");
await this.waitForLog("Node setup complete", 9000); await this.waitForLog("Node setup complete", 9000);
dbg("nim-waku node has been started"); dbg("nwaku node has been started");
} }
public stop(): void { public stop(): void {
const pid = this.process ? this.process.pid : this.pid; const pid = this.process ? this.process.pid : this.pid;
dbg(`nim-waku ${pid} getting SIGINT at ${new Date().toLocaleTimeString()}`); dbg(`nwaku ${pid} getting SIGINT at ${new Date().toLocaleTimeString()}`);
if (!this.process) throw "nim-waku process not set"; if (!this.process) throw "nwaku process not set";
const res = this.process.kill("SIGINT"); const res = this.process.kill("SIGINT");
dbg(`nim-waku ${pid} interrupted:`, res); dbg(`nwaku ${pid} interrupted:`, res);
this.process = undefined; this.process = undefined;
} }
@ -188,9 +186,9 @@ export class NimWaku {
return waitForLine(this.logPath, msg, timeout); return waitForLine(this.logPath, msg, timeout);
} }
/** Calls nim-waku2 JSON-RPC API `get_waku_v2_admin_v1_peers` to check /** Calls nwaku JSON-RPC API `get_waku_v2_admin_v1_peers` to check
* for known peers * for known peers
* @throws if nim-waku2 isn't started. * @throws if nwaku isn't started.
*/ */
async peers(): Promise<string[]> { async peers(): Promise<string[]> {
this.checkProcess(); this.checkProcess();
@ -340,9 +338,9 @@ export class NimWaku {
this.multiaddrWithId = res.listenAddresses this.multiaddrWithId = res.listenAddresses
.map((ma) => multiaddr(ma)) .map((ma) => multiaddr(ma))
.find((ma) => ma.protoNames().includes("ws")); .find((ma) => ma.protoNames().includes("ws"));
if (!this.multiaddrWithId) throw "Nim-waku did not return a ws multiaddr"; if (!this.multiaddrWithId) throw "Nwaku did not return a ws multiaddr";
const peerIdStr = this.multiaddrWithId.getPeerId(); const peerIdStr = this.multiaddrWithId.getPeerId();
if (!peerIdStr) throw "Nim-waku multiaddr does not contain peerId"; if (!peerIdStr) throw "Nwaku multiaddr does not contain peerId";
this.peerId = PeerId.createFromB58String(peerIdStr); this.peerId = PeerId.createFromB58String(peerIdStr);
return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId }; return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId };
} }
@ -372,7 +370,7 @@ export class NimWaku {
private checkProcess(): void { private checkProcess(): void {
if (!this.process) { if (!this.process) {
throw "Nim Waku isn't started"; throw "Nwaku hasn't started";
} }
} }
} }