chore!: change all instances of `PubSubTopic` to `PubsubTopic` (#1703)

* rename all PubSub patterns

* feat: forbid identifiers with camelcase pubSub (#1709)

---------

Co-authored-by: Arseniy Klempner <adklempner@gmail.com>
This commit is contained in:
Danish Arora 2023-11-14 21:22:52 +05:30 committed by GitHub
parent 535a748ae9
commit 3166a5135e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 288 additions and 287 deletions

View File

@ -123,7 +123,7 @@
"Привет", "Привет",
"مرحبا" "مرحبا"
], ],
"flagWords": ["pubSub", "pubSubTopics", "pubSubTopic"], "flagWords": ["pubSub: pubsub", "pubSubTopics: pubsubTopics", "pubSubTopic: pubsubTopic", "PubSub: Pubsub", "PubSubTopics: PubsubTopics", "PubSubTopic: PubsubTopic", "DefaultPubSubTopic: DefaultPubsubTopic"],
"ignorePaths": [ "ignorePaths": [
"package.json", "package.json",
"package-lock.json", "package-lock.json",

View File

@ -72,7 +72,8 @@
"@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/await-thenable": "error", "@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-promises": "error", "@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-explicit-any": "warn" "@typescript-eslint/no-explicit-any": "warn",
"id-match": ["error", "^(?!.*[pP]ubSub)"]
}, },
"overrides": [ "overrides": [
{ {

View File

@ -1,5 +1,5 @@
export { DefaultUserAgent } from "./lib/waku.js"; export { DefaultUserAgent } from "./lib/waku.js";
export { DefaultPubSubTopic } from "./lib/constants.js"; export { DefaultPubsubTopic } from "./lib/constants.js";
export { createEncoder, createDecoder } from "./lib/message/version_0.js"; export { createEncoder, createDecoder } from "./lib/message/version_0.js";
export type { export type {
Encoder, Encoder,

View File

@ -12,11 +12,11 @@ import {
IRelay, IRelay,
KeepAliveOptions, KeepAliveOptions,
PeersByDiscoveryResult, PeersByDiscoveryResult,
PubSubTopic, PubsubTopic,
ShardInfo ShardInfo
} from "@waku/interfaces"; } from "@waku/interfaces";
import { Libp2p, Tags } from "@waku/interfaces"; import { Libp2p, Tags } from "@waku/interfaces";
import { shardInfoToPubSubTopics } from "@waku/utils"; import { shardInfoToPubsubTopics } from "@waku/utils";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import { KeepAliveManager } from "./keep_alive_manager.js"; import { KeepAliveManager } from "./keep_alive_manager.js";
@ -45,7 +45,7 @@ export class ConnectionManager
peerId: string, peerId: string,
libp2p: Libp2p, libp2p: Libp2p,
keepAliveOptions: KeepAliveOptions, keepAliveOptions: KeepAliveOptions,
pubsubTopics: PubSubTopic[], pubsubTopics: PubsubTopic[],
relay?: IRelay, relay?: IRelay,
options?: ConnectionManagerOptions options?: ConnectionManagerOptions
): ConnectionManager { ): ConnectionManager {
@ -111,13 +111,13 @@ export class ConnectionManager
private constructor( private constructor(
libp2p: Libp2p, libp2p: Libp2p,
keepAliveOptions: KeepAliveOptions, keepAliveOptions: KeepAliveOptions,
private configuredPubSubTopics: PubSubTopic[], private configuredPubsubTopics: PubsubTopic[],
relay?: IRelay, relay?: IRelay,
options?: Partial<ConnectionManagerOptions> options?: Partial<ConnectionManagerOptions>
) { ) {
super(); super();
this.libp2p = libp2p; this.libp2p = libp2p;
this.configuredPubSubTopics = configuredPubSubTopics; this.configuredPubsubTopics = configuredPubsubTopics;
this.options = { this.options = {
maxDialAttemptsForPeer: DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER, maxDialAttemptsForPeer: DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER,
maxBootstrapPeersAllowed: DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED, maxBootstrapPeersAllowed: DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED,
@ -426,7 +426,7 @@ export class ConnectionManager
); );
log.warn( log.warn(
`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${ `Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${
this.configuredPubSubTopics this.configuredPubsubTopics
}). }).
Not dialing.` Not dialing.`
); );
@ -518,10 +518,10 @@ export class ConnectionManager
// If there's no shard information, simply return true // If there's no shard information, simply return true
if (!shardInfo) return true; if (!shardInfo) return true;
const pubsubTopics = shardInfoToPubSubTopics(shardInfo); const pubsubTopics = shardInfoToPubsubTopics(shardInfo);
const isTopicConfigured = pubsubTopics.some((topic) => const isTopicConfigured = pubsubTopics.some((topic) =>
this.configuredPubSubTopics.includes(topic) this.configuredPubsubTopics.includes(topic)
); );
return isTopicConfigured; return isTopicConfigured;
} }

View File

@ -1,4 +1,4 @@
/** /**
* DefaultPubSubTopic is the default gossipsub topic to use for Waku. * DefaultPubsubTopic is the default gossipsub topic to use for Waku.
*/ */
export const DefaultPubSubTopic = "/waku/2/default-waku/proto"; export const DefaultPubsubTopic = "/waku/2/default-waku/proto";

View File

@ -13,7 +13,7 @@ import type {
Libp2p, Libp2p,
PeerIdStr, PeerIdStr,
ProtocolCreateOptions, ProtocolCreateOptions,
PubSubTopic, PubsubTopic,
Unsubscribe Unsubscribe
} from "@waku/interfaces"; } from "@waku/interfaces";
import { WakuMessage } from "@waku/proto"; import { WakuMessage } from "@waku/proto";
@ -28,7 +28,7 @@ import * as lp from "it-length-prefixed";
import { pipe } from "it-pipe"; import { pipe } from "it-pipe";
import { BaseProtocol } from "../base_protocol.js"; import { BaseProtocol } from "../base_protocol.js";
import { DefaultPubSubTopic } from "../constants.js"; import { DefaultPubsubTopic } from "../constants.js";
import { import {
FilterPushRpc, FilterPushRpc,
@ -50,7 +50,7 @@ export const FilterCodecs = {
class Subscription { class Subscription {
private readonly peer: Peer; private readonly peer: Peer;
private readonly pubsubTopic: PubSubTopic; private readonly pubsubTopic: PubsubTopic;
private newStream: (peer: Peer) => Promise<Stream>; private newStream: (peer: Peer) => Promise<Stream>;
private subscriptionCallbacks: Map< private subscriptionCallbacks: Map<
@ -59,7 +59,7 @@ class Subscription {
>; >;
constructor( constructor(
pubsubTopic: PubSubTopic, pubsubTopic: PubsubTopic,
remotePeer: Peer, remotePeer: Peer,
newStream: (peer: Peer) => Promise<Stream> newStream: (peer: Peer) => Promise<Stream>
) { ) {
@ -256,19 +256,19 @@ class Subscription {
} }
class Filter extends BaseProtocol implements IReceiver { class Filter extends BaseProtocol implements IReceiver {
private readonly pubsubTopics: PubSubTopic[] = []; private readonly pubsubTopics: PubsubTopic[] = [];
private activeSubscriptions = new Map<string, Subscription>(); private activeSubscriptions = new Map<string, Subscription>();
private readonly NUM_PEERS_PROTOCOL = 1; private readonly NUM_PEERS_PROTOCOL = 1;
private getActiveSubscription( private getActiveSubscription(
pubsubTopic: PubSubTopic, pubsubTopic: PubsubTopic,
peerIdStr: PeerIdStr peerIdStr: PeerIdStr
): Subscription | undefined { ): Subscription | undefined {
return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`); return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`);
} }
private setActiveSubscription( private setActiveSubscription(
pubsubTopic: PubSubTopic, pubsubTopic: PubsubTopic,
peerIdStr: PeerIdStr, peerIdStr: PeerIdStr,
subscription: Subscription subscription: Subscription
): Subscription { ): Subscription {
@ -279,7 +279,7 @@ class Filter extends BaseProtocol implements IReceiver {
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) { constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
super(FilterCodecs.SUBSCRIBE, libp2p.components); super(FilterCodecs.SUBSCRIBE, libp2p.components);
this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic]; this.pubsubTopics = options?.pubsubTopics || [DefaultPubsubTopic];
libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => { libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
log.error("Failed to register ", FilterCodecs.PUSH, e); log.error("Failed to register ", FilterCodecs.PUSH, e);
@ -289,7 +289,7 @@ class Filter extends BaseProtocol implements IReceiver {
} }
async createSubscription( async createSubscription(
pubsubTopic: string = DefaultPubSubTopic pubsubTopic: string = DefaultPubsubTopic
): Promise<Subscription> { ): Promise<Subscription> {
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics); ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
@ -367,7 +367,7 @@ class Filter extends BaseProtocol implements IReceiver {
} }
if (!pubsubTopic) { if (!pubsubTopic) {
log.error("PubSub topic missing from push message"); log.error("Pubsub topic missing from push message");
return; return;
} }
@ -408,7 +408,7 @@ export function wakuFilter(
async function pushMessage<T extends IDecodedMessage>( async function pushMessage<T extends IDecodedMessage>(
subscriptionCallback: SubscriptionCallback<T>, subscriptionCallback: SubscriptionCallback<T>,
pubsubTopic: PubSubTopic, pubsubTopic: PubsubTopic,
message: WakuMessage message: WakuMessage
): Promise<void> { ): Promise<void> {
const { decoders, callback } = subscriptionCallback; const { decoders, callback } = subscriptionCallback;

View File

@ -116,7 +116,7 @@ export class KeepAliveManager {
relayPeriodSecs: number, relayPeriodSecs: number,
peerIdStr: PeerIdStr peerIdStr: PeerIdStr
): NodeJS.Timeout[] { ): NodeJS.Timeout[] {
// send a ping message to each PubSubTopic the peer is part of // send a ping message to each PubsubTopic the peer is part of
const intervals: NodeJS.Timeout[] = []; const intervals: NodeJS.Timeout[] = [];
for (const topic of relay.pubsubTopics) { for (const topic of relay.pubsubTopics) {
const meshPeers = relay.getMeshPeers(topic); const meshPeers = relay.getMeshPeers(topic);

View File

@ -6,7 +6,7 @@ import {
IMessage, IMessage,
Libp2p, Libp2p,
ProtocolCreateOptions, ProtocolCreateOptions,
PubSubTopic, PubsubTopic,
SendError, SendError,
SendResult SendResult
} from "@waku/interfaces"; } from "@waku/interfaces";
@ -22,7 +22,7 @@ import { pipe } from "it-pipe";
import { Uint8ArrayList } from "uint8arraylist"; import { Uint8ArrayList } from "uint8arraylist";
import { BaseProtocol } from "../base_protocol.js"; import { BaseProtocol } from "../base_protocol.js";
import { DefaultPubSubTopic } from "../constants.js"; import { DefaultPubsubTopic } from "../constants.js";
import { PushRpc } from "./push_rpc.js"; import { PushRpc } from "./push_rpc.js";
@ -45,12 +45,12 @@ type PreparePushMessageResult =
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/). * Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
*/ */
class LightPush extends BaseProtocol implements ILightPush { class LightPush extends BaseProtocol implements ILightPush {
private readonly pubsubTopics: PubSubTopic[]; private readonly pubsubTopics: PubsubTopic[];
private readonly NUM_PEERS_PROTOCOL = 1; private readonly NUM_PEERS_PROTOCOL = 1;
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) { constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
super(LightPushCodec, libp2p.components); super(LightPushCodec, libp2p.components);
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic]; this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubsubTopic];
} }
private async preparePushMessage( private async preparePushMessage(

View File

@ -7,12 +7,12 @@ import type {
IMetaSetter, IMetaSetter,
IProtoMessage, IProtoMessage,
IRateLimitProof, IRateLimitProof,
PubSubTopic PubsubTopic
} from "@waku/interfaces"; } from "@waku/interfaces";
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";
import { DefaultPubSubTopic } from "../constants.js"; import { DefaultPubsubTopic } from "../constants.js";
const log = new Logger("message:version-0"); const log = new Logger("message:version-0");
const OneMillion = BigInt(1_000_000); const OneMillion = BigInt(1_000_000);
@ -76,7 +76,7 @@ export class Encoder implements IEncoder {
constructor( constructor(
public contentTopic: string, public contentTopic: string,
public ephemeral: boolean = false, public ephemeral: boolean = false,
public pubsubTopic: PubSubTopic, public pubsubTopic: PubsubTopic,
public metaSetter?: IMetaSetter public metaSetter?: IMetaSetter
) { ) {
if (!contentTopic || contentTopic === "") { if (!contentTopic || contentTopic === "") {
@ -119,7 +119,7 @@ export class Encoder implements IEncoder {
* messages. * messages.
*/ */
export function createEncoder({ export function createEncoder({
pubsubTopic = DefaultPubSubTopic, pubsubTopic = DefaultPubsubTopic,
contentTopic, contentTopic,
ephemeral, ephemeral,
metaSetter metaSetter
@ -129,7 +129,7 @@ export function createEncoder({
export class Decoder implements IDecoder<DecodedMessage> { export class Decoder implements IDecoder<DecodedMessage> {
constructor( constructor(
public pubsubTopic: PubSubTopic, public pubsubTopic: PubsubTopic,
public contentTopic: string public contentTopic: string
) { ) {
if (!contentTopic || contentTopic === "") { if (!contentTopic || contentTopic === "") {
@ -182,7 +182,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
*/ */
export function createDecoder( export function createDecoder(
contentTopic: string, contentTopic: string,
pubsubTopic: PubSubTopic = DefaultPubSubTopic pubsubTopic: PubsubTopic = DefaultPubsubTopic
): Decoder { ): Decoder {
return new Decoder(pubsubTopic, contentTopic); return new Decoder(pubsubTopic, contentTopic);
} }

View File

@ -7,7 +7,7 @@ import {
IStore, IStore,
Libp2p, Libp2p,
ProtocolCreateOptions, ProtocolCreateOptions,
PubSubTopic PubsubTopic
} from "@waku/interfaces"; } from "@waku/interfaces";
import { proto_store as proto } from "@waku/proto"; import { proto_store as proto } from "@waku/proto";
import { ensurePubsubTopicIsConfigured, isDefined } from "@waku/utils"; import { ensurePubsubTopicIsConfigured, isDefined } from "@waku/utils";
@ -19,7 +19,7 @@ import { pipe } from "it-pipe";
import { Uint8ArrayList } from "uint8arraylist"; import { Uint8ArrayList } from "uint8arraylist";
import { BaseProtocol } from "../base_protocol.js"; import { BaseProtocol } from "../base_protocol.js";
import { DefaultPubSubTopic } from "../constants.js"; import { DefaultPubsubTopic } from "../constants.js";
import { toProtoMessage } from "../to_proto_message.js"; import { toProtoMessage } from "../to_proto_message.js";
import { HistoryRpc, PageDirection, Params } from "./history_rpc.js"; import { HistoryRpc, PageDirection, Params } from "./history_rpc.js";
@ -75,12 +75,12 @@ export interface QueryOptions {
* The Waku Store protocol can be used to retrieved historical messages. * The Waku Store protocol can be used to retrieved historical messages.
*/ */
class Store extends BaseProtocol implements IStore { class Store extends BaseProtocol implements IStore {
private readonly pubsubTopics: PubSubTopic[]; private readonly pubsubTopics: PubsubTopic[];
private readonly NUM_PEERS_PROTOCOL = 1; private readonly NUM_PEERS_PROTOCOL = 1;
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) { constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
super(StoreCodec, libp2p.components); super(StoreCodec, libp2p.components);
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic]; this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubsubTopic];
} }
/** /**
@ -230,29 +230,29 @@ class Store extends BaseProtocol implements IStore {
} }
// convert array to set to remove duplicates // convert array to set to remove duplicates
const uniquePubSubTopicsInQuery = Array.from( const uniquePubsubTopicsInQuery = Array.from(
new Set(decoders.map((decoder) => decoder.pubsubTopic)) new Set(decoders.map((decoder) => decoder.pubsubTopic))
); );
// If multiple pubsub topics are provided, throw an error // If multiple pubsub topics are provided, throw an error
if (uniquePubSubTopicsInQuery.length > 1) { if (uniquePubsubTopicsInQuery.length > 1) {
throw new Error( throw new Error(
"API does not support querying multiple pubsub topics at once" "API does not support querying multiple pubsub topics at once"
); );
} }
// we can be certain that there is only one pubsub topic in the query // we can be certain that there is only one pubsub topic in the query
const pubSubTopicForQuery = uniquePubSubTopicsInQuery[0]; const pubsubTopicForQuery = uniquePubsubTopicsInQuery[0];
ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubsubTopics); ensurePubsubTopicIsConfigured(pubsubTopicForQuery, this.pubsubTopics);
// check that the pubsubTopic from the Cursor and Decoder match // check that the pubsubTopic from the Cursor and Decoder match
if ( if (
options?.cursor?.pubsubTopic && options?.cursor?.pubsubTopic &&
options.cursor.pubsubTopic !== pubSubTopicForQuery options.cursor.pubsubTopic !== pubsubTopicForQuery
) { ) {
throw new Error( throw new Error(
`Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubSubTopicForQuery})` `Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubsubTopicForQuery})`
); );
} }
@ -267,16 +267,16 @@ class Store extends BaseProtocol implements IStore {
}); });
const contentTopics = decoders const contentTopics = decoders
.filter((decoder) => decoder.pubsubTopic === pubSubTopicForQuery) .filter((decoder) => decoder.pubsubTopic === pubsubTopicForQuery)
.map((dec) => dec.contentTopic); .map((dec) => dec.contentTopic);
if (contentTopics.length === 0) { if (contentTopics.length === 0) {
throw new Error("No decoders found for topic " + pubSubTopicForQuery); throw new Error("No decoders found for topic " + pubsubTopicForQuery);
} }
const queryOpts = Object.assign( const queryOpts = Object.assign(
{ {
pubsubTopic: pubSubTopicForQuery, pubsubTopic: pubsubTopicForQuery,
pageDirection: PageDirection.BACKWARD, pageDirection: PageDirection.BACKWARD,
pageSize: DefaultPageSize pageSize: DefaultPageSize
}, },

View File

@ -7,7 +7,7 @@ import type {
IRelay, IRelay,
IStore, IStore,
Libp2p, Libp2p,
PubSubTopic, PubsubTopic,
Waku Waku
} from "@waku/interfaces"; } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
@ -53,7 +53,7 @@ export class WakuNode implements Waku {
constructor( constructor(
options: WakuOptions, options: WakuOptions,
public readonly pubsubTopics: PubSubTopic[], public readonly pubsubTopics: PubsubTopic[],
libp2p: Libp2p, libp2p: Libp2p,
store?: (libp2p: Libp2p) => IStore, store?: (libp2p: Libp2p) => IStore,
lightPush?: (libp2p: Libp2p) => ILightPush, lightPush?: (libp2p: Libp2p) => ILightPush,

View File

@ -1,4 +1,4 @@
import type { PubSubTopic } from "./misc.js"; import type { PubsubTopic } from "./misc.js";
export interface IRateLimitProof { export interface IRateLimitProof {
proof: Uint8Array; proof: Uint8Array;
@ -38,7 +38,7 @@ export interface IMetaSetter {
} }
export interface EncoderOptions { export interface EncoderOptions {
pubsubTopic?: PubSubTopic; pubsubTopic?: PubsubTopic;
/** The content topic to set on outgoing messages. */ /** The content topic to set on outgoing messages. */
contentTopic: string; contentTopic: string;
/** /**
@ -55,7 +55,7 @@ export interface EncoderOptions {
} }
export interface IEncoder { export interface IEncoder {
pubsubTopic: PubSubTopic; pubsubTopic: PubsubTopic;
contentTopic: string; contentTopic: string;
ephemeral: boolean; ephemeral: boolean;
toWire: (message: IMessage) => Promise<Uint8Array | undefined>; toWire: (message: IMessage) => Promise<Uint8Array | undefined>;
@ -65,7 +65,7 @@ export interface IEncoder {
export interface IDecodedMessage { export interface IDecodedMessage {
payload: Uint8Array; payload: Uint8Array;
contentTopic: string; contentTopic: string;
pubsubTopic: PubSubTopic; pubsubTopic: PubsubTopic;
timestamp: Date | undefined; timestamp: Date | undefined;
rateLimitProof: IRateLimitProof | undefined; rateLimitProof: IRateLimitProof | undefined;
ephemeral: boolean | undefined; ephemeral: boolean | undefined;
@ -73,7 +73,7 @@ export interface IDecodedMessage {
} }
export interface IDecoder<T extends IDecodedMessage> { export interface IDecoder<T extends IDecodedMessage> {
pubsubTopic: PubSubTopic; pubsubTopic: PubsubTopic;
contentTopic: string; contentTopic: string;
fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>; fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
fromProtoObj: ( fromProtoObj: (

View File

@ -7,7 +7,7 @@ export interface IAsyncIterator<T extends IDecodedMessage> {
export type Unsubscribe = () => void | Promise<void>; export type Unsubscribe = () => void | Promise<void>;
export type PubSubTopic = string; export type PubsubTopic = string;
export type ContentTopic = string; export type ContentTopic = string;
export type PeerIdStr = string; export type PeerIdStr = string;

View File

@ -4,7 +4,7 @@ import type { Peer, PeerStore } from "@libp2p/interface/peer-store";
import type { Libp2pOptions } from "libp2p"; import type { Libp2pOptions } from "libp2p";
import type { IDecodedMessage } from "./message.js"; import type { IDecodedMessage } from "./message.js";
import type { PubSubTopic } from "./misc.js"; import type { PubsubTopic } from "./misc.js";
export enum Protocols { export enum Protocols {
Relay = "relay", Relay = "relay",
@ -27,7 +27,7 @@ export type ProtocolCreateOptions = {
* Waku implements sharding to achieve scalability * Waku implements sharding to achieve scalability
* The format of the sharded topic is `/waku/2/rs/<shard_cluster_index>/<shard_number>` * The format of the sharded topic is `/waku/2/rs/<shard_cluster_index>/<shard_number>`
* To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/). * To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
* The PubSub Topic to use. Defaults to {@link @waku/core!DefaultPubSubTopic }. * The Pubsub Topic to use. Defaults to {@link @waku/core!DefaultPubsubTopic }.
* *
* If no pubsub topic is specified, the default pubsub topic is used. * If no pubsub topic is specified, the default pubsub topic is used.
* The set of pubsub topics that are used to initialize the Waku node, will need to be used by the protocols as well * The set of pubsub topics that are used to initialize the Waku node, will need to be used by the protocols as well
@ -39,7 +39,7 @@ export type ProtocolCreateOptions = {
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details. * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
* *
*/ */
pubsubTopics?: PubSubTopic[]; pubsubTopics?: PubsubTopic[];
/** /**
* You can pass options to the `Libp2p` instance used by {@link @waku/core!WakuNode} using the `libp2p` property. * You can pass options to the `Libp2p` instance used by {@link @waku/core!WakuNode} using the `libp2p` property.
* This property is the same type as the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create) * This property is the same type as the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
@ -88,8 +88,8 @@ export enum SendError {
*/ */
SIZE_TOO_BIG = "Size is too big", SIZE_TOO_BIG = "Size is too big",
/** /**
* The PubSubTopic passed to the send function is not configured on the Waku node. * The PubsubTopic passed to the send function is not configured on the Waku node.
* Please ensure that the PubSubTopic is used when initializing the Waku node. * Please ensure that the PubsubTopic is used when initializing the Waku node.
*/ */
TOPIC_NOT_CONFIGURED = "Topic not configured", TOPIC_NOT_CONFIGURED = "Topic not configured",
/** /**

View File

@ -2,12 +2,12 @@ import type { IDecodedMessage, IDecoder } from "./message.js";
import type { import type {
ContentTopic, ContentTopic,
IAsyncIterator, IAsyncIterator,
PubSubTopic, PubsubTopic,
Unsubscribe Unsubscribe
} from "./misc.js"; } from "./misc.js";
import type { Callback } from "./protocols.js"; import type { Callback } from "./protocols.js";
export type ActiveSubscriptions = Map<PubSubTopic, ContentTopic[]>; export type ActiveSubscriptions = Map<PubsubTopic, ContentTopic[]>;
export interface IReceiver { export interface IReceiver {
toSubscriptionIterator: <T extends IDecodedMessage>( toSubscriptionIterator: <T extends IDecodedMessage>(

View File

@ -1,8 +1,8 @@
import type { GossipSub } from "@chainsafe/libp2p-gossipsub"; import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types"; import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types";
import { PubSubTopic } from "./misc.js"; import type { PubsubTopic } from "./misc.js";
import { IReceiver } from "./receiver.js"; import type { IReceiver } from "./receiver.js";
import type { ISender } from "./sender.js"; import type { ISender } from "./sender.js";
/** /**
@ -13,7 +13,7 @@ import type { ISender } from "./sender.js";
* @property getMeshPeers - Function to retrieve the mesh peers for a given topic or all topics if none is specified. Returns an array of peer IDs as strings. * @property getMeshPeers - Function to retrieve the mesh peers for a given topic or all topics if none is specified. Returns an array of peer IDs as strings.
*/ */
export interface IRelayAPI { export interface IRelayAPI {
readonly pubsubTopics: Set<PubSubTopic>; readonly pubsubTopics: Set<PubsubTopic>;
readonly gossipSub: GossipSub; readonly gossipSub: GossipSub;
start: () => Promise<void>; start: () => Promise<void>;
getMeshPeers: (topic?: TopicStr) => PeerIdStr[]; getMeshPeers: (topic?: TopicStr) => PeerIdStr[];

View File

@ -1,6 +1,6 @@
import { DefaultPubSubTopic } from "@waku/core"; import { DefaultPubsubTopic } from "@waku/core";
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0"; import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
import { IMetaSetter, PubSubTopic } from "@waku/interfaces"; import { IMetaSetter, PubsubTopic } from "@waku/interfaces";
import type { import type {
EncoderOptions as BaseEncoderOptions, EncoderOptions as BaseEncoderOptions,
IDecoder, IDecoder,
@ -33,7 +33,7 @@ const log = new Logger("message-encryption:ecies");
class Encoder implements IEncoder { class Encoder implements IEncoder {
constructor( constructor(
public pubsubTopic: PubSubTopic, public pubsubTopic: PubsubTopic,
public contentTopic: string, public contentTopic: string,
private publicKey: Uint8Array, private publicKey: Uint8Array,
private sigPrivKey?: Uint8Array, private sigPrivKey?: Uint8Array,
@ -97,7 +97,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/). * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
*/ */
export function createEncoder({ export function createEncoder({
pubsubTopic = DefaultPubSubTopic, pubsubTopic = DefaultPubsubTopic,
contentTopic, contentTopic,
publicKey, publicKey,
sigPrivKey, sigPrivKey,
@ -116,7 +116,7 @@ export function createEncoder({
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> { class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
constructor( constructor(
pubsubTopic: PubSubTopic, pubsubTopic: PubsubTopic,
contentTopic: string, contentTopic: string,
private privateKey: Uint8Array private privateKey: Uint8Array
) { ) {
@ -193,7 +193,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
export function createDecoder( export function createDecoder(
contentTopic: string, contentTopic: string,
privateKey: Uint8Array, privateKey: Uint8Array,
pubsubTopic: PubSubTopic = DefaultPubSubTopic pubsubTopic: PubsubTopic = DefaultPubsubTopic
): Decoder { ): Decoder {
return new Decoder(pubsubTopic, contentTopic, privateKey); return new Decoder(pubsubTopic, contentTopic, privateKey);
} }

View File

@ -1,4 +1,4 @@
import { DefaultPubSubTopic } from "@waku/core"; import { DefaultPubsubTopic } from "@waku/core";
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0"; import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
import type { import type {
EncoderOptions as BaseEncoderOptions, EncoderOptions as BaseEncoderOptions,
@ -7,7 +7,7 @@ import type {
IMessage, IMessage,
IMetaSetter, IMetaSetter,
IProtoMessage, IProtoMessage,
PubSubTopic PubsubTopic
} from "@waku/interfaces"; } from "@waku/interfaces";
import { WakuMessage } from "@waku/proto"; import { WakuMessage } from "@waku/proto";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
@ -29,7 +29,7 @@ const log = new Logger("message-encryption:symmetric");
class Encoder implements IEncoder { class Encoder implements IEncoder {
constructor( constructor(
public pubsubTopic: PubSubTopic, public pubsubTopic: PubsubTopic,
public contentTopic: string, public contentTopic: string,
private symKey: Uint8Array, private symKey: Uint8Array,
private sigPrivKey?: Uint8Array, private sigPrivKey?: Uint8Array,
@ -93,7 +93,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/). * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
*/ */
export function createEncoder({ export function createEncoder({
pubsubTopic = DefaultPubSubTopic, pubsubTopic = DefaultPubsubTopic,
contentTopic, contentTopic,
symKey, symKey,
sigPrivKey, sigPrivKey,
@ -112,7 +112,7 @@ export function createEncoder({
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> { class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
constructor( constructor(
pubsubTopic: PubSubTopic, pubsubTopic: PubsubTopic,
contentTopic: string, contentTopic: string,
private symKey: Uint8Array private symKey: Uint8Array
) { ) {
@ -189,7 +189,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
export function createDecoder( export function createDecoder(
contentTopic: string, contentTopic: string,
symKey: Uint8Array, symKey: Uint8Array,
pubsubTopic: PubSubTopic = DefaultPubSubTopic pubsubTopic: PubsubTopic = DefaultPubsubTopic
): Decoder { ): Decoder {
return new Decoder(pubsubTopic, contentTopic, symKey); return new Decoder(pubsubTopic, contentTopic, symKey);
} }

View File

@ -7,9 +7,9 @@ import {
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 { PeerId } from "@libp2p/interface/peer-id";
import type { PubSub } from "@libp2p/interface/pubsub"; import type { PubSub as Libp2pPubsub } from "@libp2p/interface/pubsub";
import { sha256 } from "@noble/hashes/sha256"; import { sha256 } from "@noble/hashes/sha256";
import { DefaultPubSubTopic } from "@waku/core"; import { DefaultPubsubTopic } from "@waku/core";
import { import {
ActiveSubscriptions, ActiveSubscriptions,
Callback, Callback,
@ -21,7 +21,7 @@ import {
IRelay, IRelay,
Libp2p, Libp2p,
ProtocolCreateOptions, ProtocolCreateOptions,
PubSubTopic, PubsubTopic,
SendError, SendError,
SendResult SendResult
} from "@waku/interfaces"; } from "@waku/interfaces";
@ -48,7 +48,7 @@ export type ContentTopic = string;
* Throws if libp2p.pubsub does not support Waku Relay * Throws if libp2p.pubsub does not support Waku Relay
*/ */
class Relay implements IRelay { class Relay implements IRelay {
public readonly pubsubTopics: Set<PubSubTopic>; public readonly pubsubTopics: Set<PubsubTopic>;
private defaultDecoder: IDecoder<IDecodedMessage>; private defaultDecoder: IDecoder<IDecodedMessage>;
public static multicodec: string = RelayCodecs[0]; public static multicodec: string = RelayCodecs[0];
@ -58,17 +58,17 @@ class Relay implements IRelay {
* observers called when receiving new message. * observers called when receiving new message.
* Observers under key `""` are always called. * Observers under key `""` are always called.
*/ */
private observers: Map<PubSubTopic, Map<ContentTopic, Set<unknown>>>; private observers: Map<PubsubTopic, Map<ContentTopic, Set<unknown>>>;
constructor(libp2p: Libp2p, options?: Partial<RelayCreateOptions>) { constructor(libp2p: Libp2p, options?: Partial<RelayCreateOptions>) {
if (!this.isRelayPubSub(libp2p.services.pubsub)) { if (!this.isRelayPubsub(libp2p.services.pubsub)) {
throw Error( throw Error(
`Failed to initialize Relay. libp2p.pubsub does not support ${Relay.multicodec}` `Failed to initialize Relay. libp2p.pubsub does not support ${Relay.multicodec}`
); );
} }
this.gossipSub = libp2p.services.pubsub as GossipSub; this.gossipSub = libp2p.services.pubsub as GossipSub;
this.pubsubTopics = new Set(options?.pubsubTopics ?? [DefaultPubSubTopic]); this.pubsubTopics = new Set(options?.pubsubTopics ?? [DefaultPubsubTopic]);
if (this.gossipSub.isStarted()) { if (this.gossipSub.isStarted()) {
this.subscribeToAllTopics(); this.subscribeToAllTopics();
@ -76,7 +76,7 @@ class Relay implements IRelay {
this.observers = new Map(); this.observers = new Map();
// Default PubSubTopic decoder // Default PubsubTopic decoder
// TODO: User might want to decide what decoder should be used (e.g. for RLN) // TODO: User might want to decide what decoder should be used (e.g. for RLN)
this.defaultDecoder = new TopicOnlyDecoder(); this.defaultDecoder = new TopicOnlyDecoder();
} }
@ -136,7 +136,7 @@ class Relay implements IRelay {
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T> callback: Callback<T>
): () => void { ): () => void {
const observers: Array<[PubSubTopic, Observer<T>]> = []; const observers: Array<[PubsubTopic, Observer<T>]> = [];
for (const decoder of Array.isArray(decoders) ? decoders : [decoders]) { for (const decoder of Array.isArray(decoders) ? decoders : [decoders]) {
const { pubsubTopic } = decoder; const { pubsubTopic } = decoder;
@ -156,7 +156,7 @@ class Relay implements IRelay {
} }
private removeObservers<T extends IDecodedMessage>( private removeObservers<T extends IDecodedMessage>(
observers: Array<[PubSubTopic, Observer<T>]> observers: Array<[PubsubTopic, Observer<T>]>
): void { ): void {
for (const [pubsubTopic, observer] of observers) { for (const [pubsubTopic, observer] of observers) {
const ctObs = this.observers.get(pubsubTopic); const ctObs = this.observers.get(pubsubTopic);
@ -186,7 +186,7 @@ class Relay implements IRelay {
return map; return map;
} }
public getMeshPeers(topic: TopicStr = DefaultPubSubTopic): PeerIdStr[] { public getMeshPeers(topic: TopicStr = DefaultPubsubTopic): PeerIdStr[] {
return this.gossipSub.getMeshPeers(topic); return this.gossipSub.getMeshPeers(topic);
} }
@ -270,7 +270,7 @@ class Relay implements IRelay {
this.gossipSub.subscribe(pubsubTopic); this.gossipSub.subscribe(pubsubTopic);
} }
private isRelayPubSub(pubsub: PubSub | undefined): boolean { private isRelayPubsub(pubsub: Libp2pPubsub | undefined): boolean {
return pubsub?.multicodecs?.includes(Relay.multicodec) ?? false; return pubsub?.multicodecs?.includes(Relay.multicodec) ?? false;
} }
} }

View File

@ -1,4 +1,4 @@
import { DefaultPubSubTopic } from "@waku/core"; import { DefaultPubsubTopic } from "@waku/core";
import type { import type {
IDecodedMessage, IDecodedMessage,
IDecoder, IDecoder,
@ -24,7 +24,7 @@ export class TopicOnlyMessage implements IDecodedMessage {
} }
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> { export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
pubsubTopic = DefaultPubSubTopic; pubsubTopic = DefaultPubsubTopic;
public contentTopic = ""; public contentTopic = "";
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> { fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {

View File

@ -5,7 +5,7 @@ import { mplex } from "@libp2p/mplex";
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 {
DefaultPubSubTopic, DefaultPubsubTopic,
DefaultUserAgent, DefaultUserAgent,
wakuFilter, wakuFilter,
wakuLightPush, wakuLightPush,
@ -47,7 +47,7 @@ export async function createLightNode(
options = options ?? {}; options = options ?? {};
if (!options.pubsubTopics) { if (!options.pubsubTopics) {
options.pubsubTopics = [DefaultPubSubTopic]; options.pubsubTopics = [DefaultPubsubTopic];
} }
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
@ -87,7 +87,7 @@ export async function createRelayNode(
options = options ?? {}; options = options ?? {};
if (!options.pubsubTopics) { if (!options.pubsubTopics) {
options.pubsubTopics = [DefaultPubSubTopic]; options.pubsubTopics = [DefaultPubsubTopic];
} }
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
@ -135,7 +135,7 @@ export async function createFullNode(
options = options ?? {}; options = options ?? {};
if (!options.pubsubTopics) { if (!options.pubsubTopics) {
options.pubsubTopics = [DefaultPubSubTopic]; options.pubsubTopics = [DefaultPubsubTopic];
} }
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};

View File

@ -1,4 +1,4 @@
import { DecodedMessage, DefaultPubSubTopic } from "@waku/core"; import { DecodedMessage, DefaultPubsubTopic } from "@waku/core";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { AssertionError, expect } from "chai"; import { AssertionError, expect } from "chai";
@ -70,7 +70,7 @@ export class MessageCollector {
} }
): Promise<boolean> { ): Promise<boolean> {
const startTime = Date.now(); const startTime = Date.now();
const pubsubTopic = options?.pubsubTopic || DefaultPubSubTopic; const pubsubTopic = options?.pubsubTopic || DefaultPubsubTopic;
const timeoutDuration = options?.timeoutDuration || 400; const timeoutDuration = options?.timeoutDuration || 400;
const exact = options?.exact || false; const exact = options?.exact || false;
@ -109,7 +109,7 @@ export class MessageCollector {
options: { options: {
expectedMessageText: string | Uint8Array | undefined; expectedMessageText: string | Uint8Array | undefined;
expectedContentTopic?: string; expectedContentTopic?: string;
expectedPubSubTopic?: string; expectedPubsubTopic?: string;
expectedVersion?: number; expectedVersion?: number;
expectedMeta?: Uint8Array; expectedMeta?: Uint8Array;
expectedEphemeral?: boolean; expectedEphemeral?: boolean;
@ -193,9 +193,9 @@ export class MessageCollector {
} else { } else {
// js-waku message specific assertions // js-waku message specific assertions
expect(message.pubsubTopic).to.eq( expect(message.pubsubTopic).to.eq(
options.expectedPubSubTopic || DefaultPubSubTopic, options.expectedPubsubTopic || DefaultPubsubTopic,
`Message pub/sub topic mismatch. Expected: ${ `Message pub/sub topic mismatch. Expected: ${
options.expectedPubSubTopic || DefaultPubSubTopic options.expectedPubsubTopic || DefaultPubsubTopic
}. Got: ${message.pubsubTopic}` }. Got: ${message.pubsubTopic}`
); );

View File

@ -1,7 +1,7 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface/peer-id";
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/core"; import { DefaultPubsubTopic } from "@waku/core";
import { isDefined } from "@waku/utils"; import { isDefined } from "@waku/utils";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import { bytesToHex, hexToBytes } from "@waku/utils/bytes"; import { bytesToHex, hexToBytes } from "@waku/utils/bytes";
@ -207,7 +207,7 @@ export class NimGoNode {
} }
async ensureSubscriptions( async ensureSubscriptions(
pubsubTopics: string[] = [DefaultPubSubTopic] pubsubTopics: string[] = [DefaultPubsubTopic]
): Promise<boolean> { ): Promise<boolean> {
this.checkProcess(); this.checkProcess();
@ -218,7 +218,7 @@ export class NimGoNode {
async sendMessage( async sendMessage(
message: MessageRpcQuery, message: MessageRpcQuery,
pubsubTopic: string = DefaultPubSubTopic pubsubTopic: string = DefaultPubsubTopic
): Promise<boolean> { ): Promise<boolean> {
this.checkProcess(); this.checkProcess();
@ -233,7 +233,7 @@ export class NimGoNode {
} }
async messages( async messages(
pubsubTopic: string = DefaultPubSubTopic pubsubTopic: string = DefaultPubsubTopic
): Promise<MessageRpcResponse[]> { ): Promise<MessageRpcResponse[]> {
this.checkProcess(); this.checkProcess();
@ -275,7 +275,7 @@ export class NimGoNode {
} }
return this.rpcCall<boolean>("post_waku_v2_private_v1_asymmetric_message", [ return this.rpcCall<boolean>("post_waku_v2_private_v1_asymmetric_message", [
pubsubTopic ? pubsubTopic : DefaultPubSubTopic, pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
message, message,
"0x" + bytesToHex(publicKey) "0x" + bytesToHex(publicKey)
]); ]);
@ -290,7 +290,7 @@ export class NimGoNode {
return await this.rpcCall<MessageRpcResponse[]>( return await this.rpcCall<MessageRpcResponse[]>(
"get_waku_v2_private_v1_asymmetric_messages", "get_waku_v2_private_v1_asymmetric_messages",
[ [
pubsubTopic ? pubsubTopic : DefaultPubSubTopic, pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
"0x" + bytesToHex(privateKey) "0x" + bytesToHex(privateKey)
] ]
); );
@ -317,7 +317,7 @@ export class NimGoNode {
} }
return this.rpcCall<boolean>("post_waku_v2_private_v1_symmetric_message", [ return this.rpcCall<boolean>("post_waku_v2_private_v1_symmetric_message", [
pubsubTopic ? pubsubTopic : DefaultPubSubTopic, pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
message, message,
"0x" + bytesToHex(symKey) "0x" + bytesToHex(symKey)
]); ]);
@ -332,7 +332,7 @@ export class NimGoNode {
return await this.rpcCall<MessageRpcResponse[]>( return await this.rpcCall<MessageRpcResponse[]>(
"get_waku_v2_private_v1_symmetric_messages", "get_waku_v2_private_v1_symmetric_messages",
[ [
pubsubTopic ? pubsubTopic : DefaultPubSubTopic, pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
"0x" + bytesToHex(symKey) "0x" + bytesToHex(symKey)
] ]
); );

View File

@ -1,7 +1,7 @@
import { import {
createDecoder, createDecoder,
createEncoder, createEncoder,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import type { IFilterSubscription, LightNode } from "@waku/interfaces"; import type { IFilterSubscription, LightNode } from "@waku/interfaces";
@ -23,7 +23,7 @@ import {
TestEncoder TestEncoder
} from "./utils.js"; } 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;
@ -31,21 +31,21 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
let nwaku2: NimGoNode; let nwaku2: NimGoNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
const customPubSubTopic = "/waku/2/custom-dapp/proto"; const customPubsubTopic = "/waku/2/custom-dapp/proto";
const customContentTopic = "/test/2/waku-filter"; const customContentTopic = "/test/2/waku-filter";
const newEncoder = createEncoder({ const newEncoder = createEncoder({
pubsubTopic: customPubSubTopic, pubsubTopic: customPubsubTopic,
contentTopic: customContentTopic contentTopic: customContentTopic
}); });
const newDecoder = createDecoder(customContentTopic, customPubSubTopic); const newDecoder = createDecoder(customContentTopic, customPubsubTopic);
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [ [nwaku, waku] = await runNodes(this, [
customPubSubTopic, customPubsubTopic,
DefaultPubSubTopic DefaultPubsubTopic
]); ]);
subscription = await waku.filter.createSubscription(customPubSubTopic); subscription = await waku.filter.createSubscription(customPubsubTopic);
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
@ -60,7 +60,7 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
expect(await messageCollector.waitForMessages(1)).to.eq(true); expect(await messageCollector.waitForMessages(1)).to.eq(true);
messageCollector.verifyReceivedMessage(0, { messageCollector.verifyReceivedMessage(0, {
expectedContentTopic: customContentTopic, expectedContentTopic: customContentTopic,
expectedPubSubTopic: customPubSubTopic, expectedPubsubTopic: customPubsubTopic,
expectedMessageText: "M1" expectedMessageText: "M1"
}); });
}); });
@ -68,9 +68,9 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
it("Subscribe and receive messages on 2 different pubsubtopics", async function () { it("Subscribe and receive messages on 2 different pubsubtopics", async function () {
await subscription.subscribe([newDecoder], messageCollector.callback); await subscription.subscribe([newDecoder], messageCollector.callback);
// Subscribe from the same lightnode to the 2nd pubSubtopic // Subscribe from the same lightnode to the 2nd pubsubtopic
const subscription2 = const subscription2 =
await waku.filter.createSubscription(DefaultPubSubTopic); await waku.filter.createSubscription(DefaultPubsubTopic);
const messageCollector2 = new MessageCollector(); const messageCollector2 = new MessageCollector();
@ -84,13 +84,13 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
messageCollector.verifyReceivedMessage(0, { messageCollector.verifyReceivedMessage(0, {
expectedContentTopic: customContentTopic, expectedContentTopic: customContentTopic,
expectedPubSubTopic: customPubSubTopic, expectedPubsubTopic: customPubsubTopic,
expectedMessageText: "M1" expectedMessageText: "M1"
}); });
messageCollector2.verifyReceivedMessage(0, { messageCollector2.verifyReceivedMessage(0, {
expectedContentTopic: TestContentTopic, expectedContentTopic: TestContentTopic,
expectedPubSubTopic: DefaultPubSubTopic, expectedPubsubTopic: DefaultPubsubTopic,
expectedMessageText: "M2" expectedMessageText: "M2"
}); });
}); });
@ -98,23 +98,23 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
it("Subscribe and receive messages from 2 nwaku nodes each with different pubsubtopics", async function () { it("Subscribe and receive messages from 2 nwaku nodes each with different pubsubtopics", async function () {
await subscription.subscribe([newDecoder], messageCollector.callback); await subscription.subscribe([newDecoder], messageCollector.callback);
// 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 NimGoNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
relay: true, relay: true,
topic: [DefaultPubSubTopic] topic: [DefaultPubsubTopic]
}); });
await waku.dial(await nwaku2.getMultiaddrWithId()); await waku.dial(await nwaku2.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]); await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
// Subscribe from the same lightnode to the new nwaku on the new pubSubtopic // Subscribe from the same lightnode to the new nwaku on the new pubsubtopic
const subscription2 = await waku.filter.createSubscription( const subscription2 = await waku.filter.createSubscription(
DefaultPubSubTopic, DefaultPubsubTopic,
await nwaku2.getPeerId() await nwaku2.getPeerId()
); );
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]); await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
const messageCollector2 = new MessageCollector(); const messageCollector2 = new MessageCollector();
@ -124,10 +124,10 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
// While loop is done because of https://github.com/waku-org/js-waku/issues/1606 // While loop is done because of https://github.com/waku-org/js-waku/issues/1606
while ( while (
!(await messageCollector.waitForMessages(1, { !(await messageCollector.waitForMessages(1, {
pubsubTopic: customPubSubTopic pubsubTopic: customPubsubTopic
})) || })) ||
!(await messageCollector2.waitForMessages(1, { !(await messageCollector2.waitForMessages(1, {
pubsubTopic: DefaultPubSubTopic pubsubTopic: DefaultPubsubTopic
})) }))
) { ) {
await waku.lightPush.send(newEncoder, { payload: utf8ToBytes("M1") }); await waku.lightPush.send(newEncoder, { payload: utf8ToBytes("M1") });
@ -136,13 +136,13 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
messageCollector.verifyReceivedMessage(0, { messageCollector.verifyReceivedMessage(0, {
expectedContentTopic: customContentTopic, expectedContentTopic: customContentTopic,
expectedPubSubTopic: customPubSubTopic, expectedPubsubTopic: customPubsubTopic,
expectedMessageText: "M1" expectedMessageText: "M1"
}); });
messageCollector2.verifyReceivedMessage(0, { messageCollector2.verifyReceivedMessage(0, {
expectedContentTopic: TestContentTopic, expectedContentTopic: TestContentTopic,
expectedPubSubTopic: DefaultPubSubTopic, expectedPubsubTopic: DefaultPubsubTopic,
expectedMessageText: "M2" expectedMessageText: "M2"
}); });
}); });

View File

@ -1,4 +1,4 @@
import { DefaultPubSubTopic } from "@waku/core"; import { DefaultPubsubTopic } from "@waku/core";
import type { IFilterSubscription, LightNode } from "@waku/interfaces"; 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";
@ -23,7 +23,7 @@ describe("Waku Filter V2: Ping", function () {
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]); [nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });

View File

@ -1,4 +1,4 @@
import { DefaultPubSubTopic, waitForRemotePeer } from "@waku/core"; import { DefaultPubsubTopic, waitForRemotePeer } from "@waku/core";
import type { IFilterSubscription, LightNode } from "@waku/interfaces"; import type { IFilterSubscription, LightNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";
@ -31,7 +31,7 @@ describe("Waku Filter V2: FilterPush", function () {
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]); [nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
@ -62,7 +62,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
DefaultPubSubTopic, DefaultPubsubTopic,
{ {
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"), payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
@ -93,7 +93,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
DefaultPubSubTopic, DefaultPubsubTopic,
{ {
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"), payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
@ -110,7 +110,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
"DefaultPubSubTopic", "DefaultPubsubTopic",
{ {
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"), payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
@ -141,7 +141,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
DefaultPubSubTopic, DefaultPubsubTopic,
{ {
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"), payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
timestamp: BigInt(Date.now()) * BigInt(1000000) timestamp: BigInt(Date.now()) * BigInt(1000000)
@ -156,7 +156,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
DefaultPubSubTopic, DefaultPubsubTopic,
{ {
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
timestamp: BigInt(Date.now()) * BigInt(1000000) timestamp: BigInt(Date.now()) * BigInt(1000000)
@ -176,7 +176,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
DefaultPubSubTopic, DefaultPubsubTopic,
{ {
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: 12345, payload: 12345,
@ -192,7 +192,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
DefaultPubSubTopic, DefaultPubsubTopic,
"extraField", "extraField",
{ {
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
@ -209,7 +209,7 @@ describe("Waku Filter V2: FilterPush", function () {
await delay(400); await delay(400);
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [ await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
DefaultPubSubTopic, DefaultPubsubTopic,
{ {
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"), payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),

View File

@ -1,7 +1,7 @@
import { import {
createDecoder, createDecoder,
createEncoder, createEncoder,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import type { IFilterSubscription, LightNode } from "@waku/interfaces"; import type { IFilterSubscription, LightNode } from "@waku/interfaces";
@ -40,7 +40,7 @@ describe("Waku Filter V2: Subscribe", function () {
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]); [nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
@ -377,10 +377,10 @@ describe("Waku Filter V2: Subscribe", function () {
await waku.dial(await nwaku2.getMultiaddrWithId()); await waku.dial(await nwaku2.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]); await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
const subscription2 = await waku.filter.createSubscription( const subscription2 = await waku.filter.createSubscription(
DefaultPubSubTopic, DefaultPubsubTopic,
await nwaku2.getPeerId() await nwaku2.getPeerId()
); );
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]); await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
// Send a message using the new subscription // Send a message using the new subscription
const newContentTopic = "/test/2/waku-filter"; const newContentTopic = "/test/2/waku-filter";
const newEncoder = createEncoder({ contentTopic: newContentTopic }); const newEncoder = createEncoder({ contentTopic: newContentTopic });

View File

@ -1,4 +1,4 @@
import { createDecoder, createEncoder, DefaultPubSubTopic } from "@waku/core"; import { createDecoder, createEncoder, DefaultPubsubTopic } from "@waku/core";
import type { IFilterSubscription, LightNode } from "@waku/interfaces"; 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";
@ -29,7 +29,7 @@ describe("Waku Filter V2: Unsubscribe", function () {
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]); [nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();

View File

@ -1,4 +1,4 @@
import { createEncoder, DefaultPubSubTopic } from "@waku/core"; import { createEncoder, DefaultPubsubTopic } from "@waku/core";
import { IRateLimitProof, LightNode, SendError } from "@waku/interfaces"; import { IRateLimitProof, LightNode, SendError } from "@waku/interfaces";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
@ -28,7 +28,7 @@ describe("Waku Light Push", function () {
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]); [nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
messageCollector = new MessageCollector(nwaku); messageCollector = new MessageCollector(nwaku);
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();

View File

@ -1,7 +1,7 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface/peer-id";
import { import {
createEncoder, createEncoder,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import { LightNode, Protocols, SendResult } from "@waku/interfaces"; import { LightNode, Protocols, SendResult } from "@waku/interfaces";
@ -22,25 +22,25 @@ import {
TestEncoder TestEncoder
} from "./utils.js"; } 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: NimGoNode;
let nwaku2: NimGoNode; let nwaku2: NimGoNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
const customPubSubTopic = "/waku/2/custom-dapp/proto"; const customPubsubTopic = "/waku/2/custom-dapp/proto";
const customContentTopic = "/test/2/waku-light-push/utf8"; const customContentTopic = "/test/2/waku-light-push/utf8";
const customEncoder = createEncoder({ const customEncoder = createEncoder({
contentTopic: customContentTopic, contentTopic: customContentTopic,
pubsubTopic: customPubSubTopic pubsubTopic: customPubsubTopic
}); });
let nimPeerId: PeerId; let nimPeerId: PeerId;
this.beforeEach(async function () { this.beforeEach(async function () {
this.timeout(15000); this.timeout(15000);
[nwaku, waku] = await runNodes(this, [ [nwaku, waku] = await runNodes(this, [
customPubSubTopic, customPubsubTopic,
DefaultPubSubTopic DefaultPubsubTopic
]); ]);
messageCollector = new MessageCollector(nwaku); messageCollector = new MessageCollector(nwaku);
nimPeerId = await nwaku.getPeerId(); nimPeerId = await nwaku.getPeerId();
@ -60,7 +60,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
expect( expect(
await messageCollector.waitForMessages(1, { await messageCollector.waitForMessages(1, {
pubsubTopic: customPubSubTopic pubsubTopic: customPubsubTopic
}) })
).to.eq(true); ).to.eq(true);
messageCollector.verifyReceivedMessage(0, { messageCollector.verifyReceivedMessage(0, {
@ -83,38 +83,38 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
expect( expect(
await messageCollector.waitForMessages(1, { await messageCollector.waitForMessages(1, {
pubsubTopic: customPubSubTopic pubsubTopic: customPubsubTopic
}) })
).to.eq(true); ).to.eq(true);
expect( expect(
await messageCollector2.waitForMessages(1, { await messageCollector2.waitForMessages(1, {
pubsubTopic: DefaultPubSubTopic pubsubTopic: DefaultPubsubTopic
}) })
).to.eq(true); ).to.eq(true);
messageCollector.verifyReceivedMessage(0, { messageCollector.verifyReceivedMessage(0, {
expectedMessageText: "M1", expectedMessageText: "M1",
expectedContentTopic: customContentTopic, expectedContentTopic: customContentTopic,
expectedPubSubTopic: customPubSubTopic expectedPubsubTopic: customPubsubTopic
}); });
messageCollector2.verifyReceivedMessage(0, { messageCollector2.verifyReceivedMessage(0, {
expectedMessageText: "M2", expectedMessageText: "M2",
expectedContentTopic: TestContentTopic, expectedContentTopic: TestContentTopic,
expectedPubSubTopic: DefaultPubSubTopic expectedPubsubTopic: DefaultPubsubTopic
}); });
}); });
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 NimGoNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
relay: true, relay: true,
topic: [DefaultPubSubTopic] topic: [DefaultPubsubTopic]
}); });
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]); await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
await waku.dial(await nwaku2.getMultiaddrWithId()); await waku.dial(await nwaku2.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.LightPush]); await waitForRemotePeer(waku, [Protocols.LightPush]);
@ -126,10 +126,10 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
// While loop is done because of https://github.com/waku-org/js-waku/issues/1606 // While loop is done because of https://github.com/waku-org/js-waku/issues/1606
while ( while (
!(await messageCollector.waitForMessages(1, { !(await messageCollector.waitForMessages(1, {
pubsubTopic: customPubSubTopic pubsubTopic: customPubsubTopic
})) || })) ||
!(await messageCollector2.waitForMessages(1, { !(await messageCollector2.waitForMessages(1, {
pubsubTopic: DefaultPubSubTopic pubsubTopic: DefaultPubsubTopic
})) || })) ||
pushResponse1!.recipients[0].toString() === pushResponse1!.recipients[0].toString() ===
pushResponse2!.recipients[0].toString() pushResponse2!.recipients[0].toString()
@ -145,12 +145,12 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
messageCollector.verifyReceivedMessage(0, { messageCollector.verifyReceivedMessage(0, {
expectedMessageText: "M1", expectedMessageText: "M1",
expectedContentTopic: customContentTopic, expectedContentTopic: customContentTopic,
expectedPubSubTopic: customPubSubTopic expectedPubsubTopic: customPubsubTopic
}); });
messageCollector2.verifyReceivedMessage(0, { messageCollector2.verifyReceivedMessage(0, {
expectedMessageText: "M2", expectedMessageText: "M2",
expectedContentTopic: TestContentTopic, expectedContentTopic: TestContentTopic,
expectedPubSubTopic: DefaultPubSubTopic expectedPubsubTopic: DefaultPubsubTopic
}); });
}); });
}); });

View File

@ -1,7 +1,7 @@
import type { PeerId } from "@libp2p/interface/peer-id"; import type { PeerId } from "@libp2p/interface/peer-id";
import { import {
DecodedMessage, DecodedMessage,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import { RelayNode } from "@waku/interfaces"; import { RelayNode } from "@waku/interfaces";
@ -55,7 +55,7 @@ describe("Waku Relay, Interop", function () {
while (subscribers.length === 0) { while (subscribers.length === 0) {
await delay(200); await delay(200);
subscribers = subscribers =
waku.libp2p.services.pubsub!.getSubscribers(DefaultPubSubTopic); waku.libp2p.services.pubsub!.getSubscribers(DefaultPubsubTopic);
} }
const nimPeerId = await nwaku.getPeerId(); const nimPeerId = await nwaku.getPeerId();

View File

@ -1,6 +1,6 @@
import { import {
DecodedMessage, DecodedMessage,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import { RelayNode } from "@waku/interfaces"; import { RelayNode } from "@waku/interfaces";
@ -21,7 +21,7 @@ import {
CustomContentTopic, CustomContentTopic,
CustomDecoder, CustomDecoder,
CustomEncoder, CustomEncoder,
CustomPubSubTopic, CustomPubsubTopic,
TestContentTopic, TestContentTopic,
TestDecoder, TestDecoder,
TestEncoder TestEncoder
@ -40,12 +40,12 @@ describe("Waku Relay, multiple pubsub topics", function () {
[ [
{ {
pubsub: CustomPubSubTopic, pubsub: CustomPubsubTopic,
encoder: CustomEncoder, encoder: CustomEncoder,
decoder: CustomDecoder decoder: CustomDecoder
}, },
{ {
pubsub: DefaultPubSubTopic, pubsub: DefaultPubsubTopic,
encoder: TestEncoder, encoder: TestEncoder,
decoder: TestDecoder decoder: TestDecoder
} }
@ -155,16 +155,16 @@ describe("Waku Relay, multiple pubsub topics", function () {
// Waku1 and waku2 are using multiple pubsub topis // Waku1 and waku2 are using multiple pubsub topis
[waku1, waku2, waku3] = await Promise.all([ [waku1, waku2, waku3] = await Promise.all([
createRelayNode({ createRelayNode({
pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic], pubsubTopics: [DefaultPubsubTopic, CustomPubsubTopic],
staticNoiseKey: NOISE_KEY_1 staticNoiseKey: NOISE_KEY_1
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createRelayNode({ createRelayNode({
pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic], pubsubTopics: [DefaultPubsubTopic, CustomPubsubTopic],
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createRelayNode({ createRelayNode({
pubsubTopics: [DefaultPubSubTopic], pubsubTopics: [DefaultPubsubTopic],
staticNoiseKey: NOISE_KEY_3 staticNoiseKey: NOISE_KEY_3
}).then((waku) => waku.start().then(() => waku)) }).then((waku) => waku.start().then(() => waku))
]); ]);
@ -197,7 +197,7 @@ describe("Waku Relay, multiple pubsub topics", function () {
await waku3.relay.subscribe([TestDecoder], msgCollector3.callback); await waku3.relay.subscribe([TestDecoder], msgCollector3.callback);
// The nodes are setup in such a way that all messages send should be relayed to the other nodes in the network // The nodes are setup in such a way that all messages send should be relayed to the other nodes in the network
// However onlt waku1 and waku2 are receiving messages on the CustomPubSubTopic // However onlt waku1 and waku2 are receiving messages on the CustomPubsubTopic
await waku1.relay.send(TestEncoder, { payload: utf8ToBytes("M1") }); await waku1.relay.send(TestEncoder, { payload: utf8ToBytes("M1") });
await waku1.relay.send(CustomEncoder, { payload: utf8ToBytes("M2") }); await waku1.relay.send(CustomEncoder, { payload: utf8ToBytes("M2") });
await waku2.relay.send(TestEncoder, { payload: utf8ToBytes("M3") }); await waku2.relay.send(TestEncoder, { payload: utf8ToBytes("M3") });
@ -221,11 +221,11 @@ describe("Waku Relay, multiple pubsub topics", function () {
it("n1 and n2 uses a custom pubsub, n3 uses the default pubsub", async function () { it("n1 and n2 uses a custom pubsub, n3 uses the default pubsub", async function () {
[waku1, waku2, waku3] = await Promise.all([ [waku1, waku2, waku3] = await Promise.all([
createRelayNode({ createRelayNode({
pubsubTopics: [CustomPubSubTopic], pubsubTopics: [CustomPubsubTopic],
staticNoiseKey: NOISE_KEY_1 staticNoiseKey: NOISE_KEY_1
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createRelayNode({ createRelayNode({
pubsubTopics: [CustomPubSubTopic], pubsubTopics: [CustomPubsubTopic],
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
@ -275,6 +275,6 @@ describe("Waku Relay, multiple pubsub topics", function () {
await waku3NoMsgPromise; await waku3NoMsgPromise;
expect(bytesToUtf8(waku2ReceivedMsg.payload!)).to.eq(messageText); expect(bytesToUtf8(waku2ReceivedMsg.payload!)).to.eq(messageText);
expect(waku2ReceivedMsg.pubsubTopic).to.eq(CustomPubSubTopic); expect(waku2ReceivedMsg.pubsubTopic).to.eq(CustomPubsubTopic);
}); });
}); });

View File

@ -1,4 +1,4 @@
import { createEncoder, DefaultPubSubTopic } from "@waku/core"; import { createEncoder, DefaultPubsubTopic } from "@waku/core";
import { IRateLimitProof, RelayNode, SendError } from "@waku/interfaces"; import { IRateLimitProof, RelayNode, SendError } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk"; import { createRelayNode } from "@waku/sdk";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";
@ -34,11 +34,11 @@ describe("Waku Relay, Publish", function () {
log.info("Starting JS Waku instances"); log.info("Starting JS Waku instances");
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ createRelayNode({
pubsubTopics: [DefaultPubSubTopic], pubsubTopics: [DefaultPubsubTopic],
staticNoiseKey: NOISE_KEY_1 staticNoiseKey: NOISE_KEY_1
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createRelayNode({ createRelayNode({
pubsubTopics: [DefaultPubSubTopic], pubsubTopics: [DefaultPubsubTopic],
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
}).then((waku) => waku.start().then(() => waku)) }).then((waku) => waku.start().then(() => waku))

View File

@ -1,4 +1,4 @@
import { createDecoder, createEncoder, DefaultPubSubTopic } from "@waku/core"; import { createDecoder, createEncoder, DefaultPubsubTopic } from "@waku/core";
import { RelayNode } from "@waku/interfaces"; import { RelayNode } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk"; import { createRelayNode } from "@waku/sdk";
import { utf8ToBytes } from "@waku/utils/bytes"; import { utf8ToBytes } from "@waku/utils/bytes";
@ -33,11 +33,11 @@ describe("Waku Relay, Subscribe", function () {
log.info("Starting JS Waku instances"); log.info("Starting JS Waku instances");
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ createRelayNode({
pubsubTopics: [DefaultPubSubTopic], pubsubTopics: [DefaultPubsubTopic],
staticNoiseKey: NOISE_KEY_1 staticNoiseKey: NOISE_KEY_1
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createRelayNode({ createRelayNode({
pubsubTopics: [DefaultPubSubTopic], pubsubTopics: [DefaultPubsubTopic],
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
}).then((waku) => waku.start().then(() => waku)) }).then((waku) => waku.start().then(() => waku))
@ -59,10 +59,10 @@ describe("Waku Relay, Subscribe", function () {
it("Mutual subscription", async function () { it("Mutual subscription", async function () {
await waitForAllRemotePeers(waku1, waku2); await waitForAllRemotePeers(waku1, waku2);
const subscribers1 = waku1.libp2p.services const subscribers1 = waku1.libp2p.services
.pubsub!.getSubscribers(DefaultPubSubTopic) .pubsub!.getSubscribers(DefaultPubsubTopic)
.map((p) => p.toString()); .map((p) => p.toString());
const subscribers2 = waku2.libp2p.services const subscribers2 = waku2.libp2p.services
.pubsub!.getSubscribers(DefaultPubSubTopic) .pubsub!.getSubscribers(DefaultPubsubTopic)
.map((p) => p.toString()); .map((p) => p.toString());
expect(subscribers1).to.contain(waku2.libp2p.peerId.toString()); expect(subscribers1).to.contain(waku2.libp2p.peerId.toString());

View File

@ -7,14 +7,14 @@ export const TestContentTopic = "/test/1/waku-relay/utf8";
export const TestEncoder = createEncoder({ contentTopic: TestContentTopic }); export const TestEncoder = createEncoder({ contentTopic: TestContentTopic });
export const TestDecoder = createDecoder(TestContentTopic); export const TestDecoder = createDecoder(TestContentTopic);
export const CustomContentTopic = "/test/2/waku-relay/utf8"; export const CustomContentTopic = "/test/2/waku-relay/utf8";
export const CustomPubSubTopic = "/some/pubsub/topic"; export const CustomPubsubTopic = "/some/pubsub/topic";
export const CustomEncoder = createEncoder({ export const CustomEncoder = createEncoder({
contentTopic: CustomContentTopic, contentTopic: CustomContentTopic,
pubsubTopic: CustomPubSubTopic pubsubTopic: CustomPubsubTopic
}); });
export const CustomDecoder = createDecoder( export const CustomDecoder = createDecoder(
CustomContentTopic, CustomContentTopic,
CustomPubSubTopic CustomPubsubTopic
); );
export const log = new Logger("test:relay"); export const log = new Logger("test:relay");

View File

@ -107,12 +107,12 @@ describe("Static Sharding: Peer Management", function () {
it("px service nodes not subscribed to the shard should not be dialed", async function () { it("px service nodes not subscribed to the shard should not be dialed", async function () {
this.timeout(100_000); this.timeout(100_000);
const pubSubTopicsToDial = ["/waku/2/rs/18/2"]; const pubsubTopicsToDial = ["/waku/2/rs/18/2"];
const pubSubTopicsToIgnore = ["/waku/2/rs/18/3"]; const pubsubTopicsToIgnore = ["/waku/2/rs/18/3"];
// this service node is not subscribed to the shard // this service node is not subscribed to the shard
await nwaku1.start({ await nwaku1.start({
topic: pubSubTopicsToIgnore, topic: pubsubTopicsToIgnore,
relay: true, relay: true,
discv5Discovery: true, discv5Discovery: true,
peerExchange: true peerExchange: true
@ -121,7 +121,7 @@ describe("Static Sharding: Peer Management", function () {
const enr1 = (await nwaku1.info()).enrUri; const enr1 = (await nwaku1.info()).enrUri;
await nwaku2.start({ await nwaku2.start({
topic: pubSubTopicsToDial, topic: pubsubTopicsToDial,
relay: true, relay: true,
discv5Discovery: true, discv5Discovery: true,
peerExchange: true, peerExchange: true,
@ -139,7 +139,7 @@ describe("Static Sharding: Peer Management", function () {
const nwaku3Ma = await nwaku3.getMultiaddrWithId(); const nwaku3Ma = await nwaku3.getMultiaddrWithId();
waku = await createLightNode({ waku = await createLightNode({
pubsubTopics: pubSubTopicsToDial, pubsubTopics: pubsubTopicsToDial,
libp2p: { libp2p: {
peerDiscovery: [ peerDiscovery: [
bootstrap({ list: [nwaku3Ma.toString()] }), bootstrap({ list: [nwaku3Ma.toString()] }),

View File

@ -6,8 +6,8 @@ import { tearDownNodes } from "../../src/index.js";
import { makeLogFileName } from "../../src/log_file.js"; import { makeLogFileName } from "../../src/log_file.js";
import { NimGoNode } from "../../src/node/node.js"; import { NimGoNode } from "../../src/node/node.js";
const PubSubTopic1 = "/waku/2/rs/0/2"; const PubsubTopic1 = "/waku/2/rs/0/2";
const PubSubTopic2 = "/waku/2/rs/0/3"; const PubsubTopic2 = "/waku/2/rs/0/3";
const ContentTopic = "/waku/2/content/test.js"; const ContentTopic = "/waku/2/content/test.js";
@ -29,17 +29,17 @@ describe("Static Sharding: Running Nodes", () => {
it("configure the node with multiple pubsub topics", async function () { it("configure the node with multiple pubsub topics", async function () {
this.timeout(15_000); this.timeout(15_000);
waku = await createLightNode({ waku = await createLightNode({
pubsubTopics: [PubSubTopic1, PubSubTopic2] pubsubTopics: [PubsubTopic1, PubsubTopic2]
}); });
const encoder1 = createEncoder({ const encoder1 = createEncoder({
contentTopic: ContentTopic, contentTopic: ContentTopic,
pubsubTopic: PubSubTopic1 pubsubTopic: PubsubTopic1
}); });
const encoder2 = createEncoder({ const encoder2 = createEncoder({
contentTopic: ContentTopic, contentTopic: ContentTopic,
pubsubTopic: PubSubTopic2 pubsubTopic: PubsubTopic2
}); });
const request1 = await waku.lightPush.send(encoder1, { const request1 = await waku.lightPush.send(encoder1, {
@ -57,13 +57,13 @@ describe("Static Sharding: Running Nodes", () => {
it("using a protocol with unconfigured pubsub topic should fail", async function () { it("using a protocol with unconfigured pubsub topic should fail", async function () {
this.timeout(15_000); this.timeout(15_000);
waku = await createLightNode({ waku = await createLightNode({
pubsubTopics: [PubSubTopic1] pubsubTopics: [PubsubTopic1]
}); });
// use a pubsub topic that is not configured // use a pubsub topic that is not configured
const encoder = createEncoder({ const encoder = createEncoder({
contentTopic: ContentTopic, contentTopic: ContentTopic,
pubsubTopic: PubSubTopic2 pubsubTopic: PubsubTopic2
}); });
try { try {
@ -75,7 +75,7 @@ describe("Static Sharding: Running Nodes", () => {
if ( if (
!(err instanceof Error) || !(err instanceof Error) ||
!err.message.includes( !err.message.includes(
`PubSub topic ${PubSubTopic2} has not been configured on this instance. Configured topics are: ${PubSubTopic1}` `Pubsub topic ${PubsubTopic2} has not been configured on this instance. Configured topics are: ${PubsubTopic1}`
) )
) { ) {
throw err; throw err;

View File

@ -1,4 +1,4 @@
import { createCursor, DecodedMessage, DefaultPubSubTopic } from "@waku/core"; import { createCursor, DecodedMessage, DefaultPubsubTopic } from "@waku/core";
import type { LightNode } from "@waku/interfaces"; import type { LightNode } from "@waku/interfaces";
import { bytesToUtf8 } from "@waku/utils/bytes"; import { bytesToUtf8 } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
@ -6,7 +6,7 @@ import { expect } from "chai";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js";
import { import {
customPubSubTopic, customPubsubTopic,
sendMessages, sendMessages,
startAndConnectLightNode, startAndConnectLightNode,
TestContentTopic, TestContentTopic,
@ -45,7 +45,7 @@ describe("Waku Store, cursor", function () {
nwaku, nwaku,
messageCount, messageCount,
TestContentTopic, TestContentTopic,
DefaultPubSubTopic DefaultPubsubTopic
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
@ -90,7 +90,7 @@ describe("Waku Store, cursor", function () {
}); });
it("Reusing cursor across nodes", async function () { it("Reusing cursor across nodes", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
waku2 = await startAndConnectLightNode(nwaku); waku2 = await startAndConnectLightNode(nwaku);
@ -128,7 +128,7 @@ describe("Waku Store, cursor", function () {
}); });
it("Passing cursor with wrong message digest", async function () { it("Passing cursor with wrong message digest", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const messages: DecodedMessage[] = []; const messages: DecodedMessage[] = [];
@ -170,7 +170,7 @@ describe("Waku Store, cursor", function () {
}); });
it("Passing cursor with wrong pubsubTopic", async function () { it("Passing cursor with wrong pubsubTopic", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const messages: DecodedMessage[] = []; const messages: DecodedMessage[] = [];
@ -179,7 +179,7 @@ describe("Waku Store, cursor", function () {
messages.push(msg as DecodedMessage); messages.push(msg as DecodedMessage);
} }
} }
messages[5].pubsubTopic = customPubSubTopic; messages[5].pubsubTopic = customPubsubTopic;
const cursor = await createCursor(messages[5]); const cursor = await createCursor(messages[5]);
try { try {
@ -193,7 +193,7 @@ describe("Waku Store, cursor", function () {
if ( if (
!(err instanceof Error) || !(err instanceof Error) ||
!err.message.includes( !err.message.includes(
`Cursor pubsub topic (${customPubSubTopic}) does not match decoder pubsub topic (${DefaultPubSubTopic})` `Cursor pubsub topic (${customPubsubTopic}) does not match decoder pubsub topic (${DefaultPubsubTopic})`
) )
) { ) {
throw err; throw err;

View File

@ -1,11 +1,11 @@
import { DefaultPubSubTopic } from "@waku/core"; import { DefaultPubsubTopic } from "@waku/core";
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, NimGoNode, tearDownNodes } from "../../src/index.js";
import { import {
customPubSubTopic, customPubsubTopic,
customTestDecoder, customTestDecoder,
processQueriedMessages, processQueriedMessages,
startAndConnectLightNode, startAndConnectLightNode,
@ -30,7 +30,7 @@ describe("Waku Store, error handling", function () {
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });
it("Query Generator, Wrong PubSubTopic", async function () { it("Query Generator, Wrong PubsubTopic", async function () {
try { try {
for await (const msgPromises of waku.store.queryGenerator([ for await (const msgPromises of waku.store.queryGenerator([
customTestDecoder customTestDecoder
@ -42,7 +42,7 @@ describe("Waku Store, error handling", function () {
if ( if (
!(err instanceof Error) || !(err instanceof Error) ||
!err.message.includes( !err.message.includes(
`PubSub topic ${customPubSubTopic} has not been configured on this instance. Configured topics are: ${DefaultPubSubTopic}` `Pubsub topic ${customPubsubTopic} has not been configured on this instance. Configured topics are: ${DefaultPubsubTopic}`
) )
) { ) {
throw err; throw err;
@ -50,7 +50,7 @@ describe("Waku Store, error handling", function () {
} }
}); });
it("Query Generator, Multiple PubSubTopics", async function () { it("Query Generator, Multiple PubsubTopics", async function () {
try { try {
for await (const msgPromises of waku.store.queryGenerator([ for await (const msgPromises of waku.store.queryGenerator([
TestDecoder, TestDecoder,
@ -91,12 +91,12 @@ describe("Waku Store, error handling", function () {
const messages = await processQueriedMessages( const messages = await processQueriedMessages(
waku, waku,
[TestDecoder], [TestDecoder],
DefaultPubSubTopic DefaultPubsubTopic
); );
expect(messages?.length).eq(0); expect(messages?.length).eq(0);
}); });
it("Query with Ordered Callback, Wrong PubSubTopic", async function () { it("Query with Ordered Callback, Wrong PubsubTopic", async function () {
try { try {
await waku.store.queryWithOrderedCallback( await waku.store.queryWithOrderedCallback(
[customTestDecoder], [customTestDecoder],
@ -107,7 +107,7 @@ describe("Waku Store, error handling", function () {
if ( if (
!(err instanceof Error) || !(err instanceof Error) ||
!err.message.includes( !err.message.includes(
`PubSub topic ${customPubSubTopic} has not been configured on this instance. Configured topics are: ${DefaultPubSubTopic}` `Pubsub topic ${customPubsubTopic} has not been configured on this instance. Configured topics are: ${DefaultPubsubTopic}`
) )
) { ) {
throw err; throw err;
@ -115,7 +115,7 @@ describe("Waku Store, error handling", function () {
} }
}); });
it("Query with Ordered Callback, Multiple PubSubTopics", async function () { it("Query with Ordered Callback, Multiple PubsubTopics", async function () {
try { try {
await waku.store.queryWithOrderedCallback( await waku.store.queryWithOrderedCallback(
[TestDecoder, customTestDecoder], [TestDecoder, customTestDecoder],
@ -156,7 +156,7 @@ describe("Waku Store, error handling", function () {
expect(messages?.length).eq(0); expect(messages?.length).eq(0);
}); });
it("Query with Promise Callback, Wrong PubSubTopic", async function () { it("Query with Promise Callback, Wrong PubsubTopic", async function () {
try { try {
await waku.store.queryWithPromiseCallback( await waku.store.queryWithPromiseCallback(
[customTestDecoder], [customTestDecoder],
@ -167,7 +167,7 @@ describe("Waku Store, error handling", function () {
if ( if (
!(err instanceof Error) || !(err instanceof Error) ||
!err.message.includes( !err.message.includes(
`PubSub topic ${customPubSubTopic} has not been configured on this instance. Configured topics are: ${DefaultPubSubTopic}` `Pubsub topic ${customPubsubTopic} has not been configured on this instance. Configured topics are: ${DefaultPubsubTopic}`
) )
) { ) {
throw err; throw err;
@ -175,7 +175,7 @@ describe("Waku Store, error handling", function () {
} }
}); });
it("Query with Promise Callback, Multiple PubSubTopics", async function () { it("Query with Promise Callback, Multiple PubsubTopics", async function () {
try { try {
await waku.store.queryWithPromiseCallback( await waku.store.queryWithPromiseCallback(
[TestDecoder, customTestDecoder], [TestDecoder, customTestDecoder],

View File

@ -1,7 +1,7 @@
import { import {
createDecoder, createDecoder,
DecodedMessage, DecodedMessage,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces"; import type { IMessage, LightNode } from "@waku/interfaces";
@ -43,7 +43,7 @@ import {
totalMsgs totalMsgs
} from "./utils.js"; } from "./utils.js";
const secondDecoder = createDecoder(customContentTopic, DefaultPubSubTopic); const secondDecoder = createDecoder(customContentTopic, DefaultPubsubTopic);
describe("Waku Store, general", function () { describe("Waku Store, general", function () {
this.timeout(15000); this.timeout(15000);
@ -64,12 +64,12 @@ describe("Waku Store, general", function () {
}); });
it("Query generator for multiple messages", async function () { it("Query generator for multiple messages", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const messages = await processQueriedMessages( const messages = await processQueriedMessages(
waku, waku,
[TestDecoder], [TestDecoder],
DefaultPubSubTopic DefaultPubsubTopic
); );
expect(messages?.length).eq(totalMsgs); expect(messages?.length).eq(totalMsgs);
@ -89,7 +89,7 @@ describe("Waku Store, general", function () {
payload: utf8ToBytes(testItem["value"]), payload: utf8ToBytes(testItem["value"]),
contentTopic: TestContentTopic contentTopic: TestContentTopic
}), }),
DefaultPubSubTopic DefaultPubsubTopic
) )
).to.eq(true); ).to.eq(true);
await delay(1); // to ensure each timestamp is unique. await delay(1); // to ensure each timestamp is unique.
@ -100,7 +100,7 @@ describe("Waku Store, general", function () {
messageCollector.list = await processQueriedMessages( messageCollector.list = await processQueriedMessages(
waku, waku,
[TestDecoder], [TestDecoder],
DefaultPubSubTopic DefaultPubsubTopic
); );
// checking that all message sent were retrieved // checking that all message sent were retrieved
@ -117,14 +117,14 @@ describe("Waku Store, general", function () {
payload: utf8ToBytes("M1"), payload: utf8ToBytes("M1"),
contentTopic: TestContentTopic contentTopic: TestContentTopic
}), }),
DefaultPubSubTopic DefaultPubsubTopic
); );
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: utf8ToBytes("M2"), payload: utf8ToBytes("M2"),
contentTopic: customContentTopic contentTopic: customContentTopic
}), }),
DefaultPubSubTopic DefaultPubsubTopic
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
@ -132,7 +132,7 @@ describe("Waku Store, general", function () {
messageCollector.list = await processQueriedMessages( messageCollector.list = await processQueriedMessages(
waku, waku,
[TestDecoder, secondDecoder], [TestDecoder, secondDecoder],
DefaultPubSubTopic DefaultPubsubTopic
); );
expect(messageCollector.hasMessage(TestContentTopic, "M1")).to.eq(true); expect(messageCollector.hasMessage(TestContentTopic, "M1")).to.eq(true);
expect(messageCollector.hasMessage(customContentTopic, "M2")).to.eq(true); expect(messageCollector.hasMessage(customContentTopic, "M2")).to.eq(true);
@ -146,7 +146,7 @@ describe("Waku Store, general", function () {
payload: utf8ToBytes(messageText), payload: utf8ToBytes(messageText),
contentTopic: testItem["value"] contentTopic: testItem["value"]
}), }),
DefaultPubSubTopic DefaultPubsubTopic
) )
).to.eq(true); ).to.eq(true);
await delay(1); // to ensure each timestamp is unique. await delay(1); // to ensure each timestamp is unique.
@ -166,7 +166,7 @@ describe("Waku Store, general", function () {
}); });
it("Callback on promise", async function () { it("Callback on promise", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const messages: IMessage[] = []; const messages: IMessage[] = [];
@ -188,7 +188,7 @@ describe("Waku Store, general", function () {
}); });
it("Callback on promise, aborts when callback returns true", async function () { it("Callback on promise, aborts when callback returns true", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const desiredMsgs = 14; const desiredMsgs = 14;
@ -301,7 +301,7 @@ describe("Waku Store, general", function () {
}); });
it("Ordered callback, aborts when callback returns true", async function () { it("Ordered callback, aborts when callback returns true", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const desiredMsgs = 14; const desiredMsgs = 14;
@ -320,12 +320,12 @@ describe("Waku Store, general", function () {
it("Query generator for 2000 messages", async function () { it("Query generator for 2000 messages", async function () {
this.timeout(40000); this.timeout(40000);
await sendMessages(nwaku, 2000, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, 2000, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
const messages = await processQueriedMessages( const messages = await processQueriedMessages(
waku, waku,
[TestDecoder], [TestDecoder],
DefaultPubSubTopic DefaultPubsubTopic
); );
expect(messages?.length).eq(2000); expect(messages?.length).eq(2000);

View File

@ -1,4 +1,4 @@
import { DefaultPubSubTopic, waitForRemotePeer } from "@waku/core"; import { DefaultPubsubTopic, waitForRemotePeer } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces"; import type { IMessage, LightNode } from "@waku/interfaces";
import { createLightNode, Protocols } from "@waku/sdk"; import { createLightNode, Protocols } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
@ -12,7 +12,7 @@ import {
import { import {
customContentTopic, customContentTopic,
customPubSubTopic, customPubsubTopic,
customTestDecoder, customTestDecoder,
processQueriedMessages, processQueriedMessages,
sendMessages, sendMessages,
@ -33,10 +33,10 @@ describe("Waku Store, custom pubsub topic", function () {
nwaku = new NimGoNode(makeLogFileName(this)); nwaku = new NimGoNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
topic: [customPubSubTopic, DefaultPubSubTopic], topic: [customPubsubTopic, DefaultPubsubTopic],
relay: true relay: true
}); });
await nwaku.ensureSubscriptions([customPubSubTopic, DefaultPubSubTopic]); await nwaku.ensureSubscriptions([customPubsubTopic, DefaultPubsubTopic]);
}); });
afterEach(async function () { afterEach(async function () {
@ -45,12 +45,12 @@ describe("Waku Store, custom pubsub topic", function () {
}); });
it("Generator, custom pubsub topic", async function () { it("Generator, custom pubsub topic", async function () {
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubSubTopic); await sendMessages(nwaku, totalMsgs, customContentTopic, customPubsubTopic);
waku = await startAndConnectLightNode(nwaku, [customPubSubTopic]); waku = await startAndConnectLightNode(nwaku, [customPubsubTopic]);
const messages = await processQueriedMessages( const messages = await processQueriedMessages(
waku, waku,
[customTestDecoder], [customTestDecoder],
customPubSubTopic customPubsubTopic
); );
expect(messages?.length).eq(totalMsgs); expect(messages?.length).eq(totalMsgs);
@ -64,18 +64,18 @@ describe("Waku Store, custom pubsub topic", function () {
this.timeout(10000); this.timeout(10000);
const totalMsgs = 10; const totalMsgs = 10;
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubSubTopic); await sendMessages(nwaku, totalMsgs, customContentTopic, customPubsubTopic);
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku, [ waku = await startAndConnectLightNode(nwaku, [
customPubSubTopic, customPubsubTopic,
DefaultPubSubTopic DefaultPubsubTopic
]); ]);
const customMessages = await processQueriedMessages( const customMessages = await processQueriedMessages(
waku, waku,
[customTestDecoder], [customTestDecoder],
customPubSubTopic customPubsubTopic
); );
expect(customMessages?.length).eq(totalMsgs); expect(customMessages?.length).eq(totalMsgs);
const result1 = customMessages?.findIndex((msg) => { const result1 = customMessages?.findIndex((msg) => {
@ -86,7 +86,7 @@ describe("Waku Store, custom pubsub topic", function () {
const testMessages = await processQueriedMessages( const testMessages = await processQueriedMessages(
waku, waku,
[TestDecoder], [TestDecoder],
DefaultPubSubTopic DefaultPubsubTopic
); );
expect(testMessages?.length).eq(totalMsgs); expect(testMessages?.length).eq(totalMsgs);
const result2 = testMessages?.findIndex((msg) => { const result2 = testMessages?.findIndex((msg) => {
@ -98,22 +98,22 @@ describe("Waku Store, custom pubsub topic", function () {
it("Generator, 2 nwaku nodes each with different pubsubtopics", async function () { it("Generator, 2 nwaku nodes each with different pubsubtopics", async 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 NimGoNode(makeLogFileName(this) + "2");
await nwaku2.start({ await nwaku2.start({
store: true, store: true,
topic: [DefaultPubSubTopic], topic: [DefaultPubsubTopic],
relay: true relay: true
}); });
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]); await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
const totalMsgs = 10; const totalMsgs = 10;
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubSubTopic); await sendMessages(nwaku, totalMsgs, customContentTopic, customPubsubTopic);
await sendMessages(nwaku2, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku2, totalMsgs, TestContentTopic, DefaultPubsubTopic);
waku = await createLightNode({ waku = await createLightNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
pubsubTopics: [customPubSubTopic, DefaultPubSubTopic] pubsubTopics: [customPubsubTopic, DefaultPubsubTopic]
}); });
await waku.start(); await waku.start();
@ -131,12 +131,12 @@ describe("Waku Store, custom pubsub topic", function () {
customMessages = await processQueriedMessages( customMessages = await processQueriedMessages(
waku, waku,
[customTestDecoder], [customTestDecoder],
customPubSubTopic customPubsubTopic
); );
testMessages = await processQueriedMessages( testMessages = await processQueriedMessages(
waku, waku,
[TestDecoder], [TestDecoder],
DefaultPubSubTopic DefaultPubsubTopic
); );
} }
}); });

View File

@ -1,4 +1,4 @@
import { DecodedMessage, DefaultPubSubTopic, PageDirection } from "@waku/core"; import { DecodedMessage, DefaultPubsubTopic, PageDirection } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces"; import type { IMessage, LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
@ -36,7 +36,7 @@ describe("Waku Store, order", function () {
nwaku, nwaku,
totalMsgs, totalMsgs,
TestContentTopic, TestContentTopic,
DefaultPubSubTopic DefaultPubsubTopic
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
@ -68,7 +68,7 @@ describe("Waku Store, order", function () {
nwaku, nwaku,
totalMsgs, totalMsgs,
TestContentTopic, TestContentTopic,
DefaultPubSubTopic DefaultPubsubTopic
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
@ -103,7 +103,7 @@ describe("Waku Store, order", function () {
nwaku, nwaku,
totalMsgs, totalMsgs,
TestContentTopic, TestContentTopic,
DefaultPubSubTopic DefaultPubsubTopic
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);

View File

@ -1,4 +1,4 @@
import { DefaultPubSubTopic } from "@waku/core"; import { DefaultPubsubTopic } from "@waku/core";
import type { LightNode } from "@waku/interfaces"; import type { LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
@ -42,7 +42,7 @@ describe("Waku Store, page size", function () {
nwaku, nwaku,
messageCount, messageCount,
TestContentTopic, TestContentTopic,
DefaultPubSubTopic DefaultPubsubTopic
); );
// Determine effectivePageSize for test expectations // Determine effectivePageSize for test expectations
@ -82,7 +82,7 @@ describe("Waku Store, page size", function () {
// Possible issue here because pageSize differs across implementations // Possible issue here because pageSize differs across implementations
it("Default pageSize", async function () { it("Default pageSize", async function () {
await sendMessages(nwaku, 20, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, 20, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
let messagesRetrieved = 0; let messagesRetrieved = 0;

View File

@ -1,4 +1,4 @@
import { DecodedMessage, DefaultPubSubTopic, PageDirection } from "@waku/core"; import { DecodedMessage, DefaultPubsubTopic, PageDirection } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces"; import type { IMessage, LightNode } from "@waku/interfaces";
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js"; import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js";
@ -34,7 +34,7 @@ describe("Waku Store, sorting", function () {
nwaku, nwaku,
totalMsgs, totalMsgs,
TestContentTopic, TestContentTopic,
DefaultPubSubTopic DefaultPubsubTopic
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
@ -69,7 +69,7 @@ describe("Waku Store, sorting", function () {
nwaku, nwaku,
totalMsgs, totalMsgs,
TestContentTopic, TestContentTopic,
DefaultPubSubTopic DefaultPubsubTopic
); );
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);

View File

@ -3,7 +3,7 @@ import {
createEncoder, createEncoder,
DecodedMessage, DecodedMessage,
Decoder, Decoder,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import { LightNode, Protocols } from "@waku/interfaces"; import { LightNode, Protocols } from "@waku/interfaces";
@ -19,10 +19,10 @@ export const TestContentTopic = "/test/1/waku-store/utf8";
export const TestEncoder = createEncoder({ contentTopic: TestContentTopic }); export const TestEncoder = createEncoder({ contentTopic: TestContentTopic });
export const TestDecoder = createDecoder(TestContentTopic); export const TestDecoder = createDecoder(TestContentTopic);
export const customContentTopic = "/test/2/waku-store/utf8"; export const customContentTopic = "/test/2/waku-store/utf8";
export const customPubSubTopic = "/waku/2/custom-dapp/proto"; export const customPubsubTopic = "/waku/2/custom-dapp/proto";
export const customTestDecoder = createDecoder( export const customTestDecoder = createDecoder(
customContentTopic, customContentTopic,
customPubSubTopic customPubsubTopic
); );
export const totalMsgs = 20; export const totalMsgs = 20;
export const messageText = "Store Push works!"; export const messageText = "Store Push works!";
@ -66,7 +66,7 @@ export async function processQueriedMessages(
export async function startAndConnectLightNode( export async function startAndConnectLightNode(
instance: NimGoNode, instance: NimGoNode,
pubsubTopics: string[] = [DefaultPubSubTopic] pubsubTopics: string[] = [DefaultPubsubTopic]
): Promise<LightNode> { ): Promise<LightNode> {
const waku = await createLightNode({ const waku = await createLightNode({
pubsubTopics: pubsubTopics, pubsubTopics: pubsubTopics,

View File

@ -4,7 +4,7 @@ import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { import {
createDecoder, createDecoder,
createEncoder, createEncoder,
DefaultPubSubTopic, DefaultPubsubTopic,
waitForRemotePeer waitForRemotePeer
} from "@waku/core"; } from "@waku/core";
import { LightNode } from "@waku/interfaces"; import { LightNode } from "@waku/interfaces";
@ -70,7 +70,7 @@ describe("Util: toAsyncIterator: Filter", () => {
const { value } = await iterator.next(); const { value } = await iterator.next();
expect(value.contentTopic).to.eq(TestContentTopic); expect(value.contentTopic).to.eq(TestContentTopic);
expect(value.pubsubTopic).to.eq(DefaultPubSubTopic); expect(value.pubsubTopic).to.eq(DefaultPubsubTopic);
expect(bytesToUtf8(value.payload)).to.eq(messageText); expect(bytesToUtf8(value.payload)).to.eq(messageText);
}); });

View File

@ -1,4 +1,4 @@
import { DefaultPubSubTopic, waitForRemotePeer } from "@waku/core"; import { DefaultPubsubTopic, waitForRemotePeer } from "@waku/core";
import type { LightNode, RelayNode } from "@waku/interfaces"; import type { LightNode, RelayNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { createLightNode, createRelayNode } from "@waku/sdk"; import { createLightNode, createRelayNode } from "@waku/sdk";
@ -40,7 +40,7 @@ describe("Wait for remote peer", function () {
await waku1.dial(multiAddrWithId); await waku1.dial(multiAddrWithId);
await delay(1000); await delay(1000);
await waitForRemotePeer(waku1, [Protocols.Relay]); await waitForRemotePeer(waku1, [Protocols.Relay]);
const peers = waku1.relay.getMeshPeers(DefaultPubSubTopic); const peers = waku1.relay.getMeshPeers(DefaultPubsubTopic);
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();
expect(nimPeerId).to.not.be.undefined; expect(nimPeerId).to.not.be.undefined;
@ -263,7 +263,7 @@ describe("Wait for remote peer", function () {
await waku1.dial(multiAddrWithId); await waku1.dial(multiAddrWithId);
await waitForRemotePeer(waku1); await waitForRemotePeer(waku1);
const peers = waku1.relay.getMeshPeers(DefaultPubSubTopic); const peers = waku1.relay.getMeshPeers(DefaultPubsubTopic);
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();

View File

@ -1,20 +1,20 @@
import type { PubSubTopic, ShardInfo } from "@waku/interfaces"; import type { PubsubTopic, ShardInfo } from "@waku/interfaces";
export const shardInfoToPubSubTopics = ( export const shardInfoToPubsubTopics = (
shardInfo: ShardInfo shardInfo: ShardInfo
): PubSubTopic[] => { ): PubsubTopic[] => {
return shardInfo.indexList.map( return shardInfo.indexList.map(
(index) => `/waku/2/rs/${shardInfo.cluster}/${index}` (index) => `/waku/2/rs/${shardInfo.cluster}/${index}`
); );
}; };
export function ensurePubsubTopicIsConfigured( export function ensurePubsubTopicIsConfigured(
pubsubTopic: PubSubTopic, pubsubTopic: PubsubTopic,
configuredTopics: PubSubTopic[] configuredTopics: PubsubTopic[]
): void { ): void {
if (!configuredTopics.includes(pubsubTopic)) { if (!configuredTopics.includes(pubsubTopic)) {
throw new Error( throw new Error(
`PubSub topic ${pubsubTopic} has not been configured on this instance. Configured topics are: ${configuredTopics}. Please update your configuration by passing in the topic during Waku node instantiation.` `Pubsub topic ${pubsubTopic} has not been configured on this instance. Configured topics are: ${configuredTopics}. Please update your configuration by passing in the topic during Waku node instantiation.`
); );
} }
} }