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

Commit

Permalink
remove node from unit tests, remove unused modules stubs file
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejBaj committed Feb 28, 2017
1 parent ffe05b0 commit 3e8eb41
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 285 deletions.
73 changes: 0 additions & 73 deletions test/common/modules.js

This file was deleted.

72 changes: 1 addition & 71 deletions test/common/objectStubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,6 @@ var randomPeer = {
'version': '0.0.0'
};

var modulesStub = {
transport: {
getFromPeer: sinon.stub().callsArgWith(2, null, {
success: true,
peer: randomPeer,
body: {
success: true, height: randomPeer.height, peers: [randomPeer]
}
}),
getFromRandomPeer: sinon.stub().callsArgWith(1, null, {
success: true,
peer: randomPeer,
body: {
success: true, height: randomPeer.height, peers: [randomPeer]
}
}),
headers: sinon.stub(),
consensus: sinon.stub(),
poorConsensus: sinon.stub(),
getPeers: sinon.stub(),
sandboxApi: sinon.stub(),
onBind: sinon.stub(),
onBlockchainReady: sinon.stub(),
onSignature: sinon.stub(),
onNewBlock: sinon.stub(),
onUnconfirmedTransaction: sinon.stub(),
onMessage: sinon.stub(),
cleanup: sinon.stub()
},
peers: {
accept: sinon.stub().returnsArg(0),
acceptable: sinon.stub().returnsArg(0),
list: sinon.stub(),
ban: sinon.stub(),
remove: sinon.stub(),
update: sinon.stub(),
sandboxApi: sinon.stub(),
pingPeer: sinon.stub(),
onBind: sinon.stub(),
onBlockchainReady: sinon.stub(),
onPeersReady: sinon.stub(),
cleanup: sinon.stub()
},
blocks: {
count: sinon.stub(),
getLastBlock: sinon.stub().returns({
height: 1
}),
lastReceipt: sinon.stub(),
getCommonBlock: sinon.stub(),
loadBlocksFromPeer: sinon.stub(),
loadBlocksData: sinon.stub(),
loadBlocksPart: sinon.stub(),
loadBlocksOffset: sinon.stub(),
deleteLastBlock: sinon.stub(),
loadLastBlock: sinon.stub(),
generateBlock: sinon.stub(),
processBlock: sinon.stub(),
verifyBlock: sinon.stub(),
deleteBlocksBefore: sinon.stub(),
deleteAfterBlock: sinon.stub(),
sandboxApi: sinon.stub(),
onReceiveBlock: sinon.stub(),
onBind: sinon.stub(),
cleanup: sinon.stub(),
aggregateBlocksReward: sinon.stub()
}
};

module.exports = {
randomPeer: randomPeer,
modulesStub: modulesStub
randomPeer: randomPeer
};
55 changes: 28 additions & 27 deletions test/unit/logic/peer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

var chai = require('chai');
var expect = require('chai').expect;

var express = require('express');
var ip = require('ip');
var _ = require('lodash');
var sinon = require('sinon');
var node = require('../../node.js');
var randomPeer = require('../../common/objectStubs').randomPeer;
var Peer = require('../../../logic/peer.js');

Expand All @@ -22,51 +23,51 @@ describe('peer', function () {
var peer = new Peer({});
var __peer = peer.accept(randomPeer);
['height', 'ip', 'port', 'state'].forEach(function (property) {
node.expect(__peer[property]).equals(randomPeer[property]);
expect(__peer[property]).equals(randomPeer[property]);
});
node.expect(__peer.string).equals(randomPeer.ip + ':' + randomPeer.port);
expect(__peer.string).equals(randomPeer.ip + ':' + randomPeer.port);
});

it('should accept empty peer and set default values', function () {
var __peer = peer.accept({});
node.expect(__peer.port).to.equal(0);
node.expect(__peer.ip).to.be.undefined;
node.expect(__peer.state).to.equal(1);
node.expect(__peer.height).to.be.undefined;
node.expect(__peer.string).to.be.undefined;
expect(__peer.port).to.equal(0);
expect(__peer.ip).to.be.undefined;
expect(__peer.state).to.equal(1);
expect(__peer.height).to.be.undefined;
expect(__peer.string).to.be.undefined;
});

