change names to HD and fix HD* tests
This commit is contained in:
parent
1a40e29fd2
commit
0ee93403f3
10 changed files with 272 additions and 269 deletions
|
|
@ -11,8 +11,8 @@ try {
|
|||
var copay = require('../copay'); //node
|
||||
}
|
||||
var PublicKeyRing = copay.PublicKeyRing;
|
||||
var AddressIndex = copay.AddressIndex;
|
||||
var Structure = copay.Structure;
|
||||
var HDParams = copay.HDParams;
|
||||
var HDPath = copay.HDPath;
|
||||
|
||||
|
||||
var config = {
|
||||
|
|
@ -20,42 +20,42 @@ var config = {
|
|||
};
|
||||
|
||||
var createAI = function() {
|
||||
var i = new AddressIndex();
|
||||
var i = new HDParams();
|
||||
should.exist(i);
|
||||
|
||||
i.cosigner = 1;
|
||||
i.copayerIndex = 1;
|
||||
|
||||
return i;
|
||||
};
|
||||
|
||||
describe('AddressIndex model', function() {
|
||||
describe('HDParams model', function() {
|
||||
|
||||
it('should create an instance (livenet)', function() {
|
||||
var i = new AddressIndex();
|
||||
var i = new HDParams();
|
||||
should.exist(i);
|
||||
});
|
||||
|
||||
it('should init indexes', function() {
|
||||
var is = AddressIndex.init(2);
|
||||
var is = HDParams.init(2);
|
||||
should.exist(is);
|
||||
is.length.should.equal(3);
|
||||
|
||||
var cosigners = is.map(function(i) { return i.cosigner; });
|
||||
cosigners.indexOf(Structure.SHARED_INDEX).should.not.equal(-1);
|
||||
var cosigners = is.map(function(i) { return i.copayerIndex; });
|
||||
cosigners.indexOf(HDPath.SHARED_INDEX).should.not.equal(-1);
|
||||
cosigners.indexOf(0).should.not.equal(-1);
|
||||
cosigners.indexOf(1).should.not.equal(-1);
|
||||
cosigners.indexOf(2).should.equal(-1);
|
||||
});
|
||||
|
||||
it('should serialize to object list and back', function() {
|
||||
var is = AddressIndex.init(3);
|
||||
var is = HDParams.init(3);
|
||||
should.exist(is);
|
||||
is.length.should.equal(4);
|
||||
|
||||
var list = AddressIndex.serialize(is);
|
||||
var list = HDParams.serialize(is);
|
||||
list.length.should.equal(4);
|
||||
|
||||
var is2 = AddressIndex.fromList(list);
|
||||
var is2 = HDParams.fromList(list);
|
||||
is2.length.should.equal(4);
|
||||
});
|
||||
|
||||
|
|
@ -73,8 +73,8 @@ describe('AddressIndex model', function() {
|
|||
var data = i.toObj();
|
||||
should.exist(data);
|
||||
|
||||
var i2 = AddressIndex.fromObj(data);
|
||||
i2.cosigner.should.equal(i.cosigner);
|
||||
var i2 = HDParams.fromObj(data);
|
||||
i2.copayerIndex.should.equal(i.copayerIndex);
|
||||
|
||||
i2.getChangeIndex().should.equal(changeN);
|
||||
i2.getReceiveIndex().should.equal(addressN);
|
||||
|
|
@ -83,9 +83,9 @@ describe('AddressIndex model', function() {
|
|||
it('should count generation indexes', function() {
|
||||
var j = createAI();
|
||||
for (var i = 0; i < 3; i++)
|
||||
j.increment(true);
|
||||
j.increment(true);
|
||||
for (var i = 0; i < 2; i++)
|
||||
j.increment(false);
|
||||
j.increment(false);
|
||||
|
||||
j.changeIndex.should.equal(3);
|
||||
j.receiveIndex.should.equal(2);
|
||||
|
|
@ -95,11 +95,11 @@ describe('AddressIndex model', function() {
|
|||
var j = createAI();
|
||||
|
||||
for (var i = 0; i < 15; i++)
|
||||
j.increment(true);
|
||||
j.increment(true);
|
||||
for (var i = 0; i < 7; i++)
|
||||
j.increment(false);
|
||||
var j2 = new AddressIndex({
|
||||
cosigner: j.cosigner,
|
||||
j.increment(false);
|
||||
var j2 = new HDParams({
|
||||
copayerIndex: j.copayerIndex,
|
||||
});
|
||||
j2.merge(j).should.equal(true);
|
||||
j2.changeIndex.should.equal(15);
|
||||
|
|
@ -108,9 +108,9 @@ describe('AddressIndex model', function() {
|
|||
j2.merge(j).should.equal(false);
|
||||
});
|
||||
|
||||
it('#merge should fail with different cosigner index', function() {
|
||||
var j1 = new AddressIndex({ walletId: '1234', cosigner: 2 });
|
||||
var j2 = new AddressIndex({ walletId: '1234', cosigner: 3 });
|
||||
it('#merge should fail with different copayerIndex index', function() {
|
||||
var j1 = new HDParams({ walletId: '1234', copayerIndex: 2 });
|
||||
var j2 = new HDParams({ walletId: '1234', copayerIndex: 3 });
|
||||
|
||||
var merge = function() { j2.merge(j1); };
|
||||
merge.should.throw(Error);
|
||||
|
|
@ -8,77 +8,77 @@ try {
|
|||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var Structure = require('../js/models/core/Structure');
|
||||
var HDPath = require('../js/models/core/HDPath');
|
||||
|
||||
describe('Structure model', function() {
|
||||
describe('HDPath model', function() {
|
||||
it('should have the correct constants', function() {
|
||||
Structure.MAX_NON_HARDENED.should.equal(Math.pow(2, 31) - 1);
|
||||
Structure.SHARED_INDEX.should.equal(Structure.MAX_NON_HARDENED);
|
||||
Structure.ID_INDEX.should.equal(Structure.SHARED_INDEX - 1);
|
||||
Structure.IdFullBranch.should.equal('m/45\'/2147483646/0/0');
|
||||
HDPath.MAX_NON_HARDENED.should.equal(Math.pow(2, 31) - 1);
|
||||
HDPath.SHARED_INDEX.should.equal(HDPath.MAX_NON_HARDENED);
|
||||
HDPath.ID_INDEX.should.equal(HDPath.SHARED_INDEX - 1);
|
||||
HDPath.IdFullBranch.should.equal('m/45\'/2147483646/0/0');
|
||||
});
|
||||
|
||||
it('should get the correct branches', function() {
|
||||
// shared branch (no cosigner index specified)
|
||||
Structure.FullBranch(0, false).should.equal('m/45\'/2147483647/0/0');
|
||||
HDPath.FullBranch(0, false).should.equal('m/45\'/2147483647/0/0');
|
||||
|
||||
// copayer 0, address 0, external address (receiving)
|
||||
Structure.FullBranch(0, false, 0).should.equal('m/45\'/0/0/0');
|
||||
HDPath.FullBranch(0, false, 0).should.equal('m/45\'/0/0/0');
|
||||
|
||||
// copayer 0, address 10, external address (receiving)
|
||||
Structure.FullBranch(0, false, 10).should.equal('m/45\'/10/0/0');
|
||||
HDPath.FullBranch(0, false, 10).should.equal('m/45\'/10/0/0');
|
||||
|
||||
// copayer 0, address 0, internal address (change)
|
||||
Structure.FullBranch(0, true, 0).should.equal('m/45\'/0/1/0');
|
||||
HDPath.FullBranch(0, true, 0).should.equal('m/45\'/0/1/0');
|
||||
|
||||
// copayer 0, address 10, internal address (change)
|
||||
Structure.FullBranch(10, true, 0).should.equal('m/45\'/0/1/10');
|
||||
HDPath.FullBranch(10, true, 0).should.equal('m/45\'/0/1/10');
|
||||
|
||||
// copayer 7, address 10, internal address (change)
|
||||
Structure.FullBranch(10, true, 7).should.equal('m/45\'/7/1/10');
|
||||
HDPath.FullBranch(10, true, 7).should.equal('m/45\'/7/1/10');
|
||||
});
|
||||
|
||||
[
|
||||
['m/45\'/0/0/0', {
|
||||
index: 0,
|
||||
isChange: false
|
||||
}],
|
||||
['m/45\'/0/0/1', {
|
||||
index: 1,
|
||||
isChange: false
|
||||
}],
|
||||
['m/45\'/0/0/2', {
|
||||
index: 2,
|
||||
isChange: false
|
||||
}],
|
||||
['m/45\'/0/1/0', {
|
||||
index: 0,
|
||||
isChange: true
|
||||
}],
|
||||
['m/45\'/0/1/1', {
|
||||
index: 1,
|
||||
isChange: true
|
||||
}],
|
||||
['m/45\'/0/1/2', {
|
||||
index: 2,
|
||||
isChange: true
|
||||
}],
|
||||
['m/45\'/0/0/900', {
|
||||
index: 900,
|
||||
isChange: false
|
||||
}],
|
||||
index: 0,
|
||||
isChange: false
|
||||
}],
|
||||
['m/45\'/0/0/1', {
|
||||
index: 1,
|
||||
isChange: false
|
||||
}],
|
||||
['m/45\'/0/0/2', {
|
||||
index: 2,
|
||||
isChange: false
|
||||
}],
|
||||
['m/45\'/0/1/0', {
|
||||
index: 0,
|
||||
isChange: true
|
||||
}],
|
||||
['m/45\'/0/1/1', {
|
||||
index: 1,
|
||||
isChange: true
|
||||
}],
|
||||
['m/45\'/0/1/2', {
|
||||
index: 2,
|
||||
isChange: true
|
||||
}],
|
||||
['m/45\'/0/0/900', {
|
||||
index: 900,
|
||||
isChange: false
|
||||
}],
|
||||
].forEach(function(datum) {
|
||||
var path = datum[0];
|
||||
var result = datum[1];
|
||||
it('should get the correct indices for path ' + path, function() {
|
||||
var i = Structure.indicesForPath(path);
|
||||
var i = HDPath.indicesForPath(path);
|
||||
i.index.should.equal(result.index);
|
||||
i.isChange.should.equal(result.isChange);
|
||||
});
|
||||
});
|
||||
it('should get the correct result for bitcoin uri', function() {
|
||||
var uri = 'bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8%3Famount=0.1&message=a%20bitcoin%20donation';
|
||||
var result = Structure.parseBitcoinURI(uri);
|
||||
var result = HDPath.parseBitcoinURI(uri);
|
||||
result.address.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8');
|
||||
result.amount.should.equal(0.1);
|
||||
result.message.should.equal('a bitcoin donation');
|
||||
|
|
@ -6,7 +6,7 @@ var bitcore = bitcore || require('bitcore');
|
|||
var Address = bitcore.Address;
|
||||
var buffertools = bitcore.buffertools;
|
||||
|
||||
var Structure = require('../js/models/core/Structure');
|
||||
var HDPath = require('../js/models/core/HDPath');
|
||||
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
|
|
@ -135,7 +135,7 @@ describe('PublicKeyRing model', function() {
|
|||
a.network().name.should.equal('livenet');
|
||||
if (i > 1) {
|
||||
w.getAddress(i - 1, isChange).toString().should
|
||||
.not.equal(w.getAddress(i - 2, isChange).toString());
|
||||
.not.equal(w.getAddress(i - 2, isChange).toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -170,9 +170,9 @@ describe('PublicKeyRing model', function() {
|
|||
var w = k.w;
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
w.generateAddress(true, k.pub);
|
||||
w.generateAddress(true, k.pub);
|
||||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(false, k.pub);
|
||||
w.generateAddress(false, k.pub);
|
||||
|
||||
w.getIndex(k.pub).getChangeIndex().should.equal(3);
|
||||
w.getIndex(k.pub).getReceiveIndex().should.equal(2);
|
||||
|
|
@ -240,9 +240,9 @@ describe('PublicKeyRing model', function() {
|
|||
var w = k.w;
|
||||
|
||||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(true, k.pub);
|
||||
w.generateAddress(true, k.pub);
|
||||
for (var i = 0; i < 3; i++)
|
||||
w.generateAddress(false, k.pub);
|
||||
w.generateAddress(false, k.pub);
|
||||
|
||||
var w2 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
|
|
@ -445,9 +445,9 @@ describe('PublicKeyRing model', function() {
|
|||
networkName: 'livenet',
|
||||
};
|
||||
var p = new PublicKeyRing(config);
|
||||
var i = p.getIndex(Structure.SHARED_INDEX);
|
||||
var i = p.getIndex(HDPath.SHARED_INDEX);
|
||||
should.exist(i);
|
||||
i.cosigner.should.equal(Structure.SHARED_INDEX);
|
||||
i.copayerIndex.should.equal(HDPath.SHARED_INDEX);
|
||||
});
|
||||
|
||||
it('#getIndex should throw error', function() {
|
||||
|
|
@ -467,9 +467,9 @@ describe('PublicKeyRing model', function() {
|
|||
var amount = 2;
|
||||
|
||||
for (var i = 0; i < amount; i++)
|
||||
w.generateAddress(true, k.pub);
|
||||
w.generateAddress(true, k.pub);
|
||||
for (var i = 0; i < amount; i++)
|
||||
w.generateAddress(false, k.pub);
|
||||
w.generateAddress(false, k.pub);
|
||||
|
||||
var m = w.getRedeemScriptMap([
|
||||
'm/45\'/2147483647/1/0',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue