mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-16 14:26:53 +00:00
feat: add SDK function for creating node from application and version
This commit is contained in:
parent
5e1bce494f
commit
f8b8df8c75
@ -6,6 +6,15 @@ import { CreateWakuNodeOptions, WakuNode, WakuOptions } from "./waku.js";
|
|||||||
|
|
||||||
export { Libp2pComponents };
|
export { Libp2pComponents };
|
||||||
|
|
||||||
|
export async function createApplicationNode(
|
||||||
|
application: string,
|
||||||
|
version: string,
|
||||||
|
options: CreateWakuNodeOptions = { pubsubTopics: [] }
|
||||||
|
): Promise<LightNode> {
|
||||||
|
options = options ?? {};
|
||||||
|
options.shardInfo = { application, version };
|
||||||
|
return createNode(options);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Create a Waku node configured to use autosharding or static sharding.
|
* Create a Waku node configured to use autosharding or static sharding.
|
||||||
*/
|
*/
|
||||||
|
21
packages/tests/tests/sdk/application_version.spec.ts
Normal file
21
packages/tests/tests/sdk/application_version.spec.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { createApplicationNode, WakuNode } from "@waku/sdk";
|
||||||
|
import {
|
||||||
|
contentTopicToPubsubTopic,
|
||||||
|
ensureValidContentTopic
|
||||||
|
} from "@waku/utils";
|
||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
describe("SDK: Creating by Application and Version", function () {
|
||||||
|
const ContentTopic = "/myapp/1/latest/proto";
|
||||||
|
|
||||||
|
it("given an application and version, creates a waku node with the correct pubsub topic", async function () {
|
||||||
|
const contentTopic = ensureValidContentTopic(ContentTopic);
|
||||||
|
const waku = await createApplicationNode(
|
||||||
|
contentTopic.application,
|
||||||
|
contentTopic.version
|
||||||
|
);
|
||||||
|
const expectedPubsubTopic = contentTopicToPubsubTopic(ContentTopic);
|
||||||
|
|
||||||
|
expect((waku as WakuNode).pubsubTopics).to.include(expectedPubsubTopic);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user