minor fix and tests
This commit is contained in:
parent
6a0d5ce89a
commit
7dcc8f8b34
2 changed files with 42 additions and 2 deletions
|
|
@ -12,7 +12,7 @@ function Structure() {
|
||||||
* m / purpose' / cosigner_index / change / address_index
|
* m / purpose' / cosigner_index / change / address_index
|
||||||
*/
|
*/
|
||||||
var PURPOSE = 45;
|
var PURPOSE = 45;
|
||||||
var MAX_NON_HARDENED = 0x8000000 - 1;
|
var MAX_NON_HARDENED = 0x80000000 - 1;
|
||||||
|
|
||||||
var SHARED_INDEX = MAX_NON_HARDENED - 0;
|
var SHARED_INDEX = MAX_NON_HARDENED - 0;
|
||||||
var ID_INDEX = MAX_NON_HARDENED - 1;
|
var ID_INDEX = MAX_NON_HARDENED - 1;
|
||||||
|
|
@ -35,6 +35,9 @@ Structure.FullBranch = function(address_index, isChange, cosigner_index) {
|
||||||
};
|
};
|
||||||
Structure.IdFullBranch = Structure.FullBranch(0, 0, ID_INDEX);
|
Structure.IdFullBranch = Structure.FullBranch(0, 0, ID_INDEX);
|
||||||
Structure.IdBranch = Structure.Branch(0, 0, ID_INDEX);
|
Structure.IdBranch = Structure.Branch(0, 0, ID_INDEX);
|
||||||
|
Structure.PURPOSE = PURPOSE;
|
||||||
|
Structure.MAX_NON_HARDENED = MAX_NON_HARDENED;
|
||||||
|
Structure.SHARED_INDEX = SHARED_INDEX;
|
||||||
|
Structure.ID_INDEX = ID_INDEX;
|
||||||
|
|
||||||
module.exports = require('soop')(Structure);
|
module.exports = require('soop')(Structure);
|
||||||
|
|
|
||||||
37
test/test.Structure.js
Normal file
37
test/test.Structure.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var chai = chai || require('chai');
|
||||||
|
var should = chai.should();
|
||||||
|
var bitcore = bitcore || require('bitcore');
|
||||||
|
var copay = copay || require('../copay');
|
||||||
|
var Structure = require('../js/models/core/Structure');
|
||||||
|
|
||||||
|
describe('Structure 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');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get the correct branches', function () {
|
||||||
|
// shared branch (no cosigner index specified)
|
||||||
|
Structure.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');
|
||||||
|
|
||||||
|
// copayer 0, address 10, external address (receiving)
|
||||||
|
Structure.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');
|
||||||
|
|
||||||
|
// copayer 0, address 10, internal address (change)
|
||||||
|
Structure.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');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue