mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-05-06 02:09:30 +00:00
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard). This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding. It also included various back and forth conversions between shards, pubsub topics, etc. With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded. We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration. Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage. # Conflicts: # packages/core/src/lib/connection_manager/connection_manager.ts # packages/core/src/lib/metadata/metadata.ts # packages/interfaces/src/metadata.ts # packages/interfaces/src/sharding.ts # packages/relay/src/create.ts # packages/sdk/src/filter/filter.ts # packages/sdk/src/filter/types.ts # packages/sdk/src/light_push/light_push.spec.ts # packages/tests/tests/sharding/auto_sharding.spec.ts # packages/tests/tests/sharding/static_sharding.spec.ts # Conflicts: # packages/sdk/src/store/store.ts
89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import type { IProtoMessage } from "@waku/interfaces";
|
|
import { createRoutingInfo } from "@waku/utils";
|
|
import { expect } from "chai";
|
|
|
|
import { createRLN } from "./create.js";
|
|
import type { IdentityCredential } from "./identity.js";
|
|
|
|
export interface TestRLNCodecSetup {
|
|
rlnInstance: any;
|
|
credential: IdentityCredential;
|
|
index: number;
|
|
payload: Uint8Array;
|
|
}
|
|
|
|
export const TestConstants = {
|
|
contentTopic: "/test/1/waku-message/utf8",
|
|
emptyPubsubTopic: "",
|
|
defaultIndex: 0,
|
|
defaultPayload: new Uint8Array([1, 2, 3, 4, 5]),
|
|
routingInfo: createRoutingInfo(
|
|
{
|
|
clusterId: 0,
|
|
numShardsInCluster: 2
|
|
},
|
|
{ contentTopic: "/test/1/waku-message/utf8" }
|
|
)
|
|
} as const;
|
|
|
|
export const EmptyProtoMessage = {
|
|
timestamp: undefined,
|
|
contentTopic: "",
|
|
ephemeral: undefined,
|
|
meta: undefined,
|
|
rateLimitProof: undefined,
|
|
version: undefined
|
|
} as const;
|
|
|
|
/**
|
|
* Creates a basic RLN setup for codec tests
|
|
*/
|
|
export async function createTestRLNCodecSetup(): Promise<TestRLNCodecSetup> {
|
|
const rlnInstance = await createRLN();
|
|
const credential = rlnInstance.zerokit.generateIdentityCredentials();
|
|
rlnInstance.zerokit.insertMember(credential.IDCommitment);
|
|
|
|
return {
|
|
rlnInstance,
|
|
credential,
|
|
index: TestConstants.defaultIndex,
|
|
payload: TestConstants.defaultPayload
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a meta setter function for testing
|
|
*/
|
|
export function createTestMetaSetter(): (
|
|
msg: IProtoMessage & { meta: undefined }
|
|
) => Uint8Array {
|
|
return (msg: IProtoMessage & { meta: undefined }): Uint8Array => {
|
|
const buffer = new ArrayBuffer(4);
|
|
const view = new DataView(buffer);
|
|
view.setUint32(0, msg.payload.length, false);
|
|
return new Uint8Array(buffer);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Verifies common RLN message properties
|
|
*/
|
|
export function verifyRLNMessage(
|
|
msg: any,
|
|
payload: Uint8Array,
|
|
contentTopic: string,
|
|
version: number,
|
|
rlnInstance: any
|
|
): void {
|
|
expect(msg.rateLimitProof).to.not.be.undefined;
|
|
expect(msg.verify([rlnInstance.zerokit.getMerkleRoot()])).to.be.true;
|
|
expect(msg.verifyNoRoot()).to.be.true;
|
|
expect(msg.epoch).to.not.be.undefined;
|
|
expect(msg.epoch).to.be.gt(0);
|
|
|
|
expect(msg.contentTopic).to.eq(contentTopic);
|
|
expect(msg.msg.version).to.eq(version);
|
|
expect(msg.payload).to.deep.eq(payload);
|
|
expect(msg.timestamp).to.not.be.undefined;
|
|
}
|