diff --git a/packages/sdk/src/create.ts b/packages/sdk/src/create.ts index ba3e6d9ab9..9f580e7faa 100644 --- a/packages/sdk/src/create.ts +++ b/packages/sdk/src/create.ts @@ -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 { + 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); + }); +});