|
|
@ -16,15 +16,18 @@ describe('hd-keyring', function() { |
|
|
|
keyring = new HdKeyring() |
|
|
|
keyring = new HdKeyring() |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('constructor', function() { |
|
|
|
describe('constructor', function(done) { |
|
|
|
keyring = new HdKeyring({ |
|
|
|
keyring = new HdKeyring({ |
|
|
|
mnemonic: sampleMnemonic, |
|
|
|
mnemonic: sampleMnemonic, |
|
|
|
numberOfAccounts: 2, |
|
|
|
numberOfAccounts: 2, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const accounts = keyring.getAccounts() |
|
|
|
const accounts = keyring.getAccounts() |
|
|
|
assert.equal(accounts[0], firstAcct) |
|
|
|
.then((accounts) => { |
|
|
|
assert.equal(accounts[1], secondAcct) |
|
|
|
assert.equal(accounts[0], firstAcct) |
|
|
|
|
|
|
|
assert.equal(accounts[1], secondAcct) |
|
|
|
|
|
|
|
done() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('Keyring.type', function() { |
|
|
|
describe('Keyring.type', function() { |
|
|
@ -44,49 +47,62 @@ describe('hd-keyring', function() { |
|
|
|
|
|
|
|
|
|
|
|
describe('#serialize empty wallets.', function() { |
|
|
|
describe('#serialize empty wallets.', function() { |
|
|
|
it('serializes a new mnemonic', function() { |
|
|
|
it('serializes a new mnemonic', function() { |
|
|
|
const output = keyring.serialize() |
|
|
|
keyring.serialize() |
|
|
|
assert.equal(output.numberOfAccounts, 0) |
|
|
|
.then((output) => { |
|
|
|
assert.equal(output.mnemonic, null) |
|
|
|
assert.equal(output.numberOfAccounts, 0) |
|
|
|
|
|
|
|
assert.equal(output.mnemonic, null) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('#deserialize a private key', function() { |
|
|
|
describe('#deserialize a private key', function() { |
|
|
|
it('serializes what it deserializes', function() { |
|
|
|
it('serializes what it deserializes', function(done) { |
|
|
|
keyring.deserialize({ |
|
|
|
keyring.deserialize({ |
|
|
|
mnemonic: sampleMnemonic, |
|
|
|
mnemonic: sampleMnemonic, |
|
|
|
numberOfAccounts: 1 |
|
|
|
numberOfAccounts: 1 |
|
|
|
}) |
|
|
|
}) |
|
|
|
assert.equal(keyring.wallets.length, 1, 'restores two accounts') |
|
|
|
.then(() => { |
|
|
|
keyring.addAccounts(1) |
|
|
|
assert.equal(keyring.wallets.length, 1, 'restores two accounts') |
|
|
|
|
|
|
|
keyring.addAccounts(1) |
|
|
|
const accounts = keyring.getAccounts() |
|
|
|
|
|
|
|
assert.equal(accounts[0], firstAcct) |
|
|
|
const accounts = keyring.getAccounts() |
|
|
|
assert.equal(accounts[1], secondAcct) |
|
|
|
assert.equal(accounts[0], firstAcct) |
|
|
|
assert.equal(accounts.length, 2) |
|
|
|
assert.equal(accounts[1], secondAcct) |
|
|
|
|
|
|
|
assert.equal(accounts.length, 2) |
|
|
|
const serialized = keyring.serialize() |
|
|
|
|
|
|
|
assert.equal(serialized.mnemonic, sampleMnemonic) |
|
|
|
keyring.serialize() |
|
|
|
|
|
|
|
.then((serialized) => { |
|
|
|
|
|
|
|
assert.equal(serialized.mnemonic, sampleMnemonic) |
|
|
|
|
|
|
|
done() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('#addAccounts', function() { |
|
|
|
describe('#addAccounts', function() { |
|
|
|
describe('with no arguments', function() { |
|
|
|
describe('with no arguments', function() { |
|
|
|
it('creates a single wallet', function() { |
|
|
|
it('creates a single wallet', function(done) { |
|
|
|
keyring.addAccounts() |
|
|
|
keyring.addAccounts() |
|
|
|
assert.equal(keyring.wallets.length, 1) |
|
|
|
.then(() => { |
|
|
|
|
|
|
|
assert.equal(keyring.wallets.length, 1) |
|
|
|
|
|
|
|
done() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('with a numeric argument', function() { |
|
|
|
describe('with a numeric argument', function() { |
|
|
|
it('creates that number of wallets', function() { |
|
|
|
it('creates that number of wallets', function(done) { |
|
|
|
keyring.addAccounts(3) |
|
|
|
keyring.addAccounts(3) |
|
|
|
assert.equal(keyring.wallets.length, 3) |
|
|
|
.then(() => { |
|
|
|
|
|
|
|
assert.equal(keyring.wallets.length, 3) |
|
|
|
|
|
|
|
done() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('#getAccounts', function() { |
|
|
|
describe('#getAccounts', function() { |
|
|
|
it('calls getAddress on each wallet', function() { |
|
|
|
it('calls getAddress on each wallet', function(done) { |
|
|
|
|
|
|
|
|
|
|
|
// Push a mock wallet
|
|
|
|
// Push a mock wallet
|
|
|
|
const desiredOutput = 'foo' |
|
|
|
const desiredOutput = 'foo' |
|
|
@ -101,8 +117,11 @@ describe('hd-keyring', function() { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const output = keyring.getAccounts() |
|
|
|
const output = keyring.getAccounts() |
|
|
|
assert.equal(output[0], desiredOutput) |
|
|
|
.then((output) => { |
|
|
|
assert.equal(output.length, 1) |
|
|
|
assert.equal(output[0], desiredOutput) |
|
|
|
|
|
|
|
assert.equal(output.length, 1) |
|
|
|
|
|
|
|
done() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|