Skip to content

Commit

Permalink
feat: add SDK function for creating node from application and version
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner committed Mar 4, 2024
1 parent 5e1bce4 commit f8b8df8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/sdk/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
21 changes: 21 additions & 0 deletions packages/tests/tests/sdk/application_version.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit f8b8df8

Please sign in to comment.