|
|
@ -1,5 +1,6 @@ |
|
|
|
var assert = require('assert') |
|
|
|
var crypto = require('../src/crypto') |
|
|
|
var networks = require('../src/networks') |
|
|
|
var sinon = require('sinon') |
|
|
|
|
|
|
|
var Address = require('../src/address') |
|
|
@ -29,7 +30,7 @@ describe('Wallet', function() { |
|
|
|
}) |
|
|
|
|
|
|
|
it('defaults to Bitcoin network', function() { |
|
|
|
assert.equal(wallet.getMasterKey().network, 'bitcoin') |
|
|
|
assert.equal(wallet.getMasterKey().network, networks.bitcoin) |
|
|
|
}) |
|
|
|
|
|
|
|
it("generates m/0' as the main account", function() { |
|
|
@ -59,11 +60,11 @@ describe('Wallet', function() { |
|
|
|
|
|
|
|
describe('constructor options', function() { |
|
|
|
beforeEach(function() { |
|
|
|
wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
wallet = new Wallet(seed, networks.testnet) |
|
|
|
}) |
|
|
|
|
|
|
|
it('uses the network if specified', function() { |
|
|
|
assert.equal(wallet.getMasterKey().network, 'testnet') |
|
|
|
assert.equal(wallet.getMasterKey().network, networks.testnet) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -98,7 +99,7 @@ describe('Wallet', function() { |
|
|
|
|
|
|
|
describe('generateAddress', function(){ |
|
|
|
it('generate receiving addresses', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
var expectedAddresses = [ |
|
|
|
"n1GyUANZand9Kw6hGSV9837cCC9FFUQzQa", |
|
|
|
"n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X" |
|
|
@ -112,7 +113,7 @@ describe('Wallet', function() { |
|
|
|
|
|
|
|
describe('generateChangeAddress', function(){ |
|
|
|
it('generates change addresses', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
var expectedAddresses = ["mnXiDR4MKsFxcKJEZjx4353oXvo55iuptn"] |
|
|
|
|
|
|
|
assert.equal(wallet.generateChangeAddress(), expectedAddresses[0]) |
|
|
@ -122,7 +123,7 @@ describe('Wallet', function() { |
|
|
|
|
|
|
|
describe('getPrivateKey', function(){ |
|
|
|
it('returns the private key at the given index of external account', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
|
|
|
|
assertEqual(wallet.getPrivateKey(0), wallet.getExternalAccount().derive(0).priv) |
|
|
|
assertEqual(wallet.getPrivateKey(1), wallet.getExternalAccount().derive(1).priv) |
|
|
@ -131,7 +132,7 @@ describe('Wallet', function() { |
|
|
|
|
|
|
|
describe('getInternalPrivateKey', function(){ |
|
|
|
it('returns the private key at the given index of internal account', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
|
|
|
|
assertEqual(wallet.getInternalPrivateKey(0), wallet.getInternalAccount().derive(0).priv) |
|
|
|
assertEqual(wallet.getInternalPrivateKey(1), wallet.getInternalAccount().derive(1).priv) |
|
|
@ -140,7 +141,7 @@ describe('Wallet', function() { |
|
|
|
|
|
|
|
describe('getPrivateKeyForAddress', function(){ |
|
|
|
it('returns the private key for the given address', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
wallet.generateChangeAddress() |
|
|
|
wallet.generateAddress() |
|
|
|
wallet.generateAddress() |
|
|
@ -156,7 +157,7 @@ describe('Wallet', function() { |
|
|
|
}) |
|
|
|
|
|
|
|
it('raises an error when address is not found', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
assert.throws(function() { |
|
|
|
wallet.getPrivateKeyForAddress("n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X") |
|
|
|
}, /Unknown address. Make sure the address is from the keychain and has been generated./) |
|
|
@ -434,9 +435,9 @@ describe('Wallet', function() { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('testnet', function(){ |
|
|
|
describe(networks.testnet, function(){ |
|
|
|
it('should create transaction', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
var address = wallet.generateAddress() |
|
|
|
|
|
|
|
wallet.setUnspentOutputs([{ |
|
|
@ -458,7 +459,7 @@ describe('Wallet', function() { |
|
|
|
|
|
|
|
describe('changeAddress', function(){ |
|
|
|
it('should allow custom changeAddress', function(){ |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var wallet = new Wallet(seed, networks.testnet) |
|
|
|
var address = wallet.generateAddress() |
|
|
|
|
|
|
|
wallet.setUnspentOutputs([{ |
|
|
|