add AddressIndex model
This commit is contained in:
parent
88df346c51
commit
51d5d7164e
8 changed files with 104 additions and 16 deletions
84
test/test.AddressIndex.js
Normal file
84
test/test.AddressIndex.js
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Address = bitcore.Address;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var copay = copay || require('../copay');
|
||||
var PublicKeyRing = copay.PublicKeyRing;
|
||||
var AddressIndex = copay.AddressIndex;
|
||||
|
||||
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
};
|
||||
|
||||
var createAI = function () {
|
||||
var i = new AddressIndex();
|
||||
should.exist(i);
|
||||
|
||||
i.walletId = '1234567';
|
||||
|
||||
return i;
|
||||
};
|
||||
|
||||
describe('AddressIndex model', function() {
|
||||
|
||||
it('should create an instance (livenet)', function () {
|
||||
var i = new AddressIndex();
|
||||
should.exist(i);
|
||||
});
|
||||
|
||||
it('show be able to tostore and read', function () {
|
||||
var i = createAI();
|
||||
var changeN = 2;
|
||||
var addressN = 2;
|
||||
for(var j=0; j<changeN; j++) {
|
||||
i.increment(true);
|
||||
}
|
||||
for(var j=0; j<addressN; j++) {
|
||||
i.increment(false);
|
||||
}
|
||||
|
||||
var data = i.toObj();
|
||||
should.exist(data);
|
||||
|
||||
var i2 = AddressIndex.fromObj(data);
|
||||
i2.walletId.should.equal(i.walletId);
|
||||
|
||||
i2.getChangeIndex().should.equal(changeN);
|
||||
i2.getReceiveIndex().should.equal(addressN);
|
||||
});
|
||||
|
||||
it('should count generation indexes', function () {
|
||||
var j = createAI();
|
||||
for(var i=0; i<3; i++)
|
||||
j.increment(true);
|
||||
for(var i=0; i<2; i++)
|
||||
j.increment(false);
|
||||
|
||||
j.changeIndex.should.equal(3);
|
||||
j.receiveIndex.should.equal(2);
|
||||
});
|
||||
|
||||
it('#merge tests', function () {
|
||||
var j = createAI();
|
||||
|
||||
for(var i=0; i<15; i++)
|
||||
j.increment(true);
|
||||
for(var i=0; i<7; i++)
|
||||
j.increment(false);
|
||||
var j2 = new AddressIndex({
|
||||
walletId: j.walletId,
|
||||
});
|
||||
j2.merge(j).should.equal(true);
|
||||
j2.changeIndex.should.equal(15);
|
||||
j2.receiveIndex.should.equal(7);
|
||||
|
||||
j2.merge(j).should.equal(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue