From dfd0edf451752e5e62503daa8781d9396cb01348 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 30 Jun 2020 20:11:22 +0300 Subject: [PATCH] fix: `SimplifiedMNListDiff` do not pass network to `SimplifiedMNList` (#165) --- lib/deterministicmnlist/SimplifiedMNList.js | 5 +++++ lib/deterministicmnlist/SimplifiedMNListDiff.js | 11 +++++++++-- lib/networks.js | 9 ++++++++- package-lock.json | 2 +- package.json | 2 +- test/networks.js | 16 ++++++++++++++++ 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/deterministicmnlist/SimplifiedMNList.js b/lib/deterministicmnlist/SimplifiedMNList.js index 9e44a51a2..b75a1fa0b 100644 --- a/lib/deterministicmnlist/SimplifiedMNList.js +++ b/lib/deterministicmnlist/SimplifiedMNList.js @@ -272,6 +272,11 @@ SimplifiedMNList.prototype.getValidMasternodesList = function getValidMasternode */ SimplifiedMNList.prototype.getLLMQTypes = function getLLMQTypes() { var llmqTypes = []; + + if (!this.network) { + throw new Error('Network is not set'); + } + switch (this.network.name) { case Networks.livenet.name: llmqTypes = [constants.LLMQ_TYPES.LLMQ_TYPE_50_60, diff --git a/lib/deterministicmnlist/SimplifiedMNListDiff.js b/lib/deterministicmnlist/SimplifiedMNListDiff.js index b8c02e144..e5a9013c2 100644 --- a/lib/deterministicmnlist/SimplifiedMNListDiff.js +++ b/lib/deterministicmnlist/SimplifiedMNListDiff.js @@ -151,7 +151,7 @@ SimplifiedMNListDiff.prototype.toBuffer = function toBuffer() { /** * Creates MNListDiff from object * @param obj - * @param {string} [network] + * @param {string|Network} [network] * @return {SimplifiedMNListDiff} */ SimplifiedMNListDiff.fromObject = function fromObject(obj, network) { @@ -180,8 +180,15 @@ SimplifiedMNListDiff.fromObject = function fromObject(obj, network) { if (obj.merkleRootQuorums) { simplifiedMNListDiff.merkleRootQuorums = obj.merkleRootQuorums; } - if (simplifiedMNListDiff.mnList.length >= 1) { + + if (simplifiedMNListDiff.mnList.length > 0) { + if (network && simplifiedMNListDiff.mnList[0].network.name !== network.name) { + throw new Error('votingAddress network is not equal to ' + network.name); + } + simplifiedMNListDiff.network = simplifiedMNListDiff.mnList[0].network; + } else { + simplifiedMNListDiff.network = network; } return simplifiedMNListDiff; diff --git a/lib/networks.js b/lib/networks.js index 6e9c3e3f3..75ef0b273 100644 --- a/lib/networks.js +++ b/lib/networks.js @@ -47,7 +47,14 @@ function get(arg, keys) { } return undefined; } - return networkMaps[arg]; + + var network = networkMaps[arg]; + + if (network && network === testnet && (arg === 'local' || arg === 'regtest')) { + enableRegtest(); + } + + return network; } /** diff --git a/package-lock.json b/package-lock.json index a3fbd9c92..3264b383f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dashcore-lib", - "version": "0.18.10", + "version": "0.18.11", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a34c45143..45c667ab6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dashcore-lib", - "version": "0.18.10", + "version": "0.18.11", "description": "A pure and powerful JavaScript Dash library.", "author": "Dash Core Group, Inc. ", "main": "index.js", diff --git a/test/networks.js b/test/networks.js index 87cb36163..ea7808e90 100644 --- a/test/networks.js +++ b/test/networks.js @@ -36,8 +36,24 @@ describe('Networks', function() { }); it('will get network based on string "regtest" value', function() { + networks.disableRegtest(); var network = networks.get('regtest'); network.should.equal(networks.testnet); + network.regtestEnabled.should.be.true; + }); + + it('will get network based on string "local" value', function() { + networks.disableRegtest(); + var network = networks.get('local'); + network.should.equal(networks.testnet); + network.regtestEnabled.should.be.true; + }); + + it('will get network based on string "evonet" value', function() { + networks.disableRegtest(); + var network = networks.get('evonet'); + network.should.equal(networks.testnet); + network.regtestEnabled.should.be.false; }); it('should be able to define a custom Network', function() {