Skip to content

Commit

Permalink
withdraw: fix incorrect error when we have an empty wallet.
Browse files Browse the repository at this point in the history
This also highlights the danger of searching the logs: that error
appeared previously in the logs, so we didn't notice that the actual
withdraw call gave a different error.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 19, 2018
1 parent f583e6b commit 71a40fa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ changes.
- JSON RPC: `getroute` `fuzzpercent` and `pay` `maxfeepercent` can now be > 100.
- JSON RPC: `riskfactor` in `pay` and `getroute` no longer always treated as 1.
- JSON-RPC: `listpeers` was always reporting 0 for all stats.
- JSON RPC: `withdraw all` says `Cannot afford transaction` if you have
absolutely no funds, rather than `Output 0 satoshis would be dust`.
- Protocol: don't send gossip about closed channels.
- Protocol: fix occasional deadlock when both peers flood with gossip.
- Protocol: fix occasional long delay on sending `reply_short_channel_ids_end`.
Expand Down
2 changes: 1 addition & 1 deletion common/wallet_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void wtx_init(struct command *cmd, struct wallet_tx * wtx)

static bool check_amount(const struct wallet_tx *tx, u64 amount)
{
if (!tx->utxos) {
if (tal_count(tx->utxos) == 0) {
command_fail(tx->cmd, FUND_CANNOT_AFFORD,
"Cannot afford transaction");
return false;
Expand Down
5 changes: 3 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ def test_withdraw(node_factory, bitcoind):
l1.rpc.withdraw(waddr, 'not an amount')
with pytest.raises(RpcError):
l1.rpc.withdraw(waddr, -amount)
with pytest.raises(RpcError, match=r'Cannot afford transaction'):
l1.rpc.withdraw(waddr, amount * 100)

out = l1.rpc.withdraw(waddr, 2 * amount)

Expand Down Expand Up @@ -462,9 +464,8 @@ def test_withdraw(node_factory, bitcoind):
assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 0

# This should fail, can't even afford fee.
with pytest.raises(RpcError):
with pytest.raises(RpcError, match=r'Cannot afford transaction'):
l1.rpc.withdraw(waddr, 'all')
l1.daemon.wait_for_log('Cannot afford transaction')


def test_addfunds_from_block(node_factory, bitcoind):
Expand Down

0 comments on commit 71a40fa

Please sign in to comment.