Merge branch 'master' of github.com:waku-org/js-waku into feat/shard-peer-selection

This commit is contained in:
danisharora099 2024-01-19 20:47:11 +05:30
commit 84fd1cf3fd
No known key found for this signature in database
GPG Key ID: FBD2BF500037F135
98 changed files with 10509 additions and 6908 deletions

View File

@ -85,14 +85,14 @@ jobs:
node_with_go_waku_master: node_with_go_waku_master:
uses: ./.github/workflows/test-node.yml uses: ./.github/workflows/test-node.yml
with: with:
nim_wakunode_image: wakuorg/go-waku:latest nim_wakunode_image: harbor.status.im/wakuorg/go-waku:latest
test_type: go-waku-master test_type: go-waku-master
debug: waku* debug: waku*
node_with_nwaku_master: node_with_nwaku_master:
uses: ./.github/workflows/test-node.yml uses: ./.github/workflows/test-node.yml
with: with:
nim_wakunode_image: wakuorg/nwaku:deploy-wakuv2-test nim_wakunode_image: harbor.status.im/wakuorg/nwaku:latest
test_type: nwaku-master test_type: nwaku-master
debug: waku* debug: waku*

16430
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -60,7 +60,7 @@
"playwright": "^1.40.1", "playwright": "^1.40.1",
"size-limit": "^11.0.1", "size-limit": "^11.0.1",
"ts-loader": "^9.4.2", "ts-loader": "^9.4.2",
"ts-node": "^10.9.1", "ts-node": "^10.9.2",
"typedoc": "^0.25.1", "typedoc": "^0.25.1",
"typescript": "^5.3.2" "typescript": "^5.3.2"
}, },

View File

