mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #818 from maraoz/bug/addresses-check-network
check network for addresses
* Chrome 35.0.1916 (Mac OS X 10.9.3): Executed 76 of 76 SUCCESS (0.806 secs / 0.239 secs)
* mocha: 170 passing (8s)
* browser: 100%: 128.16s
Code: OK (I am starting to like preconditions 👍 )
This commit is contained in:
commit
44ef1c4710
|
@ -13,7 +13,7 @@ angular.module('copayApp.directives')
|
|||
link: function(scope, elem, attrs, ctrl) {
|
||||
var validator = function(value) {
|
||||
var a = new Address(value);
|
||||
ctrl.$setValidity('validAddress', a.isValid());
|
||||
ctrl.$setValidity('validAddress', a.isValid() && a.network().name === config.networkName);
|
||||
return value;
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ var buffertools = bitcore.buffertools;
|
|||
var Builder = bitcore.TransactionBuilder;
|
||||
var SecureRandom = bitcore.SecureRandom;
|
||||
var Base58Check = bitcore.Base58.base58Check;
|
||||
var Address = bitcore.Address;
|
||||
|
||||
var AddressIndex = require('./AddressIndex');
|
||||
var PublicKeyRing = require('./PublicKeyRing');
|
||||
|
@ -697,7 +698,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
opts = opts || {};
|
||||
|
||||
var amountSat = bignum(amountSatStr);
|
||||
|
||||
preconditions.checkArgument(new Address(toAddress).network().name === this.getNetworkName());
|
||||
if (!pkr.isComplete()) {
|
||||
throw new Error('publicKeyRing is not complete');
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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', {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue