diff --git a/src/lib/node.spec.ts b/src/lib/node.spec.ts index 0cac489452..b129c5b876 100644 --- a/src/lib/node.spec.ts +++ b/src/lib/node.spec.ts @@ -2,6 +2,7 @@ import test from 'ava'; import Libp2p from 'libp2p'; import Pubsub from 'libp2p-interfaces/src/pubsub'; +import { delay } from '../test_utils/delay'; import { NimWaku } from '../test_utils/nim_waku'; import { createNode } from './node'; @@ -126,6 +127,41 @@ test('Nim-interop: js node sends message to nim node', async (t) => { t.is(Buffer.compare(payload, message.payload), 0); }); +test('Nim-interop: nim node sends message to js node', async (t) => { + const message = Message.fromUtf8String('Here is another message.'); + const node = await createNode(); + const wakuRelayNode = new WakuRelay(node.pubsub); + + const peerId = node.peerId.toB58String(); + const localMultiaddr = node.multiaddrs.find((addr) => + addr.toString().match(/127\.0\.0\.1/) + ); + const multiAddrWithId = localMultiaddr + '/p2p/' + peerId; + + const nimWaku = new NimWaku(t.title); + await nimWaku.start({ staticnode: multiAddrWithId }); + + await patchPeerStore(nimWaku, node); + + await wakuRelayNode.subscribe(); + + await delay(3000); + + const receivedPromise = waitForNextData(node.pubsub); + + await nimWaku.sendMessage(message); + + await delay(3000); + + const receivedMsg = await receivedPromise; + + t.is(receivedMsg.contentTopic, message.contentTopic); + t.is(receivedMsg.version, message.version); + + const payload = Buffer.from(receivedMsg.payload); + t.is(Buffer.compare(payload, message.payload), 0); +}); + function waitForNextData(pubsub: Pubsub): Promise { return new Promise((resolve) => { pubsub.once(TOPIC, resolve); diff --git a/src/lib/node.ts b/src/lib/node.ts index b7bfdc0daa..bd45856e86 100644 --- a/src/lib/node.ts +++ b/src/lib/node.ts @@ -26,6 +26,8 @@ export async function createNode() { emitSelf: true, signMessages: false, strictSigning: false, + // Ensure that no signature is expected in the messages. + globalSignaturePolicy: 'StrictNoSign', }, }, }); diff --git a/src/lib/waku_relay.ts b/src/lib/waku_relay.ts index 638f4d6cee..678a58a397 100644 --- a/src/lib/waku_relay.ts +++ b/src/lib/waku_relay.ts @@ -11,8 +11,13 @@ export const TOPIC = '/waku/2/default-waku/proto'; // This is the class to pass to libp2p as pubsub protocol export class WakuRelayPubsub extends Gossipsub { - constructor(libp2p: Libp2p) { - super(libp2p); + /** + * + * @param libp2p: Libp2p + * @param options: Partial + */ + constructor(libp2p: Libp2p, options?: any) { + super(libp2p, options); const multicodecs = [CODEC];