From aa93a441d57ba3b049c0a5b35d21fdcd43d112ee Mon Sep 17 00:00:00 2001 From: fbarbu15 Date: Tue, 10 Oct 2023 09:15:36 +0300 Subject: [PATCH] use loadash instead of custom function --- package-lock.json | 23 +++++++++++++++++-- packages/tests/package.json | 2 ++ packages/tests/src/message_collector.ts | 4 ++-- packages/tests/src/utils.ts | 7 ------ packages/tests/tests/store/index.node.spec.ts | 6 ++--- 5 files changed, 27 insertions(+), 15 deletions(-) delete mode 100644 packages/tests/src/utils.ts diff --git a/package-lock.json b/package-lock.json index 799a09ac41..6a2f998419 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3961,6 +3961,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/lodash": { + "version": "4.14.199", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.199.tgz", + "integrity": "sha512-Vrjz5N5Ia4SEzWWgIVwnHNEnb1UE1XMkvY5DGXrAeOGE9imk0hgTHh5GyDjLDJi9OTCn9oo9dXH1uToK1VRfrg==", + "dev": true + }, "node_modules/@types/markdown-it": { "version": "12.2.3", "dev": true, @@ -13571,7 +13577,8 @@ }, "node_modules/lodash": { "version": "4.17.21", - "license": "MIT" + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash-es": { "version": "4.17.21", @@ -26134,6 +26141,7 @@ "chai-as-promised": "^7.1.1", "debug": "^4.3.4", "dockerode": "^3.3.5", + "lodash": "^4.17.21", "p-retry": "^6.1.0", "p-timeout": "^6.1.0", "portfinder": "^1.0.32", @@ -26144,6 +26152,7 @@ "@libp2p/bootstrap": "^9.0.2", "@types/chai": "^4.3.5", "@types/dockerode": "^3.3.19", + "@types/lodash": "^4.14.199", "@types/mocha": "^10.0.1", "@types/sinon": "^10.0.16", "@types/tail": "^2.2.1", @@ -28698,6 +28707,12 @@ "version": "3.0.3", "dev": true }, + "@types/lodash": { + "version": "4.14.199", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.199.tgz", + "integrity": "sha512-Vrjz5N5Ia4SEzWWgIVwnHNEnb1UE1XMkvY5DGXrAeOGE9imk0hgTHh5GyDjLDJi9OTCn9oo9dXH1uToK1VRfrg==", + "dev": true + }, "@types/markdown-it": { "version": "12.2.3", "dev": true, @@ -29322,6 +29337,7 @@ "@libp2p/peer-id": "^3.0.2", "@types/chai": "^4.3.5", "@types/dockerode": "^3.3.19", + "@types/lodash": "^4.14.199", "@types/mocha": "^10.0.1", "@types/sinon": "^10.0.16", "@types/tail": "^2.2.1", @@ -29342,6 +29358,7 @@ "dockerode": "^3.3.5", "interface-datastore": "^8.2.5", "libp2p": "^0.46.12", + "lodash": "^4.17.21", "mocha": "^10.2.0", "npm-run-all": "^4.1.5", "p-retry": "^6.1.0", @@ -34746,7 +34763,9 @@ } }, "lodash": { - "version": "4.17.21" + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash-es": { "version": "4.17.21" diff --git a/packages/tests/package.json b/packages/tests/package.json index 330e46d299..b5c5a844c8 100644 --- a/packages/tests/package.json +++ b/packages/tests/package.json @@ -60,6 +60,7 @@ "chai-as-promised": "^7.1.1", "debug": "^4.3.4", "dockerode": "^3.3.5", + "lodash": "^4.17.21", "p-retry": "^6.1.0", "p-timeout": "^6.1.0", "portfinder": "^1.0.32", @@ -70,6 +71,7 @@ "@libp2p/bootstrap": "^9.0.2", "@types/chai": "^4.3.5", "@types/dockerode": "^3.3.19", + "@types/lodash": "^4.14.199", "@types/mocha": "^10.0.1", "@types/sinon": "^10.0.16", "@types/tail": "^2.2.1", diff --git a/packages/tests/src/message_collector.ts b/packages/tests/src/message_collector.ts index 79ac745138..5b26e56615 100644 --- a/packages/tests/src/message_collector.ts +++ b/packages/tests/src/message_collector.ts @@ -2,9 +2,9 @@ import { DecodedMessage, DefaultPubSubTopic } from "@waku/core"; import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { AssertionError, expect } from "chai"; import debug from "debug"; +import isEqual from "lodash/isEqual"; import { MessageRpcResponse } from "./node/interfaces.js"; -import { areUint8ArraysEqual } from "./utils.js"; import { base64ToUtf8, delay, NimGoNode } from "./index.js"; @@ -44,7 +44,7 @@ export class MessageCollector { if (typeof message.payload === "string") { return message.payload === text; } else if (message.payload instanceof Uint8Array) { - return areUint8ArraysEqual(message.payload, utf8ToBytes(text)); + return isEqual(message.payload, utf8ToBytes(text)); } return false; }); diff --git a/packages/tests/src/utils.ts b/packages/tests/src/utils.ts deleted file mode 100644 index 961f5ff440..0000000000 --- a/packages/tests/src/utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean { - if (a.length !== b.length) return false; - for (let i = 0; i < a.length; i++) { - if (a[i] !== b[i]) return false; - } - return true; -} diff --git a/packages/tests/tests/store/index.node.spec.ts b/packages/tests/tests/store/index.node.spec.ts index 964151a637..f519535a72 100644 --- a/packages/tests/tests/store/index.node.spec.ts +++ b/packages/tests/tests/store/index.node.spec.ts @@ -19,6 +19,7 @@ import { } from "@waku/message-encryption/symmetric"; import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; +import isEqual from "lodash/isEqual"; import { delay, @@ -28,7 +29,6 @@ import { tearDownNodes, TEST_STRING } from "../../src/index.js"; -import { areUint8ArraysEqual } from "../../src/utils.js"; import { customContentTopic, @@ -159,9 +159,7 @@ describe("Waku Store, general", function () { createDecoder(testItem["value"]) ])) { for await (const msg of query) { - expect( - areUint8ArraysEqual(msg!.payload, utf8ToBytes(messageText)) - ).to.eq(true); + expect(isEqual(msg!.payload, utf8ToBytes(messageText))).to.eq(true); } } }