Check peer ids on both side when connecting

This commit is contained in:
Franck Royer 2021-03-11 15:02:29 +11:00
parent 057f5f80ab
commit f0c9c3ef50
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 15 additions and 9 deletions

View File

@ -23,7 +23,6 @@ test('Can publish message', async (t) => {
await wakuRelayNode2.subscribe(); await wakuRelayNode2.subscribe();
// Setup the promise before publishing to ensure the event is not missed // Setup the promise before publishing to ensure the event is not missed
// TODO: Is it possible to import `Message` type?
const promise = waitForNextData(node1.pubsub); const promise = waitForNextData(node1.pubsub);
await delay(500); await delay(500);
@ -63,10 +62,21 @@ test('Nim-waku: nim-waku node connects to js node', async (t) => {
const nimWaku = new NimWaku(); const nimWaku = new NimWaku();
await nimWaku.start({ staticnode: multiAddrWithId }); await nimWaku.start({ staticnode: multiAddrWithId });
const peers = await nimWaku.peers(); const nimPeers = await nimWaku.peers();
console.log(peers); t.deepEqual(nimPeers, [
t.is(peers.length, 1); {
multiaddr: multiAddrWithId,
protocol: CODEC,
connected: true,
},
]);
const nimAddress = await nimWaku.info().then((info) => info.listenStr);
const nimPeerId = nimAddress.match(/[\d\w]+$/)[0];
const jsPeers = node.peerStore.peers;
t.true(jsPeers.has(nimPeerId));
}); });
function waitForNextData(pubsub: Pubsub): Promise<Message> { function waitForNextData(pubsub: Pubsub): Promise<Message> {

View File

@ -2,8 +2,6 @@ import { fc, testProp } from 'ava-fast-check';
import { Message } from './waku_message'; import { Message } from './waku_message';
// for all a, b, c strings
// b is a substring of a + b + c
testProp( testProp(
'Waku message round trip binary serialisation', 'Waku message round trip binary serialisation',
[fc.string()], [fc.string()],

View File

@ -40,7 +40,6 @@ export class NimWaku {
const logFile = await openAsync(logPath, 'w'); const logFile = await openAsync(logPath, 'w');
const mergedArgs = argsToArray(mergeArguments(args)); const mergedArgs = argsToArray(mergeArguments(args));
console.log(mergedArgs);
this.process = spawn(NIM_WAKU_BIN, mergedArgs, { this.process = spawn(NIM_WAKU_BIN, mergedArgs, {
cwd: '/home/froyer/src/status-im/nim-waku/', cwd: '/home/froyer/src/status-im/nim-waku/',
stdio: [ stdio: [
@ -56,14 +55,13 @@ export class NimWaku {
await waitForLine(logPath, 'RPC Server started'); await waitForLine(logPath, 'RPC Server started');
console.log('Nim waku RPC is started'); console.log('Nim waku RPC is started');
console.log(await this.info());
} }
/** Calls nim-waku2 JSON-RPC API `get_waku_v2_admin_v1_peers` to check /** Calls nim-waku2 JSON-RPC API `get_waku_v2_admin_v1_peers` to check
* for known peers * for known peers
* @throws if nim-waku2 isn't started. * @throws if nim-waku2 isn't started.
*/ */
async peers(): Promise<string[]> { async peers() {
this.checkProcess(); this.checkProcess();
const res = await this.rpcCall('get_waku_v2_admin_v1_peers', []); const res = await this.rpcCall('get_waku_v2_admin_v1_peers', []);