mirror of https://github.com/BTCPrivate/copay.git
add forceNetwork parameter and test it
This commit is contained in:
parent
b3f2476992
commit
00cf32fc8d
|
@ -2,6 +2,7 @@
|
||||||
var defaultConfig = {
|
var defaultConfig = {
|
||||||
// DEFAULT network (livenet or testnet)
|
// DEFAULT network (livenet or testnet)
|
||||||
networkName: 'livenet',
|
networkName: 'livenet',
|
||||||
|
forceNetwork: false,
|
||||||
|
|
||||||
// DEFAULT unit: Bit
|
// DEFAULT unit: Bit
|
||||||
unitName: 'bits',
|
unitName: 'bits',
|
||||||
|
@ -124,3 +125,4 @@ var defaultConfig = {
|
||||||
disableVideo: true,
|
disableVideo: true,
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
};
|
};
|
||||||
|
module.exports = defaultConfig;
|
||||||
|
|
|
@ -19,6 +19,7 @@ var AddressIndex = require('./AddressIndex');
|
||||||
var PublicKeyRing = require('./PublicKeyRing');
|
var PublicKeyRing = require('./PublicKeyRing');
|
||||||
var TxProposals = require('./TxProposals');
|
var TxProposals = require('./TxProposals');
|
||||||
var PrivateKey = require('./PrivateKey');
|
var PrivateKey = require('./PrivateKey');
|
||||||
|
var copayConfig = require('../../../config');
|
||||||
|
|
||||||
function Wallet(opts) {
|
function Wallet(opts) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -33,6 +34,9 @@ function Wallet(opts) {
|
||||||
throw new Error('missing required option for Wallet: ' + k);
|
throw new Error('missing required option for Wallet: ' + k);
|
||||||
self[k] = opts[k];
|
self[k] = opts[k];
|
||||||
});
|
});
|
||||||
|
if (copayConfig.forceNetwork && opts.networkName !== copayConfig.networkName)
|
||||||
|
throw new Error('Network forced to '+copayConfig.networkName+
|
||||||
|
' and tried to create a Wallet with network '+opts.networkName);
|
||||||
|
|
||||||
this.log('creating ' + opts.requiredCopayers + ' of ' + opts.totalCopayers + ' wallet');
|
this.log('creating ' + opts.requiredCopayers + ' of ' + opts.totalCopayers + ' wallet');
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ try {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var copay = require('../copay'); //node
|
var copay = require('../copay'); //node
|
||||||
}
|
}
|
||||||
|
var copayConfig = require('../config');
|
||||||
var Wallet = require('../js/models/core/Wallet');
|
var Wallet = require('../js/models/core/Wallet');
|
||||||
var Structure = copay.Structure;
|
var Structure = copay.Structure;
|
||||||
var Storage = require('./mocks/FakeStorage');
|
var Storage = require('./mocks/FakeStorage');
|
||||||
|
@ -950,4 +951,14 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#forceNetwork in config', function() {
|
||||||
|
it('should throw if network is different', function() {
|
||||||
|
var backup = copayConfig.forceNetwork;
|
||||||
|
copayConfig.forceNetwork = true;
|
||||||
|
config.networkName = 'livenet';
|
||||||
|
cachedCreateW2.should.throw(Error);
|
||||||
|
copayConfig.forceNetwork = backup;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue