From 59df4374906b9fecc212e38035488da962eb0817 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 13 Apr 2021 11:47:15 +1000 Subject: [PATCH] test: History messages through several pages are retrieved --- src/lib/waku_store/index.spec.ts | 64 +++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/src/lib/waku_store/index.spec.ts b/src/lib/waku_store/index.spec.ts index 686d199306..a6e1ddaba5 100644 --- a/src/lib/waku_store/index.spec.ts +++ b/src/lib/waku_store/index.spec.ts @@ -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); + }); });