25: Upgrade nim-waku r=D4nte a=D4nte



Co-authored-by: Franck Royer <franck@royer.one>
This commit is contained in:
bors[bot] 2021-04-09 01:58:31 +00:00 committed by GitHub
commit 71a324dd3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 76 deletions

@ -1 +1 @@
Subproject commit d1c1a0ca13e3aa2690a6550faca13210e1f46877
Subproject commit 5d138f8a2c3f18703cfe6f7497e5d3fba074cdf2

View File

@ -4,6 +4,7 @@ package waku.v2;
message WakuMessageProto {
optional bytes payload = 1;
optional uint32 content_topic = 2;
optional string content_topic = 2;
optional uint32 version = 3;
optional double timestamp = 4;
}

View File

@ -4,13 +4,13 @@ import { Reader } from 'protobufjs/minimal';
// Protecting the user from protobuf oddities
import { WakuMessageProto } from '../proto/waku/v2/waku';
const DEFAULT_CONTENT_TOPIC = 1;
const DEFAULT_CONTENT_TOPIC = '/waku/2/default-content/proto';
const DEFAULT_VERSION = 0;
export class WakuMessage {
private constructor(
public payload?: Uint8Array,
public contentTopic?: number,
public contentTopic?: string,
public version?: number
) {}

View File

@ -239,77 +239,6 @@ describe('Waku Relay', () => {
});
});
describe('Js connects to nim', function () {
let waku: Waku;
let nimWaku: NimWaku;
beforeEach(async function () {
this.timeout(10_000);
waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 });
nimWaku = new NimWaku(makeLogFileName(this));
await nimWaku.start();
await waku.dial(await nimWaku.getMultiaddrWithId());
await new Promise((resolve) =>
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
);
await waku.relay.subscribe();
await new Promise((resolve) =>
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
);
});
afterEach(async function () {
nimWaku ? nimWaku.stop() : null;
waku ? await waku.stop() : null;
});
it('nim subscribes to js', async function () {
const subscribers = waku.libp2p.pubsub.getSubscribers(
RelayDefaultTopic
);
const nimPeerId = await nimWaku.getPeerId();
expect(subscribers).to.contain(nimPeerId.toB58String());
});
it('Js publishes to nim', async function () {
const message = WakuMessage.fromUtf8String('This is a message');
await waku.relay.publish(message);
await nimWaku.waitForLog('WakuMessage received');
const msgs = await nimWaku.messages();
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
expect(msgs[0].version).to.equal(message.version);
const payload = Buffer.from(msgs[0].payload);
expect(Buffer.compare(payload, message.payload!)).to.equal(0);
});
it('Nim publishes to js', async function () {
const message = WakuMessage.fromUtf8String('Here is another message.');
const receivedPromise = waitForNextData(waku.libp2p.pubsub);
await nimWaku.sendMessage(message);
const receivedMsg = await receivedPromise;
expect(receivedMsg.contentTopic).to.eq(message.contentTopic);
expect(receivedMsg.version).to.eq(message.version);
const payload = Buffer.from(receivedMsg.payload!);
expect(Buffer.compare(payload, message.payload!)).to.eq(0);
});
});
describe('js to nim to js', function () {
let waku1: Waku;
let waku2: Waku;

View File

@ -29,6 +29,17 @@ export interface Args {
rpcAdmin?: boolean;
nodekey?: string;
portsShift?: number;
logLevel?: LogLevel;
}
export enum LogLevel {
Error = 'error',
Info = 'info',
Warn = 'warn',
Debug = 'debug',
Trace = 'trace',
Notice = 'notice',
Fatal = 'fatal',
}
export class NimWaku {
@ -61,7 +72,11 @@ export class NimWaku {
const mergedArgs = defaultArgs();
// Object.assign overrides the properties with the source (if there are conflicts)
Object.assign(mergedArgs, { portsShift: this.portsShift }, args);
Object.assign(
mergedArgs,
{ portsShift: this.portsShift, logLevel: LogLevel.Trace },
args
);
const argsArray = argsToArray(mergedArgs);
this.process = spawn(NIM_WAKU_BIN, argsArray, {