From f66e9835f1093f707198b2d4c53d28a5c8be590c Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Thu, 16 Feb 2023 13:27:39 +1100 Subject: [PATCH] test: nwaku JSON RPC API now uses base64 encoding --- packages/tests/src/nwaku.ts | 21 +++++++++----------- packages/tests/tests/light_push.node.spec.ts | 7 ++++--- packages/tests/tests/relay.node.spec.ts | 5 ++--- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/tests/src/nwaku.ts b/packages/tests/src/nwaku.ts index 23113301ce..fad08bd47e 100644 --- a/packages/tests/src/nwaku.ts +++ b/packages/tests/src/nwaku.ts @@ -81,13 +81,6 @@ export interface MessageRpcQuery { } export interface MessageRpcResponse { - payload: number[]; - contentTopic?: string; - version?: number; - timestamp?: bigint; // Unix epoch time in nanoseconds as a 64-bits integer value. -} - -export interface MessageRpcResponseHex { payload: string; contentTopic?: string; version?: number; @@ -122,7 +115,7 @@ export class Nwaku { } return { - payload: bytesToHex(message.payload), + payload: Buffer.from(message.payload).toString("base64url"), contentTopic: message.contentTopic, timestamp, }; @@ -321,10 +314,10 @@ export class Nwaku { async getAsymmetricMessages( privateKey: Uint8Array, pubSubTopic?: string - ): Promise { + ): Promise { this.checkProcess(); - return await this.rpcCall( + return await this.rpcCall( "get_waku_v2_private_v1_asymmetric_messages", [ pubSubTopic ? pubSubTopic : DefaultPubSubTopic, @@ -363,10 +356,10 @@ export class Nwaku { async getSymmetricMessages( symKey: Uint8Array, pubSubTopic?: string - ): Promise { + ): Promise { this.checkProcess(); - return await this.rpcCall( + return await this.rpcCall( "get_waku_v2_private_v1_symmetric_messages", [ pubSubTopic ? pubSubTopic : DefaultPubSubTopic, @@ -475,3 +468,7 @@ interface RpcInfoResponse { listenAddresses: string[]; enrUri?: string; } + +export function base64ToUtf8(b64: string): string { + return Buffer.from(b64, "base64").toString("utf-8"); +} diff --git a/packages/tests/tests/light_push.node.spec.ts b/packages/tests/tests/light_push.node.spec.ts index c82ad51942..72ef6b211a 100644 --- a/packages/tests/tests/light_push.node.spec.ts +++ b/packages/tests/tests/light_push.node.spec.ts @@ -2,11 +2,12 @@ import { createEncoder, waitForRemotePeer } from "@waku/core"; import { createLightNode } from "@waku/create"; import type { LightNode } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces"; -import { bytesToUtf8, utf8ToBytes } from "@waku/utils"; +import { utf8ToBytes } from "@waku/utils"; import { expect } from "chai"; import debug from "debug"; import { + base64ToUtf8, delay, makeLogFileName, MessageRpcResponse, @@ -58,7 +59,7 @@ describe("Waku Light Push [node only]", () => { } expect(msgs[0].contentTopic).to.equal(TestContentTopic); - expect(bytesToUtf8(new Uint8Array(msgs[0].payload))).to.equal(messageText); + expect(base64ToUtf8(msgs[0].payload)).to.equal(messageText); }); it("Push on custom pubsub topic", async function () { @@ -105,6 +106,6 @@ describe("Waku Light Push [node only]", () => { } expect(msgs[0].contentTopic).to.equal(TestContentTopic); - expect(bytesToUtf8(new Uint8Array(msgs[0].payload))!).to.equal(messageText); + expect(base64ToUtf8(msgs[0].payload!)).to.equal(messageText); }); }); diff --git a/packages/tests/tests/relay.node.spec.ts b/packages/tests/tests/relay.node.spec.ts index d1f085b000..e0e62e7435 100644 --- a/packages/tests/tests/relay.node.spec.ts +++ b/packages/tests/tests/relay.node.spec.ts @@ -25,6 +25,7 @@ import { expect } from "chai"; import debug from "debug"; import { + base64ToUtf8, delay, makeLogFileName, MessageRpcResponse, @@ -389,9 +390,7 @@ describe("Waku Relay [node only]", () => { expect(msgs[0].contentTopic).to.equal(TestContentTopic); expect(msgs[0].version).to.equal(0); - expect(bytesToUtf8(new Uint8Array(msgs[0].payload))).to.equal( - messageText - ); + expect(base64ToUtf8(msgs[0].payload)).to.equal(messageText); }); it("Nwaku publishes", async function () {