@ -72,6 +72,7 @@
"node": ">=18" "node": ">=18"
}, },
"dependencies": { "dependencies": {
"@libp2p/ping": "^1.0.9",
"@noble/hashes": "^1.3.2", "@noble/hashes": "^1.3.2",
"@waku/enr": "^0.0.20", "@waku/enr": "^0.0.20",
"@waku/interfaces": "0.0.21", "@waku/interfaces": "0.0.21",
@ -103,11 +104,11 @@
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"process": "^0.11.10", "process": "^0.11.10",
"rollup": "^4.6.0" "rollup": "^4.9.5"
}, },
"peerDependencies": { "peerDependencies": {
"@multiformats/multiaddr": "^12.0.0", "@multiformats/multiaddr": "^12.0.0",
"libp2p": "^0.46.3" "libp2p": "^1.1.2"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"@multiformats/multiaddr": { "@multiformats/multiaddr": {

View File

@ -1,6 +1,5 @@
import type { Libp2p } from "@libp2p/interface"; import type { Libp2p } from "@libp2p/interface";
import type { Stream } from "@libp2p/interface/connection"; import type { Peer, PeerStore, Stream } from "@libp2p/interface";
import { Peer, PeerStore } from "@libp2p/interface/peer-store";
import type { import type {
IBaseProtocol, IBaseProtocol,
Libp2pComponents, Libp2pComponents,
@ -82,7 +81,7 @@ export class BaseProtocol implements IBaseProtocol {
* *
* @param numPeers - The total number of peers to retrieve. If 0, all peers are returned. * @param numPeers - The total number of peers to retrieve. If 0, all peers are returned.
* @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve. * @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve.
* @returns A list of peers that support the protocol sorted by latency. * @returns A list of peers that support the protocol sorted by latency.
*/ */
protected async getPeers( protected async getPeers(

View File

@ -1,8 +1,5 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { Peer, PeerId, PeerInfo, PeerStore } from "@libp2p/interface";
import type { PeerInfo } from "@libp2p/interface/peer-info"; import { CustomEvent, TypedEventEmitter } from "@libp2p/interface";
import type { Peer } from "@libp2p/interface/peer-store";
import type { PeerStore } from "@libp2p/interface/peer-store";
import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
import { import {
ConnectionManagerOptions, ConnectionManagerOptions,
EConnectionStateEvents, EConnectionStateEvents,
@ -17,8 +14,7 @@ import {
ShardInfo ShardInfo
} from "@waku/interfaces"; } from "@waku/interfaces";
import { Libp2p, Tags } from "@waku/interfaces"; import { Libp2p, Tags } from "@waku/interfaces";
import { decodeRelayShard, shardInfoToPubsubTopics } from "@waku/utils"; import { decodeRelayShard, Logger, shardInfoToPubsubTopics } from "@waku/utils";
import { Logger } from "@waku/utils";
import { KeepAliveManager } from "./keep_alive_manager.js"; import { KeepAliveManager } from "./keep_alive_manager.js";
@ -29,7 +25,7 @@ export const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3;
export const DEFAULT_MAX_PARALLEL_DIALS = 3; export const DEFAULT_MAX_PARALLEL_DIALS = 3;
export class ConnectionManager export class ConnectionManager
extends EventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> extends TypedEventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents>
implements IConnectionManager implements IConnectionManager
{ {
private static instances = new Map<string, ConnectionManager>(); private static instances = new Map<string, ConnectionManager>();

View File

@ -1,6 +1,6 @@
import { Stream } from "@libp2p/interface/connection"; import { Stream } from "@libp2p/interface";
import type { Peer } from "@libp2p/interface/peer-store"; import type { Peer } from "@libp2p/interface";
import type { IncomingStreamData } from "@libp2p/interface-internal/registrar"; import type { IncomingStreamData } from "@libp2p/interface-internal";
import type { import type {
Callback, Callback,
ContentTopic, ContentTopic,
@ -304,6 +304,10 @@ class Filter extends BaseProtocol implements IReceiver {
}) })
)[0]; )[0];
if (!peer) {
throw new Error("No peer found to initiate subscription.");
}
const subscription = const subscription =
this.getActiveSubscription(pubsubTopic, peer.id.toString()) ?? this.getActiveSubscription(pubsubTopic, peer.id.toString()) ??
this.setActiveSubscription( this.setActiveSubscription(

View File

@ -1,5 +1,5 @@
import { Peer } from "@libp2p/interface/peer-store"; import { Peer } from "@libp2p/interface";
import type { Tag } from "@libp2p/interface/peer-store"; import type { Tag } from "@libp2p/interface";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { Tags } from "@waku/interfaces"; import { Tags } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";

View File

@ -1,4 +1,4 @@
import { Peer } from "@libp2p/interface/peer-store"; import { Peer } from "@libp2p/interface";
import { Tags } from "@waku/interfaces"; import { Tags } from "@waku/interfaces";
/** /**

View File

@ -1,10 +1,9 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId, PeerStore } from "@libp2p/interface";
import type { PeerStore } from "@libp2p/interface/peer-store"; import type { PingService } from "@libp2p/ping";
import type { IRelay, PeerIdStr } from "@waku/interfaces"; import type { IRelay, PeerIdStr } from "@waku/interfaces";
import type { KeepAliveOptions } from "@waku/interfaces"; import type { KeepAliveOptions } from "@waku/interfaces";
import { Logger, pubsubTopicToSingleShardInfo } from "@waku/utils"; import { Logger, pubsubTopicToSingleShardInfo } from "@waku/utils";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";
import type { PingService } from "libp2p/ping";
import { createEncoder } from "./message/version_0.js"; import { createEncoder } from "./message/version_0.js";

View File

@ -1,5 +1,4 @@
import type { Stream } from "@libp2p/interface/connection"; import type { PeerId, Stream } from "@libp2p/interface";
import type { PeerId } from "@libp2p/interface/peer-id";
import { import {
IEncoder, IEncoder,
ILightPush, ILightPush,

View File

@ -1,5 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import { IncomingStreamData, type PeerId } from "@libp2p/interface";
import { IncomingStreamData } from "@libp2p/interface/stream-handler";
import type { import type {
IMetadata, IMetadata,
Libp2pComponents, Libp2pComponents,

View File

@ -1,4 +1,4 @@
import type { Stream } from "@libp2p/interface/connection"; import type { Stream } from "@libp2p/interface";
import { sha256 } from "@noble/hashes/sha256"; import { sha256 } from "@noble/hashes/sha256";
import { import {
Cursor, Cursor,

View File

@ -1,6 +1,5 @@
import type { PeerUpdate } from "@libp2p/interface"; import type { PeerUpdate, Stream } from "@libp2p/interface";
import type { Stream } from "@libp2p/interface/connection"; import { Peer } from "@libp2p/interface";
import { Peer } from "@libp2p/interface/peer-store";
import { Libp2p } from "@waku/interfaces"; import { Libp2p } from "@waku/interfaces";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import { selectConnection } from "@waku/utils/libp2p"; import { selectConnection } from "@waku/utils/libp2p";

View File

@ -1,5 +1,5 @@
import type { Stream } from "@libp2p/interface/connection"; import type { Stream } from "@libp2p/interface";
import { isPeerId, PeerId } from "@libp2p/interface/peer-id"; import { isPeerId, PeerId } from "@libp2p/interface";
import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr";
import type { import type {
IFilter, IFilter,
@ -189,7 +189,7 @@ export class WakuNode implements Waku {
} }
isStarted(): boolean { isStarted(): boolean {
return this.libp2p.isStarted(); return this.libp2p.status == "started";
} }
isConnected(): boolean { isConnected(): boolean {

View File

@ -59,8 +59,8 @@
"uint8arrays": "^4.0.4" "uint8arrays": "^4.0.4"
}, },
"devDependencies": { "devDependencies": {
"@libp2p/peer-id": "^3.0.3", "@libp2p/peer-id": "^4.0.4",
"@libp2p/peer-id-factory": "^3.0.3", "@libp2p/peer-id-factory": "^4.0.4",
"@multiformats/multiaddr": "^12.0.0", "@multiformats/multiaddr": "^12.0.0",
"@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.0", "@rollup/plugin-json": "^6.0.0",
@ -72,7 +72,7 @@
"cspell": "^7.3.2", "cspell": "^7.3.2",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"rollup": "^4.6.0" "rollup": "^4.9.5"
}, },
"files": [ "files": [
"dist", "dist",

View File

@ -1,10 +1,11 @@
import { CustomEvent, EventEmitter } from "@libp2p/interface/events"; import {
import type { CustomEvent,
PeerDiscovery, PeerDiscovery,
PeerDiscoveryEvents PeerDiscoveryEvents,
} from "@libp2p/interface/peer-discovery"; type PeerInfo,
import { peerDiscovery as symbol } from "@libp2p/interface/peer-discovery"; peerDiscoverySymbol as symbol,
import type { PeerInfo } from "@libp2p/interface/peer-info"; TypedEventEmitter
} from "@libp2p/interface";
import type { import type {
DnsDiscOptions, DnsDiscOptions,
DnsDiscoveryComponents, DnsDiscoveryComponents,
@ -27,7 +28,7 @@ const log = new Logger("peer-discovery-dns");
* Parse options and expose function to return bootstrap peer addresses. * Parse options and expose function to return bootstrap peer addresses.
*/ */
export class PeerDiscoveryDns export class PeerDiscoveryDns
extends EventEmitter<PeerDiscoveryEvents> extends TypedEventEmitter<PeerDiscoveryEvents>
implements PeerDiscovery implements PeerDiscovery
{ {
private nextPeer: (() => AsyncGenerator<IEnr>) | undefined; private nextPeer: (() => AsyncGenerator<IEnr>) | undefined;

View File

@ -52,8 +52,8 @@
}, },
"dependencies": { "dependencies": {
"@ethersproject/rlp": "^5.7.0", "@ethersproject/rlp": "^5.7.0",
"@libp2p/crypto": "^3.0.2", "@libp2p/crypto": "^4.0.0",
"@libp2p/peer-id": "^3.0.3", "@libp2p/peer-id": "^4.0.4",
"@multiformats/multiaddr": "^12.0.0", "@multiformats/multiaddr": "^12.0.0",
"@noble/secp256k1": "^1.7.1", "@noble/secp256k1": "^1.7.1",
"@waku/utils": "0.0.14", "@waku/utils": "0.0.14",
@ -61,7 +61,7 @@
"js-sha3": "^0.9.2" "js-sha3": "^0.9.2"
}, },
"devDependencies": { "devDependencies": {
"@libp2p/peer-id-factory": "^3.0.3", "@libp2p/peer-id-factory": "^4.0.4",
"@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.0", "@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-node-resolve": "^15.2.3",
@ -75,7 +75,7 @@
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"process": "^0.11.10", "process": "^0.11.10",
"rollup": "^4.6.0", "rollup": "^4.9.5",
"uint8arrays": "^4.0.4" "uint8arrays": "^4.0.4"
}, },
"files": [ "files": [

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import type { ENRKey, ENRValue } from "@waku/interfaces"; import type { ENRKey, ENRValue } from "@waku/interfaces";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { multiaddr } from "@multiformats/multiaddr"; import { multiaddr } from "@multiformats/multiaddr";
import * as secp from "@noble/secp256k1"; import * as secp from "@noble/secp256k1";

View File

@ -1,5 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId, PeerInfo } from "@libp2p/interface";
import type { PeerInfo } from "@libp2p/interface/peer-info";
import type { Multiaddr } from "@multiformats/multiaddr"; import type { Multiaddr } from "@multiformats/multiaddr";
import type { import type {
ENRKey, ENRKey,
@ -116,8 +115,7 @@ export class ENR extends RawEnr implements IEnr {
if (!id) return; if (!id) return;
return { return {
id, id,
multiaddrs: this.getAllLocationMultiaddrs(), multiaddrs: this.getAllLocationMultiaddrs()
protocols: []
}; };
} }

View File

@ -1,6 +1,6 @@
import { unmarshalPrivateKey, unmarshalPublicKey } from "@libp2p/crypto/keys"; import { unmarshalPrivateKey, unmarshalPublicKey } from "@libp2p/crypto/keys";
import { supportedKeys } from "@libp2p/crypto/keys"; import { supportedKeys } from "@libp2p/crypto/keys";
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import { peerIdFromKeys } from "@libp2p/peer-id"; import { peerIdFromKeys } from "@libp2p/peer-id";
export function createPeerIdFromPublicKey( export function createPeerIdFromPublicKey(

View File

@ -47,11 +47,11 @@
"node": ">=18" "node": ">=18"
}, },
"devDependencies": { "devDependencies": {
"@chainsafe/libp2p-gossipsub": "^10.1.1", "@chainsafe/libp2p-gossipsub": "^11.1.0",
"@multiformats/multiaddr": "^12.0.0", "@multiformats/multiaddr": "^12.0.0",
"cspell": "^7.3.2", "cspell": "^7.3.2",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"libp2p": "^0.46.14" "libp2p": "^1.1.2"
}, },
"files": [ "files": [
"dist", "dist",

View File

@ -1,6 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { Peer, PeerId, TypedEventEmitter } from "@libp2p/interface";
import type { Peer } from "@libp2p/interface/peer-store";
import type { EventEmitter } from "@libp2p/interfaces/events";
export enum Tags { export enum Tags {
BOOTSTRAP = "bootstrap", BOOTSTRAP = "bootstrap",
@ -59,7 +57,7 @@ export interface IConnectionStateEvents {
} }
export interface IConnectionManager export interface IConnectionManager
extends EventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> { extends TypedEventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> {
getPeersByDiscovery(): Promise<PeersByDiscoveryResult>; getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
stop(): void; stop(): void;
} }

View File

@ -1,4 +1,4 @@
import { PeerStore } from "@libp2p/interface/peer-store"; import { PeerStore } from "@libp2p/interface";
export type SearchContext = { export type SearchContext = {
domain: string; domain: string;

View File

@ -1,5 +1,5 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import type { PeerInfo } from "@libp2p/interface/peer-info"; import type { PeerInfo } from "@libp2p/interface";
import type { Multiaddr } from "@multiformats/multiaddr"; import type { Multiaddr } from "@multiformats/multiaddr";
export type ENRKey = string; export type ENRKey = string;

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import type { IDecodedMessage, IDecoder, SingleShardInfo } from "./message.js"; import type { IDecodedMessage, IDecoder, SingleShardInfo } from "./message.js";
import type { ContentTopic, PubsubTopic } from "./misc.js"; import type { ContentTopic, PubsubTopic } from "./misc.js";

View File

@ -1,8 +1,8 @@
import type { GossipSub } from "@chainsafe/libp2p-gossipsub"; import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
import type { identify } from "@libp2p/identify";
import type { Libp2p as BaseLibp2p } from "@libp2p/interface"; import type { Libp2p as BaseLibp2p } from "@libp2p/interface";
import type { PingService } from "@libp2p/ping";
import type { Libp2pInit, Libp2pOptions } from "libp2p"; import type { Libp2pInit, Libp2pOptions } from "libp2p";
import type { identifyService } from "libp2p/identify";
import type { PingService } from "libp2p/ping";
import { IMetadata } from "./metadata"; import { IMetadata } from "./metadata";
@ -10,7 +10,7 @@ export type Libp2pServices = {
ping: PingService; ping: PingService;
metadata?: IMetadata; metadata?: IMetadata;
pubsub?: GossipSub; pubsub?: GossipSub;
identify: ReturnType<ReturnType<typeof identifyService>>; identify: ReturnType<ReturnType<typeof identify>>;
}; };
// TODO: Get libp2p to export this. // TODO: Get libp2p to export this.

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import type { ShardInfo } from "./enr.js"; import type { ShardInfo } from "./enr.js";
import type { IBaseProtocol, ShardingParams } from "./protocols.js"; import type { IBaseProtocol, ShardingParams } from "./protocols.js";

View File

@ -1,6 +1,6 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import type { PeerStore } from "@libp2p/interface/peer-store"; import type { PeerStore } from "@libp2p/interface";
import type { ConnectionManager } from "@libp2p/interface-internal/connection-manager"; import type { ConnectionManager } from "@libp2p/interface-internal";
import { IEnr } from "./enr.js"; import { IEnr } from "./enr.js";
import { IBaseProtocol } from "./protocols.js"; import { IBaseProtocol } from "./protocols.js";

View File

@ -1,6 +1,6 @@
import type { Libp2p } from "@libp2p/interface"; import type { Libp2p } from "@libp2p/interface";
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import type { Peer, PeerStore } from "@libp2p/interface/peer-store"; import type { Peer, PeerStore } from "@libp2p/interface";
import type { ShardInfo } from "./enr.js"; import type { ShardInfo } from "./enr.js";
import type { CreateLibp2pOptions } from "./libp2p.js"; import type { CreateLibp2pOptions } from "./libp2p.js";

View File

@ -1,5 +1,4 @@
import type { Stream } from "@libp2p/interface/connection"; import type { PeerId, Stream } from "@libp2p/interface";
import type { PeerId } from "@libp2p/interface/peer-id";
import type { Multiaddr } from "@multiformats/multiaddr"; import type { Multiaddr } from "@multiformats/multiaddr";
import { IConnectionManager } from "./connection_manager.js"; import { IConnectionManager } from "./connection_manager.js";

View File

@ -97,7 +97,7 @@
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"process": "^0.11.10", "process": "^0.11.10",
"rollup": "^4.6.0" "rollup": "^4.9.5"
}, },
"files": [ "files": [
"dist", "dist",

View File

@ -70,7 +70,7 @@
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"process": "^0.11.10", "process": "^0.11.10",
"rollup": "^4.6.0" "rollup": "^4.9.5"
}, },
"files": [ "files": [
"dist", "dist",

View File

@ -67,7 +67,7 @@
"chai": "^4.3.10", "chai": "^4.3.10",
"cspell": "^7.3.2", "cspell": "^7.3.2",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"rollup": "^4.6.0", "rollup": "^4.9.5",
"uint8arraylist": "^2.4.3" "uint8arraylist": "^2.4.3"
}, },
"files": [ "files": [

View File

@ -1,12 +1,13 @@
import type { IdentifyResult } from "@libp2p/interface"; import {
import { CustomEvent, EventEmitter } from "@libp2p/interface/events"; CustomEvent,
import type { IdentifyResult,
PeerDiscovery, PeerDiscovery,
PeerDiscoveryEvents PeerDiscoveryEvents,
} from "@libp2p/interface/peer-discovery"; PeerId,
import { peerDiscovery as symbol } from "@libp2p/interface/peer-discovery"; PeerInfo,
import type { PeerId } from "@libp2p/interface/peer-id"; peerDiscoverySymbol as symbol,
import type { PeerInfo } from "@libp2p/interface/peer-info"; TypedEventEmitter
} from "@libp2p/interface";
import { Libp2pComponents, Tags } from "@waku/interfaces"; import { Libp2pComponents, Tags } from "@waku/interfaces";
import { encodeRelayShard, Logger } from "@waku/utils"; import { encodeRelayShard, Logger } from "@waku/utils";
@ -50,7 +51,7 @@ const DEFAULT_PEER_EXCHANGE_TAG_VALUE = 50;
const DEFAULT_PEER_EXCHANGE_TAG_TTL = 100_000_000; const DEFAULT_PEER_EXCHANGE_TAG_TTL = 100_000_000;
export class PeerExchangeDiscovery export class PeerExchangeDiscovery
extends EventEmitter<PeerDiscoveryEvents> extends TypedEventEmitter<PeerDiscoveryEvents>
implements PeerDiscovery implements PeerDiscovery
{ {
private readonly components: Libp2pComponents; private readonly components: Libp2pComponents;
@ -205,7 +206,6 @@ export class PeerExchangeDiscovery
new CustomEvent<PeerInfo>("peer", { new CustomEvent<PeerInfo>("peer", {
detail: { detail: {
id: peerId, id: peerId,
protocols: [],
multiaddrs: peerInfo.multiaddrs multiaddrs: peerInfo.multiaddrs
} }
}) })

View File

@ -54,7 +54,7 @@
"cspell": "^7.3.2", "cspell": "^7.3.2",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"protons": "^7.0.2", "protons": "^7.0.2",
"rollup": "^4.6.0", "rollup": "^4.9.5",
"uint8arraylist": "^2.4.3" "uint8arraylist": "^2.4.3"
}, },
"files": [ "files": [

View File

@ -49,7 +49,7 @@
"node": ">=18" "node": ">=18"
}, },
"dependencies": { "dependencies": {
"@chainsafe/libp2p-gossipsub": "^10.1.1", "@chainsafe/libp2p-gossipsub": "^11.1.0",
"@noble/hashes": "^1.3.2", "@noble/hashes": "^1.3.2",
"@waku/core": "0.0.26", "@waku/core": "0.0.26",
"@waku/interfaces": "0.0.21", "@waku/interfaces": "0.0.21",
@ -64,7 +64,7 @@
"@waku/build-utils": "*", "@waku/build-utils": "*",
"@rollup/plugin-json": "^6.0.0", "@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-node-resolve": "^15.2.3",
"rollup": "^4.6.0" "rollup": "^4.9.5"
}, },
"files": [ "files": [
"dist", "dist",

View File

@ -6,8 +6,7 @@ import {
} from "@chainsafe/libp2p-gossipsub"; } from "@chainsafe/libp2p-gossipsub";
import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types"; import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types";
import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types"; import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types";
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PubSub as Libp2pPubsub, PeerId } from "@libp2p/interface";
import type { PubSub as Libp2pPubsub } from "@libp2p/interface/pubsub";
import { sha256 } from "@noble/hashes/sha256"; import { sha256 } from "@noble/hashes/sha256";
import { import {
ActiveSubscriptions, ActiveSubscriptions,

View File

@ -1,5 +1,5 @@
import { TopicValidatorResult } from "@libp2p/interface/pubsub"; import { TopicValidatorResult } from "@libp2p/interface";
import type { UnsignedMessage } from "@libp2p/interface/pubsub"; import type { UnsignedMessage } from "@libp2p/interface";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { createEncoder } from "@waku/core"; import { createEncoder } from "@waku/core";
import { expect } from "chai"; import { expect } from "chai";

View File

@ -1,6 +1,5 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { Message, PeerId } from "@libp2p/interface";
import type { Message } from "@libp2p/interface/pubsub"; import { TopicValidatorResult } from "@libp2p/interface";
import { TopicValidatorResult } from "@libp2p/interface/pubsub";
import { proto_message as proto } from "@waku/proto"; import { proto_message as proto } from "@waku/proto";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";

View File

@ -61,19 +61,21 @@
"node": ">=18" "node": ">=18"
}, },
"dependencies": { "dependencies": {
"@chainsafe/libp2p-noise": "^13.0.4", "@chainsafe/libp2p-noise": "^14.1.0",
"@libp2p/mplex": "^9.0.10", "@libp2p/identify": "^1.0.10",
"@libp2p/websockets": "^7.0.5", "@libp2p/mplex": "^10.0.12",
"@waku/utils": "0.0.14", "@libp2p/ping": "^1.0.9",
"@waku/relay": "0.0.9", "@libp2p/websockets": "^8.0.11",
"@waku/core": "0.0.26", "@waku/core": "0.0.26",
"@waku/dns-discovery": "0.0.20", "@waku/dns-discovery": "0.0.20",
"@waku/interfaces": "0.0.21", "@waku/interfaces": "0.0.21",
"@waku/peer-exchange": "^0.0.19", "@waku/peer-exchange": "^0.0.19",
"libp2p": "^0.46.14" "@waku/relay": "0.0.9",
"@waku/utils": "0.0.14",
"libp2p": "^1.1.2"
}, },
"devDependencies": { "devDependencies": {
"@chainsafe/libp2p-gossipsub": "^10.1.1", "@chainsafe/libp2p-gossipsub": "^11.1.0",
"@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.0", "@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-node-resolve": "^15.2.3",
@ -81,7 +83,7 @@
"cspell": "^7.3.2", "cspell": "^7.3.2",
"interface-datastore": "^8.2.10", "interface-datastore": "^8.2.10",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"rollup": "^4.6.0" "rollup": "^4.9.5"
}, },
"files": [ "files": [
"dist", "dist",

View File

@ -1,7 +1,9 @@
import type { GossipSub } from "@chainsafe/libp2p-gossipsub"; import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
import { noise } from "@chainsafe/libp2p-noise"; import { noise } from "@chainsafe/libp2p-noise";
import type { PeerDiscovery } from "@libp2p/interface/peer-discovery"; import { identify } from "@libp2p/identify";
import type { PeerDiscovery } from "@libp2p/interface";
import { mplex } from "@libp2p/mplex"; import { mplex } from "@libp2p/mplex";
import { ping } from "@libp2p/ping";
import { webSockets } from "@libp2p/websockets"; import { webSockets } from "@libp2p/websockets";
import { all as filterAll } from "@libp2p/websockets/filters"; import { all as filterAll } from "@libp2p/websockets/filters";
import { import {
@ -27,8 +29,6 @@ import type {
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange"; import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
import { RelayCreateOptions, wakuGossipSub, wakuRelay } from "@waku/relay"; import { RelayCreateOptions, wakuGossipSub, wakuRelay } from "@waku/relay";
import { createLibp2p } from "libp2p"; import { createLibp2p } from "libp2p";
import { identifyService } from "libp2p/identify";
import { pingService } from "libp2p/ping";
const DEFAULT_NODE_REQUIREMENTS = { const DEFAULT_NODE_REQUIREMENTS = {
lightPush: 1, lightPush: 1,
@ -242,10 +242,10 @@ export async function defaultLibp2p(
connectionEncryption: [noise()], connectionEncryption: [noise()],
...options, ...options,
services: { services: {
identify: identifyService({ identify: identify({
agentVersion: userAgent ?? DefaultUserAgent agentVersion: userAgent ?? DefaultUserAgent
}), }),
ping: pingService(), ping: ping(),
...metadataService, ...metadataService,
...pubsubService, ...pubsubService,
...options?.services ...options?.services

View File

@ -50,8 +50,8 @@
"node": ">=18" "node": ">=18"
}, },
"dependencies": { "dependencies": {
"@libp2p/interface-compliance-tests": "^4.1.0", "@libp2p/interface-compliance-tests": "^5.1.2",
"@libp2p/peer-id": "^3.0.3", "@libp2p/peer-id": "^4.0.4",
"@waku/core": "*", "@waku/core": "*",
"@waku/enr": "*", "@waku/enr": "*",
"@waku/interfaces": "*", "@waku/interfaces": "*",
@ -68,7 +68,7 @@
"tail": "^2.2.6" "tail": "^2.2.6"
}, },
"devDependencies": { "devDependencies": {
"@libp2p/bootstrap": "^9.0.10", "@libp2p/bootstrap": "^10.0.11",
"@types/chai": "^4.3.11", "@types/chai": "^4.3.11",
"@types/dockerode": "^3.3.19", "@types/dockerode": "^3.3.19",
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
@ -85,7 +85,7 @@
"datastore-core": "^9.2.7", "datastore-core": "^9.2.7",
"debug": "^4.3.4", "debug": "^4.3.4",
"interface-datastore": "^8.2.10", "interface-datastore": "^8.2.10",
"libp2p": "^0.46.14", "libp2p": "^1.1.2",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"mocha-multi-reporters": "^1.5.1", "mocha-multi-reporters": "^1.5.1",
"npm-run-all": "^4.1.5" "npm-run-all": "^4.1.5"

View File

@ -5,12 +5,6 @@
* @module * @module
*/ */
export * from "./async_fs.js"; export * from "./utils/index.js";
export * from "./constants.js"; export * from "./constants.js";
export * from "./delay.js"; export * from "./lib/index.js";
export * from "./log_file.js";
export * from "./node/node.js";
export * from "./teardown.js";
export * from "./message_collector.js";
export * from "./utils.js";
export * from "./waitForRemotePeerWithCodec.js";

View File

@ -3,7 +3,7 @@ import fs from "fs";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import Docker from "dockerode"; import Docker from "dockerode";
import { Args } from "./interfaces.js"; import { Args } from "../types.js";
const log = new Logger("test:docker"); const log = new Logger("test:docker");

View File

@ -0,0 +1,2 @@
export * from "./message_collector.js";
export * from "./service_node.js";

View File

@ -5,9 +5,8 @@ import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { AssertionError, expect } from "chai"; import { AssertionError, expect } from "chai";
import { equals } from "uint8arrays/equals"; import { equals } from "uint8arrays/equals";
import { MessageRpcResponse } from "./node/interfaces.js"; import { base64ToUtf8, delay, ServiceNode } from "../index.js";
import { MessageRpcResponse } from "../types.js";
import { base64ToUtf8, delay, NimGoNode } from "./index.js";
const log = new Logger("test:message-collector"); const log = new Logger("test:message-collector");
@ -20,7 +19,7 @@ export class MessageCollector {
list: Array<MessageRpcResponse | DecodedMessage> = []; list: Array<MessageRpcResponse | DecodedMessage> = [];
callback: (msg: DecodedMessage) => void = () => {}; callback: (msg: DecodedMessage) => void = () => {};
constructor(private nwaku?: NimGoNode) { constructor(private nwaku?: ServiceNode) {
if (!this.nwaku) { if (!this.nwaku) {
this.callback = (msg: DecodedMessage): void => { this.callback = (msg: DecodedMessage): void => {
log.info("Got a message"); log.info("Got a message");

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import { peerIdFromString } from "@libp2p/peer-id"; import { peerIdFromString } from "@libp2p/peer-id";
import { Multiaddr, multiaddr } from "@multiformats/multiaddr"; import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
import { DefaultPubsubTopic } from "@waku/interfaces"; import { DefaultPubsubTopic } from "@waku/interfaces";
@ -8,18 +8,18 @@ import { bytesToHex, hexToBytes } from "@waku/utils/bytes";
import pRetry from "p-retry"; import pRetry from "p-retry";
import portfinder from "portfinder"; import portfinder from "portfinder";
import { existsAsync, mkdirAsync, openAsync } from "../async_fs.js";
import { delay } from "../delay.js";
import waitForLine from "../log_file.js";
import Dockerode from "./dockerode.js";
import { import {
Args, Args,
KeyPair, KeyPair,
LogLevel, LogLevel,
MessageRpcQuery, MessageRpcQuery,
MessageRpcResponse MessageRpcResponse
} from "./interfaces.js"; } from "../types.js";
import { existsAsync, mkdirAsync, openAsync } from "../utils/async_fs.js";
import { delay } from "../utils/delay.js";
import waitForLine from "../utils/log_file.js";
import Dockerode from "./dockerode.js";
const log = new Logger("test:node"); const log = new Logger("test:node");
@ -27,7 +27,8 @@ const WAKU_SERVICE_NODE_PARAMS =
process.env.WAKU_SERVICE_NODE_PARAMS ?? undefined; process.env.WAKU_SERVICE_NODE_PARAMS ?? undefined;
const NODE_READY_LOG_LINE = "Node setup complete"; const NODE_READY_LOG_LINE = "Node setup complete";
const DOCKER_IMAGE_NAME = process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.22.0"; export const DOCKER_IMAGE_NAME =
process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.22.0";
const isGoWaku = DOCKER_IMAGE_NAME.includes("go-waku"); const isGoWaku = DOCKER_IMAGE_NAME.includes("go-waku");
@ -41,7 +42,7 @@ BigInt.prototype.toJSON = function toJSON() {
return Number(this); return Number(this);
}; };
export class NimGoNode { export class ServiceNode {
private docker?: Dockerode; private docker?: Dockerode;
private peerId?: PeerId; private peerId?: PeerId;
private multiaddrWithId?: Multiaddr; private multiaddrWithId?: Multiaddr;
@ -464,7 +465,3 @@ interface RpcInfoResponse {
listenAddresses: string[]; listenAddresses: string[];
enrUri?: string; enrUri?: string;
} }
export function base64ToUtf8(b64: string): string {
return Buffer.from(b64, "base64").toString("utf-8");
}

View File

@ -28,3 +28,5 @@ export async function waitForFile(path: string): Promise<void> {
} }
} while (!found); } while (!found);
} }
export * from "./log_file.js";

View File

@ -0,0 +1,3 @@
export function base64ToUtf8(b64: string): string {
return Buffer.from(b64, "base64").toString("utf-8");
}

View File

@ -1,3 +1,5 @@
export function delay(ms: number): Promise<void> { export function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
} }
export * from "./async_fs.js";

View File

@ -1,5 +1,7 @@
import { createDecoder, createEncoder, Decoder, Encoder } from "@waku/core"; import { createDecoder, createEncoder, Decoder, Encoder } from "@waku/core";
import { DOCKER_IMAGE_NAME } from "../lib/service_node";
// Utility to generate test data for multiple topics tests. // Utility to generate test data for multiple topics tests.
export function generateTestData(topicCount: number): { export function generateTestData(topicCount: number): {
contentTopics: string[]; contentTopics: string[];
@ -20,3 +22,19 @@ export function generateTestData(topicCount: number): {
decoders decoders
}; };
} }
// Utility to add test conditions based on nwaku/go-waku versions
export function isNwakuAtLeast(requiredVersion: string): boolean {
const versionRegex = /(?:v)?(\d+\.\d+(?:\.\d+)?)/;
const match = DOCKER_IMAGE_NAME.match(versionRegex);
if (match) {
const version = match[0].substring(1); // Remove the 'v' prefix
return (
version.localeCompare(requiredVersion, undefined, { numeric: true }) >= 0
);
} else {
// If there is no match we assume that it's a version close to master so we return True
return true;
}
}

View File

@ -0,0 +1,6 @@
export * from "./generate_test_data.js";
export * from "./teardown.js";
export * from "./random_array.js";
export * from "./wait_for_remote_peer_with_codec.js";
export * from "./delay.js";
export * from "./base64_utf8.js";

View File

@ -2,12 +2,12 @@ import { Waku } from "@waku/interfaces";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import pRetry from "p-retry"; import pRetry from "p-retry";
import { NimGoNode } from "./index.js"; import { ServiceNode } from "../lib/service_node.js";
const log = new Logger("test:teardown"); const log = new Logger("test:teardown");
export async function tearDownNodes( export async function tearDownNodes(
nwakuNodes: NimGoNode | NimGoNode[], nwakuNodes: ServiceNode | ServiceNode[],
wakuNodes: Waku | Waku[] wakuNodes: Waku | Waku[]
): Promise<void> { ): Promise<void> {
const nNodes = Array.isArray(nwakuNodes) ? nwakuNodes : [nwakuNodes]; const nNodes = Array.isArray(nwakuNodes) ? nwakuNodes : [nwakuNodes];

View File

@ -1,5 +1,5 @@
import type { IdentifyResult } from "@libp2p/interface"; import type { IdentifyResult } from "@libp2p/interface";
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import type { LightNode } from "@waku/interfaces"; import type { LightNode } from "@waku/interfaces";
/** /**

View File

@ -1,6 +1,5 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId, PeerInfo } from "@libp2p/interface";
import type { PeerInfo } from "@libp2p/interface/peer-info"; import { CustomEvent } from "@libp2p/interface";
import { CustomEvent } from "@libp2p/interfaces/events";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { Multiaddr } from "@multiformats/multiaddr"; import { Multiaddr } from "@multiformats/multiaddr";
import { import {
@ -14,8 +13,8 @@ import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import sinon, { SinonSpy, SinonStub } from "sinon"; import sinon, { SinonSpy, SinonStub } from "sinon";
import { delay } from "../dist/delay.js"; import { delay } from "../src/index.js";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../src/index.js"; import { makeLogFileName, ServiceNode, tearDownNodes } from "../src/index.js";
const TEST_TIMEOUT = 10_000; const TEST_TIMEOUT = 10_000;
const DELAY_MS = 1_000; const DELAY_MS = 1_000;
@ -62,8 +61,7 @@ describe("ConnectionManager", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: peerIdBootstrap, id: peerIdBootstrap,
multiaddrs: [], multiaddrs: []
protocols: []
} }
}) })
); );
@ -96,8 +94,7 @@ describe("ConnectionManager", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: peerIdPx, id: peerIdPx,
multiaddrs: [], multiaddrs: []
protocols: []
} }
}) })
); );
@ -312,8 +309,7 @@ describe("ConnectionManager", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: await createSecp256k1PeerId(), id: await createSecp256k1PeerId(),
multiaddrs: [], multiaddrs: []
protocols: []
} }
}) })
); );
@ -377,7 +373,7 @@ describe("ConnectionManager", function () {
// emit a peer:discovery event // emit a peer:discovery event
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { id: bootstrapPeer, multiaddrs: [], protocols: [] } detail: { id: bootstrapPeer, multiaddrs: [] }
}) })
); );
@ -399,8 +395,7 @@ describe("ConnectionManager", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: await createSecp256k1PeerId(), id: await createSecp256k1PeerId(),
multiaddrs: [], multiaddrs: []
protocols: []
} }
}) })
); );
@ -417,8 +412,7 @@ describe("ConnectionManager", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: await createSecp256k1PeerId(), id: await createSecp256k1PeerId(),
multiaddrs: [], multiaddrs: []
protocols: []
} }
}) })
); );
@ -443,8 +437,7 @@ describe("ConnectionManager", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: pxPeer, id: pxPeer,
multiaddrs: [], multiaddrs: []
protocols: []
} }
}) })
); );
@ -469,8 +462,7 @@ describe("ConnectionManager", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: await createSecp256k1PeerId(), id: await createSecp256k1PeerId(),
multiaddrs: [], multiaddrs: []
protocols: []
} }
}) })
); );
@ -486,15 +478,15 @@ describe("ConnectionManager", function () {
describe("Connection state", () => { describe("Connection state", () => {
this.timeout(20_000); this.timeout(20_000);
let nwaku1: NimGoNode; let nwaku1: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let nwaku1PeerId: Multiaddr; let nwaku1PeerId: Multiaddr;
let nwaku2PeerId: Multiaddr; let nwaku2PeerId: Multiaddr;
beforeEach(async () => { beforeEach(async () => {
this.timeout(20_000); this.timeout(20_000);
nwaku1 = new NimGoNode(makeLogFileName(this.ctx) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku2 = new NimGoNode(makeLogFileName(this.ctx) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
await nwaku1.start({ await nwaku1.start({
filter: true filter: true
}); });

View File

@ -1,5 +1,6 @@
import { EventEmitter } from "@libp2p/interface/events"; import { TypedEventEmitter } from "@libp2p/interface";
import tests from "@libp2p/interface-compliance-tests/peer-discovery"; import tests from "@libp2p/interface-compliance-tests/peer-discovery";
import { prefixLogger } from "@libp2p/logger";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { PersistentPeerStore } from "@libp2p/peer-store"; import { PersistentPeerStore } from "@libp2p/peer-store";
import { import {
@ -13,7 +14,7 @@ import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { MemoryDatastore } from "datastore-core/memory"; import { MemoryDatastore } from "datastore-core/memory";
import { delay } from "../src/delay.js"; import { delay } from "../src/index.js";
const maxQuantity = 3; const maxQuantity = 3;
@ -24,9 +25,10 @@ describe("DNS Discovery: Compliance Test", function () {
// create libp2p mock peerStore // create libp2p mock peerStore
const components = { const components = {
peerStore: new PersistentPeerStore({ peerStore: new PersistentPeerStore({
events: new EventEmitter(), events: new TypedEventEmitter(),
peerId: await createSecp256k1PeerId(), peerId: await createSecp256k1PeerId(),
datastore: new MemoryDatastore() datastore: new MemoryDatastore(),
logger: prefixLogger("dns-peer-discovery.spec.ts")
}) })
} as unknown as Libp2pComponents; } as unknown as Libp2pComponents;

View File

@ -5,12 +5,16 @@ import { Protocols } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk/relay"; import { createRelayNode } from "@waku/sdk/relay";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NOISE_KEY_1, tearDownNodes } from "../src/index.js"; import {
import { NimGoNode } from "../src/node/node.js"; makeLogFileName,
NOISE_KEY_1,
ServiceNode,
tearDownNodes
} from "../src/index.js";
describe("ENR Interop: NimGoNode", function () { describe("ENR Interop: ServiceNode", function () {
let waku: RelayNode; let waku: RelayNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
afterEach(async function () { afterEach(async function () {
this.timeout(15000); this.timeout(15000);
@ -19,7 +23,7 @@ describe("ENR Interop: NimGoNode", function () {
it("Relay", async function () { it("Relay", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
relay: true, relay: true,
store: false, store: false,
@ -51,7 +55,7 @@ describe("ENR Interop: NimGoNode", function () {
it("Relay + Store", async function () { it("Relay + Store", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
relay: true, relay: true,
store: true, store: true,
@ -83,7 +87,7 @@ describe("ENR Interop: NimGoNode", function () {
it("All", async function () { it("All", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
relay: true, relay: true,
store: true, store: true,

View File

@ -29,9 +29,9 @@ import {
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
ServiceNode,
tearDownNodes tearDownNodes
} from "../src/index.js"; } from "../src/index.js";
import { NimGoNode } from "../src/node/node.js";
const log = new Logger("test:ephemeral"); const log = new Logger("test:ephemeral");
@ -43,7 +43,7 @@ const TestDecoder = createDecoder(TestContentTopic);
describe("Waku Message Ephemeral field", () => { describe("Waku Message Ephemeral field", () => {
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
@ -54,7 +54,7 @@ describe("Waku Message Ephemeral field", () => {
beforeEach(async function () { beforeEach(async function () {
this.timeout(15_000); this.timeout(15_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
lightpush: true, lightpush: true,

View File

@ -18,18 +18,17 @@ import { expect } from "chai";
import { import {
makeLogFileName, makeLogFileName,
MessageCollector, MessageCollector,
NimGoNode, ServiceNode,
tearDownNodes tearDownNodes
} from "../../src/index.js"; } from "../../../src/index.js";
import { runNodes } from "../utils.js";
import { runNodes } from "./utils.js";
describe("Waku Filter V2: Multiple PubsubTopics", function () { describe("Waku Filter V2: Multiple PubsubTopics", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(30000); this.timeout(30000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
@ -121,7 +120,7 @@ describe("Waku Filter V2: Multiple PubsubTopics", function () {
await subscription.subscribe([customDecoder1], messageCollector.callback); await subscription.subscribe([customDecoder1], messageCollector.callback);
// Set up and start a new nwaku node with customPubsubTopic1 // Set up and start a new nwaku node with customPubsubTopic1
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
@ -185,8 +184,8 @@ describe("Waku Filter V2 (Autosharding): Multiple PubsubTopics", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(30000); this.timeout(30000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
@ -295,7 +294,7 @@ describe("Waku Filter V2 (Autosharding): Multiple PubsubTopics", function () {
await subscription.subscribe([customDecoder1], messageCollector.callback); await subscription.subscribe([customDecoder1], messageCollector.callback);
// Set up and start a new nwaku node with customPubsubTopic1 // Set up and start a new nwaku node with customPubsubTopic1
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
@ -359,8 +358,8 @@ describe("Waku Filter V2 (Named sharding): Multiple PubsubTopics", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(30000); this.timeout(30000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
@ -387,10 +386,14 @@ describe("Waku Filter V2 (Named sharding): Multiple PubsubTopics", function () {
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [ [nwaku, waku] = await runNodes(
customPubsubTopic1, this,
customPubsubTopic2 [customPubsubTopic1, customPubsubTopic2],
]); {
clusterId: 3,
shards: [1, 2]
}
);
subscription = await waku.filter.createSubscription(customPubsubTopic1); subscription = await waku.filter.createSubscription(customPubsubTopic1);
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
@ -446,7 +449,7 @@ describe("Waku Filter V2 (Named sharding): Multiple PubsubTopics", function () {
await subscription.subscribe([customDecoder1], messageCollector.callback); await subscription.subscribe([customDecoder1], messageCollector.callback);
// Set up and start a new nwaku node with customPubsubTopic1 // Set up and start a new nwaku node with customPubsubTopic1
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,

View File

@ -3,21 +3,24 @@ import type { IFilterSubscription, LightNode } from "@waku/interfaces";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { MessageCollector, NimGoNode, tearDownNodes } from "../../src/index.js"; import {
MessageCollector,
ServiceNode,
tearDownNodes
} from "../../../src/index.js";
import { import {
runNodes, runNodes,
TestContentTopic, TestContentTopic,
TestDecoder, TestDecoder,
TestEncoder, TestEncoder,
validatePingError validatePingError
} from "./utils.js"; } from "../utils.js";
describe("Waku Filter V2: Ping", function () { describe("Waku Filter V2: Ping", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(10000); this.timeout(10000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;

View File

@ -8,25 +8,24 @@ import { expect } from "chai";
import { import {
delay, delay,
MessageCollector, MessageCollector,
NimGoNode, ServiceNode,
tearDownNodes, tearDownNodes,
TEST_STRING, TEST_STRING,
TEST_TIMESTAMPS TEST_TIMESTAMPS
} from "../../src/index.js"; } from "../../../src/index.js";
import { import {
messageText, messageText,
runNodes, runNodes,
TestContentTopic, TestContentTopic,
TestDecoder, TestDecoder,
TestEncoder TestEncoder
} from "./utils.js"; } from "../utils.js";
describe("Waku Filter V2: FilterPush", function () { describe("Waku Filter V2: FilterPush", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(10000); this.timeout(10000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;

View File

@ -15,13 +15,13 @@ import { expect } from "chai";
import { import {
delay, delay,
generateTestData, generateTestData,
isNwakuAtLeast,
makeLogFileName, makeLogFileName,
MessageCollector, MessageCollector,
NimGoNode, ServiceNode,
tearDownNodes, tearDownNodes,
TEST_STRING TEST_STRING
} from "../../src/index.js"; } from "../../../src/index.js";
import { import {
messagePayload, messagePayload,
messageText, messageText,
@ -29,14 +29,14 @@ import {
TestContentTopic, TestContentTopic,
TestDecoder, TestDecoder,
TestEncoder TestEncoder
} from "./utils.js"; } from "../utils.js";
describe("Waku Filter V2: Subscribe", function () { describe("Waku Filter V2: Subscribe", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(10000); this.timeout(10000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
@ -118,7 +118,7 @@ describe("Waku Filter V2: Subscribe", function () {
// Send a test message using the relay post method. // Send a test message using the relay post method.
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: utf8ToBytes(messageText) payload: utf8ToBytes(messageText)
}) })
@ -220,11 +220,14 @@ describe("Waku Filter V2: Subscribe", function () {
}); });
}); });
it("Subscribe to 30 topics at once and receives messages", async function () { it("Subscribe to 100 topics at once and receives messages", async function () {
const topicCount = 30; let topicCount = 30;
if (isNwakuAtLeast("0.24.0")) {
this.timeout(50000);
topicCount = 100;
}
const td = generateTestData(topicCount); const td = generateTestData(topicCount);
// Subscribe to all 30 topics.
await subscription.subscribe(td.decoders, messageCollector.callback); await subscription.subscribe(td.decoders, messageCollector.callback);
// Send a unique message on each topic. // Send a unique message on each topic.
@ -234,30 +237,42 @@ describe("Waku Filter V2: Subscribe", function () {
}); });
} }
// Verify that each message was received on the corresponding topic. // Open issue here: https://github.com/waku-org/js-waku/issues/1790
expect(await messageCollector.waitForMessages(30)).to.eq(true); // That's why we use the try catch block
td.contentTopics.forEach((topic, index) => { try {
messageCollector.verifyReceivedMessage(index, { // Verify that each message was received on the corresponding topic.
expectedContentTopic: topic, expect(await messageCollector.waitForMessages(topicCount)).to.eq(true);
expectedMessageText: `Message for Topic ${index + 1}` td.contentTopics.forEach((topic, index) => {
messageCollector.verifyReceivedMessage(index, {
expectedContentTopic: topic,
expectedMessageText: `Message for Topic ${index + 1}`
});
}); });
}); } catch (error) {
console.warn(
"This test still fails because of https://github.com/waku-org/js-waku/issues/1790"
);
}
}); });
it("Error when try to subscribe to more than 30 topics", async function () { it("Error when try to subscribe to more than 101 topics", async function () {
const topicCount = 31; let topicCount = 31;
if (isNwakuAtLeast("0.24.0")) {
topicCount = 101;
}
const td = generateTestData(topicCount); const td = generateTestData(topicCount);
// Attempt to subscribe to 31 topics
try { try {
await subscription.subscribe(td.decoders, messageCollector.callback); await subscription.subscribe(td.decoders, messageCollector.callback);
throw new Error( throw new Error(
"Subscribe to 31 topics was successful but was expected to fail with a specific error." `Subscribe to ${topicCount} topics was successful but was expected to fail with a specific error.`
); );
} catch (err) { } catch (err) {
if ( if (
err instanceof Error && err instanceof Error &&
err.message.includes("exceeds maximum content topics: 30") err.message.includes(
`exceeds maximum content topics: ${topicCount - 1}`
)
) { ) {
return; return;
} else { } else {
@ -370,7 +385,7 @@ describe("Waku Filter V2: Subscribe", function () {
await subscription.subscribe([TestDecoder], messageCollector.callback); await subscription.subscribe([TestDecoder], messageCollector.callback);
// Set up and start a new nwaku node // Set up and start a new nwaku node
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,

View File

@ -7,10 +7,9 @@ import { expect } from "chai";
import { import {
generateTestData, generateTestData,
MessageCollector, MessageCollector,
NimGoNode, ServiceNode,
tearDownNodes tearDownNodes
} from "../../src/index.js"; } from "../../../src/index.js";
import { import {
messagePayload, messagePayload,
messageText, messageText,
@ -18,13 +17,13 @@ import {
TestContentTopic, TestContentTopic,
TestDecoder, TestDecoder,
TestEncoder TestEncoder
} from "./utils.js"; } from "../utils.js";
describe("Waku Filter V2: Unsubscribe", function () { describe("Waku Filter V2: Unsubscribe", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(10000); this.timeout(10000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;

View File

@ -11,7 +11,7 @@ import { Logger } from "@waku/utils";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";
import { Context } from "mocha"; import { Context } from "mocha";
import { makeLogFileName, NimGoNode, NOISE_KEY_1 } from "../../src/index.js"; import { makeLogFileName, NOISE_KEY_1, ServiceNode } from "../../src/index.js";
// Constants for test configuration. // Constants for test configuration.
export const log = new Logger("test:filter"); export const log = new Logger("test:filter");
@ -47,8 +47,8 @@ export async function runNodes(
//TODO: change this to use `ShardInfo` instead of `string[]` //TODO: change this to use `ShardInfo` instead of `string[]`
pubsubTopics: string[], pubsubTopics: string[],
shardInfo?: ShardingParams shardInfo?: ShardingParams
): Promise<[NimGoNode, LightNode]> { ): Promise<[ServiceNode, LightNode]> {
const nwaku = new NimGoNode(makeLogFileName(context)); const nwaku = new ServiceNode(makeLogFileName(context));
await nwaku.start( await nwaku.start(
{ {
@ -80,12 +80,22 @@ export async function runNodes(
log.error("jswaku node failed to start:", error); log.error("jswaku node failed to start:", error);
} }
if (waku) { if (!waku) {
await waku.dial(await nwaku.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
await nwaku.ensureSubscriptions(pubsubTopics);
return [nwaku, waku];
} else {
throw new Error("Failed to initialize waku"); throw new Error("Failed to initialize waku");
} }
await waku.dial(await nwaku.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
await nwaku.ensureSubscriptions(pubsubTopics);
const wakuConnections = waku.libp2p.getConnections();
const nwakuPeers = await nwaku.peers();
if (wakuConnections.length < 1 || nwakuPeers.length < 1) {
throw new Error(
`Expected at least 1 peer in each node. Got waku connections: ${wakuConnections.length} and nwaku: ${nwakuPeers.length}`
);
}
return [nwaku, waku];
} }

View File

@ -1,6 +1,4 @@
import type { Connection } from "@libp2p/interface/connection"; import type { Connection, Peer, PeerStore } from "@libp2p/interface";
import type { PeerStore } from "@libp2p/interface/peer-store";
import type { Peer } from "@libp2p/interface/peer-store";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { LightPushCodec, waitForRemotePeer } from "@waku/core"; import { LightPushCodec, waitForRemotePeer } from "@waku/core";
import { import {
@ -19,20 +17,18 @@ import { expect } from "chai";
import fc from "fast-check"; import fc from "fast-check";
import Sinon from "sinon"; import Sinon from "sinon";
import { makeLogFileName } from "../src/log_file.js"; import { makeLogFileName, ServiceNode, tearDownNodes } from "../src/index.js";
import { NimGoNode } from "../src/node/node.js";
import { tearDownNodes } from "../src/teardown.js";
describe("getConnectedPeersForProtocolAndShard", function () { describe("getConnectedPeersForProtocolAndShard", function () {
let waku: LightNode; let waku: LightNode;
let serviceNode1: NimGoNode; let serviceNode1: ServiceNode;
let serviceNode2: NimGoNode; let serviceNode2: ServiceNode;
const contentTopic = "/test/2/waku-light-push/utf8"; const contentTopic = "/test/2/waku-light-push/utf8";
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
serviceNode1 = new NimGoNode(makeLogFileName(this) + "1"); serviceNode1 = new ServiceNode(makeLogFileName(this) + "1");
serviceNode2 = new NimGoNode(makeLogFileName(this) + "2"); serviceNode2 = new ServiceNode(makeLogFileName(this) + "2");
}); });
afterEach(async function () { afterEach(async function () {
@ -186,7 +182,7 @@ describe("getConnectedPeersForProtocolAndShard", function () {
}); });
// and another node in the same cluster cluster as our node // and another node in the same cluster cluster as our node
const serviceNode2 = new NimGoNode(makeLogFileName(this) + "2"); const serviceNode2 = new ServiceNode(makeLogFileName(this) + "2");
await serviceNode2.start({ await serviceNode2.start({
discv5Discovery: true, discv5Discovery: true,
peerExchange: true, peerExchange: true,
@ -374,7 +370,7 @@ describe("getConnectedPeersForProtocolAndShard", function () {
}); });
// and another node in the same cluster cluster as our node // and another node in the same cluster cluster as our node
const serviceNode2 = new NimGoNode(makeLogFileName(this) + "2"); const serviceNode2 = new ServiceNode(makeLogFileName(this) + "2");
await serviceNode2.start({ await serviceNode2.start({
discv5Discovery: true, discv5Discovery: true,
peerExchange: true, peerExchange: true,

View File

@ -9,26 +9,25 @@ import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
generateRandomUint8Array,
MessageCollector, MessageCollector,
NimGoNode, ServiceNode,
tearDownNodes, tearDownNodes,
TEST_STRING TEST_STRING
} from "../../src/index.js"; } from "../../../src/index.js";
import { generateRandomUint8Array } from "../../src/random_array.js";
import { import {
messagePayload, messagePayload,
messageText, messageText,
runNodes, runNodes,
TestContentTopic, TestContentTopic,
TestEncoder TestEncoder
} from "./utils.js"; } from "../utils.js";
describe("Waku Light Push", function () { describe("Waku Light Push", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level // Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
this.beforeEach(async function () { this.beforeEach(async function () {

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import { createEncoder, waitForRemotePeer } from "@waku/core"; import { createEncoder, waitForRemotePeer } from "@waku/core";
import { import {
ContentTopicInfo, ContentTopicInfo,
@ -18,17 +18,16 @@ import { expect } from "chai";
import { import {
makeLogFileName, makeLogFileName,
MessageCollector, MessageCollector,
NimGoNode, ServiceNode,
tearDownNodes tearDownNodes
} from "../../src/index.js"; } from "../../../src/index.js";
import { messageText, runNodes } from "../utils.js";
import { messageText, runNodes } from "./utils.js";
describe("Waku Light Push : Multiple PubsubTopics", function () { describe("Waku Light Push : Multiple PubsubTopics", function () {
this.timeout(30000); this.timeout(30000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
const customPubsubTopic1 = singleShardInfoToPubsubTopic({ const customPubsubTopic1 = singleShardInfoToPubsubTopic({
clusterId: 3, clusterId: 3,
@ -126,7 +125,7 @@ describe("Waku Light Push : Multiple PubsubTopics", function () {
it("Light push messages to 2 nwaku nodes each with different pubsubtopics", async function () { it("Light push messages to 2 nwaku nodes each with different pubsubtopics", async function () {
// Set up and start a new nwaku node with Default PubsubTopic // Set up and start a new nwaku node with Default PubsubTopic
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
@ -180,8 +179,8 @@ describe("Waku Light Push : Multiple PubsubTopics", function () {
describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () { describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () {
this.timeout(30000); this.timeout(30000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
// When using lightpush, we have to use a cluster id of 1 because that is the default cluster id for autosharding // When using lightpush, we have to use a cluster id of 1 because that is the default cluster id for autosharding
@ -285,7 +284,7 @@ describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () {
it("Light push messages to 2 nwaku nodes each with different pubsubtopics", async function () { it("Light push messages to 2 nwaku nodes each with different pubsubtopics", async function () {
// Set up and start a new nwaku node with Default PubsubTopic // Set up and start a new nwaku node with Default PubsubTopic
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
@ -337,8 +336,8 @@ describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () {
describe("Waku Light Push (named sharding): Multiple PubsubTopics", function () { describe("Waku Light Push (named sharding): Multiple PubsubTopics", function () {
this.timeout(30000); this.timeout(30000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
// When using lightpush, we have to use a cluster id of 1 because that is the default cluster id for autosharding // When using lightpush, we have to use a cluster id of 1 because that is the default cluster id for autosharding
@ -438,7 +437,7 @@ describe("Waku Light Push (named sharding): Multiple PubsubTopics", function ()
it("Light push messages to 2 nwaku nodes each with different pubsubtopics", async function () { it("Light push messages to 2 nwaku nodes each with different pubsubtopics", async function () {
// Set up and start a new nwaku node with Default PubsubTopic // Set up and start a new nwaku node with Default PubsubTopic
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,

View File

@ -8,7 +8,7 @@ import {
import { createLightNode, utf8ToBytes } from "@waku/sdk"; import { createLightNode, utf8ToBytes } from "@waku/sdk";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import { makeLogFileName, NimGoNode, NOISE_KEY_1 } from "../../src/index.js"; import { makeLogFileName, NOISE_KEY_1, ServiceNode } from "../../src/index.js";
// Constants for test configuration. // Constants for test configuration.
export const log = new Logger("test:lightpush"); export const log = new Logger("test:lightpush");
@ -21,8 +21,8 @@ export async function runNodes(
context: Mocha.Context, context: Mocha.Context,
pubsubTopics: string[], pubsubTopics: string[],
shardInfo?: ShardingParams shardInfo?: ShardingParams
): Promise<[NimGoNode, LightNode]> { ): Promise<[ServiceNode, LightNode]> {
const nwaku = new NimGoNode(makeLogFileName(context)); const nwaku = new ServiceNode(makeLogFileName(context));
await nwaku.start( await nwaku.start(
{ {
lightpush: true, lightpush: true,

View File

@ -6,18 +6,21 @@ import { shardInfoToPubsubTopics } from "@waku/utils";
import chai, { expect } from "chai"; import chai, { expect } from "chai";
import chaiAsPromised from "chai-as-promised"; import chaiAsPromised from "chai-as-promised";
import { delay, tearDownNodes } from "../src/index.js"; import {
import { makeLogFileName } from "../src/log_file.js"; delay,
import { NimGoNode } from "../src/node/node.js"; makeLogFileName,
ServiceNode,
tearDownNodes
} from "../src/index.js";
chai.use(chaiAsPromised); chai.use(chaiAsPromised);
describe("Metadata Protocol", () => { describe("Metadata Protocol", () => {
let waku: LightNode; let waku: LightNode;
let nwaku1: NimGoNode; let nwaku1: ServiceNode;
beforeEach(function () { beforeEach(function () {
nwaku1 = new NimGoNode(makeLogFileName(this) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this) + "1");
}); });
afterEach(async function () { afterEach(async function () {

View File

@ -1,6 +1,6 @@
import { CustomEvent } from "@libp2p/interface/events"; import type { PeerId } from "@libp2p/interface";
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerInfo } from "@libp2p/interface";
import type { PeerInfo } from "@libp2p/interface/peer-info"; import { CustomEvent } from "@libp2p/interface";
import { multiaddr } from "@multiformats/multiaddr"; import { multiaddr } from "@multiformats/multiaddr";
import type { Multiaddr } from "@multiformats/multiaddr"; import type { Multiaddr } from "@multiformats/multiaddr";
import type { Waku } from "@waku/interfaces"; import type { Waku } from "@waku/interfaces";
@ -11,13 +11,13 @@ import Sinon, { SinonSpy, SinonStub } from "sinon";
import { import {
delay, delay,
makeLogFileName, makeLogFileName,
NimGoNode, ServiceNode,
tearDownNodes tearDownNodes
} from "../src/index.js"; } from "../src/index.js";
describe("multiaddr: dialing", function () { describe("multiaddr: dialing", function () {
let waku: Waku; let waku: Waku;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let dialPeerSpy: SinonSpy; let dialPeerSpy: SinonSpy;
let isPeerTopicConfigured: SinonStub; let isPeerTopicConfigured: SinonStub;
@ -56,7 +56,7 @@ describe("multiaddr: dialing", function () {
beforeEach(async function () { beforeEach(async function () {
this.timeout(10_000); this.timeout(10_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start(); await nwaku.start();
waku = await createLightNode(); waku = await createLightNode();
@ -84,7 +84,6 @@ describe("multiaddr: dialing", function () {
new CustomEvent<PeerInfo>("peer:discovery", { new CustomEvent<PeerInfo>("peer:discovery", {
detail: { detail: {
id: peerId, id: peerId,
protocols: [],
multiaddrs: [multiaddr] multiaddrs: [multiaddr]
} }
}) })

View File

@ -1,7 +1,7 @@
import { expect } from "chai"; import { expect } from "chai";
import { defaultArgs } from "../src/index.js"; import { defaultArgs } from "../src/index.js";
import { argsToArray } from "../src/node/dockerode.js"; import { argsToArray } from "../src/lib/dockerode.js";
describe("nwaku", () => { describe("nwaku", () => {
it("Correctly serialized arguments", function () { it("Correctly serialized arguments", function () {

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import tests from "@libp2p/interface-compliance-tests/peer-discovery"; import tests from "@libp2p/interface-compliance-tests/peer-discovery";
import type { Multiaddr } from "@multiformats/multiaddr"; import type { Multiaddr } from "@multiformats/multiaddr";
import type { LightNode, PeerInfo } from "@waku/interfaces"; import type { LightNode, PeerInfo } from "@waku/interfaces";
@ -10,20 +10,23 @@ import {
import { createLightNode, Libp2pComponents } from "@waku/sdk"; import { createLightNode, Libp2pComponents } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { delay } from "../src/delay.js"; import {
import { tearDownNodes, waitForRemotePeerWithCodec } from "../src/index.js"; delay,
import { makeLogFileName } from "../src/log_file.js"; makeLogFileName,
import { NimGoNode } from "../src/node/node.js"; ServiceNode,
tearDownNodes,
waitForRemotePeerWithCodec
} from "../src/index.js";
describe("Peer Exchange", () => { describe("Peer Exchange", () => {
describe("Locally Run Nodes", () => { describe("Locally Run Nodes", () => {
let waku: LightNode; let waku: LightNode;
let nwaku1: NimGoNode; let nwaku1: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
beforeEach(function () { beforeEach(function () {
nwaku1 = new NimGoNode(makeLogFileName(this) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this) + "1");
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
}); });
afterEach(async function () { afterEach(async function () {
@ -111,12 +114,12 @@ describe("Peer Exchange", () => {
this.timeout(55_000); this.timeout(55_000);
let waku: LightNode; let waku: LightNode;
let nwaku1: NimGoNode; let nwaku1: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
nwaku1 = new NimGoNode(makeLogFileName(this) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this) + "1");
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
}); });
tests({ tests({

View File

@ -1,4 +1,4 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import { DecodedMessage, waitForRemotePeer } from "@waku/core"; import { DecodedMessage, waitForRemotePeer } from "@waku/core";
import { DefaultPubsubTopic, Protocols, RelayNode } from "@waku/interfaces"; import { DefaultPubsubTopic, Protocols, RelayNode } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk/relay"; import { createRelayNode } from "@waku/sdk/relay";
@ -6,21 +6,22 @@ import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
base64ToUtf8,
delay, delay,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
ServiceNode,
tearDownNodes tearDownNodes
} from "../../src/index.js"; } from "../../src/index.js";
import { MessageRpcResponse } from "../../src/node/interfaces.js"; import { MessageRpcResponse } from "../../src/types.js";
import { base64ToUtf8, NimGoNode } from "../../src/node/node.js";
import { TestContentTopic, TestDecoder, TestEncoder } from "./utils.js"; import { TestContentTopic, TestDecoder, TestEncoder } from "./utils.js";
describe("Waku Relay, Interop", function () { describe("Waku Relay, Interop", function () {
this.timeout(15000); this.timeout(15000);
let waku: RelayNode; let waku: RelayNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(30000); this.timeout(30000);
@ -29,7 +30,7 @@ describe("Waku Relay, Interop", function () {
}); });
await waku.start(); await waku.start();
nwaku = new NimGoNode(this.test?.ctx?.currentTest?.title + ""); nwaku = new ServiceNode(this.test?.ctx?.currentTest?.title + "");
await nwaku.start({ relay: true }); await nwaku.start({ relay: true });
await waku.dial(await nwaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
@ -89,7 +90,7 @@ describe("Waku Relay, Interop", function () {
); );
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: utf8ToBytes(messageText) payload: utf8ToBytes(messageText)
}) })
@ -105,7 +106,7 @@ describe("Waku Relay, Interop", function () {
describe("Two nodes connected to nwaku", function () { describe("Two nodes connected to nwaku", function () {
let waku1: RelayNode; let waku1: RelayNode;
let waku2: RelayNode; let waku2: RelayNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
afterEach(async function () { afterEach(async function () {
await tearDownNodes(nwaku, [waku1, waku2]); await tearDownNodes(nwaku, [waku1, waku2]);
@ -122,7 +123,7 @@ describe("Waku Relay, Interop", function () {
}).then((waku) => waku.start().then(() => waku)) }).then((waku) => waku.start().then(() => waku))
]); ]);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ relay: true }); await nwaku.start({ relay: true });
const nwakuMultiaddr = await nwaku.getMultiaddrWithId(); const nwakuMultiaddr = await nwaku.getMultiaddrWithId();

View File

@ -6,13 +6,13 @@ import { expect } from "chai";
import { import {
delay, delay,
generateRandomUint8Array,
MessageCollector, MessageCollector,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
tearDownNodes, tearDownNodes,
TEST_STRING TEST_STRING
} from "../../src/index.js"; } from "../../src/index.js";
import { generateRandomUint8Array } from "../../src/random_array.js";
import { import {
log, log,

View File

@ -46,7 +46,7 @@ describe("Waku Relay, Subscribe", function () {
}); });
await waku1.dial(waku2.libp2p.peerId); await waku1.dial(waku2.libp2p.peerId);
log.info("before each hook done"); log.info("before each hook done");
messageCollector = new MessageCollector(); messageCollector = new MessageCollector(this.nwaku);
}); });
afterEach(async function () { afterEach(async function () {

View File

@ -1,5 +1,5 @@
import { bootstrap } from "@libp2p/bootstrap"; import { bootstrap } from "@libp2p/bootstrap";
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange"; import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
import { import {
ContentTopicInfo, ContentTopicInfo,
@ -16,27 +16,29 @@ import chai, { expect } from "chai";
import chaiAsPromised from "chai-as-promised"; import chaiAsPromised from "chai-as-promised";
import Sinon, { SinonSpy } from "sinon"; import Sinon, { SinonSpy } from "sinon";
import { delay } from "../../src/delay.js"; import {
import { makeLogFileName } from "../../src/log_file.js"; delay,
import { NimGoNode } from "../../src/node/node.js"; makeLogFileName,
import { tearDownNodes } from "../../src/teardown.js"; ServiceNode,
tearDownNodes
} from "../../src/index.js";
chai.use(chaiAsPromised); chai.use(chaiAsPromised);
describe("Static Sharding: Peer Management", function () { describe("Static Sharding: Peer Management", function () {
describe("Peer Exchange", function () { describe("Peer Exchange", function () {
let waku: LightNode; let waku: LightNode;
let nwaku1: NimGoNode; let nwaku1: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let nwaku3: NimGoNode; let nwaku3: ServiceNode;
let dialPeerSpy: SinonSpy; let dialPeerSpy: SinonSpy;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku1 = new NimGoNode(makeLogFileName(this) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this) + "1");
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
nwaku3 = new NimGoNode(makeLogFileName(this) + "3"); nwaku3 = new ServiceNode(makeLogFileName(this) + "3");
}); });
afterEach(async function () { afterEach(async function () {
@ -199,17 +201,17 @@ describe("Autosharding: Peer Management", function () {
describe("Peer Exchange", function () { describe("Peer Exchange", function () {
let waku: LightNode; let waku: LightNode;
let nwaku1: NimGoNode; let nwaku1: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
let nwaku3: NimGoNode; let nwaku3: ServiceNode;
let dialPeerSpy: SinonSpy; let dialPeerSpy: SinonSpy;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku1 = new NimGoNode(makeLogFileName(this) + "1_auto"); nwaku1 = new ServiceNode(makeLogFileName(this) + "1_auto");
nwaku2 = new NimGoNode(makeLogFileName(this) + "2_auto"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2_auto");
nwaku3 = new NimGoNode(makeLogFileName(this) + "3_auto"); nwaku3 = new ServiceNode(makeLogFileName(this) + "3_auto");
}); });
afterEach(async function () { afterEach(async function () {

View File

@ -13,9 +13,11 @@ import {
import { singleShardInfoToPubsubTopic } from "@waku/utils"; import { singleShardInfoToPubsubTopic } from "@waku/utils";
import { expect } from "chai"; import { expect } from "chai";
import { tearDownNodes } from "../../src/index.js"; import {
import { makeLogFileName } from "../../src/log_file.js"; makeLogFileName,
import { NimGoNode } from "../../src/node/node.js"; ServiceNode,
tearDownNodes
} from "../../src/index.js";
const PubsubTopic1 = singleShardInfoToPubsubTopic({ const PubsubTopic1 = singleShardInfoToPubsubTopic({
clusterId: 0, clusterId: 0,
@ -34,11 +36,11 @@ const ContentTopic2 = "/myapp/1/latest/proto";
describe("Static Sharding: Running Nodes", () => { describe("Static Sharding: Running Nodes", () => {
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15_000); this.timeout(15_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
}); });
@ -109,11 +111,11 @@ describe("Static Sharding: Running Nodes", () => {
describe("Autosharding: Running Nodes", () => { describe("Autosharding: Running Nodes", () => {
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15_000); this.timeout(15_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
}); });

View File

@ -4,7 +4,11 @@ import { DefaultPubsubTopic } from "@waku/interfaces";
import { bytesToUtf8 } from "@waku/utils/bytes"; import { bytesToUtf8 } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import {
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../../src/index.js";
import { import {
customShardedPubsubTopic1, customShardedPubsubTopic1,
@ -19,11 +23,11 @@ describe("Waku Store, cursor", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let waku2: LightNode; let waku2: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });

View File

@ -2,7 +2,11 @@ import { DefaultPubsubTopic } from "@waku/interfaces";
import { IMessage, type LightNode } from "@waku/interfaces"; import { IMessage, type LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import {
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../../src/index.js";
import { import {
customDecoder1, customDecoder1,
@ -15,11 +19,11 @@ import {
describe("Waku Store, error handling", function () { describe("Waku Store, error handling", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);

View File

@ -22,7 +22,7 @@ import {
delay, delay,
makeLogFileName, makeLogFileName,
MessageCollector, MessageCollector,
NimGoNode, ServiceNode,
tearDownNodes, tearDownNodes,
TEST_STRING TEST_STRING
} from "../../src/index.js"; } from "../../src/index.js";
@ -46,11 +46,11 @@ describe("Waku Store, general", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let waku2: LightNode; let waku2: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
@ -82,7 +82,7 @@ describe("Waku Store, general", function () {
for (const testItem of TEST_STRING) { for (const testItem of TEST_STRING) {
expect( expect(
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: utf8ToBytes(testItem["value"]), payload: utf8ToBytes(testItem["value"]),
contentTopic: TestContentTopic contentTopic: TestContentTopic
}), }),
@ -93,7 +93,7 @@ describe("Waku Store, general", function () {
} }
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const messageCollector = new MessageCollector(); const messageCollector = new MessageCollector(nwaku);
messageCollector.list = await processQueriedMessages( messageCollector.list = await processQueriedMessages(
waku, waku,
[TestDecoder], [TestDecoder],
@ -110,14 +110,14 @@ describe("Waku Store, general", function () {
it("Query generator for multiple messages with multiple decoders", async function () { it("Query generator for multiple messages with multiple decoders", async function () {
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: utf8ToBytes("M1"), payload: utf8ToBytes("M1"),
contentTopic: TestContentTopic contentTopic: TestContentTopic
}), }),
DefaultPubsubTopic DefaultPubsubTopic
); );
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: utf8ToBytes("M2"), payload: utf8ToBytes("M2"),
contentTopic: customContentTopic1 contentTopic: customContentTopic1
}), }),
@ -125,7 +125,7 @@ describe("Waku Store, general", function () {
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const messageCollector = new MessageCollector(); const messageCollector = new MessageCollector(nwaku);
messageCollector.list = await processQueriedMessages( messageCollector.list = await processQueriedMessages(
waku, waku,
[TestDecoder, secondDecoder], [TestDecoder, secondDecoder],
@ -139,7 +139,7 @@ describe("Waku Store, general", function () {
for (const testItem of TEST_STRING) { for (const testItem of TEST_STRING) {
expect( expect(
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: utf8ToBytes(messageText), payload: utf8ToBytes(messageText),
contentTopic: testItem["value"] contentTopic: testItem["value"]
}), }),

View File

@ -1,13 +1,16 @@
import { createDecoder, waitForRemotePeer } from "@waku/core"; import { createDecoder, waitForRemotePeer } from "@waku/core";
import type { ContentTopicInfo, IMessage, LightNode } from "@waku/interfaces"; import type { ContentTopicInfo, IMessage, LightNode } from "@waku/interfaces";
import { createLightNode, Protocols } from "@waku/sdk"; import { createLightNode, Protocols } from "@waku/sdk";
import { contentTopicToPubsubTopic } from "@waku/utils"; import {
contentTopicToPubsubTopic,
singleShardInfosToShardInfo
} from "@waku/utils";
import { expect } from "chai"; import { expect } from "chai";
import { import {
makeLogFileName, makeLogFileName,
NimGoNode,
NOISE_KEY_1, NOISE_KEY_1,
ServiceNode,
tearDownNodes tearDownNodes
} from "../../src/index.js"; } from "../../src/index.js";
@ -32,12 +35,12 @@ import {
describe("Waku Store, custom pubsub topic", function () { describe("Waku Store, custom pubsub topic", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2], pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2],
@ -122,7 +125,7 @@ describe("Waku Store, custom pubsub topic", function () {
this.timeout(10000); this.timeout(10000);
// Set up and start a new nwaku node with Default Pubsubtopic // Set up and start a new nwaku node with Default Pubsubtopic
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
store: true, store: true,
pubsubTopic: [customShardedPubsubTopic2], pubsubTopic: [customShardedPubsubTopic2],
@ -179,8 +182,8 @@ describe("Waku Store, custom pubsub topic", function () {
describe("Waku Store (Autosharding), custom pubsub topic", function () { describe("Waku Store (Autosharding), custom pubsub topic", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
const customContentTopic1 = "/waku/2/content/utf8"; const customContentTopic1 = "/waku/2/content/utf8";
const customContentTopic2 = "/myapp/1/latest/proto"; const customContentTopic2 = "/myapp/1/latest/proto";
@ -210,7 +213,7 @@ describe("Waku Store (Autosharding), custom pubsub topic", function () {
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
pubsubTopic: [autoshardingPubsubTopic1, autoshardingPubsubTopic2], pubsubTopic: [autoshardingPubsubTopic1, autoshardingPubsubTopic2],
@ -284,7 +287,7 @@ describe("Waku Store (Autosharding), custom pubsub topic", function () {
this.timeout(10000); this.timeout(10000);
// Set up and start a new nwaku node with Default Pubsubtopic // Set up and start a new nwaku node with Default Pubsubtopic
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
store: true, store: true,
pubsubTopic: [autoshardingPubsubTopic2], pubsubTopic: [autoshardingPubsubTopic2],
@ -331,8 +334,8 @@ describe("Waku Store (Autosharding), custom pubsub topic", function () {
describe("Waku Store (named sharding), custom pubsub topic", function () { describe("Waku Store (named sharding), custom pubsub topic", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
let nwaku2: NimGoNode; let nwaku2: ServiceNode;
const customDecoder1 = createDecoder( const customDecoder1 = createDecoder(
customContentTopic1, customContentTopic1,
@ -345,16 +348,29 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this));
const shardInfo = singleShardInfosToShardInfo([
customShardInfo1,
customShardInfo2
]);
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
relay: true,
pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2], pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2],
relay: true clusterId: shardInfo.clusterId
}); });
await nwaku.ensureSubscriptions([ await nwaku.ensureSubscriptions([
customShardedPubsubTopic1, customShardedPubsubTopic1,
customShardedPubsubTopic2 customShardedPubsubTopic2
]); ]);
waku = await startAndConnectLightNode(
nwaku,
[customShardedPubsubTopic1, customShardedPubsubTopic2],
shardInfo
);
}); });
afterEach(async function () { afterEach(async function () {
@ -369,10 +385,7 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customContentTopic1, customContentTopic1,
customShardedPubsubTopic1 customShardedPubsubTopic1
); );
waku = await startAndConnectLightNode(nwaku, [
customShardedPubsubTopic1,
customShardedPubsubTopic2
]);
const messages = await processQueriedMessages( const messages = await processQueriedMessages(
waku, waku,
[customDecoder1], [customDecoder1],
@ -403,11 +416,6 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customShardedPubsubTopic2 customShardedPubsubTopic2
); );
waku = await startAndConnectLightNode(nwaku, [
customShardedPubsubTopic1,
customShardedPubsubTopic2
]);
const customMessages = await processQueriedMessages( const customMessages = await processQueriedMessages(
waku, waku,
[customDecoder1], [customDecoder1],
@ -435,7 +443,7 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
this.timeout(10000); this.timeout(10000);
// Set up and start a new nwaku node with Default Pubsubtopic // Set up and start a new nwaku node with Default Pubsubtopic
nwaku2 = new NimGoNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
store: true, store: true,
pubsubTopic: [customShardedPubsubTopic2], pubsubTopic: [customShardedPubsubTopic2],
@ -458,13 +466,6 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customShardedPubsubTopic2 customShardedPubsubTopic2
); );
waku = await createLightNode({
staticNoiseKey: NOISE_KEY_1,
pubsubTopics: [customShardedPubsubTopic1, customShardedPubsubTopic2]
});
await waku.start();
await waku.dial(await nwaku.getMultiaddrWithId());
await waku.dial(await nwaku2.getMultiaddrWithId()); await waku.dial(await nwaku2.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Store]); await waitForRemotePeer(waku, [Protocols.Store]);

View File

@ -3,7 +3,11 @@ import type { IMessage, LightNode } from "@waku/interfaces";
import { DefaultPubsubTopic } from "@waku/interfaces"; import { DefaultPubsubTopic } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import {
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../../src/index.js";
import { import {
chunkAndReverseArray, chunkAndReverseArray,
@ -17,11 +21,11 @@ import {
describe("Waku Store, order", function () { describe("Waku Store, order", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });

View File

@ -2,7 +2,11 @@ import { DefaultPubsubTopic } from "@waku/interfaces";
import type { LightNode } from "@waku/interfaces"; import type { LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import {
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../../src/index.js";
import { import {
sendMessages, sendMessages,
@ -14,11 +18,11 @@ import {
describe("Waku Store, page size", function () { describe("Waku Store, page size", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });

View File

@ -2,7 +2,11 @@ import { DecodedMessage, PageDirection } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces"; import type { IMessage, LightNode } from "@waku/interfaces";
import { DefaultPubsubTopic } from "@waku/interfaces"; import { DefaultPubsubTopic } from "@waku/interfaces";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import {
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../../src/index.js";
import { import {
sendMessages, sendMessages,
@ -15,11 +19,11 @@ import {
describe("Waku Store, sorting", function () { describe("Waku Store, sorting", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });

View File

@ -1,7 +1,11 @@
import type { IMessage, LightNode } from "@waku/interfaces"; import type { IMessage, LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import {
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../../src/index.js";
import { import {
adjustDate, adjustDate,
@ -13,11 +17,11 @@ import {
describe("Waku Store, time filter", function () { describe("Waku Store, time filter", function () {
this.timeout(15000); this.timeout(15000);
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
@ -42,7 +46,7 @@ describe("Waku Store, time filter", function () {
const msgTimestamp = adjustDate(new Date(), msgTime); const msgTimestamp = adjustDate(new Date(), msgTime);
expect( expect(
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: new Uint8Array([0]), payload: new Uint8Array([0]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
timestamp: msgTimestamp timestamp: msgTimestamp
@ -87,7 +91,7 @@ describe("Waku Store, time filter", function () {
const msgTimestamp = adjustDate(new Date(), msgTime); const msgTimestamp = adjustDate(new Date(), msgTime);
expect( expect(
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: new Uint8Array([0]), payload: new Uint8Array([0]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
timestamp: msgTimestamp timestamp: msgTimestamp

View File

@ -17,7 +17,7 @@ import { createLightNode } from "@waku/sdk";
import { Logger, singleShardInfoToPubsubTopic } from "@waku/utils"; import { Logger, singleShardInfoToPubsubTopic } from "@waku/utils";
import { expect } from "chai"; import { expect } from "chai";
import { delay, NimGoNode, NOISE_KEY_1 } from "../../src"; import { delay, NOISE_KEY_1, ServiceNode } from "../../src";
export const log = new Logger("test:store"); export const log = new Logger("test:store");
@ -47,7 +47,7 @@ export const totalMsgs = 20;
export const messageText = "Store Push works!"; export const messageText = "Store Push works!";
export async function sendMessages( export async function sendMessages(
instance: NimGoNode, instance: ServiceNode,
numMessages: number, numMessages: number,
contentTopic: string, contentTopic: string,
pubsubTopic: string pubsubTopic: string
@ -55,7 +55,7 @@ export async function sendMessages(
for (let i = 0; i < numMessages; i++) { for (let i = 0; i < numMessages; i++) {
expect( expect(
await instance.sendMessage( await instance.sendMessage(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: contentTopic contentTopic: contentTopic
}), }),
@ -67,14 +67,14 @@ export async function sendMessages(
} }
export async function sendMessagesAutosharding( export async function sendMessagesAutosharding(
instance: NimGoNode, instance: ServiceNode,
numMessages: number, numMessages: number,
contentTopic: string contentTopic: string
): Promise<void> { ): Promise<void> {
for (let i = 0; i < numMessages; i++) { for (let i = 0; i < numMessages; i++) {
expect( expect(
await instance.sendMessageAutosharding( await instance.sendMessageAutosharding(
NimGoNode.toMessageRpcQuery({ ServiceNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: contentTopic contentTopic: contentTopic
}) })
@ -102,21 +102,32 @@ export async function processQueriedMessages(
} }
export async function startAndConnectLightNode( export async function startAndConnectLightNode(
instance: NimGoNode, instance: ServiceNode,
pubsubTopics: string[] = [DefaultPubsubTopic], pubsubTopics: string[] = [DefaultPubsubTopic],
shardInfo?: ShardingParams shardInfo?: ShardingParams
): Promise<LightNode> { ): Promise<LightNode> {
const waku = await createLightNode({ const waku = await createLightNode({
pubsubTopics: shardInfo ? undefined : pubsubTopics,
staticNoiseKey: NOISE_KEY_1,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
...((pubsubTopics.length !== 1 || ...((pubsubTopics.length !== 1 ||
pubsubTopics[0] !== DefaultPubsubTopic) && { pubsubTopics[0] !== DefaultPubsubTopic) && {
shardInfo: shardInfo shardInfo: shardInfo
}), })
pubsubTopics: shardInfo ? undefined : pubsubTopics,
staticNoiseKey: NOISE_KEY_1
}); });
await waku.start(); await waku.start();
await waku.dial(await instance.getMultiaddrWithId()); await waku.dial(await instance.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Store]); await waitForRemotePeer(waku, [Protocols.Store]);
const wakuConnections = waku.libp2p.getConnections();
const nwakuPeers = await instance.peers();
if (wakuConnections.length < 1 || nwakuPeers.length < 1) {
throw new Error(
`Expected at least 1 peer in each node. Got waku connections: ${wakuConnections.length} and nwaku: ${nwakuPeers.length}`
);
}
log.info("Waku node created"); log.info("Waku node created");
return waku; return waku;
} }

View File

@ -14,9 +14,9 @@ import {
delay, delay,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
ServiceNode,
tearDownNodes tearDownNodes
} from "../src/index.js"; } from "../src/index.js";
import { NimGoNode } from "../src/node/node.js";
chai.use(chaiAsPromised); chai.use(chaiAsPromised);
@ -26,11 +26,11 @@ const TestDecoder = createDecoder(TestContentTopic);
describe("Util: toAsyncIterator: Filter", () => { describe("Util: toAsyncIterator: Filter", () => {
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
lightpush: true, lightpush: true,

View File

@ -9,14 +9,14 @@ import {
delay, delay,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
ServiceNode,
tearDownNodes tearDownNodes
} from "../src/index.js"; } from "../src/index.js";
import { NimGoNode } from "../src/node/node.js";
describe("Wait for remote peer", function () { describe("Wait for remote peer", function () {
let waku1: RelayNode; let waku1: RelayNode;
let waku2: LightNode; let waku2: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
afterEach(async function () { afterEach(async function () {
this.timeout(15000); this.timeout(15000);
@ -25,7 +25,7 @@ describe("Wait for remote peer", function () {
it("Relay - dialed first", async function () { it("Relay - dialed first", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
relay: true, relay: true,
store: false, store: false,
@ -50,7 +50,7 @@ describe("Wait for remote peer", function () {
it("Relay - dialed after", async function () { it("Relay - dialed after", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
relay: true, relay: true,
store: false, store: false,
@ -98,7 +98,7 @@ describe("Wait for remote peer", function () {
it("Store - dialed first", async function () { it("Store - dialed first", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
relay: false, relay: false,
@ -126,7 +126,7 @@ describe("Wait for remote peer", function () {
it("Store - dialed after - with timeout", async function () { it("Store - dialed after - with timeout", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
relay: false, relay: false,
@ -156,7 +156,7 @@ describe("Wait for remote peer", function () {
it("LightPush", async function () { it("LightPush", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
lightpush: true, lightpush: true,
filter: false, filter: false,
@ -184,7 +184,7 @@ describe("Wait for remote peer", function () {
it("Filter", async function () { it("Filter", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
lightpush: false, lightpush: false,
@ -212,7 +212,7 @@ describe("Wait for remote peer", function () {
it("Light Node - default protocols", async function () { it("Light Node - default protocols", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
@ -252,7 +252,7 @@ describe("Wait for remote peer", function () {
it("Privacy Node - default protocol", async function () { it("Privacy Node - default protocol", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: false, filter: false,
lightpush: false, lightpush: false,

View File

@ -4,11 +4,11 @@ import { LightNode } from "@waku/interfaces";
import { createLightNode } from "@waku/sdk"; import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../src/index.js"; import { makeLogFileName, ServiceNode, tearDownNodes } from "../src/index.js";
describe("Use static and several ENR trees for bootstrap", function () { describe("Use static and several ENR trees for bootstrap", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
afterEach(async function () { afterEach(async function () {
this.timeout(15000); this.timeout(15000);
@ -18,7 +18,7 @@ describe("Use static and several ENR trees for bootstrap", function () {
it("", async function () { it("", async function () {
this.timeout(10_000); this.timeout(10_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start(); await nwaku.start();
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();

View File

@ -1,5 +1,5 @@
import { bootstrap } from "@libp2p/bootstrap"; import { bootstrap } from "@libp2p/bootstrap";
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface";
import { import {
DecodedMessage, DecodedMessage,
DefaultUserAgent, DefaultUserAgent,
@ -24,18 +24,18 @@ import {
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
ServiceNode,
tearDownNodes tearDownNodes
} from "../src/index.js"; } from "../src/index.js";
import { NimGoNode } from "../src/node/node.js";
const TestContentTopic = "/test/1/waku/utf8"; const TestContentTopic = "/test/1/waku/utf8";
const TestEncoder = createPlainEncoder({ contentTopic: TestContentTopic }); const TestEncoder = createPlainEncoder({ contentTopic: TestContentTopic });
describe("Waku Dial [node only]", function () { describe("Waku Dial [node only]", function () {
describe("Interop: NimGoNode", function () { describe("Interop: ServiceNode", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
afterEach(async function () { afterEach(async function () {
this.timeout(15000); this.timeout(15000);
@ -44,7 +44,7 @@ describe("Waku Dial [node only]", function () {
it("connects to nwaku", async function () { it("connects to nwaku", async function () {
this.timeout(20_000); this.timeout(20_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
store: true, store: true,
@ -77,7 +77,7 @@ describe("Waku Dial [node only]", function () {
expect.fail("uncaughtException", e) expect.fail("uncaughtException", e)
); );
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
store: true, store: true,
@ -100,7 +100,7 @@ describe("Waku Dial [node only]", function () {
describe("Bootstrap", function () { describe("Bootstrap", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: NimGoNode; let nwaku: ServiceNode;
afterEach(async function () { afterEach(async function () {
this.timeout(15000); this.timeout(15000);
@ -110,7 +110,7 @@ describe("Waku Dial [node only]", function () {
it("Passing an array", async function () { it("Passing an array", async function () {
this.timeout(10_000); this.timeout(10_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start(); await nwaku.start();
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createLightNode({ waku = await createLightNode({
@ -133,7 +133,7 @@ describe("Waku Dial [node only]", function () {
it("Using a function", async function () { it("Using a function", async function () {
this.timeout(10_000); this.timeout(10_000);
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start(); await nwaku.start();
const nwakuMa = await nwaku.getMultiaddrWithId(); const nwakuMa = await nwaku.getMultiaddrWithId();

View File

@ -80,9 +80,8 @@
"@waku/build-utils": "*", "@waku/build-utils": "*",
"cspell": "^7.3.2", "cspell": "^7.3.2",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"rollup": "^4.6.0", "fast-check": "^3.14.0",
"fast-check": "^3.14.0" "rollup": "^4.9.5"
}, },
"files": [ "files": [
"dist", "dist",

View File

@ -2,6 +2,7 @@ import { sha256 } from "@noble/hashes/sha256";
import { import {
DefaultPubsubTopic, DefaultPubsubTopic,
PubsubTopic, PubsubTopic,
ShardInfo,
ShardingParams, ShardingParams,
SingleShardInfo SingleShardInfo
} from "@waku/interfaces"; } from "@waku/interfaces";
@ -17,6 +18,26 @@ export const singleShardInfoToPubsubTopic = (
return `/waku/2/rs/${shardInfo.clusterId}/${shardInfo.shard}`; return `/waku/2/rs/${shardInfo.clusterId}/${shardInfo.shard}`;
}; };
export const singleShardInfosToShardInfo = (
singleShardInfos: SingleShardInfo[]
): ShardInfo => {
if (singleShardInfos.length === 0) throw new Error("Invalid shard");
const clusterIds = singleShardInfos.map((shardInfo) => shardInfo.clusterId);
if (new Set(clusterIds).size !== 1) {
throw new Error("Passed shard infos have different clusterIds");
}
const shards = singleShardInfos
.map((shardInfo) => shardInfo.shard)
.filter((shard): shard is number => shard !== undefined);
return {
clusterId: singleShardInfos[0].clusterId,
shards
};
};
export const shardInfoToPubsubTopics = ( export const shardInfoToPubsubTopics = (
shardInfo: ShardingParams shardInfo: ShardingParams
): PubsubTopic[] => { ): PubsubTopic[] => {

View File

@ -1,6 +1,5 @@
import type { Connection } from "@libp2p/interface/connection"; import type { Connection, Peer, PeerStore } from "@libp2p/interface";
import type { Peer, PeerStore } from "@libp2p/interface/peer-store"; import { ShardingParams } from "@waku/interfaces";
import type { ShardingParams } from "@waku/interfaces";
import { bytesToUtf8 } from "../bytes/index.js"; import { bytesToUtf8 } from "../bytes/index.js";
import { decodeRelayShard } from "../common/relay_shard_codec.js"; import { decodeRelayShard } from "../common/relay_shard_codec.js";