mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-04 08:34:57 +00:00
Use websocket instead of tcp in interop tests (#418)
This commit is contained in:
parent
cba5212872
commit
34e4cbba73
36
package-lock.json
generated
36
package-lock.json
generated
@ -62,7 +62,6 @@
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-typescript": "^5.5.1",
|
||||
"libp2p-tcp": "^0.17.1",
|
||||
"mocha": "^9.1.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15.1.0",
|
||||
@ -10455,25 +10454,6 @@
|
||||
"varint": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/libp2p-tcp": {
|
||||
"version": "0.17.1",
|
||||
"resolved": "https://registry.npmjs.org/libp2p-tcp/-/libp2p-tcp-0.17.1.tgz",
|
||||
"integrity": "sha512-Kxqb0gEi1BZT0guhWbmeyG+XhJHqod6jM3NvSvjwUaD6XmKFVt9yj4IPGnTfKPOSrkcWwAUhk6Qbv0eKSHlCnw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"abortable-iterator": "^3.0.0",
|
||||
"class-is": "^1.1.0",
|
||||
"debug": "^4.3.1",
|
||||
"err-code": "^3.0.1",
|
||||
"libp2p-utils": "^0.4.0",
|
||||
"mafmt": "^10.0.0",
|
||||
"multiaddr": "^10.0.0",
|
||||
"stream-to-it": "^0.2.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/libp2p-utils": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/libp2p-utils/-/libp2p-utils-0.4.1.tgz",
|
||||
@ -26098,22 +26078,6 @@
|
||||
"varint": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"libp2p-tcp": {
|
||||
"version": "0.17.1",
|
||||
"resolved": "https://registry.npmjs.org/libp2p-tcp/-/libp2p-tcp-0.17.1.tgz",
|
||||
"integrity": "sha512-Kxqb0gEi1BZT0guhWbmeyG+XhJHqod6jM3NvSvjwUaD6XmKFVt9yj4IPGnTfKPOSrkcWwAUhk6Qbv0eKSHlCnw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"abortable-iterator": "^3.0.0",
|
||||
"class-is": "^1.1.0",
|
||||
"debug": "^4.3.1",
|
||||
"err-code": "^3.0.1",
|
||||
"libp2p-utils": "^0.4.0",
|
||||
"mafmt": "^10.0.0",
|
||||
"multiaddr": "^10.0.0",
|
||||
"stream-to-it": "^0.2.2"
|
||||
}
|
||||
},
|
||||
"libp2p-utils": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/libp2p-utils/-/libp2p-utils-0.4.1.tgz",
|
||||
|
@ -107,7 +107,6 @@
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-typescript": "^5.5.1",
|
||||
"libp2p-tcp": "^0.17.1",
|
||||
"mocha": "^9.1.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15.1.0",
|
||||
|
@ -64,12 +64,14 @@ export class Bootstrap {
|
||||
maxPeers
|
||||
);
|
||||
} else if (opts.peers !== undefined && opts.peers.length > 0) {
|
||||
dbg('Use provided list of peers.');
|
||||
|
||||
const allPeers: Multiaddr[] = opts.peers.map(
|
||||
(node: string) => new Multiaddr(node)
|
||||
);
|
||||
const peers = getPseudoRandomSubset(allPeers, maxPeers);
|
||||
dbg(
|
||||
'Use provided list of peers (reduced to maxPeers)',
|
||||
allPeers.map((ma) => ma.toString())
|
||||
);
|
||||
this.getBootstrapPeers = (): Promise<Multiaddr[]> =>
|
||||
Promise.resolve(peers);
|
||||
} else if (typeof opts.getPeers === 'function') {
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { expect } from 'chai';
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: No types available
|
||||
import TCP from 'libp2p-tcp';
|
||||
import debug from 'debug';
|
||||
import PeerId from 'peer-id';
|
||||
|
||||
import {
|
||||
@ -11,27 +9,72 @@ import {
|
||||
NOISE_KEY_2,
|
||||
} from '../test_utils/';
|
||||
|
||||
import { delay } from './delay';
|
||||
import { Waku } from './waku';
|
||||
import { WakuMessage } from './waku_message';
|
||||
import { generateSymmetricKey } from './waku_message/version_1';
|
||||
import { RelayCodecs } from './waku_relay';
|
||||
|
||||
const dbg = debug('waku:test');
|
||||
|
||||
const TestContentTopic = '/test/1/waku/utf8';
|
||||
|
||||
describe('Waku Dial [node only]', function () {
|
||||
let waku: Waku;
|
||||
let waku2: Waku;
|
||||
let nimWaku: NimWaku;
|
||||
describe('Interop: Nim', function () {
|
||||
let waku: Waku;
|
||||
let nimWaku: NimWaku;
|
||||
|
||||
afterEach(async function () {
|
||||
this.timeout(10_000);
|
||||
afterEach(async function () {
|
||||
nimWaku ? nimWaku.stop() : null;
|
||||
waku ? await waku.stop() : null;
|
||||
});
|
||||
|
||||
nimWaku ? nimWaku.stop() : null;
|
||||
// TODO: Clarify whether nwaku's `get_waku_v2_admin_v1_peers` can be expected
|
||||
// to return peers with inbound connections.
|
||||
it.skip('js connects to nim', async function () {
|
||||
this.timeout(20_000);
|
||||
nimWaku = new NimWaku(makeLogFileName(this));
|
||||
await nimWaku.start();
|
||||
const multiAddrWithId = await nimWaku.getMultiaddrWithId();
|
||||
|
||||
await Promise.all([waku ? waku.stop() : null, waku2 ? waku2.stop() : null]);
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
});
|
||||
await waku.dial(multiAddrWithId);
|
||||
await waku.waitForConnectedPeer([RelayCodecs]);
|
||||
|
||||
let nimPeers = await nimWaku.peers();
|
||||
while (nimPeers.length === 0) {
|
||||
await delay(200);
|
||||
nimPeers = await nimWaku.peers();
|
||||
dbg('nimPeers', nimPeers);
|
||||
}
|
||||
|
||||
expect(nimPeers).to.deep.equal([
|
||||
{
|
||||
multiaddr: multiAddrWithId,
|
||||
protocol: '/vac/waku/relay/2.0.0',
|
||||
connected: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
const jsPeers = waku.libp2p.peerStore.peers;
|
||||
|
||||
expect(jsPeers.has(nimPeerId.toB58String())).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Bootstrap', function () {
|
||||
it('Passing a boolean', async function () {
|
||||
let waku: Waku;
|
||||
let nimWaku: NimWaku;
|
||||
|
||||
afterEach(async function () {
|
||||
nimWaku ? nimWaku.stop() : null;
|
||||
waku ? await waku.stop() : null;
|
||||
});
|
||||
|
||||
it('Enabling default [live data]', async function () {
|
||||
// This test depends on fleets.status.im being online.
|
||||
// This dependence must be removed once DNS discovery is implemented
|
||||
this.timeout(20_000);
|
||||
@ -53,22 +96,13 @@ describe('Waku Dial [node only]', function () {
|
||||
it('Passing an array', async function () {
|
||||
this.timeout(10_000);
|
||||
|
||||
nimWaku = new NimWaku(makeLogFileName(this));
|
||||
await nimWaku.start();
|
||||
const multiAddrWithId = await nimWaku.getMultiaddrWithId();
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: {
|
||||
addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] },
|
||||
modules: { transport: [TCP] },
|
||||
},
|
||||
});
|
||||
|
||||
const multiAddrWithId = waku.getLocalMultiaddrWithID();
|
||||
|
||||
waku2 = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: {
|
||||
modules: { transport: [TCP] },
|
||||
},
|
||||
bootstrap: { peers: [multiAddrWithId] },
|
||||
bootstrap: { peers: [multiAddrWithId.toString()] },
|
||||
});
|
||||
|
||||
const connectedPeerID: PeerId = await new Promise((resolve) => {
|
||||
@ -77,31 +111,18 @@ describe('Waku Dial [node only]', function () {
|
||||
});
|
||||
});
|
||||
|
||||
expect(connectedPeerID.toB58String()).to.eq(
|
||||
waku2.libp2p.peerId.toB58String()
|
||||
);
|
||||
expect(connectedPeerID.toB58String()).to.eq(multiAddrWithId.getPeerId());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Bootstrap', function () {
|
||||
it('Passing a function', async function () {
|
||||
this.timeout(10_000);
|
||||
|
||||
nimWaku = new NimWaku(makeLogFileName(this));
|
||||
await nimWaku.start();
|
||||
const multiAddrWithId = await nimWaku.getMultiaddrWithId();
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: {
|
||||
addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] },
|
||||
modules: { transport: [TCP] },
|
||||
},
|
||||
});
|
||||
|
||||
const multiAddrWithId = waku.getLocalMultiaddrWithID();
|
||||
|
||||
waku2 = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: {
|
||||
modules: { transport: [TCP] },
|
||||
},
|
||||
bootstrap: {
|
||||
getPeers: async () => {
|
||||
return [multiAddrWithId];
|
||||
@ -115,43 +136,7 @@ describe('Waku Dial [node only]', function () {
|
||||
});
|
||||
});
|
||||
|
||||
expect(connectedPeerID.toB58String()).to.eq(
|
||||
waku2.libp2p.peerId.toB58String()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Interop: Nim', function () {
|
||||
it('nim connects to js', async function () {
|
||||
this.timeout(10_000);
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: {
|
||||
addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] },
|
||||
modules: { transport: [TCP] },
|
||||
},
|
||||
});
|
||||
|
||||
const multiAddrWithId = waku.getLocalMultiaddrWithID();
|
||||
|
||||
nimWaku = new NimWaku(makeLogFileName(this));
|
||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
||||
|
||||
const nimPeers = await nimWaku.peers();
|
||||
|
||||
expect(nimPeers).to.deep.equal([
|
||||
{
|
||||
multiaddr: multiAddrWithId,
|
||||
protocol: '/vac/waku/relay/2.0.0',
|
||||
connected: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
const jsPeers = waku.libp2p.peerStore.peers;
|
||||
|
||||
expect(jsPeers.has(nimPeerId.toB58String())).to.be.true;
|
||||
expect(connectedPeerID.toB58String()).to.eq(multiAddrWithId.getPeerId());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,4 @@
|
||||
import { expect } from 'chai';
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: No types available
|
||||
import TCP from 'libp2p-tcp';
|
||||
|
||||
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../../test_utils';
|
||||
import { delay } from '../delay';
|
||||
@ -27,7 +24,6 @@ describe('Waku Light Push [node only]', () => {
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer();
|
||||
@ -64,7 +60,6 @@ describe('Waku Light Push [node only]', () => {
|
||||
waku = await Waku.create({
|
||||
pubSubTopic: customPubSubTopic,
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer();
|
||||
|
@ -1,8 +1,5 @@
|
||||
import { expect } from 'chai';
|
||||
import debug from 'debug';
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: No types available
|
||||
import TCP from 'libp2p-tcp';
|
||||
|
||||
import {
|
||||
makeLogFileName,
|
||||
@ -13,6 +10,7 @@ import {
|
||||
import { delay } from '../delay';
|
||||
import { hexToBuf } from '../utils';
|
||||
import { Waku } from '../waku';
|
||||
import { RelayCodecs } from '../waku_relay';
|
||||
|
||||
import {
|
||||
generatePrivateKey,
|
||||
@ -33,19 +31,17 @@ describe('Waku Message [node only]', function () {
|
||||
|
||||
beforeEach(async function () {
|
||||
this.timeout(30_000);
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: {
|
||||
addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] },
|
||||
modules: { transport: [TCP] },
|
||||
},
|
||||
});
|
||||
|
||||
const multiAddrWithId = waku.getLocalMultiaddrWithID();
|
||||
nimWaku = new NimWaku(makeLogFileName(this));
|
||||
await nimWaku.start({ staticnode: multiAddrWithId, rpcPrivate: true });
|
||||
await nimWaku.start({ rpcPrivate: true });
|
||||
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([RelayCodecs]);
|
||||
|
||||
// Wait for one heartbeat to ensure mesh is updated
|
||||
await new Promise((resolve) =>
|
||||
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
|
||||
);
|
||||
@ -78,7 +74,8 @@ describe('Waku Message [node only]', function () {
|
||||
|
||||
const publicKey = getPublicKey(privateKey);
|
||||
dbg('Post message');
|
||||
await nimWaku.postAsymmetricMessage(message, publicKey);
|
||||
const res = await nimWaku.postAsymmetricMessage(message, publicKey);
|
||||
expect(res).to.be.true;
|
||||
|
||||
const receivedMsg = await receivedMsgPromise;
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
import { expect } from 'chai';
|
||||
import debug from 'debug';
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: No types available
|
||||
import TCP from 'libp2p-tcp';
|
||||
|
||||
import {
|
||||
makeLogFileName,
|
||||
@ -326,181 +323,90 @@ describe('Waku Relay [node only]', () => {
|
||||
});
|
||||
|
||||
describe('Interop: Nim', function () {
|
||||
describe('Nim connects to js', function () {
|
||||
let waku: Waku;
|
||||
let nimWaku: NimWaku;
|
||||
let waku: Waku;
|
||||
let nimWaku: NimWaku;
|
||||
|
||||
beforeEach(async function () {
|
||||
this.timeout(30_000);
|
||||
|
||||
log('Create waku node');
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: {
|
||||
addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] },
|
||||
modules: { transport: [TCP] },
|
||||
},
|
||||
});
|
||||
|
||||
const multiAddrWithId = waku.getLocalMultiaddrWithID();
|
||||
nimWaku = new NimWaku(makeLogFileName(this));
|
||||
log('Starting nim-waku');
|
||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
||||
|
||||
log('Waiting for heartbeat');
|
||||
await new Promise((resolve) =>
|
||||
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
|
||||
);
|
||||
beforeEach(async function () {
|
||||
this.timeout(30_000);
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
this.timeout(5000);
|
||||
nimWaku ? nimWaku.stop() : null;
|
||||
waku ? await waku.stop() : null;
|
||||
});
|
||||
nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + '');
|
||||
await nimWaku.start();
|
||||
|
||||
it('nim subscribes to js', async function () {
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
const subscribers =
|
||||
waku.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([RelayCodecs]);
|
||||
|
||||
expect(subscribers).to.contain(nimPeerId.toB58String());
|
||||
});
|
||||
|
||||
it('Js publishes to nim', async function () {
|
||||
this.timeout(5000);
|
||||
|
||||
const messageText = 'This is a message';
|
||||
const message = await WakuMessage.fromUtf8String(
|
||||
messageText,
|
||||
TestContentTopic
|
||||
);
|
||||
|
||||
await waku.relay.send(message);
|
||||
|
||||
let msgs: WakuMessage[] = [];
|
||||
|
||||
while (msgs.length === 0) {
|
||||
await delay(200);
|
||||
msgs = await nimWaku.messages();
|
||||
}
|
||||
|
||||
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
||||
expect(msgs[0].version).to.equal(message.version);
|
||||
expect(msgs[0].payloadAsUtf8).to.equal(messageText);
|
||||
});
|
||||
|
||||
it('Nim publishes to js', async function () {
|
||||
this.timeout(5000);
|
||||
const messageText = 'Here is another message.';
|
||||
const message = await WakuMessage.fromUtf8String(
|
||||
messageText,
|
||||
TestContentTopic
|
||||
);
|
||||
|
||||
const receivedMsgPromise: Promise<WakuMessage> = new Promise(
|
||||
(resolve) => {
|
||||
waku.relay.addObserver(resolve);
|
||||
}
|
||||
);
|
||||
|
||||
await nimWaku.sendMessage(message);
|
||||
|
||||
const receivedMsg = await receivedMsgPromise;
|
||||
|
||||
expect(receivedMsg.contentTopic).to.eq(message.contentTopic);
|
||||
expect(receivedMsg.version).to.eq(message.version);
|
||||
expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
|
||||
// Wait for one heartbeat to ensure mesh is updated
|
||||
await new Promise((resolve) => {
|
||||
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Js connects to nim', function () {
|
||||
let waku: Waku;
|
||||
let nimWaku: NimWaku;
|
||||
afterEach(async function () {
|
||||
nimWaku ? nimWaku.stop() : null;
|
||||
waku ? await waku.stop() : null;
|
||||
});
|
||||
|
||||
beforeEach(async function () {
|
||||
this.timeout(30_000);
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
it('nim subscribes to js', async function () {
|
||||
let subscribers: string[] = [];
|
||||
|
||||
nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + '');
|
||||
await nimWaku.start();
|
||||
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([RelayCodecs]);
|
||||
|
||||
// Wait for one heartbeat to ensure mesh is updated
|
||||
await new Promise((resolve) => {
|
||||
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
nimWaku ? nimWaku.stop() : null;
|
||||
waku ? await waku.stop() : null;
|
||||
});
|
||||
|
||||
it('nim subscribes to js', async function () {
|
||||
let subscribers: string[] = [];
|
||||
|
||||
while (subscribers.length === 0) {
|
||||
await delay(200);
|
||||
subscribers = waku.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
|
||||
}
|
||||
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
expect(subscribers).to.contain(nimPeerId.toB58String());
|
||||
});
|
||||
|
||||
it('Js publishes to nim', async function () {
|
||||
this.timeout(30000);
|
||||
|
||||
const messageText = 'This is a message';
|
||||
const message = await WakuMessage.fromUtf8String(
|
||||
messageText,
|
||||
TestContentTopic
|
||||
);
|
||||
await delay(1000);
|
||||
await waku.relay.send(message);
|
||||
|
||||
let msgs: WakuMessage[] = [];
|
||||
|
||||
while (msgs.length === 0) {
|
||||
console.log('Waiting for messages');
|
||||
await delay(200);
|
||||
msgs = await nimWaku.messages();
|
||||
}
|
||||
|
||||
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
||||
expect(msgs[0].version).to.equal(message.version);
|
||||
expect(msgs[0].payloadAsUtf8).to.equal(messageText);
|
||||
});
|
||||
|
||||
it('Nim publishes to js', async function () {
|
||||
while (subscribers.length === 0) {
|
||||
await delay(200);
|
||||
subscribers = waku.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
|
||||
}
|
||||
|
||||
const messageText = 'Here is another message.';
|
||||
const message = await WakuMessage.fromUtf8String(
|
||||
messageText,
|
||||
TestContentTopic
|
||||
);
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
expect(subscribers).to.contain(nimPeerId.toB58String());
|
||||
});
|
||||
|
||||
const receivedMsgPromise: Promise<WakuMessage> = new Promise(
|
||||
(resolve) => {
|
||||
waku.relay.addObserver(resolve);
|
||||
}
|
||||
);
|
||||
it('Js publishes to nim', async function () {
|
||||
this.timeout(30000);
|
||||
|
||||
await nimWaku.sendMessage(message);
|
||||
const messageText = 'This is a message';
|
||||
const message = await WakuMessage.fromUtf8String(
|
||||
messageText,
|
||||
TestContentTopic
|
||||
);
|
||||
await delay(1000);
|
||||
await waku.relay.send(message);
|
||||
|
||||
const receivedMsg = await receivedMsgPromise;
|
||||
let msgs: WakuMessage[] = [];
|
||||
|
||||
expect(receivedMsg.contentTopic).to.eq(message.contentTopic);
|
||||
expect(receivedMsg.version).to.eq(message.version);
|
||||
expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
|
||||
});
|
||||
while (msgs.length === 0) {
|
||||
console.log('Waiting for messages');
|
||||
await delay(200);
|
||||
msgs = await nimWaku.messages();
|
||||
}
|
||||
|
||||
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
||||
expect(msgs[0].version).to.equal(message.version);
|
||||
expect(msgs[0].payloadAsUtf8).to.equal(messageText);
|
||||
});
|
||||
|
||||
it('Nim publishes to js', async function () {
|
||||
await delay(200);
|
||||
|
||||
const messageText = 'Here is another message.';
|
||||
const message = await WakuMessage.fromUtf8String(
|
||||
messageText,
|
||||
TestContentTopic
|
||||
);
|
||||
|
||||
const receivedMsgPromise: Promise<WakuMessage> = new Promise(
|
||||
(resolve) => {
|
||||
waku.relay.addObserver(resolve);
|
||||
}
|
||||
);
|
||||
|
||||
await nimWaku.sendMessage(message);
|
||||
|
||||
const receivedMsg = await receivedMsgPromise;
|
||||
|
||||
expect(receivedMsg.contentTopic).to.eq(message.contentTopic);
|
||||
expect(receivedMsg.version).to.eq(message.version);
|
||||
expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
|
||||
});
|
||||
|
||||
describe.skip('js to nim to js', function () {
|
||||
@ -521,11 +427,9 @@ describe('Waku Relay [node only]', () => {
|
||||
[waku1, waku2] = await Promise.all([
|
||||
Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
}),
|
||||
Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
}),
|
||||
]);
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
import { expect } from 'chai';
|
||||
import debug from 'debug';
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: No types available
|
||||
import TCP from 'libp2p-tcp';
|
||||
|
||||
import {
|
||||
makeLogFileName,
|
||||
@ -52,7 +49,6 @@ describe('Waku Store', () => {
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([[StoreCodec]]);
|
||||
@ -83,7 +79,6 @@ describe('Waku Store', () => {
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([[StoreCodec]]);
|
||||
@ -121,7 +116,6 @@ describe('Waku Store', () => {
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([[StoreCodec]]);
|
||||
@ -156,7 +150,6 @@ describe('Waku Store', () => {
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([[StoreCodec]]);
|
||||
@ -194,7 +187,6 @@ describe('Waku Store', () => {
|
||||
waku = await Waku.create({
|
||||
pubSubTopic: customPubSubTopic,
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([[StoreCodec]]);
|
||||
@ -262,11 +254,9 @@ describe('Waku Store', () => {
|
||||
const [waku1, waku2, nimWakuMultiaddr] = await Promise.all([
|
||||
Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
}),
|
||||
Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
}),
|
||||
nimWaku.getMultiaddrWithId(),
|
||||
]);
|
||||
@ -375,11 +365,9 @@ describe('Waku Store', () => {
|
||||
const [waku1, waku2, nimWakuMultiaddr] = await Promise.all([
|
||||
Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
}),
|
||||
Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
}),
|
||||
nimWaku.getMultiaddrWithId(),
|
||||
]);
|
||||
@ -463,7 +451,6 @@ describe('Waku Store', () => {
|
||||
|
||||
waku = await Waku.create({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
await waku.dial(await nimWaku.getMultiaddrWithId());
|
||||
await waku.waitForConnectedPeer([[StoreCodec]]);
|
||||
|
@ -14,6 +14,7 @@ it('Correctly serialized arguments', function () {
|
||||
'--relay=true',
|
||||
'--rpc=true',
|
||||
'--rpc-admin=true',
|
||||
'--websocket-support=true',
|
||||
'--ports-shift=42',
|
||||
];
|
||||
|
||||
|
@ -12,6 +12,7 @@ import debug from 'debug';
|
||||
import { Multiaddr, multiaddr } from 'multiaddr';
|
||||
import PeerId from 'peer-id';
|
||||
|
||||
import { delay } from '../lib/delay';
|
||||
import { hexToBuf } from '../lib/utils';
|
||||
import { DefaultPubSubTopic } from '../lib/waku';
|
||||
import { WakuMessage } from '../lib/waku_message';
|
||||
@ -22,7 +23,6 @@ import waitForLine from './log_file';
|
||||
|
||||
const dbg = debug('waku:nim-waku');
|
||||
|
||||
const NIM_WAKU_DEFAULT_P2P_PORT = 60000;
|
||||
const NIM_WAKU_DEFAULT_RPC_PORT = 8545;
|
||||
const NIM_WAKU_DIR = appRoot + '/nim-waku';
|
||||
const NIM_WAKU_BIN = NIM_WAKU_DIR + '/build/wakunode2';
|
||||
@ -43,6 +43,7 @@ export interface Args {
|
||||
lightpush?: boolean;
|
||||
topics?: string;
|
||||
rpcPrivate?: boolean;
|
||||
websocketSupport?: boolean;
|
||||
}
|
||||
|
||||
export enum LogLevel {
|
||||
@ -140,13 +141,16 @@ export class NimWaku {
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
dbg(
|
||||
`nim-waku ${
|
||||
this.process ? this.process.pid : this.pid
|
||||
} getting SIGINT at ${new Date().toLocaleTimeString()}`
|
||||
);
|
||||
this.process ? this.process.kill('SIGINT') : null;
|
||||
this.process = undefined;
|
||||
// If killed too fast the SIGINT may not be registered
|
||||
delay(100).then(() => {
|
||||
dbg(
|
||||
`nim-waku ${
|
||||
this.process ? this.process.pid : this.pid
|
||||
} getting SIGINT at ${new Date().toLocaleTimeString()}`
|
||||
);
|
||||
this.process ? this.process.kill('SIGINT') : null;
|
||||
this.process = undefined;
|
||||
});
|
||||
}
|
||||
|
||||
async waitForLog(msg: string, timeout: number): Promise<void> {
|
||||
@ -318,19 +322,16 @@ export class NimWaku {
|
||||
return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId };
|
||||
}
|
||||
const res = await this.info();
|
||||
this.multiaddrWithId = res.listenAddresses.map((ma) => multiaddr(ma))[0];
|
||||
if (!this.multiaddrWithId) throw 'Nim-waku did not return a multiaddr';
|
||||
this.multiaddrWithId = res.listenAddresses
|
||||
.map((ma) => multiaddr(ma))
|
||||
.find((ma) => ma.protoNames().includes('ws'));
|
||||
if (!this.multiaddrWithId) throw 'Nim-waku did not return a ws multiaddr';
|
||||
const peerIdStr = this.multiaddrWithId.getPeerId();
|
||||
if (!peerIdStr) throw 'Nim-waku multiaddr does not contain peerId';
|
||||
this.peerId = PeerId.createFromB58String(peerIdStr);
|
||||
return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId };
|
||||
}
|
||||
|
||||
get multiaddr(): Multiaddr {
|
||||
const port = NIM_WAKU_DEFAULT_P2P_PORT + this.portsShift;
|
||||
return multiaddr(`/ip4/127.0.0.1/tcp/${port}/`);
|
||||
}
|
||||
|
||||
get rpcUrl(): string {
|
||||
const port = NIM_WAKU_DEFAULT_RPC_PORT + this.portsShift;
|
||||
return `http://localhost:${port}/`;
|
||||
@ -386,6 +387,7 @@ export function defaultArgs(): Args {
|
||||
relay: true,
|
||||
rpc: true,
|
||||
rpcAdmin: true,
|
||||
websocketSupport: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user