mirror of https://github.com/waku-org/js-waku.git
Implement reception of messages over waku-relay
This commit is contained in:
parent
57fa974812
commit
953aeea053
|
@ -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<Message> {
|
||||
return new Promise((resolve) => {
|
||||
pubsub.once(TOPIC, resolve);
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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<GossipInputOptions>
|
||||
*/
|
||||
constructor(libp2p: Libp2p, options?: any) {
|
||||
super(libp2p, options);
|
||||
|
||||
const multicodecs = [CODEC];
|
||||
|
||||
|
|
Loading…
Reference in New Issue