mirror of https://github.com/waku-org/js-waku.git
test: remove dupe functions
This commit is contained in:
parent
cdd0752ad6
commit
024209fdd0
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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[];
|
||||
|
|
Loading…
Reference in New Issue