mirror of
https://github.com/status-im/js-waku.git
synced 2025-02-22 18:08:14 +00:00
test: Send message from js node to nim node
This commit is contained in:
parent
c99e02af20
commit
548c50668a
@ -4,6 +4,6 @@ package waku.v2;
|
|||||||
|
|
||||||
message WakuMessage {
|
message WakuMessage {
|
||||||
optional bytes payload = 1;
|
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;
|
optional uint32 version = 3;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import test from 'ava';
|
import test from 'ava';
|
||||||
import Pubsub from 'libp2p-interfaces/src/pubsub';
|
import Pubsub from 'libp2p-interfaces/src/pubsub';
|
||||||
|
|
||||||
import { delay } from '../test_utils/delay';
|
|
||||||
import { NimWaku } from '../test_utils/nim_waku';
|
import { NimWaku } from '../test_utils/nim_waku';
|
||||||
|
|
||||||
import { createNode } from './node';
|
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()));
|
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 node = await createNode();
|
||||||
|
const wakuRelayNode = new WakuRelay(node.pubsub);
|
||||||
|
|
||||||
const peerId = node.peerId.toB58String();
|
const peerId = node.peerId.toB58String();
|
||||||
|
|
||||||
const localMultiaddr = node.multiaddrs.find((addr) =>
|
const localMultiaddr = node.multiaddrs.find((addr) =>
|
||||||
addr.toString().match(/127\.0\.0\.1/)
|
addr.toString().match(/127\.0\.0\.1/)
|
||||||
);
|
);
|
||||||
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
||||||
|
|
||||||
const nimWaku = new NimWaku();
|
const nimWaku = new NimWaku(t.title);
|
||||||
await nimWaku.start(t.title, { staticnode: multiAddrWithId });
|
await nimWaku.start({ staticnode: multiAddrWithId });
|
||||||
|
|
||||||
const wakuRelayNode = new WakuRelay(node.pubsub);
|
await wakuRelayNode.publish(message);
|
||||||
await wakuRelayNode.subscribe();
|
|
||||||
|
|
||||||
// Setup the promise before publishing to ensure the event is not missed
|
await nimWaku.waitForLog('WakuMessage received');
|
||||||
const promise = waitForNextData(node.pubsub);
|
|
||||||
|
|
||||||
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);
|
const payload = Buffer.from(msgs[0].payload);
|
||||||
|
t.is(Buffer.compare(payload, message.payload), 0);
|
||||||
await delay(1000);
|
|
||||||
|
|
||||||
const received = await promise;
|
|
||||||
|
|
||||||
t.true(received.isEqualTo(message));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function waitForNextData(pubsub: Pubsub): Promise<Message> {
|
function waitForNextData(pubsub: Pubsub): Promise<Message> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user