100% coverage of wallet.js
This commit is contained in:
parent
4f578dd5c1
commit
b79ccb2c0c
2 changed files with 11 additions and 7 deletions
|
@ -3,7 +3,7 @@ var Transaction = require('./transaction').Transaction
|
||||||
var HDNode = require('./hdwallet.js')
|
var HDNode = require('./hdwallet.js')
|
||||||
var rng = require('secure-random')
|
var rng = require('secure-random')
|
||||||
|
|
||||||
var Wallet = function (seed, options) {
|
function Wallet(seed, options) {
|
||||||
if (!(this instanceof Wallet)) { return new Wallet(seed, options); }
|
if (!(this instanceof Wallet)) { return new Wallet(seed, options); }
|
||||||
|
|
||||||
var options = options || {}
|
var options = options || {}
|
||||||
|
@ -119,20 +119,20 @@ var Wallet = function (seed, options) {
|
||||||
function validateUnspentOutput(uo) {
|
function validateUnspentOutput(uo) {
|
||||||
var missingField
|
var missingField
|
||||||
|
|
||||||
if(isNullOrUndefined(uo.hash) && isNullOrUndefined(uo.hashLittleEndian)){
|
if (isNullOrUndefined(uo.hash) && isNullOrUndefined(uo.hashLittleEndian)) {
|
||||||
missingField = "hash(or hashLittleEndian)"
|
missingField = "hash(or hashLittleEndian)"
|
||||||
}
|
}
|
||||||
|
|
||||||
var requiredKeys = ['outputIndex', 'address', 'value']
|
var requiredKeys = ['outputIndex', 'address', 'value']
|
||||||
requiredKeys.forEach(function(key){
|
requiredKeys.forEach(function (key) {
|
||||||
if(isNullOrUndefined(uo[key])){
|
if (isNullOrUndefined(uo[key])){
|
||||||
missingField = key
|
missingField = key
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if(missingField) {
|
if (missingField) {
|
||||||
var message = [
|
var message = [
|
||||||
'Invalid unspent output: key', field, 'is missing.',
|
'Invalid unspent output: key', missingField, 'is missing.',
|
||||||
'A valid unspent output must contain'
|
'A valid unspent output must contain'
|
||||||
]
|
]
|
||||||
message.push(requiredKeys.join(', '))
|
message.push(requiredKeys.join(', '))
|
||||||
|
@ -141,7 +141,7 @@ var Wallet = function (seed, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNullOrUndefined(value){
|
function isNullOrUndefined(value) {
|
||||||
return value == undefined
|
return value == undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,10 @@ describe('Wallet', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
|
it('should be ok to call without new', function() {
|
||||||
|
assert.ok(Wallet(seed) instanceof Wallet)
|
||||||
|
})
|
||||||
|
|
||||||
it('defaults to Bitcoin mainnet', function() {
|
it('defaults to Bitcoin mainnet', function() {
|
||||||
assert.equal(wallet.getMasterKey().network, 'mainnet')
|
assert.equal(wallet.getMasterKey().network, 'mainnet')
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue