feat: add SDK function for creating node from application and version

This commit is contained in:
Arseniy Klempner 2024-03-01 15:51:47 -08:00
parent 5e1bce494f
commit f8b8df8c75
No known key found for this signature in database
GPG Key ID: 59967D458EFBF01B
2 changed files with 30 additions and 0 deletions

View File

@ -6,6 +6,15 @@ import { CreateWakuNodeOptions, WakuNode, WakuOptions } from "./waku.js";
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.
*/

View 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);
});
});