test: History messages through several pages are retrieved

This commit is contained in:
Franck Royer 2021-04-13 11:47:15 +10:00
parent 2b1862320f
commit 59df437490
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 50 additions and 14 deletions

View File

@ -33,19 +33,6 @@ describe('Waku Store', () => {
await new Promise((resolve) =>
waku0.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
);
await waku0.relay.publish(
WakuMessage.fromUtf8String('A message from relay.')
);
await nimWaku.sendMessage(
WakuMessage.fromUtf8String('Another message from json rpc.')
);
waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 });
await waku.dial(await nimWaku.getMultiaddrWithId());
await delay(500);
});
afterEach(async function () {
@ -54,6 +41,17 @@ describe('Waku Store', () => {
});
it('Retrieves history', async function () {
this.timeout(5_000);
for (let i = 0; i < 2; i++) {
await nimWaku.sendMessage(WakuMessage.fromUtf8String(`Message ${i}`));
}
waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 });
await waku.dial(await nimWaku.getMultiaddrWithId());
await delay(500);
const nimPeerId = await nimWaku.getPeerId();
const response = await waku.store.queryHistory(nimPeerId);
@ -65,8 +63,46 @@ describe('Waku Store', () => {
return WakuMessage.fromProto(protoMsg);
})
.findIndex((msg) => {
return msg.utf8Payload() === 'A message from relay.';
return msg.utf8Payload() === 'Message 0';
});
expect(result).to.not.eq(-1);
});
it('Retrieves all history element through paging', async function () {
this.timeout(5_000);
for (let i = 0; i < 20; i++) {
await nimWaku.sendMessage(WakuMessage.fromUtf8String(`Message ${i}`));
}
waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 });
await waku.dial(await nimWaku.getMultiaddrWithId());
await delay(500);
const nimPeerId = await nimWaku.getPeerId();
const response = await waku.store.queryHistory(nimPeerId);
const messages = response?.messages;
expect(messages?.length).eq(20);
expect(
messages
?.map((protoMsg) => {
return WakuMessage.fromProto(protoMsg);
})
.findIndex((msg) => {
return msg.utf8Payload() === 'Message 0';
})
).to.not.eq(-1);
expect(
messages
?.map((protoMsg) => {
return WakuMessage.fromProto(protoMsg);
})
.findIndex((msg) => {
return msg.utf8Payload() === 'Message 19';
})
).to.not.eq(-1);
});
});