test: Send message from js node to nim node

This commit is contained in:
Franck Royer 2021-03-15 13:27:50 +11:00
parent c99e02af20
commit 548c50668a
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 13 additions and 19 deletions

View File

@ -4,6 +4,6 @@ package waku.v2;
message WakuMessage {
optional bytes payload = 1;
optional fixed32 content_topic = 2;
optional uint32 content_topic = 2; // Follow nim-waku implementation and not the spec
optional uint32 version = 3;
}

View File

@ -1,7 +1,6 @@
import test from 'ava';
import Pubsub from 'libp2p-interfaces/src/pubsub';
import { delay } from '../test_utils/delay';
import { NimWaku } from '../test_utils/nim_waku';
import { createNode } from './node';
@ -97,36 +96,31 @@ test('Nim-interop: js node receives default subscription from nim node', async (
t.true(subscribers.includes(nimPeerId.toB58String()));
});
test('Nim-interop: nim node sends message', async (t) => {
test('Nim-interop: js node sends message to nim node', async (t) => {
const message = Message.fromUtf8String('This is a 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();
await nimWaku.start(t.title, { staticnode: multiAddrWithId });
const nimWaku = new NimWaku(t.title);
await nimWaku.start({ staticnode: multiAddrWithId });
const wakuRelayNode = new WakuRelay(node.pubsub);
await wakuRelayNode.subscribe();
await wakuRelayNode.publish(message);
// Setup the promise before publishing to ensure the event is not missed
const promise = waitForNextData(node.pubsub);
await nimWaku.waitForLog('WakuMessage received');
const message = Message.fromUtf8String('This is a message.');
const msgs = await nimWaku.messages();
await delay(500);
t.is(msgs[0].contentTopic, message.contentTopic);
t.is(msgs[0].version, message.version);
await nimWaku.sendMessage(message);
await delay(1000);
const received = await promise;
t.true(received.isEqualTo(message));
const payload = Buffer.from(msgs[0].payload);
t.is(Buffer.compare(payload, message.payload), 0);
});
function waitForNextData(pubsub: Pubsub): Promise<Message> {