From 024209fdd01b4f1807c5995875dcb68bd35a34d1 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 26 May 2022 15:50:51 +1000 Subject: [PATCH] test: remove dupe functions --- src/test_utils/nwaku.node.spec.ts | 21 +-------------------- src/test_utils/nwaku.ts | 24 +----------------------- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/src/test_utils/nwaku.node.spec.ts b/src/test_utils/nwaku.node.spec.ts index ac893bd226..95e1ffdf16 100644 --- a/src/test_utils/nwaku.node.spec.ts +++ b/src/test_utils/nwaku.node.spec.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { argsToArray, bytesToHex, defaultArgs, strToHex } from "./nwaku"; +import { argsToArray, defaultArgs } from "./nwaku"; describe("nwaku", () => { it("Correctly serialized arguments", function () { @@ -21,23 +21,4 @@ describe("nwaku", () => { expect(actual).to.deep.equal(expected); }); - - it("Convert utf-8 string to hex", function () { - const str = "This is an utf-8 string."; - const expected = "5468697320697320616e207574662d3820737472696e672e"; - - const actual = strToHex(str); - expect(actual).deep.equal(expected); - }); - - it("Convert buffer to hex", function () { - const buf = Uint8Array.from([ - 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x75, - 0x74, 0x66, 0x2d, 0x38, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - ]); - const expected = "5468697320697320616e207574662d3820737472696e672e"; - - const actual = bytesToHex(buf); - expect(actual).to.deep.equal(expected); - }); }); diff --git a/src/test_utils/nwaku.ts b/src/test_utils/nwaku.ts index 73bc34e9a8..6ad046fd59 100644 --- a/src/test_utils/nwaku.ts +++ b/src/test_utils/nwaku.ts @@ -13,7 +13,7 @@ import debug from "debug"; import portfinder from "portfinder"; import { DefaultPubSubTopic } from "../lib/constants"; -import { hexToBytes } from "../lib/utils"; +import { bytesToHex, hexToBytes } from "../lib/utils"; import { WakuMessage } from "../lib/waku_message"; import * as proto from "../proto/message"; @@ -405,28 +405,6 @@ export function defaultArgs(): Args { }; } -export function strToHex(str: string): string { - let hex: string; - try { - hex = unescape(encodeURIComponent(str)) - .split("") - .map(function (v) { - return v.charCodeAt(0).toString(16); - }) - .join(""); - } catch (e) { - hex = str; - console.log("invalid text input: " + str); - } - return hex; -} - -export function bytesToHex(buffer: Uint8Array): string { - return Array.prototype.map - .call(buffer, (x) => ("00" + x.toString(16)).slice(-2)) - .join(""); -} - interface RpcInfoResponse { // multiaddrs including peer id. listenAddresses: string[];