add more tests

This commit is contained in:
Matias Alejo Garcia 2014-04-04 20:16:15 -03:00
commit f089246b88
2 changed files with 34 additions and 7 deletions

View file

@ -84,6 +84,8 @@ PublicKeyRing.read = function (id, passphrase) {
w.requiredCopayers = data.neededCopayers;
w.totalCopayers = data.totalCopayers;
w.addressIndex = data.addressIndex;
w.changeAddressIndex = data.changeAddressIndex;
// this.bip32 = ;
w.copayersBIP32 = data.copayersExtPubKeys.map( function (pk) {
@ -95,16 +97,22 @@ PublicKeyRing.read = function (id, passphrase) {
return w;
};
PublicKeyRing.prototype.serialize = function () {
return JSON.stringify({
PublicKeyRing.prototype._toObj = function() {
return {
id: this.id,
network: this.network.name,
requiredCopayers: this.neededCopayers,
totalCopayers: this.totalCopayers,
changeAddressIndex: this.changeAddressIndex,
addressIndex: this.addressIndex,
copayersExtPubKeys: this.copayersBIP32.map( function (b) {
return b.extendedPublicKeyString();
}),
});
};
};
PublicKeyRing.prototype.serialize = function () {
return JSON.stringify(this._toObj());
};

View file

@ -75,6 +75,10 @@ describe('PublicKeyRing model', function() {
var k = createW();
var w = k.w;
var copayers = k.copayers;
for(var i=0; i<3; i++)
w.generateAddress(true);
for(var i=0; i<5; i++)
w.generateAddress(false);
w.store().should.equal(true);
var ID = w.id;
@ -86,7 +90,9 @@ describe('PublicKeyRing model', function() {
w2.addCopayer.bind().should.throw();
for(var i =0; i<5; i++)
w2.addCopayer.bind(copayers[i]).should.throw();
w2.changeAddressIndex.should.equal(3);
w2.addressIndex.should.equal(5);
});
@ -101,7 +107,6 @@ describe('PublicKeyRing model', function() {
a.isValid().should.equal(true);
a.isScript().should.equal(true);
a.network().name.should.equal('livenet');
if (i>1) {
w.getAddress(i-1,isChange).should
.not.equal(w.getAddress(i-2,isChange));
@ -124,12 +129,26 @@ describe('PublicKeyRing model', function() {
var as = w.getAddresses();
as.length.should.equal(12);
for(var i in as) {
var a = new Address(as[i]);
for(var j in as) {
var a = new Address(as[j]);
a.isValid().should.equal(true);
}
});
it('should count generation indexes', function () {
var k = createW();
var w = k.w;
for(var i=0; i<3; i++)
w.generateAddress(true);
for(var i=0; i<5; i++)
w.generateAddress(false);
w.changeAddressIndex.should.equal(3);
w.addressIndex.should.equal(5);
});
});