it('should accept peer with ip as long', function () {
var __peer = peer.accept({ip: ip.toLong(randomPeer.ip)});
node.expect(__peer.ip).to.equal(randomPeer.ip);
expect(__peer.ip).to.equal(randomPeer.ip);
});

it('should convert dappid to array', function () {
var __peer = peer.accept({dappid: 'random-dapp-id'});
node.expect(__peer.dappid).to.be.an('array');
node.expect(_.isEqual(__peer.dappid, ['random-dapp-id'])).to.be.ok;
expect(__peer.dappid).to.be.an('array');
expect(_.isEqual(__peer.dappid, ['random-dapp-id'])).to.be.ok;
});
});

describe('parseInt', function () {

it('should always return a number', function () {
node.expect(peer.parseInt('1')).to.equal(1);
node.expect(peer.parseInt(1)).to.equal(1);
expect(peer.parseInt('1')).to.equal(1);
expect(peer.parseInt(1)).to.equal(1);
});

it('should return default value when NaN passed', function () {
node.expect(peer.parseInt('not a number', 1)).to.equal(1);
node.expect(peer.parseInt(undefined, 1)).to.equal(1);
node.expect(peer.parseInt(null, 1)).to.equal(1);
expect(peer.parseInt('not a number', 1)).to.equal(1);
expect(peer.parseInt(undefined, 1)).to.equal(1);
expect(peer.parseInt(null, 1)).to.equal(1);
});
});

describe('applyHeaders', function () {

it('should not apply random values to the peer scope', function () {
peer.applyHeaders({headerA: 'HeaderA'});
node.expect(peer.headerA).to.not.exist;
expect(peer.headerA).to.not.exist;
});

it('should apply value defined as header', function () {
Expand All @@ -76,7 +77,7 @@ describe('peer', function () {
var headers = {};
headers[header] = randomPeer[header];
peer.applyHeaders(headers);
node.expect(peer[header]).to.equal(randomPeer[header]);
expect(peer[header]).to.equal(randomPeer[header]);
});

peer = initialPeer;
Expand All @@ -85,27 +86,27 @@ describe('peer', function () {
it('should parse height and port', function () {
var appliedHeaders = peer.applyHeaders({port: '4000', height: '1'});

node.expect(appliedHeaders.port).to.equal(4000);
node.expect(appliedHeaders.height).to.equal(1);
expect(appliedHeaders.port).to.equal(4000);
expect(appliedHeaders.height).to.equal(1);
});
});

describe('update', function () {

it('should apply random values to the peer scope', function () {
peer.update({someProp: 'someValue'});
node.expect(peer.someProp).to.exist.and.equal('someValue');
expect(peer.someProp).to.exist.and.equal('someValue');
delete peer.someProp;
});

it('should not apply undefined to the peer scope', function () {
peer.update({someProp: undefined});
node.expect(peer.someProp).to.not.exist;
expect(peer.someProp).to.not.exist;
});

it('should not apply null to the peer scope', function () {
peer.update({someProp: null});
node.expect(peer.someProp).to.not.exist;
expect(peer.someProp).to.not.exist;
});

it('should not change state of banned peer', function () {
Expand All @@ -114,7 +115,7 @@ describe('peer', function () {
peer.state = 0;
// Try to unban peer
peer.update({state: 2});
node.expect(peer.state).to.equal(0);
expect(peer.state).to.equal(0);
peer.state = initialState;
});
});
Expand All @@ -128,9 +129,9 @@ describe('peer', function () {
var peerCopy = peer.object();
_.keys(randomPeer).forEach(function (property) {
if (peer.properties.indexOf(property) !== -1) {
node.expect(peerCopy[property]).to.equal(randomPeer[property]);
expect(peerCopy[property]).to.equal(randomPeer[property]);
if (peer.nullable.indexOf(property) !== -1 && !randomPeer[property]) {
node.expect(peerCopy[property]).to.be.null;
expect(peerCopy[property]).to.be.null;
}
}
});
Expand All @@ -141,7 +142,7 @@ describe('peer', function () {
var initialState = peer.state;
peer.update({state: 'unreadable'});
var peerCopy = peer.object();
node.expect(peerCopy.state).to.equal(1);
expect(peerCopy.state).to.equal(1);
peer.state = initialState;
});
});
Expand Down
Loading

0 comments on commit 3e8eb41

Please sign in to comment.