From 00cf32fc8d5f2da7007d843ad3683f478f29c7da Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 8 Jul 2014 12:34:49 -0300 Subject: [PATCH 1/3] add forceNetwork parameter and test it --- config.js | 2 ++ js/models/core/Wallet.js | 4 ++++ test/test.Wallet.js | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/config.js b/config.js index d2ac2e75d..05bb71331 100644 --- a/config.js +++ b/config.js @@ -2,6 +2,7 @@ var defaultConfig = { // DEFAULT network (livenet or testnet) networkName: 'livenet', + forceNetwork: false, // DEFAULT unit: Bit unitName: 'bits', @@ -124,3 +125,4 @@ var defaultConfig = { disableVideo: true, verbose: 1, }; +module.exports = defaultConfig; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 7e892dd42..5e0be4c44 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -19,6 +19,7 @@ var AddressIndex = require('./AddressIndex'); var PublicKeyRing = require('./PublicKeyRing'); var TxProposals = require('./TxProposals'); var PrivateKey = require('./PrivateKey'); +var copayConfig = require('../../../config'); function Wallet(opts) { var self = this; @@ -33,6 +34,9 @@ function Wallet(opts) { throw new Error('missing required option for Wallet: ' + 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'); diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 42991ed57..b1f354cc6 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -8,6 +8,7 @@ try { } catch (e) { var copay = require('../copay'); //node } +var copayConfig = require('../config'); var Wallet = require('../js/models/core/Wallet'); var Structure = copay.Structure; 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; + }); + }); + }); From 1bf20dfe1fc39e1c2964d540992fb8f5e18e052a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 8 Jul 2014 13:03:59 -0300 Subject: [PATCH 2/3] fix index.html tests --- config.js | 3 ++- util/build.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index 05bb71331..9b24dbf01 100644 --- a/config.js +++ b/config.js @@ -125,4 +125,5 @@ var defaultConfig = { disableVideo: true, verbose: 1, }; -module.exports = defaultConfig; +if (typeof module !== 'undefined') + module.exports = defaultConfig; diff --git a/util/build.js b/util/build.js index e7cf06fa5..aff69a73c 100755 --- a/util/build.js +++ b/util/build.js @@ -87,6 +87,12 @@ var createBundle = function(opts) { b.require('./js/models/core/Message', { expose: '../js/models/core/Message' }); + b.require('./config', { + expose: '../config' + }); + b.require('./js/models/core/Structure', { + expose: '../js/models/core/Structure' + }); if (opts.dontminify) { //include dev dependencies From 4d70f0cf245f6b151fef1617e03ad0d6deb44a56 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 8 Jul 2014 13:23:43 -0300 Subject: [PATCH 3/3] add message for unchangeable network --- index.html | 11 +++++++++-- js/controllers/settings.js | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 5a354b627..6c67ace6c 100644 --- a/index.html +++ b/index.html @@ -845,8 +845,15 @@
Bitcoin Network - - +
+ + +
+
+ Network has been fixed to {{networkName}} in this setup. See copay.io + for options to use Copay on both livenet and testnet. +
Wallet Unit diff --git a/js/controllers/settings.js b/js/controllers/settings.js index 5d1d21868..cb1c7852c 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -12,6 +12,7 @@ angular.module('copayApp.controllers').controller('SettingsController', $scope.networkPort = config.network.port; $scope.networkSecure = config.network.secure || false; $scope.disableVideo = typeof config.disableVideo === undefined ? true : config.disableVideo; + $scope.forceNetwork = config.forceNetwork; $scope.unitOpts = [{ name: 'Satoshis (100,000,000 satoshis = 1BTC)',