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 9f198dd commit a4f3ac0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/sdk/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import { CreateWakuNodeOptions, WakuNode, WakuOptions } from "./waku.js";

export { Libp2pComponents };

export async function createApplicationNode(
application: string,
version: string,
options?: ProtocolCreateOptions &
Partial<WakuOptions> &
Partial<RelayCreateOptions>
): 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 a4f3ac0

Please sign in to comment.