Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: new store tests #1627

Merged
merged 21 commits into from
Oct 10, 2023
Merged

chore: new store tests #1627

merged 21 commits into from
Oct 10, 2023

Conversation

fbarbu15
Copy link
Collaborator

@fbarbu15 fbarbu15 commented Oct 2, 2023

Problem

There were only 9 store tests and the protocol was lacking in coverage

Solution

Reached ~60 tests and increased coverage

Notes

In this PR I also did some refactoring to common methods so they work for store as well. In doing this there are some updates to other tests from other protocols.
Also I increased some timeouts to some flaky tests/methods

@fbarbu15 fbarbu15 added the E:End-to-end testing See https://github.com/waku-org/pm/issues/34 for details label Oct 2, 2023
@fbarbu15 fbarbu15 changed the title Chore/new store tests chorenew store tests Oct 2, 2023
@fbarbu15 fbarbu15 changed the title chorenew store tests chore: new store tests Oct 2, 2023
@github-actions
Copy link

github-actions bot commented Oct 2, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku core 27.87 KB (0%) 558 ms (0%) 392 ms (+14.3% 🔺) 949 ms
Waku Simple Light Node 262.91 KB (0%) 5.3 s (0%) 1.3 s (+36.64% 🔺) 6.6 s
ECIES encryption 29.58 KB (-0.45% 🔽) 592 ms (-0.45% 🔽) 333 ms (-14.15% 🔽) 924 ms
Symmetric encryption 29.59 KB (-0.45% 🔽) 592 ms (-0.45% 🔽) 444 ms (+67.59% 🔺) 1.1 s
DNS discovery 110.67 KB (-0.04% 🔽) 2.3 s (-0.04% 🔽) 792 ms (+9.83% 🔺) 3.1 s
Privacy preserving protocols 117.44 KB (0%) 2.4 s (0%) 682 ms (+8.06% 🔺) 3.1 s
Light protocols 26.01 KB (0%) 521 ms (0%) 284 ms (-3.51% 🔽) 805 ms
History retrieval protocols 25.22 KB (0%) 505 ms (0%) 243 ms (-12.29% 🔽) 747 ms
Deterministic Message Hashing 5.65 KB (0%) 113 ms (0%) 100 ms (-1.76% 🔽) 213 ms

@fbarbu15 fbarbu15 marked this pull request as ready for review October 6, 2023 10:50
@fbarbu15 fbarbu15 requested a review from a team as a code owner October 6, 2023 10:50

import { NimGoNode } from "./index.js";

const log = debug("waku:test");

export function tearDownNodes(
export async function tearDownNodes(
nwakuNodes: NimGoNode[],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I see we do tearDownNodes([nodeA], [nodeB]);
type can be changed to NimGoNode | NimGoNode[] and condition inside made like here

const decodersArray = Array.isArray(decoders) ? decoders : [decoders];

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks better with this change

@@ -0,0 +1,7 @@
export function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe some package can handle that for us as well as other utils we have specific for tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I found lodash for this specific function and started using it
Will review other "generic" custom test utils if they can be replaced with known packages but in another PR because this one is already big enough

Copy link
Collaborator

@weboko weboko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome job 🔥

@fbarbu15 fbarbu15 merged commit ac00004 into master Oct 10, 2023
9 of 11 checks passed
@fbarbu15 fbarbu15 deleted the chore/new-store-tests branch October 10, 2023 06:42
@@ -0,0 +1,7 @@
export function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use uint8arrays/equal as we already import this package and use it.

import { equals } from "uint8arrays/equals";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, didn't knew about this one

@@ -341,7 +342,7 @@ describe("Waku Filter V2: Subscribe", function () {
}

// Check if both messages were received
expect(messageCollector.hasMessage(TestContentTopic, "M1")).to.be.true;
expect(messageCollector.hasMessage(newContentTopic, "M2")).to.be.true;
expect(messageCollector.hasMessage(TestContentTopic, "M1")).to.eq(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, did we end having "true-ish" value returned instead of true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, seems that .to.be.true was passing even when the value was not actually true. So i've replaced it with .to.eq(true) which seems stricter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, seems that .to.be.true was passing even when the value was not actually true. So i've replaced it with .to.eq(true) which seems stricter

I'd try to fix your hasMessage function 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed this function and similar functions that used .to.be.true and all the paths return True or False and they work as expected now. However those functions had changes in the recent path so it's indeed possible that they were missbehaving when I spotted this issue with .to.be.true.

@@ -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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have uint8arrays dependency already and it has uint8arrays/equal

@@ -26,7 +29,7 @@ export async function tearDownNodes(
}
});

const stopWakuNodes = wakuNodes.map(async (waku) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently thought about this and remoteNode might be the best descriptive

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is outdated and not sure I understand you suggestion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I saw a wNode name and we have a weird "NimGoWaku" naming var in the code. I am saying that maybe we should use "remoteNode" as a terminology instead. It's a nitpick. Cc @waku-org/js-waku-developers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, ok that makes sense. Will update it with a next PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E:End-to-end testing See https://github.com/waku-org/pm/issues/34 for details
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants