From 8ed47b2cf76504b1a7bfb2f80ead0a4f19450007 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 12 Mar 2021 09:46:47 +1100 Subject: [PATCH] Nim-interop: subscribe At this stage, we are only able to check that the subscription works on js side: it confirms that the nim node is considered as subscribing to the same topic. --- src/lib/node.spec.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/lib/node.spec.ts b/src/lib/node.spec.ts index 9f6b659836..e4d4705310 100644 --- a/src/lib/node.spec.ts +++ b/src/lib/node.spec.ts @@ -8,7 +8,7 @@ import { createNode } from './node'; import { Message } from './waku_message'; import { CODEC, TOPIC, WakuRelay } from './waku_relay'; -test('Can publish message', async (t) => { +test('Publishes message', async (t) => { const message = Message.fromString('Bird bird bird, bird is the word!'); const [node1, node2] = await Promise.all([createNode(), createNode()]); @@ -34,7 +34,7 @@ test('Can publish message', async (t) => { t.true(node1Received.isEqualTo(message)); }); -test('Register waku relay protocol', async (t) => { +test('Registers waku relay protocol', async (t) => { const node = await createNode(); const protocols = Array.from(node.upgrader.protocols.keys()); @@ -49,7 +49,7 @@ test('Does not register any sub protocol', async (t) => { t.truthy(protocols.findIndex((value) => value.match(/sub/))); }); -test('Nim-waku: nim-waku node connects to js node', async (t) => { +test('Nim-interop: nim-waku node connects to js node', async (t) => { const node = await createNode(); const peerId = node.peerId.toB58String(); @@ -79,6 +79,31 @@ test('Nim-waku: nim-waku node connects to js node', async (t) => { t.true(jsPeers.has(nimPeerId)); }); +test('Nim-interop: js node subscribes to default waku topic (only checking js side)', async (t) => { + const node = await createNode(); + + const peerId = node.peerId.toB58String(); + + console.log(`js peer id: ${peerId}`); + + const localMultiaddr = node.multiaddrs.find((addr) => + addr.toString().match(/127\.0\.0\.1/) + ); + const multiAddrWithId = localMultiaddr + '/p2p/' + peerId; + + const nimWaku = new NimWaku(); + await nimWaku.start({ staticnode: multiAddrWithId }); + + const wakuRelayNode = new WakuRelay(node.pubsub); + await wakuRelayNode.subscribe(); + + const nimAddress = await nimWaku.info().then((info) => info.listenStr); + const nimPeerId = nimAddress.match(/[\d\w]+$/)[0]; + const subscribers = node.pubsub.getSubscribers(TOPIC); + + t.true(subscribers.includes(nimPeerId)); +}); + function waitForNextData(pubsub: Pubsub): Promise { return new Promise((resolve) => { pubsub.once(TOPIC, resolve);