From a4f3ac0bbc7d0b296f250b1d58e987c393598bff Mon Sep 17 00:00:00 2001 From: Arseniy Klempner Date: Fri, 1 Mar 2024 15:51:47 -0800 Subject: [PATCH] feat: add SDK function for creating node from application and version --- packages/sdk/src/create.ts | 11 ++++++++++ .../tests/sdk/application_version.spec.ts | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 packages/tests/tests/sdk/application_version.spec.ts diff --git a/packages/sdk/src/create.ts b/packages/sdk/src/create.ts index ba3e6d9ab9..5a7928392b 100644 --- a/packages/sdk/src/create.ts +++ b/packages/sdk/src/create.ts @@ -6,6 +6,17 @@ import { CreateWakuNodeOptions, WakuNode, WakuOptions } from "./waku.js"; export { Libp2pComponents }; +export async function createApplicationNode( + application: string, + version: string, + options?: ProtocolCreateOptions & + Partial & + Partial +): Promise { + options = options ?? {}; + options.shardInfo = { application, version }; + return createNode(options); +} /** * Create a Waku node configured to use autosharding or static sharding. */ diff --git a/packages/tests/tests/sdk/application_version.spec.ts b/packages/tests/tests/sdk/application_version.spec.ts new file mode 100644 index 0000000000..657b6aeda8 --- /dev/null +++ b/packages/tests/tests/sdk/application_version.spec.ts @@ -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); + }); +});