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

Commit

Permalink
Adds test to improved peer discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
toschdev committed Apr 27, 2017
1 parent 8818427 commit 159f887
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/api/liskApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ function LiskAPI (options) {
this.nethash = this.getNethash(options.nethash);
}

/**
* @method netHashOptions
* @return {object}
*/

LiskAPI.prototype.netHashOptions = function () {

return {
Expand All @@ -109,6 +114,11 @@ LiskAPI.prototype.netHashOptions = function () {

};

/**
* @method getNethash
* @return {object}
*/

LiskAPI.prototype.getNethash = function (providedNethash) {

var NetHash = (this.testnet) ? this.netHashOptions().testnet : this.netHashOptions().mainnet;
Expand Down
40 changes: 40 additions & 0 deletions test/api/liskApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ describe('Lisk.api()', function () {

(LISK.testnet).should.be.true;
});

it('should set to mainnet', function () {
var LISK = lisk.api();
LISK.setTestnet(false);

(LISK.testnet).should.be.false;
});
});

describe('#setNode', function () {
Expand Down Expand Up @@ -633,6 +640,39 @@ describe('Lisk.api()', function () {
done();
});
});

it('should redial to new node when randomPeer is set true', function (done) {
var thisLSK = lisk.api({ randomPeer: true, node: '123' });
thisLSK.getAccount('12731041415715717263L', function (data) {
(data).should.be.ok;
(data.success).should.be.equal(true);
done();
});
});

it('should not redial to new node when randomPeer is set to true but unknown nethash provided', function () {
var thisLSK = lisk.api({ randomPeer: true, node: '123', nethash: '123' });
(thisLSK.checkReDial()).should.be.equal(false);

});

it('should redial to mainnet nodes when nethash is set and randomPeer is true', function () {
var thisLSK = lisk.api({ randomPeer: true, node: '123', nethash: 'ed14889723f24ecc54871d058d98ce91ff2f973192075c0155ba2b7b70ad2511' });
(thisLSK.checkReDial()).should.be.equal(true);
(thisLSK.testnet).should.be.equal(false);
});

it('should redial to testnet nodes when nethash is set and randomPeer is true', function () {
var thisLSK = lisk.api({ randomPeer: true, node: '123', nethash: 'da3ed6a45429278bac2666961289ca17ad86595d33b31037615d4b8e8f158bba' });
(thisLSK.checkReDial()).should.be.equal(true);
(thisLSK.testnet).should.be.equal(true);
});

it('should not redial when randomPeer is set false', function () {
var thisLSK = lisk.api({ randomPeer: false});
(thisLSK.checkReDial()).should.be.equal(false);
});

});

describe('#sendRequest with promise', function () {
Expand Down

0 comments on commit 159f887

Please sign in to comment.