Add some test and refactor getCosigner

This commit is contained in:
Yemel Jardi 2014-07-04 09:45:02 -03:00
commit 7562c3f9e7
4 changed files with 54 additions and 18 deletions

View file

@ -47,6 +47,18 @@ describe('AddressIndex model', function() {
cosigners.indexOf(2).should.equal(-1);
});
it('should serialize to object list and back', function() {
var is = AddressIndex.init(3);
should.exist(is);
is.length.should.equal(4);
var list = AddressIndex.serialize(is);
list.length.should.equal(4);
var is2 = AddressIndex.fromList(list);
is2.length.should.equal(4);
});
it('show be able to store and read', function() {
var i = createAI();
var changeN = 2;

View file

@ -343,14 +343,14 @@ describe('Wallet model', function() {
var w = createW();
var aiObj = {
indexes: [{
cosigner: Structure.SHARED_INDEX,
cosigner: 0,
changeIndex: 3,
receiveIndex: 2
}]
};
w._handleIndexes('senderID', aiObj, true);
w.publicKeyRing.getSharedIndex().getReceiveIndex(2);
w.publicKeyRing.getSharedIndex().getChangeIndex(3);
w.publicKeyRing.getIndex(0).getReceiveIndex(2);
w.publicKeyRing.getIndex(0).getChangeIndex(3);
});
it('handle network pubKeyRings correctly', function() {
@ -367,7 +367,7 @@ describe('Wallet model', function() {
requiredCopayers: w.requiredCopayers,
totalCopayers: w.totalCopayers,
indexes: [{
cosigner: Structure.SHARED_INDEX,
cosigner: 0,
changeIndex: 2,
receiveIndex: 3
}],
@ -377,8 +377,8 @@ describe('Wallet model', function() {
w._handlePublicKeyRing('senderID', {
publicKeyRing: pkrObj
}, true);
w.publicKeyRing.getSharedIndex().getReceiveIndex(2);
w.publicKeyRing.getSharedIndex().getChangeIndex(3);
w.publicKeyRing.getIndex(0).getReceiveIndex(2);
w.publicKeyRing.getIndex(0).getChangeIndex(3);
for (var i = 0; i < w.requiredCopayers; i++) {
w.publicKeyRing.toObj().copayersExtPubKeys[i].should.equal(cepk[i]);
}

View file

@ -69,6 +69,35 @@ describe('Unit: Testing Filters', function() {
}));
});
describe('removeEmpty addresses', function() {
it('should work with empty lists', inject(function($filter) {
var removeEmpty = $filter('removeEmpty');
expect(removeEmpty([]).length).to.equal(0);
}));
it('should filter empty addresses from other copayers', inject(function($filter) {
var removeEmpty = $filter('removeEmpty');
var addresses = [{
owned: true,
balance: 0
}, {
owned: false,
balance: 0
}, {
owned: true,
balance: 0
}, {
owned: false,
balance: 0
}];
expect(removeEmpty(addresses).length).to.equal(2);
addresses[1].owned = true;
expect(removeEmpty(addresses).length).to.equal(3);
addresses[3].balance = 10;
expect(removeEmpty(addresses).length).to.equal(4);
}));
});
describe('noFractionNumber bits', function() {
beforeEach(function() {
config.unitToSatoshi = 100;