mirror of https://github.com/status-im/js-waku.git
test: nwaku JSON RPC API now uses base64 encoding
This commit is contained in:
parent
5a92d74c62
commit
f66e9835f1
|
@ -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<MessageRpcResponseHex[]> {
|
||||
): Promise<MessageRpcResponse[]> {
|
||||
this.checkProcess();
|
||||
|
||||
return await this.rpcCall<MessageRpcResponseHex[]>(
|
||||
return await this.rpcCall<MessageRpcResponse[]>(
|
||||
"get_waku_v2_private_v1_asymmetric_messages",
|
||||
[
|
||||
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
|
||||
|
@ -363,10 +356,10 @@ export class Nwaku {
|
|||
async getSymmetricMessages(
|
||||
symKey: Uint8Array,
|
||||
pubSubTopic?: string
|
||||
): Promise<MessageRpcResponseHex[]> {
|
||||
): Promise<MessageRpcResponse[]> {
|
||||
this.checkProcess();
|
||||
|
||||
return await this.rpcCall<MessageRpcResponseHex[]>(
|
||||
return await this.rpcCall<MessageRpcResponse[]>(
|
||||
"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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in New Issue