adjustments

This commit is contained in:
fbarbu15 2023-10-06 11:24:10 +03:00
parent 0b1f2ec31d
commit 5519877b5e
No known key found for this signature in database
GPG Key ID: D75221C8DEA22501
3 changed files with 75 additions and 31 deletions

View File

@ -106,20 +106,32 @@ describe("Waku Store, cursor", function () {
cursor.digest = new Uint8Array([]); cursor.digest = new Uint8Array([]);
const messagesAfterCursor: DecodedMessage[] = []; const messagesAfterCursor: DecodedMessage[] = [];
for await (const page of waku.store.queryGenerator([TestDecoder], { try {
cursor for await (const page of waku.store.queryGenerator([TestDecoder], {
})) { cursor
for await (const msg of page.reverse()) { })) {
if (msg) { for await (const msg of page.reverse()) {
messagesAfterCursor.push(msg as DecodedMessage); if (msg) {
messagesAfterCursor.push(msg as DecodedMessage);
}
} }
} }
expect(messagesAfterCursor.length).to.eql(0);
} catch (error) {
if (
nwaku.type() === "go-waku" &&
typeof error === "string" &&
error.includes("History response contains an Error: INVALID_CURSOR")
) {
return;
}
throw error instanceof Error
? new Error(`Unexpected error: ${error.message}`)
: error;
} }
expect(messagesAfterCursor.length).be.eql(0);
}); });
// Skipped because of strange results. Generator retrieves messages even if cursor is using a different customPubSubTopic. // PubsubTopic is ignored in the cursor. Needs fixing so it throws an error if it doesn't match with Decoder
// My guess is that pubsubTopic is not used. Need to confirm
it.skip("Passing cursor with wrong pubSubTopic", async function () { it.skip("Passing cursor with wrong pubSubTopic", async function () {
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic);
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);

View File

@ -29,7 +29,7 @@ describe("Waku Store, page size", function () {
}); });
[ [
[0, 30], [0, 110],
[1, 4], [1, 4],
[3, 20], [3, 20],
[10, 10], [10, 10],
@ -48,7 +48,11 @@ describe("Waku Store, page size", function () {
// Determine effectivePageSize for test expectations // Determine effectivePageSize for test expectations
let effectivePageSize = pageSize; let effectivePageSize = pageSize;
if (pageSize === 0) { if (pageSize === 0) {
effectivePageSize = 20; if (nwaku.type() == "go-waku") {
effectivePageSize = 100;
} else {
effectivePageSize = 20;
}
} else if (pageSize > 100) { } else if (pageSize > 100) {
effectivePageSize = 100; effectivePageSize = 100;
} }

View File

@ -28,26 +28,19 @@ describe("Waku Store, time filter", function () {
}); });
[ [
[-10000, -10, 10], [-19000, -10, 10],
[-10000, 1, 4], [-19000, 1, 4],
[-10000, -2, -1], [-19000, -2, -1],
[-10000, 0, 1000], [-19000, 0, 1000],
[-10000, -1000, 0], [-19000, -1000, 0],
[10000, 4, 1], [19000, 4, 1],
[10000, -10, 10] [19000, -10010, -9990],
].forEach(([msgTimeAdjustment, startTime, endTime]) => { [19000, -10, 10]
it(`msgTime: ${adjustDate( ].forEach(([msgTime, startTime, endTime]) => {
new Date(), it(`msgTime: ${msgTime} ms from now, startTime: ${
msgTimeAdjustment msgTime + startTime
)}, startTime: ${adjustDate( }, endTime: ${msgTime + endTime}`, async function () {
adjustDate(new Date(), msgTimeAdjustment), const msgTimestamp = adjustDate(new Date(), msgTime);
startTime
)}, endTime: ${adjustDate(
adjustDate(new Date(), msgTimeAdjustment),
endTime
)}`, async function () {
const msgTimestamp = adjustDate(new Date(), msgTimeAdjustment);
expect( expect(
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
@ -85,4 +78,39 @@ describe("Waku Store, time filter", function () {
} }
}); });
}); });
[-20000, 40000].forEach((msgTime) => {
it(`Timestamp too far from node time: ${msgTime} ms from now`, async function () {
const msgTimestamp = adjustDate(new Date(), msgTime);
expect(
await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({
payload: new Uint8Array([0]),
contentTopic: TestContentTopic,
timestamp: msgTimestamp
})
)
).to.be.true;
waku = await startAndConnectLightNode(nwaku);
const messages: IMessage[] = [];
await waku.store.queryWithOrderedCallback(
[TestDecoder],
(msg) => {
if (msg) {
messages.push(msg);
}
},
{
timeFilter: {
startTime: adjustDate(msgTimestamp, -1000),
endTime: adjustDate(msgTimestamp, 1000)
}
}
);
expect(messages.length).eq(0);
});
});
}); });