From 3150eb50f0280773fc8ce9b699753d1c58156b33 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Mon, 12 Feb 2018 16:05:31 -0800 Subject: [PATCH] Starts on tests for larger peer groups --- src/lib/Bridge.js | 9 ++++----- test/threePeers.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 test/threePeers.js diff --git a/src/lib/Bridge.js b/src/lib/Bridge.js index f22f9b6..fd826c4 100644 --- a/src/lib/Bridge.js +++ b/src/lib/Bridge.js @@ -78,11 +78,11 @@ class Bridge { // messages) if (i == 0) { this.getBridgeData(this.addrs[0], this.addrs[1], this.clients[0], (err) => { - if (err) { logger.log('warn', `ERROR: ${err}`); } + if (err) { logger.warn(err); } }); } else { this.getBridgeData(this.addrs[1], this.addrs[0], this.clients[1], (err) => { - if (err) { logger.log('warn', `ERROR: ${err}`); } + if (err) { logger.warn(err); } }); } setInterval(() => { @@ -287,7 +287,6 @@ class Bridge { case 'PING': this.addPeer(msg.from); default: - logger.log('info', `Got msg with no type: ${msg}`) break; } } @@ -348,7 +347,7 @@ class Bridge { this.peers[host].send('msg', msg); }) // Grab some peers - /*contacted.forEach((p) => { + contacted.forEach((p) => { if (Object.keys(this.peers).indexOf(p) == -1) { const params = p.split(':') if (params[0] != this.externalHost && parseInt(params[1]) != parseInt(this.port)) { @@ -357,7 +356,7 @@ class Bridge { } } }) - config.addPeers(toAdd, this.datadir, this.index, this.handleAddPeer);*/ + config.addPeers(toAdd, this.datadir, this.index, this.handleAddPeer); } // Ping peers diff --git a/test/threePeers.js b/test/threePeers.js new file mode 100644 index 0000000..e6170e7 --- /dev/null +++ b/test/threePeers.js @@ -0,0 +1,37 @@ +// Connect to three peers (four total clients) +// The peers will have no peers themselves +// Send a message with a signature request containing all four peers +// Check to see if the three peers now have all the peers themselves +const assert = require('assert'); +const fs = require('fs'); +const Bridge = require('../src/lib/Bridge.js'); +const Log = require('../src/log.js'); +const Web3 = require('web3'); +const config = require('../data/config.json'); +const Peers = require('../src/peers.js'); + +const index = Object.keys(config)[0]; +const web3A = new Web3(new Web3.providers.HttpProvider('http://localhost:7545')); +const web3B = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); +const hosts = [web3A, web3B] + +Log.setLogger(`${process.cwd()}`); + +const b2 = new Bridge({ + port: 10000, + clients: hosts, + index: index, + peers: [] +}) + +const peerHosts = [ 'localhost:10000' ] +Peers.connectToPeers(peerHosts, (err, peers) => { + const b1 = new Bridge({ + port: 9999, + clients: hosts, + index: index, + peers: peers + }) +}) + +fs.unlinkSync(`${process.cwd()}/log`)