Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Starts on tests for larger peer groups
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-miller-0 committed Feb 13, 2018
1 parent f4e2e25 commit 3150eb5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/lib/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -287,7 +287,6 @@ class Bridge {
case 'PING':
this.addPeer(msg.from);
default:
logger.log('info', `Got msg with no type: ${msg}`)
break;
}
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions test/threePeers.js
Original file line number Diff line number Diff line change
@@ -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`)

0 comments on commit 3150eb5

Please sign in to comment.