Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
extend handshake unit tests coverage
Browse files Browse the repository at this point in the history
- fix remaining issues with other unit tests failing
- correct ports switching in config.non-forge.json
  • Loading branch information
MaciejBaj committed Jul 25, 2017
1 parent d5a864f commit 10ddcfd
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 14 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ d.run(function () {
appName: 'lisk',
workerController: workersController.path,
perMessageDeflate: false,
secretKey: 'liskSecretKey',
pingInterval: 5000,
// How many milliseconds to wait without receiving a ping
// before closing the socket
Expand Down
2 changes: 1 addition & 1 deletion helpers/wsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var middleware = {

Handshake: function (system) {
return function (headers, cb) {

headers = headers || {};
var peer = new Peer(headers);
headers.state = Peer.STATE.CONNECTED;

Expand Down
4 changes: 3 additions & 1 deletion logic/broadcaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ Broadcaster.prototype.broadcast = function (params, options, cb) {
},
function sendToPeer (peers, waterCb) {
library.logger.debug('Begin broadcast', options);
if (params.limit === self.config.peerLimit) { peers = peers.slice(0, self.config.broadcastLimit); }
if (params.limit === self.config.peerLimit) {
peers = peers.slice(0, self.config.broadcastLimit);
}
async.eachLimit(peers, self.config.parallelLimit, function (peer, eachLimitCb) {
peer.rpc[options.api](options.data, function (err, result) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion schema/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {
max: 16
}
},
required: ['port', 'version', 'nethash']
required: ['ip', 'port', 'version', 'nethash']
},
commonBlock: {
id: 'transport.commonBlock',
Expand Down
4 changes: 2 additions & 2 deletions test/integration/configs/config.non-forge.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"port": 4000,
"httpPort": 5000,
"port": 5000,
"httpPort": 4000,
"address": "0.0.0.0",
"version": "0.0.0a",
"minVersion": "0.0.0a",
Expand Down
4 changes: 0 additions & 4 deletions test/unit/helpers/RPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ describe('wsRPC', function () {
expect(wsRPC.scClient).to.have.property('connections').to.be.a('object').and.to.be.empty;
});

it('should have wsServer field unset', function () {
expect(wsRPC).to.have.property('wsServer').and.to.be.null;
});

describe('setServer', function () {

before(function () {
Expand Down
63 changes: 60 additions & 3 deletions test/unit/helpers/wsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ describe('handshake', function () {
});
});

it('should return error when null request passed', function (done) {
it('should return error when empty undefined request', function (done) {

handshake(null, function (err, data) {
handshake(undefined, function (err, data) {
expect(err).not.to.be.empty;
expect(err).to.have.property('error').that.is.an('array');
done();
});
});

it('should return error when wrong request passed', function (done) {
it('should return error when empty null request', function (done) {

handshake(null, function (err, data) {
expect(err).not.to.be.empty;
Expand All @@ -67,4 +67,61 @@ describe('handshake', function () {
});
});

it('should return error when 0 as request', function (done) {

handshake(0, function (err, data) {
expect(err).not.to.be.empty;
expect(err).to.have.property('error').that.is.an('array');
done();
});
});

it('should return error when empty request passed', function (done) {

handshake({}, function (err, data) {
expect(err).not.to.be.empty;
expect(err).to.have.property('error').that.is.an('array');
done();
});
});

it('should return error when wrong request without version passed', function (done) {
var malformedRequest = _.clone(validRequest);
delete malformedRequest.version;
handshake(malformedRequest, function (err, data) {
expect(err).not.to.be.empty;
expect(err).to.have.property('error').that.is.an('array');
done();
});
});

it('should return error when wrong request without port passed', function (done) {
var malformedRequest = _.clone(validRequest);
delete malformedRequest.port;
handshake(malformedRequest, function (err, data) {
expect(err).not.to.be.empty;
expect(err).to.have.property('error').that.is.an('array');
done();
});
});

it('should return error when wrong request without ip passed', function (done) {
var malformedRequest = _.clone(validRequest);
delete malformedRequest.ip;
handshake(malformedRequest, function (err, data) {
expect(err).not.to.be.empty;
expect(err).to.have.property('error').that.is.an('array');
done();
});
});

it('should return error when wrong request without nethash passed', function (done) {
var malformedRequest = _.clone(validRequest);
delete malformedRequest.nethash;
handshake(malformedRequest, function (err, data) {
expect(err).not.to.be.empty;
expect(err).to.have.property('error').that.is.an('array');
done();
});
});
});
7 changes: 5 additions & 2 deletions test/unit/modules/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ describe('peers', function () {
peers.update(secondPeer);
getPeers(function (err, __peers) {
expect(__peers).to.have.a.lengthOf(2);
expect(__peers[0]).to.have.property('string').equal(randomPeer.ip + ':' + randomPeer.port);
expect(__peers[1]).to.have.property('string').equal(secondPeer.ip + ':' + secondPeer.port);
var peersAddresses = __peers.map(function (p) {
return p.string;
});
expect(peersAddresses.indexOf(randomPeer.ip + ':' + randomPeer.port) !== -1).to.be.ok;
expect(peersAddresses.indexOf(secondPeer.ip + ':' + secondPeer.port) !== -1).to.be.ok;
done();
});
});
Expand Down

0 comments on commit 10ddcfd

Please sign in to comment.