Skip to content

Commit

Permalink
chore: update tests for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Jun 20, 2024
1 parent 67af266 commit 9875578
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 38 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export { StoreCore } from "./lib/store/v3/index.js";
export * as waku_store_v2 from "./lib/store/v2/index.js";
export { StoreCore as StoreCoreV2 } from "./lib/store/v2/index.js";

export { PageDirection } from "./lib/store/v2/index.js";

export { waitForRemotePeer } from "./lib/wait_for_remote_peer.js";

export { ConnectionManager } from "./lib/connection_manager.js";
Expand Down
8 changes: 3 additions & 5 deletions packages/tests/tests/store/cursor.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe("Waku Store, cursor", function () {
).to.be.eq(bytesToUtf8(messages[messages.length - 1].payload));
});

it("Passing cursor with wrong message digest", async function () {
it("Passing invalid cursor", async function () {
await sendMessages(
nwaku,
totalMsgs,
Expand All @@ -146,10 +146,9 @@ describe("Waku Store, cursor", function () {
messages.push(msg as DecodedMessage);
}
}
const cursor = waku.store.createCursor(messages[5]);

// setting a wrong digest
cursor.digest = new Uint8Array([]);
// setting an invalid cursor
const cursor = new Uint8Array([2, 3]);

const messagesAfterCursor: DecodedMessage[] = [];
try {
Expand All @@ -162,7 +161,6 @@ describe("Waku Store, cursor", function () {
}
}
}
// Should return same as go-waku. Raised bug: https://github.com/waku-org/nwaku/issues/2117
expect(messagesAfterCursor.length).to.eql(0);
} catch (error) {
if (
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/tests/store/index.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe("Waku Store, general", function () {
}
return messages.length >= desiredMsgs;
},
{ pageSize: 7 }
{ paginationLimit: 7 }
);

expect(messages?.length).eq(desiredMsgs);
Expand Down Expand Up @@ -334,7 +334,7 @@ describe("Waku Store, general", function () {
messages.push(msg);
return messages.length >= desiredMsgs;
},
{ pageSize: 7 }
{ paginationLimit: 7 }
);

expect(messages?.length).eq(desiredMsgs);
Expand Down
20 changes: 10 additions & 10 deletions packages/tests/tests/store/order.node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DecodedMessage, PageDirection } from "@waku/core";
import { DecodedMessage } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces";
import { expect } from "chai";

Expand Down Expand Up @@ -31,7 +31,7 @@ describe("Waku Store, order", function () {
await tearDownNodes(nwaku, waku);
});

[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
[true, false].forEach((pageDirection) => {
it(`Query Generator - ${pageDirection}`, async function () {
await sendMessages(
nwaku,
Expand All @@ -42,7 +42,7 @@ describe("Waku Store, order", function () {

const messages: IMessage[] = [];
for await (const query of waku.store.queryGenerator([TestDecoder], {
pageDirection: pageDirection
paginationForward: pageDirection
})) {
for await (const msg of query) {
if (msg) {
Expand All @@ -52,7 +52,7 @@ describe("Waku Store, order", function () {
}

let expectedPayloads = Array.from(Array(totalMsgs).keys());
if (pageDirection === PageDirection.BACKWARD) {
if (pageDirection === true) {
expectedPayloads = chunkAndReverseArray(expectedPayloads, 10);
}

Expand All @@ -62,7 +62,7 @@ describe("Waku Store, order", function () {
});
});

[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
[true, false].forEach((pageDirection) => {
it(`Promise Callback - ${pageDirection}`, async function () {
await sendMessages(
nwaku,
Expand All @@ -81,12 +81,12 @@ describe("Waku Store, order", function () {
}
},
{
pageDirection: pageDirection
paginationForward: pageDirection
}
);

let expectedPayloads = Array.from(Array(totalMsgs).keys());
if (pageDirection === PageDirection.BACKWARD) {
if (pageDirection === false) {
expectedPayloads = chunkAndReverseArray(expectedPayloads, 10);
}

Expand All @@ -96,7 +96,7 @@ describe("Waku Store, order", function () {
});
});

[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
[true, false].forEach((pageDirection) => {
it(`Ordered Callback - ${pageDirection}`, async function () {
await sendMessages(
nwaku,
Expand All @@ -112,11 +112,11 @@ describe("Waku Store, order", function () {
messages.push(msg);
},
{
pageDirection: pageDirection
paginationForward: pageDirection
}
);

if (pageDirection === PageDirection.BACKWARD) {
if (pageDirection === false) {
messages.reverse();
}
expect(messages?.length).eq(totalMsgs);
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/store/page_size.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Waku Store, page size", function () {

let messagesRetrieved = 0;
for await (const query of waku.store.queryGenerator([TestDecoder], {
pageSize: pageSize
paginationLimit: pageSize
})) {
// Calculate expected page size
const expectedPageSize = Math.min(
Expand Down
17 changes: 7 additions & 10 deletions packages/tests/tests/store/sorting.node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DecodedMessage, PageDirection } from "@waku/core";
import { DecodedMessage } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces";

import {
Expand Down Expand Up @@ -29,7 +29,7 @@ describe("Waku Store, sorting", function () {
await tearDownNodes(nwaku, waku);
});

[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
[true, false].forEach((pageDirection) => {
it(`Query Generator sorting by timestamp while page direction is ${pageDirection}`, async function () {
await sendMessages(
nwaku,
Expand All @@ -39,7 +39,7 @@ describe("Waku Store, sorting", function () {
);

for await (const query of waku.store.queryGenerator([TestDecoder], {
pageDirection: PageDirection.FORWARD
paginationForward: true
})) {
const page: IMessage[] = [];
for await (const msg of query) {
Expand All @@ -63,7 +63,7 @@ describe("Waku Store, sorting", function () {
});
});

[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
[true, false].forEach((pageDirection) => {
it(`Ordered Callback sorting by timestamp while page direction is ${pageDirection}`, async function () {
await sendMessages(
nwaku,
Expand All @@ -79,7 +79,7 @@ describe("Waku Store, sorting", function () {
messages.push(msg);
},
{
pageDirection: pageDirection
paginationForward: pageDirection
}
);
// Extract timestamps
Expand All @@ -88,15 +88,12 @@ describe("Waku Store, sorting", function () {
);
// Check if timestamps are sorted
for (let i = 1; i < timestamps.length; i++) {
if (
pageDirection === PageDirection.FORWARD &&
timestamps[i] < timestamps[i - 1]
) {
if (pageDirection === true && timestamps[i] < timestamps[i - 1]) {
throw new Error(
`Messages are not sorted by timestamp in FORWARD direction. Found out of order at index ${i}`
);
} else if (
pageDirection === PageDirection.BACKWARD &&
pageDirection === false &&
timestamps[i] > timestamps[i - 1]
) {
throw new Error(
Expand Down
12 changes: 4 additions & 8 deletions packages/tests/tests/store/time_filter.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ describe("Waku Store, time filter", function () {
}
},
{
timeFilter: {
startTime: adjustDate(msgTimestamp, startTime),
endTime: adjustDate(msgTimestamp, endTime)
}
timeStart: adjustDate(msgTimestamp, startTime),
timeEnd: adjustDate(msgTimestamp, endTime)
}
);

Expand Down Expand Up @@ -103,10 +101,8 @@ describe("Waku Store, time filter", function () {
}
},
{
timeFilter: {
startTime: adjustDate(msgTimestamp, -1000),
endTime: adjustDate(msgTimestamp, 1000)
}
timeStart: adjustDate(msgTimestamp, -1000),
timeEnd: adjustDate(msgTimestamp, 1000)
}
);

Expand Down

0 comments on commit 9875578

Please sign in to comment.