100% coverage of wallet.js

This commit is contained in:
lms 2014-04-01 21:03:41 +02:00
parent 4f578dd5c1
commit b79ccb2c0c
2 changed files with 11 additions and 7 deletions

View file

@ -3,7 +3,7 @@ var Transaction = require('./transaction').Transaction
var HDNode = require('./hdwallet.js')
var rng = require('secure-random')
var Wallet = function (seed, options) {
function Wallet(seed, options) {
if (!(this instanceof Wallet)) { return new Wallet(seed, options); }
var options = options || {}
@ -119,20 +119,20 @@ var Wallet = function (seed, options) {
function validateUnspentOutput(uo) {
var missingField
if(isNullOrUndefined(uo.hash) && isNullOrUndefined(uo.hashLittleEndian)){
if (isNullOrUndefined(uo.hash) && isNullOrUndefined(uo.hashLittleEndian)) {
missingField = "hash(or hashLittleEndian)"
}
var requiredKeys = ['outputIndex', 'address', 'value']
requiredKeys.forEach(function(key){
if(isNullOrUndefined(uo[key])){
requiredKeys.forEach(function (key) {
if (isNullOrUndefined(uo[key])){
missingField = key
}
})
if(missingField) {
if (missingField) {
var message = [
'Invalid unspent output: key', field, 'is missing.',
'Invalid unspent output: key', missingField, 'is missing.',
'A valid unspent output must contain'
]
message.push(requiredKeys.join(', '))
@ -141,7 +141,7 @@ var Wallet = function (seed, options) {
}
}
function isNullOrUndefined(value){
function isNullOrUndefined(value) {
return value == undefined
}

View file

@ -22,6 +22,10 @@ describe('Wallet', 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() {
assert.equal(wallet.getMasterKey().network, 'mainnet')
})