mirror of https://github.com/waku-org/js-waku.git
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:
parent
535a748ae9
commit
3166a5135e
|
@ -123,7 +123,7 @@
|
|||
"Привет",
|
||||
"مرحبا"
|
||||
],
|
||||
"flagWords": ["pubSub", "pubSubTopics", "pubSubTopic"],
|
||||
"flagWords": ["pubSub: pubsub", "pubSubTopics: pubsubTopics", "pubSubTopic: pubsubTopic", "PubSub: Pubsub", "PubSubTopics: PubsubTopics", "PubSubTopic: PubsubTopic", "DefaultPubSubTopic: DefaultPubsubTopic"],
|
||||
"ignorePaths": [
|
||||
"package.json",
|
||||
"package-lock.json",
|
||||
|
|
|
@ -72,7 +72,8 @@
|
|||
"@typescript-eslint/no-floating-promises": "error",
|
||||
"@typescript-eslint/await-thenable": "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": [
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 type {
|
||||
Encoder,
|
||||
|
|
|
@ -12,11 +12,11 @@ import {
|
|||
IRelay,
|
||||
KeepAliveOptions,
|
||||
PeersByDiscoveryResult,
|
||||
PubSubTopic,
|
||||
PubsubTopic,
|
||||
ShardInfo
|
||||
} 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 { KeepAliveManager } from "./keep_alive_manager.js";
|
||||
|
@ -45,7 +45,7 @@ export class ConnectionManager
|
|||
peerId: string,
|
||||
libp2p: Libp2p,
|
||||
keepAliveOptions: KeepAliveOptions,
|
||||
pubsubTopics: PubSubTopic[],
|
||||
pubsubTopics: PubsubTopic[],
|
||||
relay?: IRelay,
|
||||
options?: ConnectionManagerOptions
|
||||
): ConnectionManager {
|
||||
|
@ -111,13 +111,13 @@ export class ConnectionManager
|
|||
private constructor(
|
||||
libp2p: Libp2p,
|
||||
keepAliveOptions: KeepAliveOptions,
|
||||
private configuredPubSubTopics: PubSubTopic[],
|
||||
private configuredPubsubTopics: PubsubTopic[],
|
||||
relay?: IRelay,
|
||||
options?: Partial<ConnectionManagerOptions>
|
||||
) {
|
||||
super();
|
||||
this.libp2p = libp2p;
|
||||
this.configuredPubSubTopics = configuredPubSubTopics;
|
||||
this.configuredPubsubTopics = configuredPubsubTopics;
|
||||
this.options = {
|
||||
maxDialAttemptsForPeer: DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER,
|
||||
maxBootstrapPeersAllowed: DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED,
|
||||
|
@ -426,7 +426,7 @@ export class ConnectionManager
|
|||
);
|
||||
log.warn(
|
||||
`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${
|
||||
this.configuredPubSubTopics
|
||||
this.configuredPubsubTopics
|
||||
}).
|
||||
Not dialing.`
|
||||
);
|
||||
|
@ -518,10 +518,10 @@ export class ConnectionManager
|
|||
// If there's no shard information, simply return true
|
||||
if (!shardInfo) return true;
|
||||
|
||||
const pubsubTopics = shardInfoToPubSubTopics(shardInfo);
|
||||
const pubsubTopics = shardInfoToPubsubTopics(shardInfo);
|
||||
|
||||
const isTopicConfigured = pubsubTopics.some((topic) =>
|
||||
this.configuredPubSubTopics.includes(topic)
|
||||
this.configuredPubsubTopics.includes(topic)
|
||||
);
|
||||
return isTopicConfigured;
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -13,7 +13,7 @@ import type {
|
|||
Libp2p,
|
||||
PeerIdStr,
|
||||
ProtocolCreateOptions,
|
||||
PubSubTopic,
|
||||
PubsubTopic,
|
||||
Unsubscribe
|
||||
} from "@waku/interfaces";
|
||||
import { WakuMessage } from "@waku/proto";
|
||||
|
@ -28,7 +28,7 @@ import * as lp from "it-length-prefixed";
|
|||
import { pipe } from "it-pipe";
|
||||
|
||||
import { BaseProtocol } from "../base_protocol.js";
|
||||
import { DefaultPubSubTopic } from "../constants.js";
|
||||
import { DefaultPubsubTopic } from "../constants.js";
|
||||
|
||||
import {
|
||||
FilterPushRpc,
|
||||
|
@ -50,7 +50,7 @@ export const FilterCodecs = {
|
|||
|
||||
class Subscription {
|
||||
private readonly peer: Peer;
|
||||
private readonly pubsubTopic: PubSubTopic;
|
||||
private readonly pubsubTopic: PubsubTopic;
|
||||
private newStream: (peer: Peer) => Promise<Stream>;
|
||||
|
||||
private subscriptionCallbacks: Map<
|
||||
|
@ -59,7 +59,7 @@ class Subscription {
|
|||
>;
|
||||
|
||||
constructor(
|
||||
pubsubTopic: PubSubTopic,
|
||||
pubsubTopic: PubsubTopic,
|
||||
remotePeer: Peer,
|
||||
newStream: (peer: Peer) => Promise<Stream>
|
||||
) {
|
||||
|
@ -256,19 +256,19 @@ class Subscription {
|
|||
}
|
||||
|
||||
class Filter extends BaseProtocol implements IReceiver {
|
||||
private readonly pubsubTopics: PubSubTopic[] = [];
|
||||
private readonly pubsubTopics: PubsubTopic[] = [];
|
||||
private activeSubscriptions = new Map<string, Subscription>();
|
||||
private readonly NUM_PEERS_PROTOCOL = 1;
|
||||
|
||||
private getActiveSubscription(
|
||||
pubsubTopic: PubSubTopic,
|
||||
pubsubTopic: PubsubTopic,
|
||||
peerIdStr: PeerIdStr
|
||||
): Subscription | undefined {
|
||||
return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`);
|
||||
}
|
||||
|
||||
private setActiveSubscription(
|
||||
pubsubTopic: PubSubTopic,
|
||||
pubsubTopic: PubsubTopic,
|
||||
peerIdStr: PeerIdStr,
|
||||
subscription: Subscription
|
||||
): Subscription {
|
||||
|
@ -279,7 +279,7 @@ class Filter extends BaseProtocol implements IReceiver {
|
|||
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
||||
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) => {
|
||||
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
||||
|
@ -289,7 +289,7 @@ class Filter extends BaseProtocol implements IReceiver {
|
|||
}
|
||||
|
||||
async createSubscription(
|
||||
pubsubTopic: string = DefaultPubSubTopic
|
||||
pubsubTopic: string = DefaultPubsubTopic
|
||||
): Promise<Subscription> {
|
||||
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
|
||||
|
||||
|
@ -367,7 +367,7 @@ class Filter extends BaseProtocol implements IReceiver {
|
|||
}
|
||||
|
||||
if (!pubsubTopic) {
|
||||
log.error("PubSub topic missing from push message");
|
||||
log.error("Pubsub topic missing from push message");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ export function wakuFilter(
|
|||
|
||||
async function pushMessage<T extends IDecodedMessage>(
|
||||
subscriptionCallback: SubscriptionCallback<T>,
|
||||
pubsubTopic: PubSubTopic,
|
||||
pubsubTopic: PubsubTopic,
|
||||
message: WakuMessage
|
||||
): Promise<void> {
|
||||
const { decoders, callback } = subscriptionCallback;
|
||||
|
|
|
@ -116,7 +116,7 @@ export class KeepAliveManager {
|
|||
relayPeriodSecs: number,
|
||||
peerIdStr: PeerIdStr
|
||||
): 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[] = [];
|
||||
for (const topic of relay.pubsubTopics) {
|
||||
const meshPeers = relay.getMeshPeers(topic);
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
IMessage,
|
||||
Libp2p,
|
||||
ProtocolCreateOptions,
|
||||
PubSubTopic,
|
||||
PubsubTopic,
|
||||
SendError,
|
||||
SendResult
|
||||
} from "@waku/interfaces";
|
||||
|
@ -22,7 +22,7 @@ import { pipe } from "it-pipe";
|
|||
import { Uint8ArrayList } from "uint8arraylist";
|
||||
|
||||
import { BaseProtocol } from "../base_protocol.js";
|
||||
import { DefaultPubSubTopic } from "../constants.js";
|
||||
import { DefaultPubsubTopic } from "../constants.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/).
|
||||
*/
|
||||
class LightPush extends BaseProtocol implements ILightPush {
|
||||
private readonly pubsubTopics: PubSubTopic[];
|
||||
private readonly pubsubTopics: PubsubTopic[];
|
||||
private readonly NUM_PEERS_PROTOCOL = 1;
|
||||
|
||||
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
||||
super(LightPushCodec, libp2p.components);
|
||||
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
|
||||
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubsubTopic];
|
||||
}
|
||||
|
||||
private async preparePushMessage(
|
||||
|
|
|
@ -7,12 +7,12 @@ import type {
|
|||
IMetaSetter,
|
||||
IProtoMessage,
|
||||
IRateLimitProof,
|
||||
PubSubTopic
|
||||
PubsubTopic
|
||||
} from "@waku/interfaces";
|
||||
import { proto_message as proto } from "@waku/proto";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
||||
import { DefaultPubSubTopic } from "../constants.js";
|
||||
import { DefaultPubsubTopic } from "../constants.js";
|
||||
|
||||
const log = new Logger("message:version-0");
|
||||
const OneMillion = BigInt(1_000_000);
|
||||
|
@ -76,7 +76,7 @@ export class Encoder implements IEncoder {
|
|||
constructor(
|
||||
public contentTopic: string,
|
||||
public ephemeral: boolean = false,
|
||||
public pubsubTopic: PubSubTopic,
|
||||
public pubsubTopic: PubsubTopic,
|
||||
public metaSetter?: IMetaSetter
|
||||
) {
|
||||
if (!contentTopic || contentTopic === "") {
|
||||
|
@ -119,7 +119,7 @@ export class Encoder implements IEncoder {
|
|||
* messages.
|
||||
*/
|
||||
export function createEncoder({
|
||||
pubsubTopic = DefaultPubSubTopic,
|
||||
pubsubTopic = DefaultPubsubTopic,
|
||||
contentTopic,
|
||||
ephemeral,
|
||||
metaSetter
|
||||
|
@ -129,7 +129,7 @@ export function createEncoder({
|
|||
|
||||
export class Decoder implements IDecoder<DecodedMessage> {
|
||||
constructor(
|
||||
public pubsubTopic: PubSubTopic,
|
||||
public pubsubTopic: PubsubTopic,
|
||||
public contentTopic: string
|
||||
) {
|
||||
if (!contentTopic || contentTopic === "") {
|
||||
|
@ -182,7 +182,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|||
*/
|
||||
export function createDecoder(
|
||||
contentTopic: string,
|
||||
pubsubTopic: PubSubTopic = DefaultPubSubTopic
|
||||
pubsubTopic: PubsubTopic = DefaultPubsubTopic
|
||||
): Decoder {
|
||||
return new Decoder(pubsubTopic, contentTopic);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
IStore,
|
||||
Libp2p,
|
||||
ProtocolCreateOptions,
|
||||
PubSubTopic
|
||||
PubsubTopic
|
||||
} from "@waku/interfaces";
|
||||
import { proto_store as proto } from "@waku/proto";
|
||||
import { ensurePubsubTopicIsConfigured, isDefined } from "@waku/utils";
|
||||
|
@ -19,7 +19,7 @@ import { pipe } from "it-pipe";
|
|||
import { Uint8ArrayList } from "uint8arraylist";
|
||||
|
||||
import { BaseProtocol } from "../base_protocol.js";
|
||||
import { DefaultPubSubTopic } from "../constants.js";
|
||||
import { DefaultPubsubTopic } from "../constants.js";
|
||||
import { toProtoMessage } from "../to_proto_message.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.
|
||||
*/
|
||||
class Store extends BaseProtocol implements IStore {
|
||||
private readonly pubsubTopics: PubSubTopic[];
|
||||
private readonly pubsubTopics: PubsubTopic[];
|
||||
private readonly NUM_PEERS_PROTOCOL = 1;
|
||||
|
||||
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
||||
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
|
||||
const uniquePubSubTopicsInQuery = Array.from(
|
||||
const uniquePubsubTopicsInQuery = Array.from(
|
||||
new Set(decoders.map((decoder) => decoder.pubsubTopic))
|
||||
);
|
||||
|
||||
// If multiple pubsub topics are provided, throw an error
|
||||
if (uniquePubSubTopicsInQuery.length > 1) {
|
||||
if (uniquePubsubTopicsInQuery.length > 1) {
|
||||
throw new Error(
|
||||
"API does not support querying multiple pubsub topics at once"
|
||||
);
|
||||
}
|
||||
|
||||
// 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
|
||||
if (
|
||||
options?.cursor?.pubsubTopic &&
|
||||
options.cursor.pubsubTopic !== pubSubTopicForQuery
|
||||
options.cursor.pubsubTopic !== pubsubTopicForQuery
|
||||
) {
|
||||
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
|
||||
.filter((decoder) => decoder.pubsubTopic === pubSubTopicForQuery)
|
||||
.filter((decoder) => decoder.pubsubTopic === pubsubTopicForQuery)
|
||||
.map((dec) => dec.contentTopic);
|
||||
|
||||
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(
|
||||
{
|
||||
pubsubTopic: pubSubTopicForQuery,
|
||||
pubsubTopic: pubsubTopicForQuery,
|
||||
pageDirection: PageDirection.BACKWARD,
|
||||
pageSize: DefaultPageSize
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ import type {
|
|||
IRelay,
|
||||
IStore,
|
||||
Libp2p,
|
||||
PubSubTopic,
|
||||
PubsubTopic,
|
||||
Waku
|
||||
} from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
|
@ -53,7 +53,7 @@ export class WakuNode implements Waku {
|
|||
|
||||
constructor(
|
||||
options: WakuOptions,
|
||||
public readonly pubsubTopics: PubSubTopic[],
|
||||
public readonly pubsubTopics: PubsubTopic[],
|
||||
libp2p: Libp2p,
|
||||
store?: (libp2p: Libp2p) => IStore,
|
||||
lightPush?: (libp2p: Libp2p) => ILightPush,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { PubSubTopic } from "./misc.js";
|
||||
import type { PubsubTopic } from "./misc.js";
|
||||
|
||||
export interface IRateLimitProof {
|
||||
proof: Uint8Array;
|
||||
|
@ -38,7 +38,7 @@ export interface IMetaSetter {
|
|||
}
|
||||
|
||||
export interface EncoderOptions {
|
||||
pubsubTopic?: PubSubTopic;
|
||||
pubsubTopic?: PubsubTopic;
|
||||
/** The content topic to set on outgoing messages. */
|
||||
contentTopic: string;
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ export interface EncoderOptions {
|
|||
}
|
||||
|
||||
export interface IEncoder {
|
||||
pubsubTopic: PubSubTopic;
|
||||
pubsubTopic: PubsubTopic;
|
||||
contentTopic: string;
|
||||
ephemeral: boolean;
|
||||
toWire: (message: IMessage) => Promise<Uint8Array | undefined>;
|
||||
|
@ -65,7 +65,7 @@ export interface IEncoder {
|
|||
export interface IDecodedMessage {
|
||||
payload: Uint8Array;
|
||||
contentTopic: string;
|
||||
pubsubTopic: PubSubTopic;
|
||||
pubsubTopic: PubsubTopic;
|
||||
timestamp: Date | undefined;
|
||||
rateLimitProof: IRateLimitProof | undefined;
|
||||
ephemeral: boolean | undefined;
|
||||
|
@ -73,7 +73,7 @@ export interface IDecodedMessage {
|
|||
}
|
||||
|
||||
export interface IDecoder<T extends IDecodedMessage> {
|
||||
pubsubTopic: PubSubTopic;
|
||||
pubsubTopic: PubsubTopic;
|
||||
contentTopic: string;
|
||||
fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
|
||||
fromProtoObj: (
|
||||
|
|
|
@ -7,7 +7,7 @@ export interface IAsyncIterator<T extends IDecodedMessage> {
|
|||
|
||||
export type Unsubscribe = () => void | Promise<void>;
|
||||
|
||||
export type PubSubTopic = string;
|
||||
export type PubsubTopic = string;
|
||||
export type ContentTopic = string;
|
||||
|
||||
export type PeerIdStr = string;
|
||||
|
|
|
@ -4,7 +4,7 @@ import type { Peer, PeerStore } from "@libp2p/interface/peer-store";
|
|||
import type { Libp2pOptions } from "libp2p";
|
||||
|
||||
import type { IDecodedMessage } from "./message.js";
|
||||
import type { PubSubTopic } from "./misc.js";
|
||||
import type { PubsubTopic } from "./misc.js";
|
||||
|
||||
export enum Protocols {
|
||||
Relay = "relay",
|
||||
|
@ -27,7 +27,7 @@ export type ProtocolCreateOptions = {
|
|||
* Waku implements sharding to achieve scalability
|
||||
* 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/).
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
pubsubTopics?: PubSubTopic[];
|
||||
pubsubTopics?: PubsubTopic[];
|
||||
/**
|
||||
* 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)
|
||||
|
@ -88,8 +88,8 @@ export enum SendError {
|
|||
*/
|
||||
SIZE_TOO_BIG = "Size is too big",
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
TOPIC_NOT_CONFIGURED = "Topic not configured",
|
||||
/**
|
||||
|
|
|
@ -2,12 +2,12 @@ import type { IDecodedMessage, IDecoder } from "./message.js";
|
|||
import type {
|
||||
ContentTopic,
|
||||
IAsyncIterator,
|
||||
PubSubTopic,
|
||||
PubsubTopic,
|
||||
Unsubscribe
|
||||
} from "./misc.js";
|
||||
import type { Callback } from "./protocols.js";
|
||||
|
||||
export type ActiveSubscriptions = Map<PubSubTopic, ContentTopic[]>;
|
||||
export type ActiveSubscriptions = Map<PubsubTopic, ContentTopic[]>;
|
||||
|
||||
export interface IReceiver {
|
||||
toSubscriptionIterator: <T extends IDecodedMessage>(
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
|
||||
import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types";
|
||||
|
||||
import { PubSubTopic } from "./misc.js";
|
||||
import { IReceiver } from "./receiver.js";
|
||||
import type { PubsubTopic } from "./misc.js";
|
||||
import type { IReceiver } from "./receiver.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.
|
||||
*/
|
||||
export interface IRelayAPI {
|
||||
readonly pubsubTopics: Set<PubSubTopic>;
|
||||
readonly pubsubTopics: Set<PubsubTopic>;
|
||||
readonly gossipSub: GossipSub;
|
||||
start: () => Promise<void>;
|
||||
getMeshPeers: (topic?: TopicStr) => PeerIdStr[];
|
||||
|
|
|
@ -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 { IMetaSetter, PubSubTopic } from "@waku/interfaces";
|
||||
import { IMetaSetter, PubsubTopic } from "@waku/interfaces";
|
||||
import type {
|
||||
EncoderOptions as BaseEncoderOptions,
|
||||
IDecoder,
|
||||
|
@ -33,7 +33,7 @@ const log = new Logger("message-encryption:ecies");
|
|||
|
||||
class Encoder implements IEncoder {
|
||||
constructor(
|
||||
public pubsubTopic: PubSubTopic,
|
||||
public pubsubTopic: PubsubTopic,
|
||||
public contentTopic: string,
|
||||
private publicKey: Uint8Array,
|
||||
private sigPrivKey?: Uint8Array,
|
||||
|
@ -97,7 +97,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|||
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
||||
*/
|
||||
export function createEncoder({
|
||||
pubsubTopic = DefaultPubSubTopic,
|
||||
pubsubTopic = DefaultPubsubTopic,
|
||||
contentTopic,
|
||||
publicKey,
|
||||
sigPrivKey,
|
||||
|
@ -116,7 +116,7 @@ export function createEncoder({
|
|||
|
||||
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
constructor(
|
||||
pubsubTopic: PubSubTopic,
|
||||
pubsubTopic: PubsubTopic,
|
||||
contentTopic: string,
|
||||
private privateKey: Uint8Array
|
||||
) {
|
||||
|
@ -193,7 +193,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|||
export function createDecoder(
|
||||
contentTopic: string,
|
||||
privateKey: Uint8Array,
|
||||
pubsubTopic: PubSubTopic = DefaultPubSubTopic
|
||||
pubsubTopic: PubsubTopic = DefaultPubsubTopic
|
||||
): Decoder {
|
||||
return new Decoder(pubsubTopic, contentTopic, privateKey);
|
||||
}
|
||||
|
|
|
@ -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 type {
|
||||
EncoderOptions as BaseEncoderOptions,
|
||||
|
@ -7,7 +7,7 @@ import type {
|
|||
IMessage,
|
||||
IMetaSetter,
|
||||
IProtoMessage,
|
||||
PubSubTopic
|
||||
PubsubTopic
|
||||
} from "@waku/interfaces";
|
||||
import { WakuMessage } from "@waku/proto";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
@ -29,7 +29,7 @@ const log = new Logger("message-encryption:symmetric");
|
|||
|
||||
class Encoder implements IEncoder {
|
||||
constructor(
|
||||
public pubsubTopic: PubSubTopic,
|
||||
public pubsubTopic: PubsubTopic,
|
||||
public contentTopic: string,
|
||||
private symKey: Uint8Array,
|
||||
private sigPrivKey?: Uint8Array,
|
||||
|
@ -93,7 +93,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|||
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
||||
*/
|
||||
export function createEncoder({
|
||||
pubsubTopic = DefaultPubSubTopic,
|
||||
pubsubTopic = DefaultPubsubTopic,
|
||||
contentTopic,
|
||||
symKey,
|
||||
sigPrivKey,
|
||||
|
@ -112,7 +112,7 @@ export function createEncoder({
|
|||
|
||||
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
constructor(
|
||||
pubsubTopic: PubSubTopic,
|
||||
pubsubTopic: PubsubTopic,
|
||||
contentTopic: string,
|
||||
private symKey: Uint8Array
|
||||
) {
|
||||
|
@ -189,7 +189,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|||
export function createDecoder(
|
||||
contentTopic: string,
|
||||
symKey: Uint8Array,
|
||||
pubsubTopic: PubSubTopic = DefaultPubSubTopic
|
||||
pubsubTopic: PubsubTopic = DefaultPubsubTopic
|
||||
): Decoder {
|
||||
return new Decoder(pubsubTopic, contentTopic, symKey);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ import {
|
|||
import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types";
|
||||
import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types";
|
||||
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 { DefaultPubSubTopic } from "@waku/core";
|
||||
import { DefaultPubsubTopic } from "@waku/core";
|
||||
import {
|
||||
ActiveSubscriptions,
|
||||
Callback,
|
||||
|
@ -21,7 +21,7 @@ import {
|
|||
IRelay,
|
||||
Libp2p,
|
||||
ProtocolCreateOptions,
|
||||
PubSubTopic,
|
||||
PubsubTopic,
|
||||
SendError,
|
||||
SendResult
|
||||
} from "@waku/interfaces";
|
||||
|
@ -48,7 +48,7 @@ export type ContentTopic = string;
|
|||
* Throws if libp2p.pubsub does not support Waku Relay
|
||||
*/
|
||||
class Relay implements IRelay {
|
||||
public readonly pubsubTopics: Set<PubSubTopic>;
|
||||
public readonly pubsubTopics: Set<PubsubTopic>;
|
||||
private defaultDecoder: IDecoder<IDecodedMessage>;
|
||||
|
||||
public static multicodec: string = RelayCodecs[0];
|
||||
|
@ -58,17 +58,17 @@ class Relay implements IRelay {
|
|||
* observers called when receiving new message.
|
||||
* 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>) {
|
||||
if (!this.isRelayPubSub(libp2p.services.pubsub)) {
|
||||
if (!this.isRelayPubsub(libp2p.services.pubsub)) {
|
||||
throw Error(
|
||||
`Failed to initialize Relay. libp2p.pubsub does not support ${Relay.multicodec}`
|
||||
);
|
||||
}
|
||||
|
||||
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()) {
|
||||
this.subscribeToAllTopics();
|
||||
|
@ -76,7 +76,7 @@ class Relay implements IRelay {
|
|||
|
||||
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)
|
||||
this.defaultDecoder = new TopicOnlyDecoder();
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ class Relay implements IRelay {
|
|||
decoders: IDecoder<T> | IDecoder<T>[],
|
||||
callback: Callback<T>
|
||||
): () => void {
|
||||
const observers: Array<[PubSubTopic, Observer<T>]> = [];
|
||||
const observers: Array<[PubsubTopic, Observer<T>]> = [];
|
||||
|
||||
for (const decoder of Array.isArray(decoders) ? decoders : [decoders]) {
|
||||
const { pubsubTopic } = decoder;
|
||||
|
@ -156,7 +156,7 @@ class Relay implements IRelay {
|
|||
}
|
||||
|
||||
private removeObservers<T extends IDecodedMessage>(
|
||||
observers: Array<[PubSubTopic, Observer<T>]>
|
||||
observers: Array<[PubsubTopic, Observer<T>]>
|
||||
): void {
|
||||
for (const [pubsubTopic, observer] of observers) {
|
||||
const ctObs = this.observers.get(pubsubTopic);
|
||||
|
@ -186,7 +186,7 @@ class Relay implements IRelay {
|
|||
return map;
|
||||
}
|
||||
|
||||
public getMeshPeers(topic: TopicStr = DefaultPubSubTopic): PeerIdStr[] {
|
||||
public getMeshPeers(topic: TopicStr = DefaultPubsubTopic): PeerIdStr[] {
|
||||
return this.gossipSub.getMeshPeers(topic);
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ class Relay implements IRelay {
|
|||
this.gossipSub.subscribe(pubsubTopic);
|
||||
}
|
||||
|
||||
private isRelayPubSub(pubsub: PubSub | undefined): boolean {
|
||||
private isRelayPubsub(pubsub: Libp2pPubsub | undefined): boolean {
|
||||
return pubsub?.multicodecs?.includes(Relay.multicodec) ?? false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DefaultPubSubTopic } from "@waku/core";
|
||||
import { DefaultPubsubTopic } from "@waku/core";
|
||||
import type {
|
||||
IDecodedMessage,
|
||||
IDecoder,
|
||||
|
@ -24,7 +24,7 @@ export class TopicOnlyMessage implements IDecodedMessage {
|
|||
}
|
||||
|
||||
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
||||
pubsubTopic = DefaultPubSubTopic;
|
||||
pubsubTopic = DefaultPubsubTopic;
|
||||
public contentTopic = "";
|
||||
|
||||
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { mplex } from "@libp2p/mplex";
|
|||
import { webSockets } from "@libp2p/websockets";
|
||||
import { all as filterAll } from "@libp2p/websockets/filters";
|
||||
import {
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
DefaultUserAgent,
|
||||
wakuFilter,
|
||||
wakuLightPush,
|
||||
|
@ -47,7 +47,7 @@ export async function createLightNode(
|
|||
options = options ?? {};
|
||||
|
||||
if (!options.pubsubTopics) {
|
||||
options.pubsubTopics = [DefaultPubSubTopic];
|
||||
options.pubsubTopics = [DefaultPubsubTopic];
|
||||
}
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
|
@ -87,7 +87,7 @@ export async function createRelayNode(
|
|||
options = options ?? {};
|
||||
|
||||
if (!options.pubsubTopics) {
|
||||
options.pubsubTopics = [DefaultPubSubTopic];
|
||||
options.pubsubTopics = [DefaultPubsubTopic];
|
||||
}
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
|
@ -135,7 +135,7 @@ export async function createFullNode(
|
|||
options = options ?? {};
|
||||
|
||||
if (!options.pubsubTopics) {
|
||||
options.pubsubTopics = [DefaultPubSubTopic];
|
||||
options.pubsubTopics = [DefaultPubsubTopic];
|
||||
}
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DecodedMessage, DefaultPubSubTopic } from "@waku/core";
|
||||
import { DecodedMessage, DefaultPubsubTopic } from "@waku/core";
|
||||
import { Logger } from "@waku/utils";
|
||||
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { AssertionError, expect } from "chai";
|
||||
|
@ -70,7 +70,7 @@ export class MessageCollector {
|
|||
}
|
||||
): Promise<boolean> {
|
||||
const startTime = Date.now();
|
||||
const pubsubTopic = options?.pubsubTopic || DefaultPubSubTopic;
|
||||
const pubsubTopic = options?.pubsubTopic || DefaultPubsubTopic;
|
||||
const timeoutDuration = options?.timeoutDuration || 400;
|
||||
const exact = options?.exact || false;
|
||||
|
||||
|
@ -109,7 +109,7 @@ export class MessageCollector {
|
|||
options: {
|
||||
expectedMessageText: string | Uint8Array | undefined;
|
||||
expectedContentTopic?: string;
|
||||
expectedPubSubTopic?: string;
|
||||
expectedPubsubTopic?: string;
|
||||
expectedVersion?: number;
|
||||
expectedMeta?: Uint8Array;
|
||||
expectedEphemeral?: boolean;
|
||||
|
@ -193,9 +193,9 @@ export class MessageCollector {
|
|||
} else {
|
||||
// js-waku message specific assertions
|
||||
expect(message.pubsubTopic).to.eq(
|
||||
options.expectedPubSubTopic || DefaultPubSubTopic,
|
||||
options.expectedPubsubTopic || DefaultPubsubTopic,
|
||||
`Message pub/sub topic mismatch. Expected: ${
|
||||
options.expectedPubSubTopic || DefaultPubSubTopic
|
||||
options.expectedPubsubTopic || DefaultPubsubTopic
|
||||
}. Got: ${message.pubsubTopic}`
|
||||
);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { PeerId } from "@libp2p/interface/peer-id";
|
||||
import { peerIdFromString } from "@libp2p/peer-id";
|
||||
import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
|
||||
import { DefaultPubSubTopic } from "@waku/core";
|
||||
import { DefaultPubsubTopic } from "@waku/core";
|
||||
import { isDefined } from "@waku/utils";
|
||||
import { Logger } from "@waku/utils";
|
||||
import { bytesToHex, hexToBytes } from "@waku/utils/bytes";
|
||||
|
@ -207,7 +207,7 @@ export class NimGoNode {
|
|||
}
|
||||
|
||||
async ensureSubscriptions(
|
||||
pubsubTopics: string[] = [DefaultPubSubTopic]
|
||||
pubsubTopics: string[] = [DefaultPubsubTopic]
|
||||
): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
|
@ -218,7 +218,7 @@ export class NimGoNode {
|
|||
|
||||
async sendMessage(
|
||||
message: MessageRpcQuery,
|
||||
pubsubTopic: string = DefaultPubSubTopic
|
||||
pubsubTopic: string = DefaultPubsubTopic
|
||||
): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
|
@ -233,7 +233,7 @@ export class NimGoNode {
|
|||
}
|
||||
|
||||
async messages(
|
||||
pubsubTopic: string = DefaultPubSubTopic
|
||||
pubsubTopic: string = DefaultPubsubTopic
|
||||
): Promise<MessageRpcResponse[]> {
|
||||
this.checkProcess();
|
||||
|
||||
|
@ -275,7 +275,7 @@ export class NimGoNode {
|
|||
}
|
||||
|
||||
return this.rpcCall<boolean>("post_waku_v2_private_v1_asymmetric_message", [
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
|
||||
message,
|
||||
"0x" + bytesToHex(publicKey)
|
||||
]);
|
||||
|
@ -290,7 +290,7 @@ export class NimGoNode {
|
|||
return await this.rpcCall<MessageRpcResponse[]>(
|
||||
"get_waku_v2_private_v1_asymmetric_messages",
|
||||
[
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
|
||||
"0x" + bytesToHex(privateKey)
|
||||
]
|
||||
);
|
||||
|
@ -317,7 +317,7 @@ export class NimGoNode {
|
|||
}
|
||||
|
||||
return this.rpcCall<boolean>("post_waku_v2_private_v1_symmetric_message", [
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
|
||||
message,
|
||||
"0x" + bytesToHex(symKey)
|
||||
]);
|
||||
|
@ -332,7 +332,7 @@ export class NimGoNode {
|
|||
return await this.rpcCall<MessageRpcResponse[]>(
|
||||
"get_waku_v2_private_v1_symmetric_messages",
|
||||
[
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
|
||||
"0x" + bytesToHex(symKey)
|
||||
]
|
||||
);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
createDecoder,
|
||||
createEncoder,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
import type { IFilterSubscription, LightNode } from "@waku/interfaces";
|
||||
|
@ -23,7 +23,7 @@ import {
|
|||
TestEncoder
|
||||
} 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
|
||||
this.timeout(30000);
|
||||
let waku: LightNode;
|
||||
|
@ -31,21 +31,21 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
|||
let nwaku2: NimGoNode;
|
||||
let subscription: IFilterSubscription;
|
||||
let messageCollector: MessageCollector;
|
||||
const customPubSubTopic = "/waku/2/custom-dapp/proto";
|
||||
const customPubsubTopic = "/waku/2/custom-dapp/proto";
|
||||
const customContentTopic = "/test/2/waku-filter";
|
||||
const newEncoder = createEncoder({
|
||||
pubsubTopic: customPubSubTopic,
|
||||
pubsubTopic: customPubsubTopic,
|
||||
contentTopic: customContentTopic
|
||||
});
|
||||
const newDecoder = createDecoder(customContentTopic, customPubSubTopic);
|
||||
const newDecoder = createDecoder(customContentTopic, customPubsubTopic);
|
||||
|
||||
this.beforeEach(async function () {
|
||||
this.timeout(15000);
|
||||
[nwaku, waku] = await runNodes(this, [
|
||||
customPubSubTopic,
|
||||
DefaultPubSubTopic
|
||||
customPubsubTopic,
|
||||
DefaultPubsubTopic
|
||||
]);
|
||||
subscription = await waku.filter.createSubscription(customPubSubTopic);
|
||||
subscription = await waku.filter.createSubscription(customPubsubTopic);
|
||||
messageCollector = new MessageCollector();
|
||||
});
|
||||
|
||||
|
@ -60,7 +60,7 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
|||
expect(await messageCollector.waitForMessages(1)).to.eq(true);
|
||||
messageCollector.verifyReceivedMessage(0, {
|
||||
expectedContentTopic: customContentTopic,
|
||||
expectedPubSubTopic: customPubSubTopic,
|
||||
expectedPubsubTopic: customPubsubTopic,
|
||||
expectedMessageText: "M1"
|
||||
});
|
||||
});
|
||||
|
@ -68,9 +68,9 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
|||
it("Subscribe and receive messages on 2 different pubsubtopics", async function () {
|
||||
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 =
|
||||
await waku.filter.createSubscription(DefaultPubSubTopic);
|
||||
await waku.filter.createSubscription(DefaultPubsubTopic);
|
||||
|
||||
const messageCollector2 = new MessageCollector();
|
||||
|
||||
|
@ -84,13 +84,13 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
|||
|
||||
messageCollector.verifyReceivedMessage(0, {
|
||||
expectedContentTopic: customContentTopic,
|
||||
expectedPubSubTopic: customPubSubTopic,
|
||||
expectedPubsubTopic: customPubsubTopic,
|
||||
expectedMessageText: "M1"
|
||||
});
|
||||
|
||||
messageCollector2.verifyReceivedMessage(0, {
|
||||
expectedContentTopic: TestContentTopic,
|
||||
expectedPubSubTopic: DefaultPubSubTopic,
|
||||
expectedPubsubTopic: DefaultPubsubTopic,
|
||||
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 () {
|
||||
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");
|
||||
await nwaku2.start({
|
||||
filter: true,
|
||||
lightpush: true,
|
||||
relay: true,
|
||||
topic: [DefaultPubSubTopic]
|
||||
topic: [DefaultPubsubTopic]
|
||||
});
|
||||
await waku.dial(await nwaku2.getMultiaddrWithId());
|
||||
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(
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
await nwaku2.getPeerId()
|
||||
);
|
||||
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]);
|
||||
await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
|
||||
|
||||
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 (
|
||||
!(await messageCollector.waitForMessages(1, {
|
||||
pubsubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubsubTopic
|
||||
})) ||
|
||||
!(await messageCollector2.waitForMessages(1, {
|
||||
pubsubTopic: DefaultPubSubTopic
|
||||
pubsubTopic: DefaultPubsubTopic
|
||||
}))
|
||||
) {
|
||||
await waku.lightPush.send(newEncoder, { payload: utf8ToBytes("M1") });
|
||||
|
@ -136,13 +136,13 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
|||
|
||||
messageCollector.verifyReceivedMessage(0, {
|
||||
expectedContentTopic: customContentTopic,
|
||||
expectedPubSubTopic: customPubSubTopic,
|
||||
expectedPubsubTopic: customPubsubTopic,
|
||||
expectedMessageText: "M1"
|
||||
});
|
||||
|
||||
messageCollector2.verifyReceivedMessage(0, {
|
||||
expectedContentTopic: TestContentTopic,
|
||||
expectedPubSubTopic: DefaultPubSubTopic,
|
||||
expectedPubsubTopic: DefaultPubsubTopic,
|
||||
expectedMessageText: "M2"
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DefaultPubSubTopic } from "@waku/core";
|
||||
import { DefaultPubsubTopic } from "@waku/core";
|
||||
import type { IFilterSubscription, LightNode } from "@waku/interfaces";
|
||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
@ -23,7 +23,7 @@ describe("Waku Filter V2: Ping", function () {
|
|||
|
||||
this.beforeEach(async function () {
|
||||
this.timeout(15000);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
|
||||
subscription = await waku.filter.createSubscription();
|
||||
messageCollector = new MessageCollector();
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DefaultPubSubTopic, waitForRemotePeer } from "@waku/core";
|
||||
import { DefaultPubsubTopic, waitForRemotePeer } from "@waku/core";
|
||||
import type { IFilterSubscription, LightNode } from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||
|
@ -31,7 +31,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
|
||||
this.beforeEach(async function () {
|
||||
this.timeout(15000);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
|
||||
subscription = await waku.filter.createSubscription();
|
||||
messageCollector = new MessageCollector();
|
||||
});
|
||||
|
@ -62,7 +62,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
{
|
||||
contentTopic: TestContentTopic,
|
||||
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
|
||||
|
@ -93,7 +93,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
{
|
||||
contentTopic: TestContentTopic,
|
||||
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
|
||||
|
@ -110,7 +110,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
"DefaultPubSubTopic",
|
||||
"DefaultPubsubTopic",
|
||||
{
|
||||
contentTopic: TestContentTopic,
|
||||
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
|
||||
|
@ -141,7 +141,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
{
|
||||
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
|
||||
timestamp: BigInt(Date.now()) * BigInt(1000000)
|
||||
|
@ -156,7 +156,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
{
|
||||
contentTopic: TestContentTopic,
|
||||
timestamp: BigInt(Date.now()) * BigInt(1000000)
|
||||
|
@ -176,7 +176,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
{
|
||||
contentTopic: TestContentTopic,
|
||||
payload: 12345,
|
||||
|
@ -192,7 +192,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
"extraField",
|
||||
{
|
||||
contentTopic: TestContentTopic,
|
||||
|
@ -209,7 +209,7 @@ describe("Waku Filter V2: FilterPush", function () {
|
|||
await delay(400);
|
||||
|
||||
await nwaku.rpcCall("post_waku_v2_relay_v1_message", [
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
{
|
||||
contentTopic: TestContentTopic,
|
||||
payload: Buffer.from(utf8ToBytes(messageText)).toString("base64"),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
createDecoder,
|
||||
createEncoder,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
import type { IFilterSubscription, LightNode } from "@waku/interfaces";
|
||||
|
@ -40,7 +40,7 @@ describe("Waku Filter V2: Subscribe", function () {
|
|||
|
||||
this.beforeEach(async function () {
|
||||
this.timeout(15000);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
|
||||
subscription = await waku.filter.createSubscription();
|
||||
messageCollector = new MessageCollector();
|
||||
|
||||
|
@ -377,10 +377,10 @@ describe("Waku Filter V2: Subscribe", function () {
|
|||
await waku.dial(await nwaku2.getMultiaddrWithId());
|
||||
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
|
||||
const subscription2 = await waku.filter.createSubscription(
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
await nwaku2.getPeerId()
|
||||
);
|
||||
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]);
|
||||
await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
|
||||
// Send a message using the new subscription
|
||||
const newContentTopic = "/test/2/waku-filter";
|
||||
const newEncoder = createEncoder({ contentTopic: newContentTopic });
|
||||
|
|
|
@ -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 { utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
@ -29,7 +29,7 @@ describe("Waku Filter V2: Unsubscribe", function () {
|
|||
|
||||
this.beforeEach(async function () {
|
||||
this.timeout(15000);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
|
||||
subscription = await waku.filter.createSubscription();
|
||||
messageCollector = new MessageCollector();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createEncoder, DefaultPubSubTopic } from "@waku/core";
|
||||
import { createEncoder, DefaultPubsubTopic } from "@waku/core";
|
||||
import { IRateLimitProof, LightNode, SendError } from "@waku/interfaces";
|
||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
@ -28,7 +28,7 @@ describe("Waku Light Push", function () {
|
|||
|
||||
this.beforeEach(async function () {
|
||||
this.timeout(15000);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubSubTopic]);
|
||||
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
|
||||
messageCollector = new MessageCollector(nwaku);
|
||||
|
||||
await nwaku.ensureSubscriptions();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { PeerId } from "@libp2p/interface/peer-id";
|
||||
import {
|
||||
createEncoder,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
import { LightNode, Protocols, SendResult } from "@waku/interfaces";
|
||||
|
@ -22,25 +22,25 @@ import {
|
|||
TestEncoder
|
||||
} from "./utils.js";
|
||||
|
||||
describe("Waku Light Push : Multiple PubSubtopics", function () {
|
||||
describe("Waku Light Push : Multiple PubsubTopics", function () {
|
||||
this.timeout(30000);
|
||||
let waku: LightNode;
|
||||
let nwaku: NimGoNode;
|
||||
let nwaku2: NimGoNode;
|
||||
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 customEncoder = createEncoder({
|
||||
contentTopic: customContentTopic,
|
||||
pubsubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubsubTopic
|
||||
});
|
||||
let nimPeerId: PeerId;
|
||||
|
||||
this.beforeEach(async function () {
|
||||
this.timeout(15000);
|
||||
[nwaku, waku] = await runNodes(this, [
|
||||
customPubSubTopic,
|
||||
DefaultPubSubTopic
|
||||
customPubsubTopic,
|
||||
DefaultPubsubTopic
|
||||
]);
|
||||
messageCollector = new MessageCollector(nwaku);
|
||||
nimPeerId = await nwaku.getPeerId();
|
||||
|
@ -60,7 +60,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
|||
|
||||
expect(
|
||||
await messageCollector.waitForMessages(1, {
|
||||
pubsubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubsubTopic
|
||||
})
|
||||
).to.eq(true);
|
||||
messageCollector.verifyReceivedMessage(0, {
|
||||
|
@ -83,38 +83,38 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
|||
|
||||
expect(
|
||||
await messageCollector.waitForMessages(1, {
|
||||
pubsubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubsubTopic
|
||||
})
|
||||
).to.eq(true);
|
||||
|
||||
expect(
|
||||
await messageCollector2.waitForMessages(1, {
|
||||
pubsubTopic: DefaultPubSubTopic
|
||||
pubsubTopic: DefaultPubsubTopic
|
||||
})
|
||||
).to.eq(true);
|
||||
|
||||
messageCollector.verifyReceivedMessage(0, {
|
||||
expectedMessageText: "M1",
|
||||
expectedContentTopic: customContentTopic,
|
||||
expectedPubSubTopic: customPubSubTopic
|
||||
expectedPubsubTopic: customPubsubTopic
|
||||
});
|
||||
messageCollector2.verifyReceivedMessage(0, {
|
||||
expectedMessageText: "M2",
|
||||
expectedContentTopic: TestContentTopic,
|
||||
expectedPubSubTopic: DefaultPubSubTopic
|
||||
expectedPubsubTopic: DefaultPubsubTopic
|
||||
});
|
||||
});
|
||||
|
||||
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");
|
||||
await nwaku2.start({
|
||||
filter: true,
|
||||
lightpush: true,
|
||||
relay: true,
|
||||
topic: [DefaultPubSubTopic]
|
||||
topic: [DefaultPubsubTopic]
|
||||
});
|
||||
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]);
|
||||
await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
|
||||
await waku.dial(await nwaku2.getMultiaddrWithId());
|
||||
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 (
|
||||
!(await messageCollector.waitForMessages(1, {
|
||||
pubsubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubsubTopic
|
||||
})) ||
|
||||
!(await messageCollector2.waitForMessages(1, {
|
||||
pubsubTopic: DefaultPubSubTopic
|
||||
pubsubTopic: DefaultPubsubTopic
|
||||
})) ||
|
||||
pushResponse1!.recipients[0].toString() ===
|
||||
pushResponse2!.recipients[0].toString()
|
||||
|
@ -145,12 +145,12 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
|||
messageCollector.verifyReceivedMessage(0, {
|
||||
expectedMessageText: "M1",
|
||||
expectedContentTopic: customContentTopic,
|
||||
expectedPubSubTopic: customPubSubTopic
|
||||
expectedPubsubTopic: customPubsubTopic
|
||||
});
|
||||
messageCollector2.verifyReceivedMessage(0, {
|
||||
expectedMessageText: "M2",
|
||||
expectedContentTopic: TestContentTopic,
|
||||
expectedPubSubTopic: DefaultPubSubTopic
|
||||
expectedPubsubTopic: DefaultPubsubTopic
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { PeerId } from "@libp2p/interface/peer-id";
|
||||
import {
|
||||
DecodedMessage,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
import { RelayNode } from "@waku/interfaces";
|
||||
|
@ -55,7 +55,7 @@ describe("Waku Relay, Interop", function () {
|
|||
while (subscribers.length === 0) {
|
||||
await delay(200);
|
||||
subscribers =
|
||||
waku.libp2p.services.pubsub!.getSubscribers(DefaultPubSubTopic);
|
||||
waku.libp2p.services.pubsub!.getSubscribers(DefaultPubsubTopic);
|
||||
}
|
||||
|
||||
const nimPeerId = await nwaku.getPeerId();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
DecodedMessage,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
import { RelayNode } from "@waku/interfaces";
|
||||
|
@ -21,7 +21,7 @@ import {
|
|||
CustomContentTopic,
|
||||
CustomDecoder,
|
||||
CustomEncoder,
|
||||
CustomPubSubTopic,
|
||||
CustomPubsubTopic,
|
||||
TestContentTopic,
|
||||
TestDecoder,
|
||||
TestEncoder
|
||||
|
@ -40,12 +40,12 @@ describe("Waku Relay, multiple pubsub topics", function () {
|
|||
|
||||
[
|
||||
{
|
||||
pubsub: CustomPubSubTopic,
|
||||
pubsub: CustomPubsubTopic,
|
||||
encoder: CustomEncoder,
|
||||
decoder: CustomDecoder
|
||||
},
|
||||
{
|
||||
pubsub: DefaultPubSubTopic,
|
||||
pubsub: DefaultPubsubTopic,
|
||||
encoder: TestEncoder,
|
||||
decoder: TestDecoder
|
||||
}
|
||||
|
@ -155,16 +155,16 @@ describe("Waku Relay, multiple pubsub topics", function () {
|
|||
// Waku1 and waku2 are using multiple pubsub topis
|
||||
[waku1, waku2, waku3] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic],
|
||||
pubsubTopics: [DefaultPubsubTopic, CustomPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic],
|
||||
pubsubTopics: [DefaultPubsubTopic, CustomPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubsubTopics: [DefaultPubSubTopic],
|
||||
pubsubTopics: [DefaultPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_3
|
||||
}).then((waku) => waku.start().then(() => waku))
|
||||
]);
|
||||
|
@ -197,7 +197,7 @@ describe("Waku Relay, multiple pubsub topics", function () {
|
|||
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
|
||||
// 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(CustomEncoder, { payload: utf8ToBytes("M2") });
|
||||
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 () {
|
||||
[waku1, waku2, waku3] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubsubTopics: [CustomPubSubTopic],
|
||||
pubsubTopics: [CustomPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubsubTopics: [CustomPubSubTopic],
|
||||
pubsubTopics: [CustomPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
|
@ -275,6 +275,6 @@ describe("Waku Relay, multiple pubsub topics", function () {
|
|||
await waku3NoMsgPromise;
|
||||
|
||||
expect(bytesToUtf8(waku2ReceivedMsg.payload!)).to.eq(messageText);
|
||||
expect(waku2ReceivedMsg.pubsubTopic).to.eq(CustomPubSubTopic);
|
||||
expect(waku2ReceivedMsg.pubsubTopic).to.eq(CustomPubsubTopic);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createEncoder, DefaultPubSubTopic } from "@waku/core";
|
||||
import { createEncoder, DefaultPubsubTopic } from "@waku/core";
|
||||
import { IRateLimitProof, RelayNode, SendError } from "@waku/interfaces";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||
|
@ -34,11 +34,11 @@ describe("Waku Relay, Publish", function () {
|
|||
log.info("Starting JS Waku instances");
|
||||
[waku1, waku2] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubsubTopics: [DefaultPubSubTopic],
|
||||
pubsubTopics: [DefaultPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubsubTopics: [DefaultPubSubTopic],
|
||||
pubsubTopics: [DefaultPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createDecoder, createEncoder, DefaultPubSubTopic } from "@waku/core";
|
||||
import { createDecoder, createEncoder, DefaultPubsubTopic } from "@waku/core";
|
||||
import { RelayNode } from "@waku/interfaces";
|
||||
import { createRelayNode } from "@waku/sdk";
|
||||
import { utf8ToBytes } from "@waku/utils/bytes";
|
||||
|
@ -33,11 +33,11 @@ describe("Waku Relay, Subscribe", function () {
|
|||
log.info("Starting JS Waku instances");
|
||||
[waku1, waku2] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubsubTopics: [DefaultPubSubTopic],
|
||||
pubsubTopics: [DefaultPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubsubTopics: [DefaultPubSubTopic],
|
||||
pubsubTopics: [DefaultPubsubTopic],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku))
|
||||
|
@ -59,10 +59,10 @@ describe("Waku Relay, Subscribe", function () {
|
|||
it("Mutual subscription", async function () {
|
||||
await waitForAllRemotePeers(waku1, waku2);
|
||||
const subscribers1 = waku1.libp2p.services
|
||||
.pubsub!.getSubscribers(DefaultPubSubTopic)
|
||||
.pubsub!.getSubscribers(DefaultPubsubTopic)
|
||||
.map((p) => p.toString());
|
||||
const subscribers2 = waku2.libp2p.services
|
||||
.pubsub!.getSubscribers(DefaultPubSubTopic)
|
||||
.pubsub!.getSubscribers(DefaultPubsubTopic)
|
||||
.map((p) => p.toString());
|
||||
|
||||
expect(subscribers1).to.contain(waku2.libp2p.peerId.toString());
|
||||
|
|
|
@ -7,14 +7,14 @@ export const TestContentTopic = "/test/1/waku-relay/utf8";
|
|||
export const TestEncoder = createEncoder({ contentTopic: TestContentTopic });
|
||||
export const TestDecoder = createDecoder(TestContentTopic);
|
||||
export const CustomContentTopic = "/test/2/waku-relay/utf8";
|
||||
export const CustomPubSubTopic = "/some/pubsub/topic";
|
||||
export const CustomPubsubTopic = "/some/pubsub/topic";
|
||||
export const CustomEncoder = createEncoder({
|
||||
contentTopic: CustomContentTopic,
|
||||
pubsubTopic: CustomPubSubTopic
|
||||
pubsubTopic: CustomPubsubTopic
|
||||
});
|
||||
export const CustomDecoder = createDecoder(
|
||||
CustomContentTopic,
|
||||
CustomPubSubTopic
|
||||
CustomPubsubTopic
|
||||
);
|
||||
|
||||
export const log = new Logger("test:relay");
|
||||
|
|
|
@ -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 () {
|
||||
this.timeout(100_000);
|
||||
const pubSubTopicsToDial = ["/waku/2/rs/18/2"];
|
||||
const pubSubTopicsToIgnore = ["/waku/2/rs/18/3"];
|
||||
const pubsubTopicsToDial = ["/waku/2/rs/18/2"];
|
||||
const pubsubTopicsToIgnore = ["/waku/2/rs/18/3"];
|
||||
|
||||
// this service node is not subscribed to the shard
|
||||
await nwaku1.start({
|
||||
topic: pubSubTopicsToIgnore,
|
||||
topic: pubsubTopicsToIgnore,
|
||||
relay: true,
|
||||
discv5Discovery: true,
|
||||
peerExchange: true
|
||||
|
@ -121,7 +121,7 @@ describe("Static Sharding: Peer Management", function () {
|
|||
const enr1 = (await nwaku1.info()).enrUri;
|
||||
|
||||
await nwaku2.start({
|
||||
topic: pubSubTopicsToDial,
|
||||
topic: pubsubTopicsToDial,
|
||||
relay: true,
|
||||
discv5Discovery: true,
|
||||
peerExchange: true,
|
||||
|
@ -139,7 +139,7 @@ describe("Static Sharding: Peer Management", function () {
|
|||
const nwaku3Ma = await nwaku3.getMultiaddrWithId();
|
||||
|
||||
waku = await createLightNode({
|
||||
pubsubTopics: pubSubTopicsToDial,
|
||||
pubsubTopics: pubsubTopicsToDial,
|
||||
libp2p: {
|
||||
peerDiscovery: [
|
||||
bootstrap({ list: [nwaku3Ma.toString()] }),
|
||||
|
|
|
@ -6,8 +6,8 @@ import { tearDownNodes } from "../../src/index.js";
|
|||
import { makeLogFileName } from "../../src/log_file.js";
|
||||
import { NimGoNode } from "../../src/node/node.js";
|
||||
|
||||
const PubSubTopic1 = "/waku/2/rs/0/2";
|
||||
const PubSubTopic2 = "/waku/2/rs/0/3";
|
||||
const PubsubTopic1 = "/waku/2/rs/0/2";
|
||||
const PubsubTopic2 = "/waku/2/rs/0/3";
|
||||
|
||||
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 () {
|
||||
this.timeout(15_000);
|
||||
waku = await createLightNode({
|
||||
pubsubTopics: [PubSubTopic1, PubSubTopic2]
|
||||
pubsubTopics: [PubsubTopic1, PubsubTopic2]
|
||||
});
|
||||
|
||||
const encoder1 = createEncoder({
|
||||
contentTopic: ContentTopic,
|
||||
pubsubTopic: PubSubTopic1
|
||||
pubsubTopic: PubsubTopic1
|
||||
});
|
||||
|
||||
const encoder2 = createEncoder({
|
||||
contentTopic: ContentTopic,
|
||||
pubsubTopic: PubSubTopic2
|
||||
pubsubTopic: PubsubTopic2
|
||||
});
|
||||
|
||||
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 () {
|
||||
this.timeout(15_000);
|
||||
waku = await createLightNode({
|
||||
pubsubTopics: [PubSubTopic1]
|
||||
pubsubTopics: [PubsubTopic1]
|
||||
});
|
||||
|
||||
// use a pubsub topic that is not configured
|
||||
const encoder = createEncoder({
|
||||
contentTopic: ContentTopic,
|
||||
pubsubTopic: PubSubTopic2
|
||||
pubsubTopic: PubsubTopic2
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -75,7 +75,7 @@ describe("Static Sharding: Running Nodes", () => {
|
|||
if (
|
||||
!(err instanceof Error) ||
|
||||
!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;
|
||||
|
|
|
@ -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 { bytesToUtf8 } from "@waku/utils/bytes";
|
||||
import { expect } from "chai";
|
||||
|
@ -6,7 +6,7 @@ import { expect } from "chai";
|
|||
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js";
|
||||
|
||||
import {
|
||||
customPubSubTopic,
|
||||
customPubsubTopic,
|
||||
sendMessages,
|
||||
startAndConnectLightNode,
|
||||
TestContentTopic,
|
||||
|
@ -45,7 +45,7 @@ describe("Waku Store, cursor", function () {
|
|||
nwaku,
|
||||
messageCount,
|
||||
TestContentTopic,
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
|
@ -90,7 +90,7 @@ describe("Waku Store, cursor", function () {
|
|||
});
|
||||
|
||||
it("Reusing cursor across nodes", async function () {
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic);
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
|
||||
waku = 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 () {
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic);
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
const messages: DecodedMessage[] = [];
|
||||
|
@ -170,7 +170,7 @@ describe("Waku Store, cursor", 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);
|
||||
|
||||
const messages: DecodedMessage[] = [];
|
||||
|
@ -179,7 +179,7 @@ describe("Waku Store, cursor", function () {
|
|||
messages.push(msg as DecodedMessage);
|
||||
}
|
||||
}
|
||||
messages[5].pubsubTopic = customPubSubTopic;
|
||||
messages[5].pubsubTopic = customPubsubTopic;
|
||||
const cursor = await createCursor(messages[5]);
|
||||
|
||||
try {
|
||||
|
@ -193,7 +193,7 @@ describe("Waku Store, cursor", function () {
|
|||
if (
|
||||
!(err instanceof Error) ||
|
||||
!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;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { DefaultPubSubTopic } from "@waku/core";
|
||||
import { DefaultPubsubTopic } from "@waku/core";
|
||||
import { IMessage, type LightNode } from "@waku/interfaces";
|
||||
import { expect } from "chai";
|
||||
|
||||
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js";
|
||||
|
||||
import {
|
||||
customPubSubTopic,
|
||||
customPubsubTopic,
|
||||
customTestDecoder,
|
||||
processQueriedMessages,
|
||||
startAndConnectLightNode,
|
||||
|
@ -30,7 +30,7 @@ describe("Waku Store, error handling", function () {
|
|||
await tearDownNodes(nwaku, waku);
|
||||
});
|
||||
|
||||
it("Query Generator, Wrong PubSubTopic", async function () {
|
||||
it("Query Generator, Wrong PubsubTopic", async function () {
|
||||
try {
|
||||
for await (const msgPromises of waku.store.queryGenerator([
|
||||
customTestDecoder
|
||||
|
@ -42,7 +42,7 @@ describe("Waku Store, error handling", function () {
|
|||
if (
|
||||
!(err instanceof Error) ||
|
||||
!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;
|
||||
|
@ -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 {
|
||||
for await (const msgPromises of waku.store.queryGenerator([
|
||||
TestDecoder,
|
||||
|
@ -91,12 +91,12 @@ describe("Waku Store, error handling", function () {
|
|||
const messages = await processQueriedMessages(
|
||||
waku,
|
||||
[TestDecoder],
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
expect(messages?.length).eq(0);
|
||||
});
|
||||
|
||||
it("Query with Ordered Callback, Wrong PubSubTopic", async function () {
|
||||
it("Query with Ordered Callback, Wrong PubsubTopic", async function () {
|
||||
try {
|
||||
await waku.store.queryWithOrderedCallback(
|
||||
[customTestDecoder],
|
||||
|
@ -107,7 +107,7 @@ describe("Waku Store, error handling", function () {
|
|||
if (
|
||||
!(err instanceof Error) ||
|
||||
!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;
|
||||
|
@ -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 {
|
||||
await waku.store.queryWithOrderedCallback(
|
||||
[TestDecoder, customTestDecoder],
|
||||
|
@ -156,7 +156,7 @@ describe("Waku Store, error handling", function () {
|
|||
expect(messages?.length).eq(0);
|
||||
});
|
||||
|
||||
it("Query with Promise Callback, Wrong PubSubTopic", async function () {
|
||||
it("Query with Promise Callback, Wrong PubsubTopic", async function () {
|
||||
try {
|
||||
await waku.store.queryWithPromiseCallback(
|
||||
[customTestDecoder],
|
||||
|
@ -167,7 +167,7 @@ describe("Waku Store, error handling", function () {
|
|||
if (
|
||||
!(err instanceof Error) ||
|
||||
!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;
|
||||
|
@ -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 {
|
||||
await waku.store.queryWithPromiseCallback(
|
||||
[TestDecoder, customTestDecoder],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
createDecoder,
|
||||
DecodedMessage,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
import type { IMessage, LightNode } from "@waku/interfaces";
|
||||
|
@ -43,7 +43,7 @@ import {
|
|||
totalMsgs
|
||||
} from "./utils.js";
|
||||
|
||||
const secondDecoder = createDecoder(customContentTopic, DefaultPubSubTopic);
|
||||
const secondDecoder = createDecoder(customContentTopic, DefaultPubsubTopic);
|
||||
|
||||
describe("Waku Store, general", function () {
|
||||
this.timeout(15000);
|
||||
|
@ -64,12 +64,12 @@ describe("Waku Store, general", 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);
|
||||
const messages = await processQueriedMessages(
|
||||
waku,
|
||||
[TestDecoder],
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
|
||||
expect(messages?.length).eq(totalMsgs);
|
||||
|
@ -89,7 +89,7 @@ describe("Waku Store, general", function () {
|
|||
payload: utf8ToBytes(testItem["value"]),
|
||||
contentTopic: TestContentTopic
|
||||
}),
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
)
|
||||
).to.eq(true);
|
||||
await delay(1); // to ensure each timestamp is unique.
|
||||
|
@ -100,7 +100,7 @@ describe("Waku Store, general", function () {
|
|||
messageCollector.list = await processQueriedMessages(
|
||||
waku,
|
||||
[TestDecoder],
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
|
||||
// checking that all message sent were retrieved
|
||||
|
@ -117,14 +117,14 @@ describe("Waku Store, general", function () {
|
|||
payload: utf8ToBytes("M1"),
|
||||
contentTopic: TestContentTopic
|
||||
}),
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
await nwaku.sendMessage(
|
||||
NimGoNode.toMessageRpcQuery({
|
||||
payload: utf8ToBytes("M2"),
|
||||
contentTopic: customContentTopic
|
||||
}),
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
|
@ -132,7 +132,7 @@ describe("Waku Store, general", function () {
|
|||
messageCollector.list = await processQueriedMessages(
|
||||
waku,
|
||||
[TestDecoder, secondDecoder],
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
expect(messageCollector.hasMessage(TestContentTopic, "M1")).to.eq(true);
|
||||
expect(messageCollector.hasMessage(customContentTopic, "M2")).to.eq(true);
|
||||
|
@ -146,7 +146,7 @@ describe("Waku Store, general", function () {
|
|||
payload: utf8ToBytes(messageText),
|
||||
contentTopic: testItem["value"]
|
||||
}),
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
)
|
||||
).to.eq(true);
|
||||
await delay(1); // to ensure each timestamp is unique.
|
||||
|
@ -166,7 +166,7 @@ describe("Waku Store, general", function () {
|
|||
});
|
||||
|
||||
it("Callback on promise", async function () {
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic);
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
const messages: IMessage[] = [];
|
||||
|
@ -188,7 +188,7 @@ describe("Waku Store, general", 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);
|
||||
|
||||
const desiredMsgs = 14;
|
||||
|
@ -301,7 +301,7 @@ describe("Waku Store, general", 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);
|
||||
|
||||
const desiredMsgs = 14;
|
||||
|
@ -320,12 +320,12 @@ describe("Waku Store, general", function () {
|
|||
|
||||
it("Query generator for 2000 messages", async function () {
|
||||
this.timeout(40000);
|
||||
await sendMessages(nwaku, 2000, TestContentTopic, DefaultPubSubTopic);
|
||||
await sendMessages(nwaku, 2000, TestContentTopic, DefaultPubsubTopic);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
const messages = await processQueriedMessages(
|
||||
waku,
|
||||
[TestDecoder],
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
|
||||
expect(messages?.length).eq(2000);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DefaultPubSubTopic, waitForRemotePeer } from "@waku/core";
|
||||
import { DefaultPubsubTopic, waitForRemotePeer } from "@waku/core";
|
||||
import type { IMessage, LightNode } from "@waku/interfaces";
|
||||
import { createLightNode, Protocols } from "@waku/sdk";
|
||||
import { expect } from "chai";
|
||||
|
@ -12,7 +12,7 @@ import {
|
|||
|
||||
import {
|
||||
customContentTopic,
|
||||
customPubSubTopic,
|
||||
customPubsubTopic,
|
||||
customTestDecoder,
|
||||
processQueriedMessages,
|
||||
sendMessages,
|
||||
|
@ -33,10 +33,10 @@ describe("Waku Store, custom pubsub topic", function () {
|
|||
nwaku = new NimGoNode(makeLogFileName(this));
|
||||
await nwaku.start({
|
||||
store: true,
|
||||
topic: [customPubSubTopic, DefaultPubSubTopic],
|
||||
topic: [customPubsubTopic, DefaultPubsubTopic],
|
||||
relay: true
|
||||
});
|
||||
await nwaku.ensureSubscriptions([customPubSubTopic, DefaultPubSubTopic]);
|
||||
await nwaku.ensureSubscriptions([customPubsubTopic, DefaultPubsubTopic]);
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
|
@ -45,12 +45,12 @@ describe("Waku Store, custom pubsub topic", function () {
|
|||
});
|
||||
|
||||
it("Generator, custom pubsub topic", async function () {
|
||||
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubSubTopic);
|
||||
waku = await startAndConnectLightNode(nwaku, [customPubSubTopic]);
|
||||
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubsubTopic);
|
||||
waku = await startAndConnectLightNode(nwaku, [customPubsubTopic]);
|
||||
const messages = await processQueriedMessages(
|
||||
waku,
|
||||
[customTestDecoder],
|
||||
customPubSubTopic
|
||||
customPubsubTopic
|
||||
);
|
||||
|
||||
expect(messages?.length).eq(totalMsgs);
|
||||
|
@ -64,18 +64,18 @@ describe("Waku Store, custom pubsub topic", function () {
|
|||
this.timeout(10000);
|
||||
|
||||
const totalMsgs = 10;
|
||||
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubSubTopic);
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic);
|
||||
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubsubTopic);
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubsubTopic);
|
||||
|
||||
waku = await startAndConnectLightNode(nwaku, [
|
||||
customPubSubTopic,
|
||||
DefaultPubSubTopic
|
||||
customPubsubTopic,
|
||||
DefaultPubsubTopic
|
||||
]);
|
||||
|
||||
const customMessages = await processQueriedMessages(
|
||||
waku,
|
||||
[customTestDecoder],
|
||||
customPubSubTopic
|
||||
customPubsubTopic
|
||||
);
|
||||
expect(customMessages?.length).eq(totalMsgs);
|
||||
const result1 = customMessages?.findIndex((msg) => {
|
||||
|
@ -86,7 +86,7 @@ describe("Waku Store, custom pubsub topic", function () {
|
|||
const testMessages = await processQueriedMessages(
|
||||
waku,
|
||||
[TestDecoder],
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
expect(testMessages?.length).eq(totalMsgs);
|
||||
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 () {
|
||||
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");
|
||||
await nwaku2.start({
|
||||
store: true,
|
||||
topic: [DefaultPubSubTopic],
|
||||
topic: [DefaultPubsubTopic],
|
||||
relay: true
|
||||
});
|
||||
await nwaku2.ensureSubscriptions([DefaultPubSubTopic]);
|
||||
await nwaku2.ensureSubscriptions([DefaultPubsubTopic]);
|
||||
|
||||
const totalMsgs = 10;
|
||||
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubSubTopic);
|
||||
await sendMessages(nwaku2, totalMsgs, TestContentTopic, DefaultPubSubTopic);
|
||||
await sendMessages(nwaku, totalMsgs, customContentTopic, customPubsubTopic);
|
||||
await sendMessages(nwaku2, totalMsgs, TestContentTopic, DefaultPubsubTopic);
|
||||
|
||||
waku = await createLightNode({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
pubsubTopics: [customPubSubTopic, DefaultPubSubTopic]
|
||||
pubsubTopics: [customPubsubTopic, DefaultPubsubTopic]
|
||||
});
|
||||
await waku.start();
|
||||
|
||||
|
@ -131,12 +131,12 @@ describe("Waku Store, custom pubsub topic", function () {
|
|||
customMessages = await processQueriedMessages(
|
||||
waku,
|
||||
[customTestDecoder],
|
||||
customPubSubTopic
|
||||
customPubsubTopic
|
||||
);
|
||||
testMessages = await processQueriedMessages(
|
||||
waku,
|
||||
[TestDecoder],
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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 { expect } from "chai";
|
||||
|
||||
|
@ -36,7 +36,7 @@ describe("Waku Store, order", function () {
|
|||
nwaku,
|
||||
totalMsgs,
|
||||
TestContentTopic,
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe("Waku Store, order", function () {
|
|||
nwaku,
|
||||
totalMsgs,
|
||||
TestContentTopic,
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
|
@ -103,7 +103,7 @@ describe("Waku Store, order", function () {
|
|||
nwaku,
|
||||
totalMsgs,
|
||||
TestContentTopic,
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DefaultPubSubTopic } from "@waku/core";
|
||||
import { DefaultPubsubTopic } from "@waku/core";
|
||||
import type { LightNode } from "@waku/interfaces";
|
||||
import { expect } from "chai";
|
||||
|
||||
|
@ -42,7 +42,7 @@ describe("Waku Store, page size", function () {
|
|||
nwaku,
|
||||
messageCount,
|
||||
TestContentTopic,
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
|
||||
// Determine effectivePageSize for test expectations
|
||||
|
@ -82,7 +82,7 @@ describe("Waku Store, page size", function () {
|
|||
|
||||
// Possible issue here because pageSize differs across implementations
|
||||
it("Default pageSize", async function () {
|
||||
await sendMessages(nwaku, 20, TestContentTopic, DefaultPubSubTopic);
|
||||
await sendMessages(nwaku, 20, TestContentTopic, DefaultPubsubTopic);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
let messagesRetrieved = 0;
|
||||
|
|
|
@ -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 { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js";
|
||||
|
@ -34,7 +34,7 @@ describe("Waku Store, sorting", function () {
|
|||
nwaku,
|
||||
totalMsgs,
|
||||
TestContentTopic,
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
|
@ -69,7 +69,7 @@ describe("Waku Store, sorting", function () {
|
|||
nwaku,
|
||||
totalMsgs,
|
||||
TestContentTopic,
|
||||
DefaultPubSubTopic
|
||||
DefaultPubsubTopic
|
||||
);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
createEncoder,
|
||||
DecodedMessage,
|
||||
Decoder,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
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 TestDecoder = createDecoder(TestContentTopic);
|
||||
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(
|
||||
customContentTopic,
|
||||
customPubSubTopic
|
||||
customPubsubTopic
|
||||
);
|
||||
export const totalMsgs = 20;
|
||||
export const messageText = "Store Push works!";
|
||||
|
@ -66,7 +66,7 @@ export async function processQueriedMessages(
|
|||
|
||||
export async function startAndConnectLightNode(
|
||||
instance: NimGoNode,
|
||||
pubsubTopics: string[] = [DefaultPubSubTopic]
|
||||
pubsubTopics: string[] = [DefaultPubsubTopic]
|
||||
): Promise<LightNode> {
|
||||
const waku = await createLightNode({
|
||||
pubsubTopics: pubsubTopics,
|
||||
|
|
|
@ -4,7 +4,7 @@ import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
|
|||
import {
|
||||
createDecoder,
|
||||
createEncoder,
|
||||
DefaultPubSubTopic,
|
||||
DefaultPubsubTopic,
|
||||
waitForRemotePeer
|
||||
} from "@waku/core";
|
||||
import { LightNode } from "@waku/interfaces";
|
||||
|
@ -70,7 +70,7 @@ describe("Util: toAsyncIterator: Filter", () => {
|
|||
const { value } = await iterator.next();
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DefaultPubSubTopic, waitForRemotePeer } from "@waku/core";
|
||||
import { DefaultPubsubTopic, waitForRemotePeer } from "@waku/core";
|
||||
import type { LightNode, RelayNode } from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import { createLightNode, createRelayNode } from "@waku/sdk";
|
||||
|
@ -40,7 +40,7 @@ describe("Wait for remote peer", function () {
|
|||
await waku1.dial(multiAddrWithId);
|
||||
await delay(1000);
|
||||
await waitForRemotePeer(waku1, [Protocols.Relay]);
|
||||
const peers = waku1.relay.getMeshPeers(DefaultPubSubTopic);
|
||||
const peers = waku1.relay.getMeshPeers(DefaultPubsubTopic);
|
||||
const nimPeerId = multiAddrWithId.getPeerId();
|
||||
|
||||
expect(nimPeerId).to.not.be.undefined;
|
||||
|
@ -263,7 +263,7 @@ describe("Wait for remote peer", function () {
|
|||
await waku1.dial(multiAddrWithId);
|
||||
await waitForRemotePeer(waku1);
|
||||
|
||||
const peers = waku1.relay.getMeshPeers(DefaultPubSubTopic);
|
||||
const peers = waku1.relay.getMeshPeers(DefaultPubsubTopic);
|
||||
|
||||
const nimPeerId = multiAddrWithId.getPeerId();
|
||||
|
||||
|
|
|
@ -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
|
||||
): PubSubTopic[] => {
|
||||
): PubsubTopic[] => {
|
||||
return shardInfo.indexList.map(
|
||||
(index) => `/waku/2/rs/${shardInfo.cluster}/${index}`
|
||||
);
|
||||
};
|
||||
|
||||
export function ensurePubsubTopicIsConfigured(
|
||||
pubsubTopic: PubSubTopic,
|
||||
configuredTopics: PubSubTopic[]
|
||||
pubsubTopic: PubsubTopic,
|
||||
configuredTopics: PubsubTopic[]
|
||||
): void {
|
||||
if (!configuredTopics.includes(pubsubTopic)) {
|
||||
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.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue