mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #2318 from matiaspando/iss2308
To avoid errors on invalid address
This commit is contained in:
commit
e8d3de7460
|
@ -62,7 +62,7 @@ angular.module('copayApp.controllers').controller('ReceiveController',
|
|||
var w = $rootScope.wallet;
|
||||
var balance = w.balanceInfo.balanceByAddr;
|
||||
|
||||
var addresses = w.getAddressesOrderer();
|
||||
var addresses = w.getAddressesOrdered();
|
||||
if (addresses) {
|
||||
$scope.addrLength = addresses.length;
|
||||
|
||||
|
|
|
@ -358,10 +358,6 @@ Network.prototype.getOnlinePeerIDs = function() {
|
|||
return this.connectedPeers;
|
||||
};
|
||||
|
||||
Network.prototype.getPeer = function() {
|
||||
return this.peer;
|
||||
};
|
||||
|
||||
|
||||
Network.prototype.getCopayerIds = function() {
|
||||
if (this.allowedCopayerIds) {
|
||||
|
|
|
@ -658,7 +658,7 @@ Wallet.prototype._onAddressBook = function(senderId, data) {
|
|||
var self = this,
|
||||
hasChange;
|
||||
_.each(data.addressBook, function(value, key) {
|
||||
if (key && !self.addressBook[key] && Address.validate(key)) {
|
||||
if (key && !self.addressBook[key] && _.isString(key) && Address.validate(key)) {
|
||||
|
||||
self.addressBook[key] = _.pick(value, ['createdTs', 'label']);
|
||||
|
||||
|
|
|
@ -257,6 +257,26 @@ describe('Network / Async', function() {
|
|||
n.networkNonce.toString('hex').should.equal(hex);
|
||||
});
|
||||
|
||||
it('should return an error', function() {
|
||||
var hex = '0000';
|
||||
var n = createN();
|
||||
(function() {
|
||||
n.setHexNonce(hex);
|
||||
}).should.throw('incorrect length');
|
||||
});
|
||||
|
||||
it('should iterateNonce', function() {
|
||||
var n = createN();
|
||||
n.iterateNonce = sinon.spy();
|
||||
n.setHexNonce();
|
||||
n.iterateNonce.callCount.should.be.equal(1);
|
||||
n.setHexNonce(null);
|
||||
n.iterateNonce.callCount.should.be.equal(2);
|
||||
n.setHexNonce(undefined);
|
||||
n.iterateNonce.callCount.should.be.equal(3);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setHexNonces', function() {
|
||||
|
@ -323,4 +343,111 @@ describe('Network / Async', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('#_arrayRemove', function() {
|
||||
it('should remove an element from an array', function() {
|
||||
var array = ['1', '2', '3', '4'];
|
||||
array = Async._arrayRemove('2', array);
|
||||
array.length.should.be.equal(3);
|
||||
array.indexOf('2').should.be.equal(-1);
|
||||
array = Async._arrayRemove('5', array);
|
||||
array.length.should.be.equal(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getOnlinePeerIDs', function() {
|
||||
it('should get peer ids that are online', function() {
|
||||
var n = createN();
|
||||
n.getOnlinePeerIDs().length.should.be.equal(0);
|
||||
n._addCopayer('ab0001');
|
||||
n.getOnlinePeerIDs().length.should.be.equal(1);
|
||||
n._addCopayer('ab0001');
|
||||
n.getOnlinePeerIDs().length.should.be.equal(1);
|
||||
n._addCopayer('ab0002');
|
||||
n.getOnlinePeerIDs().length.should.be.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#connectedCopayers', function() {
|
||||
it('should get peer ids that are online', function() {
|
||||
var n = createN();
|
||||
n.connectedCopayers().length.should.be.equal(0);
|
||||
n._addCopayer('ab0001');
|
||||
n.connectedCopayers().length.should.be.equal(1);
|
||||
n._addCopayer('ab0001');
|
||||
n.connectedCopayers().length.should.be.equal(1);
|
||||
n._addCopayer('ab0002');
|
||||
n.connectedCopayers().length.should.be.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#_deletePeer', function() {
|
||||
it('should delete a Peer', function() {
|
||||
var n = createN();
|
||||
n._addCopayer('ab0001');
|
||||
n.connectedPeers.length.should.be.equal(1);
|
||||
var peerId = n.connectedPeers[0];
|
||||
n._deletePeer(peerId);
|
||||
n.connectedPeers.length.should.be.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCopayerIds', function() {
|
||||
it('should return the copayer ids', function() {
|
||||
var n = createN();
|
||||
n.getCopayerIds().length.should.be.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isOnline', function() {
|
||||
it('should return if is online', function() {
|
||||
var n = createN();
|
||||
n.isOnline().should.be.true;
|
||||
n.cleanUp();
|
||||
n.isOnline().should.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#greet', function() {
|
||||
it('should greet ', function() {
|
||||
var n = createN();
|
||||
n.greet('03b51d01d798522cf61211b4dfcdd6db219ee33cf166e1cb7f43d836ab00ccddee', 'mySecret');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setCopayers', function() {
|
||||
it('should setCopayers ', function() {
|
||||
var n = createN();
|
||||
n.connectedPeers.length.should.be.equal(0);
|
||||
var cids = ['abc001', 'abc002'];
|
||||
n.setCopayers(cids);
|
||||
n.connectedPeers.length.should.be.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('#lockIncommingConnections', function() {
|
||||
it('should lock Incomming Connections ', function() {
|
||||
var n = createN();
|
||||
var cids = ['abc001', 'abc002', 'abc003'];
|
||||
n.setCopayers(cids);
|
||||
|
||||
var lockIds = ['abc001', 'abc002'];
|
||||
n.lockIncommingConnections(lockIds);
|
||||
console.log(n.allowedCopayerIds);
|
||||
Object.keys(n.allowedCopayerIds).length.should.be.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getKey', function() {
|
||||
it('should return the key or generate a new one ', function() {
|
||||
var n = createN();
|
||||
n.key = null;
|
||||
var k1 = n.getKey();
|
||||
k1.should.not.be.undefined;
|
||||
var k2 = n.getKey();
|
||||
k2.should.not.be.undefined;
|
||||
k1.should.be.equal(k2);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -52,7 +52,7 @@ describe("Unit: Controllers", function() {
|
|||
//
|
||||
// TODO Use the REAL wallet, and stub only networking and DB components!
|
||||
//
|
||||
|
||||
|
||||
var w = {};
|
||||
w.id = 1234;
|
||||
w.isComplete = sinon.stub().returns(true);
|
||||
|
@ -148,8 +148,80 @@ describe("Unit: Controllers", function() {
|
|||
c = $controller('ReceiveController', {
|
||||
$scope: scope,
|
||||
});
|
||||
|
||||
|
||||
var createW = function(N, conf) {
|
||||
|
||||
var c = JSON.parse(JSON.stringify(conf || walletConfig));
|
||||
if (!N) N = c.totalCopayers;
|
||||
|
||||
var mainPrivateKey = new copay.PrivateKey({
|
||||
networkName: walletConfig.networkName
|
||||
});
|
||||
var mainCopayerEPK = mainPrivateKey.deriveBIP45Branch().extendedPublicKeyString();
|
||||
c.privateKey = mainPrivateKey;
|
||||
|
||||
c.publicKeyRing = new copay.PublicKeyRing({
|
||||
networkName: c.networkName,
|
||||
requiredCopayers: Math.min(N, c.requiredCopayers),
|
||||
totalCopayers: N,
|
||||
});
|
||||
c.publicKeyRing.addCopayer(mainCopayerEPK);
|
||||
|
||||
c.publicKeyRing.getAddressesOrdered = sinon.stub().returns(null);
|
||||
|
||||
c.txProposals = new copay.TxProposals({
|
||||
networkName: c.networkName,
|
||||
});
|
||||
|
||||
c.blockchain = new Blockchain(walletConfig.blockchain);
|
||||
|
||||
c.network = sinon.stub();
|
||||
c.network.setHexNonce = sinon.stub();
|
||||
c.network.setHexNonces = sinon.stub();
|
||||
c.network.getHexNonce = sinon.stub();
|
||||
c.network.getHexNonces = sinon.stub();
|
||||
c.network.peerFromCopayer = sinon.stub().returns('xxxx');
|
||||
c.network.send = sinon.stub();
|
||||
|
||||
c.addressBook = {
|
||||
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ': {
|
||||
label: 'John',
|
||||
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||
createdTs: 1403102115,
|
||||
hidden: false
|
||||
},
|
||||
'2MtP8WyiwG7ZdVWM96CVsk2M1N8zyfiVQsY': {
|
||||
label: 'Jennifer',
|
||||
copayerId: '032991f836543a492bd6d0bb112552bfc7c5f3b7d5388fcbcbf2fbb893b44770d7',
|
||||
createdTs: 1403103115,
|
||||
hidden: false
|
||||
}
|
||||
};
|
||||
|
||||
c.networkName = walletConfig.networkName;
|
||||
c.version = '0.0.1';
|
||||
|
||||
c.balanceInfo = {};
|
||||
|
||||
return new Wallet(c);
|
||||
};
|
||||
|
||||
$rootScope.wallet = createW();
|
||||
$rootScope.wallet.balanceInfo = {};
|
||||
}));
|
||||
|
||||
it('should exist', function() {
|
||||
should.exist(c);
|
||||
});
|
||||
|
||||
it('should call setAddressList', function() {
|
||||
scope.setAddressList();
|
||||
expect(scope.addresses).to.be.empty;
|
||||
scope.toggleShowAll();
|
||||
scope.setAddressList();
|
||||
expect(scope.addresses).to.be.empty;
|
||||
});
|
||||
});
|
||||
|
||||
describe('History Controller', function() {
|
||||
|
|
Loading…
Reference in New Issue