2017-10-19 04:28:45 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
|
2018-03-05 03:31:09 +03:00
|
|
|
if (global.ethers) {
|
|
|
|
console.log('Using global ethers; ' + __filename);
|
|
|
|
var ethers = global.ethers;
|
|
|
|
} else {
|
|
|
|
var ethers = require('..');
|
|
|
|
}
|
|
|
|
|
2017-10-19 04:28:45 +03:00
|
|
|
var utils = require('./utils');
|
|
|
|
|
|
|
|
describe('Test HD Node Derivation', function(test) {
|
|
|
|
|
|
|
|
var tests = utils.loadTests('hdnode');
|
|
|
|
tests.forEach(function(test) {
|
|
|
|
it('Derives the HD nodes - ' + test.name, function() {
|
2017-10-23 00:47:17 +03:00
|
|
|
this.timeout(10000);
|
|
|
|
|
2018-03-05 03:31:09 +03:00
|
|
|
var rootNode = new ethers.HDNode.fromSeed(test.seed);
|
2017-10-19 04:28:45 +03:00
|
|
|
test.hdnodes.forEach(function(nodeTest) {
|
|
|
|
|
|
|
|
var node = rootNode.derivePath(nodeTest.path);
|
|
|
|
assert.equal(node.privateKey, nodeTest.privateKey,
|
|
|
|
'Generates privateKey - ' + nodeTest.privateKey);
|
|
|
|
|
2018-03-05 03:31:09 +03:00
|
|
|
var wallet = new ethers.Wallet(node.privateKey);
|
2017-10-19 04:28:45 +03:00
|
|
|
assert.equal(wallet.address.toLowerCase(), nodeTest.address,
|
|
|
|
'Generates address - ' + nodeTest.privateKey);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Test HD Mnemonic Phrases', function testMnemonic() {
|
|
|
|
var tests = utils.loadTests('hdnode');
|
|
|
|
tests.forEach(function(test) {
|
|
|
|
it(('converts mnemonic phrases - ' + test.name), function() {
|
2017-10-23 00:47:17 +03:00
|
|
|
this.timeout(1000000);
|
|
|
|
|
2018-03-05 03:31:09 +03:00
|
|
|
assert.equal(ethers.HDNode.entropyToMnemonic(test.entropy), test.mnemonic,
|
2017-10-19 04:28:45 +03:00
|
|
|
'Converts entropy to mnemonic ' + test.name);
|
2018-03-05 03:31:09 +03:00
|
|
|
assert.equal(ethers.HDNode.mnemonicToEntropy(test.mnemonic), test.entropy,
|
2017-10-19 04:28:45 +03:00
|
|
|
'Converts mnemonic to entropy - ' + test.mnemonic);
|
2018-03-05 03:31:09 +03:00
|
|
|
assert.equal(ethers.HDNode.mnemonicToSeed(test.mnemonic, test.password), test.seed,
|
2017-10-19 04:28:45 +03:00
|
|
|
'Converts mnemonic to seed - ' + test.mnemonic + ':' + test.password);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|