js-waku/src/lib/waku.spec.ts

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-03-22 16:02:10 +11:00
import { expect } from 'chai';
import TCP from 'libp2p-tcp';
2021-03-22 16:02:10 +11:00
import {
makeLogFileName,
NimWaku,
NOISE_KEY_1,
NOISE_KEY_2,
} from '../test_utils/';
2021-03-10 17:39:53 +11:00
2021-03-19 14:40:16 +11:00
import Waku from './waku';
import { RelayCodec } from './waku_relay';
describe('Waku Dial', function () {
it('js connects to js', async function () {
this.timeout(10_000);
const [waku1, waku2] = await Promise.all([
Waku.create({
staticNoiseKey: NOISE_KEY_1,
listenAddresses: ['/ip4/0.0.0.0/tcp/0/wss'],
}),
Waku.create({ staticNoiseKey: NOISE_KEY_2 }),
]);
const waku1MultiAddrWithId = waku1.getLocalMultiaddrWithID();
await waku2.dial(waku1MultiAddrWithId);
const waku2PeerId = waku2.libp2p.peerId;
const waku1Peers = waku1.libp2p.peerStore.peers;
expect(waku1Peers.has(waku2PeerId.toB58String())).to.be.true;
await Promise.all([waku1.stop(), waku2.stop()]);
});
2021-03-22 16:02:10 +11:00
describe('Interop: Nim', function () {
it('nim connects to js', async function () {
this.timeout(10_000);
const waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1,
listenAddresses: ['/ip4/0.0.0.0/tcp/0'],
modules: { transport: [TCP] },
});
2021-03-10 17:39:53 +11:00
2021-04-06 11:06:10 +10:00
const multiAddrWithId = waku.getLocalMultiaddrWithID();
2021-03-11 10:54:35 +11:00
2021-03-25 15:49:07 +11:00
const nimWaku = new NimWaku(makeLogFileName(this));
2021-03-19 15:03:31 +11:00
await nimWaku.start({ staticnode: multiAddrWithId });
2021-03-10 17:39:53 +11:00
2021-03-19 15:03:31 +11:00
const nimPeers = await nimWaku.peers();
2021-03-10 17:39:53 +11:00
2021-03-22 16:02:10 +11:00
expect(nimPeers).to.deep.equal([
2021-03-19 15:03:31 +11:00
{
multiaddr: multiAddrWithId,
protocol: RelayCodec,
2021-03-19 15:03:31 +11:00
connected: true,
},
]);
2021-03-19 15:03:31 +11:00
const nimPeerId = await nimWaku.getPeerId();
const jsPeers = waku.libp2p.peerStore.peers;
2021-03-22 16:02:10 +11:00
expect(jsPeers.has(nimPeerId.toB58String())).to.be.true;
nimWaku.stop();
await waku.stop();
2021-03-19 15:03:31 +11:00
});
});
2021-03-10 17:39:53 +11:00
});