Skip to content

Commit

Permalink
fix: SimplifiedMNListDiff do not pass network to SimplifiedMNList (
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov authored Jun 30, 2020
1 parent 22e94ed commit dfd0edf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/deterministicmnlist/SimplifiedMNList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions lib/deterministicmnlist/SimplifiedMNListDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion lib/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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. <dev@dash.org>",
"main": "index.js",
Expand Down
16 changes: 16 additions & 0 deletions test/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit dfd0edf

Please sign in to comment.