Reorg tests, add describe sections

This commit is contained in:
Franck Royer 2021-03-19 15:03:31 +11:00
parent 7d595b0c8f
commit 13e941513d
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 118 additions and 110 deletions

View File

@ -3,7 +3,9 @@ import { NimWaku } from '../test_utils/nim_waku';
import Waku from './waku';
import { CODEC } from './waku_relay';
test('Nim-interop: nim-waku node connects to js node', async () => {
describe('Waku', () => {
describe('Interop: Nim', () => {
test('nim connects to js', async () => {
const waku = await Waku.create();
const peerId = waku.libp2p.peerId.toB58String();
@ -30,4 +32,6 @@ test('Nim-interop: nim-waku node connects to js node', async () => {
const jsPeers = waku.libp2p.peerStore.peers;
expect(jsPeers.has(nimPeerId.toB58String())).toBeTruthy();
});
});
});

View File

@ -8,8 +8,9 @@ import Waku from './waku';
import { Message } from './waku_message';
import { CODEC, TOPIC } from './waku_relay';
// TODO: Fix this, see https://github.com/ChainSafe/js-libp2p-gossipsub/issues/151
test.skip('Publishes message', async () => {
describe('Waku Relay', () => {
// TODO: Fix this, see https://github.com/ChainSafe/js-libp2p-gossipsub/issues/151
test.skip('Publish', async () => {
const message = Message.fromUtf8String('Bird bird bird, bird is the word!');
const [waku1, waku2] = await Promise.all([Waku.create(), Waku.create()]);
@ -36,24 +37,25 @@ test.skip('Publishes message', async () => {
const node1Received = await promise;
expect(node1Received.isEqualTo(message)).toBeTruthy();
});
});
test('Registers waku relay protocol', async () => {
test('Registers waku relay protocol', async () => {
const waku = await Waku.create();
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
expect(protocols.findIndex((value) => value == CODEC)).toBeTruthy();
});
});
test('Does not register any sub protocol', async () => {
test('Does not register any sub protocol', async () => {
const waku = await Waku.create();
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
expect(protocols.findIndex((value) => value.match(/sub/))).toBeTruthy();
});
});
test('Nim-interop: js node receives default subscription from nim node', async () => {
describe('Interop: Nim', () => {
test('nim subscribes to js', async () => {
const waku = await Waku.create();
const peerId = waku.libp2p.peerId.toB58String();
@ -70,9 +72,9 @@ test('Nim-interop: js node receives default subscription from nim node', async (
const subscribers = waku.libp2p.pubsub.getSubscribers(TOPIC);
expect(subscribers).toContain(nimPeerId.toB58String());
});
});
test('Nim-interop: js node sends message to nim node', async () => {
test('Js publishes to nim', async () => {
const message = Message.fromUtf8String('This is a message');
const waku = await Waku.create();
@ -103,9 +105,9 @@ test('Nim-interop: js node sends message to nim node', async () => {
const payload = Buffer.from(msgs[0].payload);
expect(Buffer.compare(payload, message.payload)).toBe(0);
});
});
test('Nim-interop: nim node sends message to js node', async () => {
test('Nim publishes to js', async () => {
const message = Message.fromUtf8String('Here is another message.');
const waku = await Waku.create();
@ -137,6 +139,8 @@ test('Nim-interop: nim node sends message to js node', async () => {
const payload = Buffer.from(receivedMsg.payload);
expect(Buffer.compare(payload, message.payload)).toBe(0);
});
});
});
function waitForNextData(pubsub: Pubsub): Promise<Message> {