2014-02-27 04:54:54 +01:00
|
|
|
var Wallet = require('../src/wallet.js')
|
2014-03-11 16:42:01 +01:00
|
|
|
var HDNode = require('../src/hdwallet.js')
|
|
|
|
var convert = require('../src/convert.js')
|
2014-02-27 04:54:54 +01:00
|
|
|
var assert = require('assert')
|
2014-03-11 16:42:01 +01:00
|
|
|
var SHA256 = require('crypto-js/sha256')
|
|
|
|
var Crypto = require('crypto-js')
|
2014-02-27 04:54:54 +01:00
|
|
|
|
|
|
|
describe('Wallet', function() {
|
2014-03-11 16:42:01 +01:00
|
|
|
var seed;
|
|
|
|
beforeEach(function(){
|
|
|
|
seed = convert.wordArrayToBytes(SHA256("don't use a string seed like this in real life"))
|
|
|
|
})
|
2014-02-27 04:54:54 +01:00
|
|
|
|
2014-03-11 16:42:01 +01:00
|
|
|
describe('constructor', function() {
|
2014-02-27 04:54:54 +01:00
|
|
|
var wallet;
|
|
|
|
beforeEach(function() {
|
|
|
|
wallet = new Wallet(seed)
|
|
|
|
})
|
|
|
|
|
2014-02-28 07:27:31 +01:00
|
|
|
it('defaults to Bitcoin mainnet', function() {
|
2014-02-28 09:57:44 +01:00
|
|
|
assert.equal(wallet.getMasterKey().network, 'mainnet')
|
2014-02-27 04:54:54 +01:00
|
|
|
})
|
|
|
|
|
2014-03-11 16:42:01 +01:00
|
|
|
it("generates m/0' as the main account", function() {
|
|
|
|
var mainAccount = wallet.accountZero
|
|
|
|
assert.equal(mainAccount.index, 0 + HDNode.HIGHEST_BIT)
|
|
|
|
assert.equal(mainAccount.depth, 1)
|
2014-02-27 04:54:54 +01:00
|
|
|
})
|
|
|
|
|
2014-03-11 16:42:01 +01:00
|
|
|
it("generates m/0'/0 as the external account", function() {
|
|
|
|
var account = wallet.externalAccount
|
|
|
|
assert.equal(account.index, 0)
|
|
|
|
assert.equal(account.depth, 2)
|
2014-02-27 04:54:54 +01:00
|
|
|
})
|
|
|
|
|
2014-03-11 16:42:01 +01:00
|
|
|
it("generates m/0'/1 as the internal account", function() {
|
|
|
|
var account = wallet.internalAccount
|
|
|
|
assert.equal(account.index, 1)
|
|
|
|
assert.equal(account.depth, 2)
|
2014-02-27 04:54:54 +01:00
|
|
|
})
|
|
|
|
|
2014-03-11 16:42:01 +01:00
|
|
|
describe('constructor options', function() {
|
|
|
|
var wallet;
|
|
|
|
beforeEach(function() {
|
|
|
|
wallet = new Wallet(seed, {network: 'testnet'})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('uses the network if specified', function() {
|
|
|
|
assert.equal(wallet.getMasterKey().network, 'testnet')
|
|
|
|
})
|
2014-02-27 04:54:54 +01:00
|
|
|
})
|
|
|
|
})
|
2014-02-28 05:05:48 +01:00
|
|
|
|
2014-03-11 16:42:01 +01:00
|
|
|
describe('generateAddress', function(){
|
|
|
|
var wallet;
|
|
|
|
beforeEach(function() { wallet = new Wallet(seed, {network: 'testnet'}) })
|
|
|
|
|
|
|
|
it('defaults to generating receiving addresses', function(){
|
|
|
|
assert.equal(wallet.generateAddress(), "n1GyUANZand9Kw6hGSV9837cCC9FFUQzQa")
|
|
|
|
assert.equal(wallet.generateAddress(), "n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X")
|
|
|
|
})
|
|
|
|
})
|
2014-02-27 04:54:54 +01:00
|
|
|
})
|