Merge pull request #664 from pinheadmz/patch-9

Wallet: better error for send() if no outputs given
This commit is contained in:
Braydon Fuller 2019-03-01 12:36:10 -08:00
commit 07f55479eb
No known key found for this signature in database
GPG Key ID: F24F232D108B3AD4
2 changed files with 17 additions and 1 deletions

View File

@ -1244,7 +1244,7 @@ class Wallet extends EventEmitter {
const mtx = new MTX();
assert(Array.isArray(outputs), 'Outputs must be an array.');
assert(outputs.length > 0, 'No outputs available.');
assert(outputs.length > 0, 'At least one output required.');
// Add the outputs
for (const obj of outputs) {

View File

@ -18,6 +18,7 @@ const Input = require('../lib/primitives/input');
const Outpoint = require('../lib/primitives/outpoint');
const Script = require('../lib/script/script');
const HD = require('../lib/hd');
const Wallet = require('../lib/wallet/wallet');
const KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt'
+ 'qUP9iWfcHgJofs25xbaUpCps9GDXj83NiWvQCAkWQhVj5J4CorfnpKX94AZ';
@ -1642,6 +1643,21 @@ describe('Wallet', function() {
});
}
it('should throw error with missing outputs', async () => {
const wallet = new Wallet({});
let err = null;
try {
await wallet.send({outputs: []});
} catch (e) {
err = e;
}
assert(err);
assert.equal(err.message, 'At least one output required.');
});
it('should cleanup', async () => {
consensus.COINBASE_MATURITY = 100;
// await wdb.close();