copay/test/test.HDPath.js

80 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-05-30 06:29:51 -07:00
'use strict';
var chai = chai || require('chai');
var should = chai.should();
var bitcore = bitcore || require('bitcore');
try {
var copay = require('copay'); //browser
} catch (e) {
var copay = require('../copay'); //node
}
2014-07-29 07:23:58 -07:00
var HDPath = require('../js/models/core/HDPath');
2014-05-30 06:29:51 -07:00
2014-07-29 07:23:58 -07:00
describe('HDPath model', function() {
it('should have the correct constants', function() {
2014-07-29 07:23:58 -07:00
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');
2014-05-30 06:29:51 -07:00
});
it('should get the correct branches', function() {
2014-05-30 06:29:51 -07:00
// shared branch (no cosigner index specified)
2014-07-29 07:23:58 -07:00
HDPath.FullBranch(0, false).should.equal('m/45\'/2147483647/0/0');
2014-05-30 06:29:51 -07:00
// copayer 0, address 0, external address (receiving)
2014-07-29 07:23:58 -07:00
HDPath.FullBranch(0, false, 0).should.equal('m/45\'/0/0/0');
2014-05-30 06:29:51 -07:00
// copayer 0, address 10, external address (receiving)
2014-07-29 07:23:58 -07:00
HDPath.FullBranch(0, false, 10).should.equal('m/45\'/10/0/0');
2014-05-30 06:29:51 -07:00
// copayer 0, address 0, internal address (change)
2014-07-29 07:23:58 -07:00
HDPath.FullBranch(0, true, 0).should.equal('m/45\'/0/1/0');
2014-05-30 06:29:51 -07:00
// copayer 0, address 10, internal address (change)
2014-07-29 07:23:58 -07:00
HDPath.FullBranch(10, true, 0).should.equal('m/45\'/0/1/10');
2014-05-30 06:29:51 -07:00
// copayer 7, address 10, internal address (change)
2014-07-29 07:23:58 -07:00
HDPath.FullBranch(10, true, 7).should.equal('m/45\'/7/1/10');
2014-05-30 06:29:51 -07:00
});
2014-06-24 13:08:38 -07:00
[
2014-07-03 09:13:45 -07:00
['m/45\'/0/0/0', {
2014-07-29 07:23:58 -07:00
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
}],
2014-06-24 13:08:38 -07:00
].forEach(function(datum) {
var path = datum[0];
var result = datum[1];
2014-07-30 17:20:08 -07:00
it('should get the correct indexes for path ' + path, function() {
var i = HDPath.indexesForPath(path);
i.addressIndex.should.equal(result.index);
2014-06-24 13:08:38 -07:00
i.isChange.should.equal(result.isChange);
});
});
2014-05-30 06:29:51 -07:00
});