mirror of
https://github.com/logos-messaging/waku-tests.git
synced 2026-01-02 14:23:07 +00:00
Split test fleet and prod fleet
This commit is contained in:
parent
e4acc07ad4
commit
0e227d0cb0
242
index.js
242
index.js
@ -2,17 +2,11 @@ import { expect } from "chai";
|
|||||||
import { describe } from "mocha";
|
import { describe } from "mocha";
|
||||||
import { Multiaddr } from "multiaddr";
|
import { Multiaddr } from "multiaddr";
|
||||||
import { Protocols, Waku, WakuMessage } from "js-waku";
|
import { Protocols, Waku, WakuMessage } from "js-waku";
|
||||||
import { discovery } from "js-waku";
|
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import delay from "./delay.js";
|
import delay from "./delay.js";
|
||||||
|
|
||||||
const prodFleet =
|
export default function runAll(nodes) {
|
||||||
discovery.predefined.fleets.fleets["wakuv2.prod"]["waku-websocket"];
|
describe("Run Waku Test Suite", () => {
|
||||||
const testFleet =
|
|
||||||
discovery.predefined.fleets.fleets["wakuv2.test"]["waku-websocket"];
|
|
||||||
|
|
||||||
describe("Test nwaku fleets", () => {
|
|
||||||
describe("Prod Fleet", () => {
|
|
||||||
const wakus = [];
|
const wakus = [];
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@ -26,8 +20,6 @@ describe("Test nwaku fleets", () => {
|
|||||||
// This dependence must be removed once DNS discovery is implemented
|
// This dependence must be removed once DNS discovery is implemented
|
||||||
this.timeout(20000);
|
this.timeout(20000);
|
||||||
|
|
||||||
const nodes = Object.values(prodFleet);
|
|
||||||
|
|
||||||
const peerIds = nodes.map((a) => {
|
const peerIds = nodes.map((a) => {
|
||||||
const ma = new Multiaddr(a);
|
const ma = new Multiaddr(a);
|
||||||
return ma.getPeerId();
|
return ma.getPeerId();
|
||||||
@ -44,8 +36,7 @@ describe("Test nwaku fleets", () => {
|
|||||||
wakus[i].libp2p.connectionManager.on("peer:connect", (connection) => {
|
wakus[i].libp2p.connectionManager.on("peer:connect", (connection) => {
|
||||||
resolve(connection.remotePeer);
|
resolve(connection.remotePeer);
|
||||||
});
|
});
|
||||||
}).then((connectedPeerID) => {
|
}).then((peerId) => {
|
||||||
const peerId = connectedPeerID;
|
|
||||||
console.log("connected", peerId.toB58String());
|
console.log("connected", peerId.toB58String());
|
||||||
expect(peerId.toB58String()).to.eq(peerIds[i]);
|
expect(peerId.toB58String()).to.eq(peerIds[i]);
|
||||||
});
|
});
|
||||||
@ -61,8 +52,6 @@ describe("Test nwaku fleets", () => {
|
|||||||
|
|
||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
|
|
||||||
const nodes = Object.values(prodFleet);
|
|
||||||
|
|
||||||
expect(nodes.length).to.eq(3);
|
expect(nodes.length).to.eq(3);
|
||||||
|
|
||||||
const promises = nodes.map(async (node, i) => {
|
const promises = nodes.map(async (node, i) => {
|
||||||
@ -126,8 +115,6 @@ describe("Test nwaku fleets", () => {
|
|||||||
|
|
||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
|
|
||||||
const nodes = Object.values(prodFleet);
|
|
||||||
|
|
||||||
expect(nodes.length).to.eq(3);
|
expect(nodes.length).to.eq(3);
|
||||||
|
|
||||||
const promises = nodes.map(async (node, i) => {
|
const promises = nodes.map(async (node, i) => {
|
||||||
@ -188,8 +175,6 @@ describe("Test nwaku fleets", () => {
|
|||||||
// This dependence must be removed once DNS discovery is implemented
|
// This dependence must be removed once DNS discovery is implemented
|
||||||
this.timeout(30000);
|
this.timeout(30000);
|
||||||
|
|
||||||
const nodes = Object.values(prodFleet);
|
|
||||||
|
|
||||||
expect(nodes.length).to.eq(3);
|
expect(nodes.length).to.eq(3);
|
||||||
|
|
||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
@ -232,223 +217,4 @@ describe("Test nwaku fleets", () => {
|
|||||||
await Promise.all(storePromises);
|
await Promise.all(storePromises);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
describe("Test Fleet", () => {
|
|
||||||
const wakus = [];
|
|
||||||
|
|
||||||
afterEach(function () {
|
|
||||||
wakus.forEach((waku) => {
|
|
||||||
waku.stop().catch((e) => console.log("Waku failed to stop", e));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Connect", async function () {
|
|
||||||
// This test depends on fleets.status.im being online.
|
|
||||||
// This dependence must be removed once DNS discovery is implemented
|
|
||||||
this.timeout(20000);
|
|
||||||
|
|
||||||
const nodes = Object.values(testFleet);
|
|
||||||
|
|
||||||
const peerIds = nodes.map((a) => {
|
|
||||||
const ma = new Multiaddr(a);
|
|
||||||
return ma.getPeerId();
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(nodes.length).to.eq(3);
|
|
||||||
|
|
||||||
const promises = nodes.map(async (node, i) => {
|
|
||||||
wakus[i] = await Waku.create({
|
|
||||||
bootstrap: { peers: [node] },
|
|
||||||
});
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
wakus[i].libp2p.connectionManager.on("peer:connect", (connection) => {
|
|
||||||
resolve(connection.remotePeer);
|
|
||||||
});
|
|
||||||
}).then((peerId) => {
|
|
||||||
expect(peerId.toB58String()).to.eq(peerIds[i]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Relay", async function () {
|
|
||||||
// This test depends on fleets.status.im being online.
|
|
||||||
// This dependence must be removed once DNS discovery is implemented
|
|
||||||
this.timeout(60000);
|
|
||||||
|
|
||||||
const id = uuidv4();
|
|
||||||
|
|
||||||
const nodes = Object.values(testFleet);
|
|
||||||
|
|
||||||
expect(nodes.length).to.eq(3);
|
|
||||||
|
|
||||||
const promises = nodes.map(async (node, i) => {
|
|
||||||
wakus[i] = await Waku.create({
|
|
||||||
bootstrap: { peers: [node] },
|
|
||||||
});
|
|
||||||
|
|
||||||
await wakus[i].waitForRemotePeer([Protocols.Relay]);
|
|
||||||
console.log(node + ": ready");
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
// All connected and relay ready
|
|
||||||
|
|
||||||
const contentTopic = "/js-waku-testing/1/relay-test/utf8";
|
|
||||||
|
|
||||||
const messages = [];
|
|
||||||
|
|
||||||
wakus.forEach((waku) => {
|
|
||||||
waku.relay.addObserver(
|
|
||||||
(message) => {
|
|
||||||
messages.push({
|
|
||||||
msg: message.payloadAsUtf8,
|
|
||||||
timestamp: message.timestamp,
|
|
||||||
rcvd: new Date(),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[contentTopic]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const relayPromises = wakus.map(async (waku, i) => {
|
|
||||||
const msg = await WakuMessage.fromUtf8String(
|
|
||||||
`sent from ${i} - ${id}`,
|
|
||||||
contentTopic
|
|
||||||
);
|
|
||||||
return waku.relay.send(msg);
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(relayPromises);
|
|
||||||
await delay(20000);
|
|
||||||
|
|
||||||
console.log(messages);
|
|
||||||
|
|
||||||
messages.forEach((msg) => {
|
|
||||||
const diff = msg.rcvd.getTime() - msg.timestamp.getTime();
|
|
||||||
console.log(msg.timestamp, msg.rcvd, diff + "ms");
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(messages.length).to.gte(nodes.length);
|
|
||||||
|
|
||||||
for (let i = 0; i < wakus.length; i++) {
|
|
||||||
expect(messages.map((m) => m.msg)).to.contain(`sent from ${i} - ${id}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Light Push", async function () {
|
|
||||||
// This test depends on fleets.status.im being online.
|
|
||||||
// This dependence must be removed once DNS discovery is implemented
|
|
||||||
this.timeout(60000);
|
|
||||||
|
|
||||||
const id = uuidv4();
|
|
||||||
|
|
||||||
const nodes = Object.values(testFleet);
|
|
||||||
|
|
||||||
expect(nodes.length).to.eq(3);
|
|
||||||
|
|
||||||
const promises = nodes.map(async (node, i) => {
|
|
||||||
wakus[i] = await Waku.create({
|
|
||||||
bootstrap: { peers: [node] },
|
|
||||||
});
|
|
||||||
|
|
||||||
await wakus[i].waitForRemotePeer([Protocols.LightPush]);
|
|
||||||
console.log(node + ": ready");
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
// All connected and relay ready
|
|
||||||
|
|
||||||
const contentTopic = "/js-waku-testing/1/relay-test/utf8";
|
|
||||||
|
|
||||||
const messages = [];
|
|
||||||
|
|
||||||
wakus.forEach((waku) => {
|
|
||||||
waku.relay.addObserver(
|
|
||||||
(message) => {
|
|
||||||
messages.push({
|
|
||||||
msg: message.payloadAsUtf8,
|
|
||||||
timestamp: message.timestamp,
|
|
||||||
rcvd: new Date(),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[contentTopic]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const relayPromises = wakus.map(async (waku, i) => {
|
|
||||||
const msg = await WakuMessage.fromUtf8String(
|
|
||||||
`sent from ${i} - ${id}`,
|
|
||||||
contentTopic
|
|
||||||
);
|
|
||||||
return waku.lightPush.push(msg);
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(relayPromises);
|
|
||||||
|
|
||||||
console.log(messages);
|
|
||||||
|
|
||||||
messages.forEach((msg) => {
|
|
||||||
const diff = msg.rcvd.getTime() - msg.timestamp.getTime();
|
|
||||||
console.log(msg.timestamp, msg.rcvd, diff + "ms");
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(messages.length).to.gte(nodes.length);
|
|
||||||
|
|
||||||
for (let i = 0; i < wakus.length; i++) {
|
|
||||||
expect(messages.map((m) => m.msg)).to.contain(`sent from ${i} - ${id}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Store", async function () {
|
|
||||||
// This test depends on fleets.status.im being online.
|
|
||||||
// This dependence must be removed once DNS discovery is implemented
|
|
||||||
this.timeout(30000);
|
|
||||||
|
|
||||||
const nodes = Object.values(testFleet);
|
|
||||||
|
|
||||||
expect(nodes.length).to.eq(3);
|
|
||||||
|
|
||||||
const id = uuidv4();
|
|
||||||
|
|
||||||
const promises = nodes.map(async (node, i) => {
|
|
||||||
wakus[i] = await Waku.create({
|
|
||||||
bootstrap: { peers: [node] },
|
|
||||||
});
|
|
||||||
|
|
||||||
await wakus[i].waitForRemotePeer([Protocols.Relay]);
|
|
||||||
console.log(node + ": ready");
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
// All connected and relay ready
|
|
||||||
|
|
||||||
const contentTopic = "/js-waku-testing/1/store-test/utf8";
|
|
||||||
|
|
||||||
const relayPromises = wakus.map(async (waku, i) => {
|
|
||||||
const msg = await WakuMessage.fromUtf8String(
|
|
||||||
`sent from ${i} - ${id}`,
|
|
||||||
contentTopic
|
|
||||||
);
|
|
||||||
return waku.relay.send(msg);
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(relayPromises);
|
|
||||||
await delay(5000);
|
|
||||||
|
|
||||||
const storePromises = wakus.map(async (waku, index) => {
|
|
||||||
const messages = await waku.store.queryHistory([contentTopic]);
|
|
||||||
const payloads = messages.map((msg) => msg.payloadAsUtf8);
|
|
||||||
console.log(index, payloads);
|
|
||||||
|
|
||||||
for (let i = 0; i < wakus.length; i++) {
|
|
||||||
expect(payloads).to.contain(`sent from ${i} - ${id}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(storePromises);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@ -6,7 +6,8 @@
|
|||||||
"lint": "eslint . --ext .js",
|
"lint": "eslint . --ext .js",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"fix": "run-s lint format",
|
"fix": "run-s lint format",
|
||||||
"run": "mocha 'index.js'"
|
"prod": "mocha prodFleet.js",
|
||||||
|
"test": "mocha testFleet.js"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"env": {
|
"env": {
|
||||||
|
|||||||
11
prodFleet.js
Normal file
11
prodFleet.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { describe } from "mocha";
|
||||||
|
import { discovery } from "js-waku";
|
||||||
|
import runAll from "./index.js";
|
||||||
|
|
||||||
|
const prodFleet =
|
||||||
|
discovery.predefined.fleets.fleets["wakuv2.prod"]["waku-websocket"];
|
||||||
|
const nodes = Object.values(prodFleet);
|
||||||
|
|
||||||
|
describe("Prod Fleet", async () => {
|
||||||
|
await runAll(nodes);
|
||||||
|
});
|
||||||
11
testFleet.js
Normal file
11
testFleet.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { describe } from "mocha";
|
||||||
|
import { discovery } from "js-waku";
|
||||||
|
import runAll from "./index.js";
|
||||||
|
|
||||||
|
const testFleet =
|
||||||
|
discovery.predefined.fleets.fleets["wakuv2.test"]["waku-websocket"];
|
||||||
|
const nodes = Object.values(testFleet);
|
||||||
|
|
||||||
|
describe("Prod Fleet", async () => {
|
||||||
|
await runAll(nodes);
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user