mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-02-08 10:13:12 +00:00
Note that we currently only support one, and only one, pubsub topic for a given instance across the codebase. The PubSub topic needs to be set when instantiating the Waku* classes. At this stage, we believe that most DApp will use, and only use, the default PubSub topic. Some application want to use an alternative topic but not use the default one so this behaviour should be fine. See #174 for details.
95 lines
2.7 KiB
TypeScript
95 lines
2.7 KiB
TypeScript
import { expect } from 'chai';
|
|
import TCP from 'libp2p-tcp';
|
|
|
|
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../../test_utils';
|
|
import { delay } from '../delay';
|
|
import { Waku } from '../waku';
|
|
import { WakuMessage } from '../waku_message';
|
|
|
|
describe('Waku Light Push', () => {
|
|
let waku: Waku;
|
|
let nimWaku: NimWaku;
|
|
|
|
afterEach(async function () {
|
|
nimWaku ? nimWaku.stop() : null;
|
|
waku ? await waku.stop() : null;
|
|
});
|
|
|
|
it('Push successfully', async function () {
|
|
this.timeout(5_000);
|
|
|
|
nimWaku = new NimWaku(makeLogFileName(this));
|
|
await nimWaku.start({ lightpush: true });
|
|
|
|
waku = await Waku.create({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
libp2p: { modules: { transport: [TCP] } },
|
|
});
|
|
await waku.dial(await nimWaku.getMultiaddrWithId());
|
|
|
|
// Wait for identify protocol to finish
|
|
await new Promise((resolve) => {
|
|
waku.libp2p.peerStore.once('change:protocols', resolve);
|
|
});
|
|
|
|
const nimPeerId = await nimWaku.getPeerId();
|
|
|
|
const messageText = 'Light Push works!';
|
|
const message = WakuMessage.fromUtf8String(messageText);
|
|
|
|
const pushResponse = await waku.lightPush.push(nimPeerId, message);
|
|
expect(pushResponse?.isSuccess).to.be.true;
|
|
|
|
let msgs: WakuMessage[] = [];
|
|
|
|
while (msgs.length === 0) {
|
|
await delay(200);
|
|
msgs = await nimWaku.messages();
|
|
}
|
|
|
|
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
|
expect(msgs[0].version).to.equal(message.version);
|
|
expect(msgs[0].payloadAsUtf8).to.equal(messageText);
|
|
});
|
|
|
|
it('Push on custom pubsub topic', async function () {
|
|
this.timeout(5_000);
|
|
|
|
const customPubSubTopic = '/waku/2/custom-dapp/proto';
|
|
|
|
nimWaku = new NimWaku(makeLogFileName(this));
|
|
await nimWaku.start({ lightpush: true, topics: customPubSubTopic });
|
|
|
|
waku = await Waku.create({
|
|
pubsubTopic: customPubSubTopic,
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
libp2p: { modules: { transport: [TCP] } },
|
|
});
|
|
await waku.dial(await nimWaku.getMultiaddrWithId());
|
|
|
|
// Wait for identify protocol to finish
|
|
await new Promise((resolve) => {
|
|
waku.libp2p.peerStore.once('change:protocols', resolve);
|
|
});
|
|
|
|
const nimPeerId = await nimWaku.getPeerId();
|
|
|
|
const messageText = 'Light Push works!';
|
|
const message = WakuMessage.fromUtf8String(messageText);
|
|
|
|
const pushResponse = await waku.lightPush.push(nimPeerId, message);
|
|
expect(pushResponse?.isSuccess).to.be.true;
|
|
|
|
let msgs: WakuMessage[] = [];
|
|
|
|
while (msgs.length === 0) {
|
|
await delay(200);
|
|
msgs = await nimWaku.messages();
|
|
}
|
|
|
|
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
|
expect(msgs[0].version).to.equal(message.version);
|
|
expect(msgs[0].payloadAsUtf8).to.equal(messageText);
|
|
});
|
|
});
|