add more tests
This commit is contained in:
parent
8b42f8508b
commit
f089246b88
2 changed files with 34 additions and 7 deletions
|
|
@ -84,6 +84,8 @@ PublicKeyRing.read = function (id, passphrase) {
|
||||||
|
|
||||||
w.requiredCopayers = data.neededCopayers;
|
w.requiredCopayers = data.neededCopayers;
|
||||||
w.totalCopayers = data.totalCopayers;
|
w.totalCopayers = data.totalCopayers;
|
||||||
|
w.addressIndex = data.addressIndex;
|
||||||
|
w.changeAddressIndex = data.changeAddressIndex;
|
||||||
|
|
||||||
// this.bip32 = ;
|
// this.bip32 = ;
|
||||||
w.copayersBIP32 = data.copayersExtPubKeys.map( function (pk) {
|
w.copayersBIP32 = data.copayersExtPubKeys.map( function (pk) {
|
||||||
|
|
@ -95,16 +97,22 @@ PublicKeyRing.read = function (id, passphrase) {
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
PublicKeyRing.prototype.serialize = function () {
|
PublicKeyRing.prototype._toObj = function() {
|
||||||
return JSON.stringify({
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
network: this.network.name,
|
network: this.network.name,
|
||||||
requiredCopayers: this.neededCopayers,
|
requiredCopayers: this.neededCopayers,
|
||||||
totalCopayers: this.totalCopayers,
|
totalCopayers: this.totalCopayers,
|
||||||
|
changeAddressIndex: this.changeAddressIndex,
|
||||||
|
addressIndex: this.addressIndex,
|
||||||
copayersExtPubKeys: this.copayersBIP32.map( function (b) {
|
copayersExtPubKeys: this.copayersBIP32.map( function (b) {
|
||||||
return b.extendedPublicKeyString();
|
return b.extendedPublicKeyString();
|
||||||
}),
|
}),
|
||||||
});
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
PublicKeyRing.prototype.serialize = function () {
|
||||||
|
return JSON.stringify(this._toObj());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ describe('PublicKeyRing model', function() {
|
||||||
var k = createW();
|
var k = createW();
|
||||||
var w = k.w;
|
var w = k.w;
|
||||||
var copayers = k.copayers;
|
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);
|
w.store().should.equal(true);
|
||||||
var ID = w.id;
|
var ID = w.id;
|
||||||
|
|
@ -86,7 +90,9 @@ describe('PublicKeyRing model', function() {
|
||||||
w2.addCopayer.bind().should.throw();
|
w2.addCopayer.bind().should.throw();
|
||||||
for(var i =0; i<5; i++)
|
for(var i =0; i<5; i++)
|
||||||
w2.addCopayer.bind(copayers[i]).should.throw();
|
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.isValid().should.equal(true);
|
||||||
a.isScript().should.equal(true);
|
a.isScript().should.equal(true);
|
||||||
a.network().name.should.equal('livenet');
|
a.network().name.should.equal('livenet');
|
||||||
|
|
||||||
if (i>1) {
|
if (i>1) {
|
||||||
w.getAddress(i-1,isChange).should
|
w.getAddress(i-1,isChange).should
|
||||||
.not.equal(w.getAddress(i-2,isChange));
|
.not.equal(w.getAddress(i-2,isChange));
|
||||||
|
|
@ -124,12 +129,26 @@ describe('PublicKeyRing model', function() {
|
||||||
|
|
||||||
var as = w.getAddresses();
|
var as = w.getAddresses();
|
||||||
as.length.should.equal(12);
|
as.length.should.equal(12);
|
||||||
for(var i in as) {
|
for(var j in as) {
|
||||||
var a = new Address(as[i]);
|
var a = new Address(as[j]);
|
||||||
a.isValid().should.equal(true);
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue