use loadash instead of custom function

This commit is contained in:
fbarbu15 2023-10-10 09:15:36 +03:00
parent c9389e3d07
commit aa93a441d5
No known key found for this signature in database
GPG Key ID: D75221C8DEA22501
5 changed files with 27 additions and 15 deletions

23
package-lock.json generated
View File

@ -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"

View File

@ -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",

View File

@ -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;
});

View File

@ -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;
}

View File

@ -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);
}
}
}