diff --git a/js/directives.js b/js/directives.js index 0ff54d56e..cac0adb93 100644 --- a/js/directives.js +++ b/js/directives.js @@ -29,8 +29,7 @@ angular.module('copayApp.directives') restrict: 'A', link: function(scope, element, attrs, ctrl) { setTimeout(function() { - scope.$apply(function() { - }); + scope.$apply(function() {}); }, 5000); } }; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index acca81d38..0adaffe3c 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -697,8 +697,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos opts = opts || {}; var amountSat = bignum(amountSatStr); - preconditions.checkArgument(new Address(toAddress).network().name === this.networkName); - + preconditions.checkArgument(new Address(toAddress).network().name === this.getNetworkName()); if (!pkr.isComplete()) { throw new Error('publicKeyRing is not complete'); } diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 20dd4b6ba..d53182fcd 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -172,6 +172,24 @@ describe('Wallet model', function() { return w; }; + it('#create, fail for network', function() { + + var w = cachedCreateW2(); + + unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString(); + unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true); + + var f = function() { + var ntxid = w.createTxSync( + '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', + '123456789', + null, + unspentTest + ); + }; + f.should.throw(Error); + }); + it('#create, 1 sign', function() { var w = cachedCreateW2(); @@ -180,7 +198,7 @@ describe('Wallet model', function() { unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true); var ntxid = w.createTxSync( - '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', + 'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79', '123456789', null, unspentTest @@ -205,7 +223,7 @@ describe('Wallet model', function() { unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true); var ntxid = w.createTxSync( - '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', + 'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79', '123456789', comment, unspentTest @@ -228,7 +246,7 @@ describe('Wallet model', function() { var badCreate = function() { w.createTxSync( - '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', + 'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79', '123456789', comment, unspentTest @@ -262,7 +280,7 @@ describe('Wallet model', function() { unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange).toString(); unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange); w.createTxSync( - '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', + 'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79', '123456789', null, unspentTest diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 4ee1d4302..3e396def7 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -174,12 +174,17 @@ describe("Unit: Controllers", function() { expect(scope.showAddressBook()).equal(true); }); - it('should validate address', function() { - form.newaddress.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); + it('should validate address with network', function() { + form.newaddress.$setViewValue('1JqniWpWNA6Yvdivg3y9izLidETnurxRQm'); expect(form.newaddress.$invalid).to.equal(false); }); - it('should not validate address', function() { + it('should not validate address with other network', function() { + form.newaddress.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); + expect(form.newaddress.$invalid).to.equal(true); + }); + + it('should not validate random address', function() { form.newaddress.$setViewValue('thisisaninvalidaddress'); expect(form.newaddress.$invalid).to.equal(true); }); @@ -194,7 +199,7 @@ describe("Unit: Controllers", function() { }); it('should create a transaction proposal', function() { - sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); + sendForm.address.$setViewValue('1JqniWpWNA6Yvdivg3y9izLidETnurxRQm'); sendForm.amount.$setViewValue(1000); var spy = sinon.spy(scope.wallet, 'createTx'); @@ -205,7 +210,7 @@ describe("Unit: Controllers", function() { }); it('should create and send a transaction proposal', function() { - sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); + sendForm.address.$setViewValue('1JqniWpWNA6Yvdivg3y9izLidETnurxRQm'); sendForm.amount.$setViewValue(1000); scope.wallet.totalCopayers = scope.wallet.requiredCopayers = 1; @@ -372,7 +377,7 @@ describe("Unit: Controllers", function() { var what; beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); - var routeParams = { + var routeParams = { data: 'bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8%3Famount=0.1&message=a%20bitcoin%20donation' }; what = $controller('UriPaymentController', { diff --git a/test/unit/directives/directivesSpec.js b/test/unit/directives/directivesSpec.js index ff3efc4a8..dbca2ce8e 100644 --- a/test/unit/directives/directivesSpec.js +++ b/test/unit/directives/directivesSpec.js @@ -36,11 +36,17 @@ describe("Unit: Testing Directives", function() { form = $scope.form; })); - it('should validate', function() { + it('should validate with network', function() { + config.networkName = 'testnet'; form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); expect(form.address.$invalid).to.equal(false); }); - it('should not validate', function() { + it('should not validate with other network', function() { + config.networkName = 'livenet'; + form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); + expect(form.address.$invalid).to.equal(true); + }); + it('should not validate random', function() { form.address.$setViewValue('thisisaninvalidaddress'); expect(form.address.$invalid).to.equal(true); });