Improve test readability

By avoiding buffer comparison.
This commit is contained in:
Franck Royer 2021-05-10 14:10:37 +10:00
parent 54f32bacad
commit de3dcd9e22
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 18 additions and 22 deletions

View File

@ -71,7 +71,8 @@ describe('Waku Relay', () => {
it('Publish', async function () {
this.timeout(10000);
const message = WakuMessage.fromUtf8String('JS to JS communication works');
const messageText = 'JS to JS communication works';
const message = WakuMessage.fromUtf8String(messageText);
const receivedMsgPromise: Promise<WakuMessage> = new Promise((resolve) => {
waku2.relay.addObserver(resolve);
@ -83,9 +84,7 @@ describe('Waku Relay', () => {
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);
expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
});
describe('Interop: Nim', function () {
@ -127,7 +126,8 @@ describe('Waku Relay', () => {
it('Js publishes to nim', async function () {
this.timeout(5000);
const message = WakuMessage.fromUtf8String('This is a message');
const messageText = 'This is a message';
const message = WakuMessage.fromUtf8String(messageText);
await waku.relay.send(message);
@ -140,14 +140,13 @@ describe('Waku Relay', () => {
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);
expect(msgs[0].payloadAsUtf8).to.equal(messageText);
});
it('Nim publishes to js', async function () {
this.timeout(5000);
const message = WakuMessage.fromUtf8String('Here is another message.');
const messageText = 'Here is another message.';
const message = WakuMessage.fromUtf8String(messageText);
const receivedMsgPromise: Promise<WakuMessage> = new Promise(
(resolve) => {
@ -161,9 +160,7 @@ describe('Waku Relay', () => {
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);
expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
});
});
@ -214,7 +211,8 @@ describe('Waku Relay', () => {
it('Js publishes to nim', async function () {
this.timeout(30000);
const message = WakuMessage.fromUtf8String('This is a message');
const messageText = 'This is a message';
const message = WakuMessage.fromUtf8String(messageText);
await delay(1000);
await waku.relay.send(message);
@ -228,15 +226,14 @@ describe('Waku Relay', () => {
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);
expect(msgs[0].payloadAsUtf8).to.equal(messageText);
});
it('Nim publishes to js', async function () {
await delay(200);
const message = WakuMessage.fromUtf8String('Here is another message.');
const messageText = 'Here is another message.';
const message = WakuMessage.fromUtf8String(messageText);
const receivedMsgPromise: Promise<WakuMessage> = new Promise(
(resolve) => {
@ -250,9 +247,7 @@ describe('Waku Relay', () => {
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);
expect(receivedMsg.payloadAsUtf8).to.eq(messageText);
});
});

View File

@ -9,6 +9,7 @@ import PeerId from 'peer-id';
import { WakuMessage } from '../lib/waku_message';
import { RelayDefaultTopic } from '../lib/waku_relay';
import * as proto from '../proto/waku/v2/message';
import { existsAsync, mkdirAsync, openAsync } from './async_fs';
import waitForLine from './log_file';
@ -167,9 +168,9 @@ export class NimWaku {
async messages(): Promise<WakuMessage[]> {
this.checkProcess();
return this.rpcCall<WakuMessage[]>('get_waku_v2_relay_v1_messages', [
return this.rpcCall<proto.WakuMessage[]>('get_waku_v2_relay_v1_messages', [
RelayDefaultTopic,
]);
]).then((msgs) => msgs.map((protoMsg) => new WakuMessage(protoMsg)));
}
async getPeerId(): Promise<PeerId> {