mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-27 11:30:49 +00:00
test: uses full nodes in tests
Ref: https://github.com/status-im/nwaku/issues/1085
This commit is contained in:
parent
9fc16143fa
commit
91e4d1b435
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Simple connection management that selects the most recent connection for store, light push and filter requests.
|
- Simple connection management that selects the most recent connection for store, light push and filter requests.
|
||||||
- `createLightNode` to create a Waku node for resource restricted environment with Light Push, Filter and Relay.
|
- `createLightNode` to create a Waku node for resource restricted environment with Light Push, Filter and Relay.
|
||||||
- `createPrivacyNode` to create a Waku node for privacy preserving usage with Relay only.
|
- `createPrivacyNode` to create a Waku node for privacy preserving usage with Relay only.
|
||||||
|
- `createFullNode` to create a Waku node for with all protocols, for **testing purposes only**.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import { all as filterAll } from "@libp2p/websockets/filters";
|
|||||||
import { createLibp2p, Libp2pOptions } from "libp2p";
|
import { createLibp2p, Libp2pOptions } from "libp2p";
|
||||||
import type { Libp2p } from "libp2p";
|
import type { Libp2p } from "libp2p";
|
||||||
|
|
||||||
import type { Waku, WakuLight, WakuPrivacy } from "./interfaces";
|
import type { Waku, WakuFull, WakuLight, WakuPrivacy } from "./interfaces";
|
||||||
import { PeerDiscoveryStaticPeers } from "./peer_discovery_static_list";
|
import { PeerDiscoveryStaticPeers } from "./peer_discovery_static_list";
|
||||||
import { getPredefinedBootstrapNodes } from "./predefined_bootstrap_nodes";
|
import { getPredefinedBootstrapNodes } from "./predefined_bootstrap_nodes";
|
||||||
import { WakuNode, WakuOptions } from "./waku";
|
import { WakuNode, WakuOptions } from "./waku";
|
||||||
@ -100,6 +100,44 @@ export async function createPrivacyNode(
|
|||||||
return new WakuNode(options ?? {}, libp2p) as WakuPrivacy;
|
return new WakuNode(options ?? {}, libp2p) as WakuPrivacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Waku node that uses all Waku protocols.
|
||||||
|
*
|
||||||
|
* This helper is not recommended except if:
|
||||||
|
* - you are interfacing with nwaku v0.11 or below
|
||||||
|
* - you are doing some form of testing
|
||||||
|
*
|
||||||
|
* If you are building a full node, it is recommended to use
|
||||||
|
* [nwaku](github.com/status-im/nwaku) and its JSON RPC API or wip REST API.
|
||||||
|
*
|
||||||
|
* @see https://github.com/status-im/nwaku/issues/1085
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function createFullNode(
|
||||||
|
options?: CreateOptions & WakuOptions
|
||||||
|
): Promise<WakuFull> {
|
||||||
|
const libp2pOptions = options?.libp2p ?? {};
|
||||||
|
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
||||||
|
if (options?.defaultBootstrap) {
|
||||||
|
peerDiscovery.push(defaultPeerDiscovery());
|
||||||
|
Object.assign(libp2pOptions, { peerDiscovery });
|
||||||
|
}
|
||||||
|
|
||||||
|
const libp2p = await defaultLibp2p(new WakuRelay(options), libp2pOptions);
|
||||||
|
|
||||||
|
const wakuStore = new WakuStore(libp2p, options);
|
||||||
|
const wakuLightPush = new WakuLightPush(libp2p, options);
|
||||||
|
const wakuFilter = new WakuFilter(libp2p, options);
|
||||||
|
|
||||||
|
return new WakuNode(
|
||||||
|
options ?? {},
|
||||||
|
libp2p,
|
||||||
|
wakuStore,
|
||||||
|
wakuLightPush,
|
||||||
|
wakuFilter
|
||||||
|
) as WakuFull;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use { @link createLightNode } (only compatible with nwaku v0.12),
|
* @deprecated use { @link createLightNode } (only compatible with nwaku v0.12),
|
||||||
* { @link createPrivacyNode } or { @link Waku.constructor } instead;
|
* { @link createPrivacyNode } or { @link Waku.constructor } instead;
|
||||||
|
@ -51,3 +51,10 @@ export interface WakuPrivacy extends Waku {
|
|||||||
filter: undefined;
|
filter: undefined;
|
||||||
lightPush: undefined;
|
lightPush: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WakuFull extends Waku {
|
||||||
|
relay: WakuRelay;
|
||||||
|
store: WakuStore;
|
||||||
|
filter: WakuFilter;
|
||||||
|
lightPush: WakuLightPush;
|
||||||
|
}
|
||||||
|
@ -3,8 +3,8 @@ import debug from "debug";
|
|||||||
|
|
||||||
import { makeLogFileName, NOISE_KEY_1, Nwaku } 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 { createLightNode } from "../create_waku";
|
import { createFullNode } from "../create_waku";
|
||||||
import type { WakuLight } from "../interfaces";
|
import type { WakuFull } from "../interfaces";
|
||||||
import { waitForRemotePeer } from "../wait_for_remote_peer";
|
import { waitForRemotePeer } from "../wait_for_remote_peer";
|
||||||
import { Protocols } from "../waku";
|
import { Protocols } from "../waku";
|
||||||
import { WakuMessage } from "../waku_message";
|
import { WakuMessage } from "../waku_message";
|
||||||
@ -14,7 +14,7 @@ const log = debug("waku:test");
|
|||||||
const TestContentTopic = "/test/1/waku-filter";
|
const TestContentTopic = "/test/1/waku-filter";
|
||||||
|
|
||||||
describe("Waku Filter", () => {
|
describe("Waku Filter", () => {
|
||||||
let waku: WakuLight;
|
let waku: WakuFull;
|
||||||
let nwaku: Nwaku;
|
let nwaku: Nwaku;
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
@ -26,7 +26,7 @@ describe("Waku Filter", () => {
|
|||||||
this.timeout(15000);
|
this.timeout(15000);
|
||||||
nwaku = new Nwaku(makeLogFileName(this));
|
nwaku = new Nwaku(makeLogFileName(this));
|
||||||
await nwaku.start({ filter: true, lightpush: true });
|
await nwaku.start({ filter: true, lightpush: true });
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
|
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
|
||||||
});
|
});
|
||||||
|
@ -3,8 +3,8 @@ import debug from "debug";
|
|||||||
|
|
||||||
import { makeLogFileName, NOISE_KEY_1, Nwaku } 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 { createLightNode } from "../create_waku";
|
import { createFullNode } from "../create_waku";
|
||||||
import type { WakuLight } from "../interfaces";
|
import type { WakuFull } from "../interfaces";
|
||||||
import { waitForRemotePeer } from "../wait_for_remote_peer";
|
import { waitForRemotePeer } from "../wait_for_remote_peer";
|
||||||
import { Protocols } from "../waku";
|
import { Protocols } from "../waku";
|
||||||
import { WakuMessage } from "../waku_message";
|
import { WakuMessage } from "../waku_message";
|
||||||
@ -14,7 +14,7 @@ const log = debug("waku:test:lightpush");
|
|||||||
const TestContentTopic = "/test/1/waku-light-push/utf8";
|
const TestContentTopic = "/test/1/waku-light-push/utf8";
|
||||||
|
|
||||||
describe("Waku Light Push [node only]", () => {
|
describe("Waku Light Push [node only]", () => {
|
||||||
let waku: WakuLight;
|
let waku: WakuFull;
|
||||||
let nwaku: Nwaku;
|
let nwaku: Nwaku;
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
@ -28,7 +28,7 @@ describe("Waku Light Push [node only]", () => {
|
|||||||
nwaku = new Nwaku(makeLogFileName(this));
|
nwaku = new Nwaku(makeLogFileName(this));
|
||||||
await nwaku.start({ lightpush: true });
|
await nwaku.start({ lightpush: true });
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
@ -64,7 +64,7 @@ describe("Waku Light Push [node only]", () => {
|
|||||||
nwaku = new Nwaku(makeLogFileName(this));
|
nwaku = new Nwaku(makeLogFileName(this));
|
||||||
await nwaku.start({ lightpush: true, topics: customPubSubTopic });
|
await nwaku.start({ lightpush: true, topics: customPubSubTopic });
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
pubSubTopic: customPubSubTopic,
|
pubSubTopic: customPubSubTopic,
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
|
@ -7,13 +7,13 @@ import {
|
|||||||
NOISE_KEY_2,
|
NOISE_KEY_2,
|
||||||
Nwaku,
|
Nwaku,
|
||||||
} from "../../test_utils";
|
} from "../../test_utils";
|
||||||
import { createLightNode } from "../create_waku";
|
import { createFullNode } from "../create_waku";
|
||||||
import {
|
import {
|
||||||
generatePrivateKey,
|
generatePrivateKey,
|
||||||
generateSymmetricKey,
|
generateSymmetricKey,
|
||||||
getPublicKey,
|
getPublicKey,
|
||||||
} from "../crypto";
|
} from "../crypto";
|
||||||
import type { WakuLight } from "../interfaces";
|
import type { WakuFull } from "../interfaces";
|
||||||
import { waitForRemotePeer } from "../wait_for_remote_peer";
|
import { waitForRemotePeer } from "../wait_for_remote_peer";
|
||||||
import { Protocols } from "../waku";
|
import { Protocols } from "../waku";
|
||||||
import { DecryptionMethod, WakuMessage } from "../waku_message";
|
import { DecryptionMethod, WakuMessage } from "../waku_message";
|
||||||
@ -25,7 +25,7 @@ const log = debug("waku:test:store");
|
|||||||
const TestContentTopic = "/test/1/waku-store/utf8";
|
const TestContentTopic = "/test/1/waku-store/utf8";
|
||||||
|
|
||||||
describe("Waku Store", () => {
|
describe("Waku Store", () => {
|
||||||
let waku: WakuLight;
|
let waku: WakuFull;
|
||||||
let nwaku: Nwaku;
|
let nwaku: Nwaku;
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
@ -49,7 +49,7 @@ describe("Waku Store", () => {
|
|||||||
).to.be.true;
|
).to.be.true;
|
||||||
}
|
}
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
@ -82,7 +82,7 @@ describe("Waku Store", () => {
|
|||||||
).to.be.true;
|
).to.be.true;
|
||||||
}
|
}
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
@ -122,7 +122,7 @@ describe("Waku Store", () => {
|
|||||||
).to.be.true;
|
).to.be.true;
|
||||||
}
|
}
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
@ -159,7 +159,7 @@ describe("Waku Store", () => {
|
|||||||
).to.be.true;
|
).to.be.true;
|
||||||
}
|
}
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
@ -202,7 +202,7 @@ describe("Waku Store", () => {
|
|||||||
).to.be.true;
|
).to.be.true;
|
||||||
}
|
}
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
pubSubTopic: customPubSubTopic,
|
pubSubTopic: customPubSubTopic,
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
@ -269,10 +269,10 @@ describe("Waku Store", () => {
|
|||||||
log("Messages have been encrypted");
|
log("Messages have been encrypted");
|
||||||
|
|
||||||
const [waku1, waku2, nimWakuMultiaddr] = await Promise.all([
|
const [waku1, waku2, nimWakuMultiaddr] = await Promise.all([
|
||||||
createLightNode({
|
createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
}).then((waku) => waku.start().then(() => waku)),
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
createLightNode({
|
createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_2,
|
staticNoiseKey: NOISE_KEY_2,
|
||||||
}).then((waku) => waku.start().then(() => waku)),
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
nwaku.getMultiaddrWithId(),
|
nwaku.getMultiaddrWithId(),
|
||||||
@ -371,10 +371,10 @@ describe("Waku Store", () => {
|
|||||||
log("Messages have been encrypted");
|
log("Messages have been encrypted");
|
||||||
|
|
||||||
const [waku1, waku2, nimWakuMultiaddr] = await Promise.all([
|
const [waku1, waku2, nimWakuMultiaddr] = await Promise.all([
|
||||||
createLightNode({
|
createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
}).then((waku) => waku.start().then(() => waku)),
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
createLightNode({
|
createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_2,
|
staticNoiseKey: NOISE_KEY_2,
|
||||||
}).then((waku) => waku.start().then(() => waku)),
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
nwaku.getMultiaddrWithId(),
|
nwaku.getMultiaddrWithId(),
|
||||||
@ -458,7 +458,7 @@ describe("Waku Store", () => {
|
|||||||
).to.be.true;
|
).to.be.true;
|
||||||
}
|
}
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createFullNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user