diff --git a/lightningd/pay.c b/lightningd/pay.c index da17474b40c3..e69ca6ec2aa8 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -1525,13 +1525,13 @@ static struct command_result *json_listsendpays(struct command *cmd, const struct wallet_payment **payments; struct json_stream *response; struct sha256 *rhash; - const char *invstring, *status; + const char *invstring, *status_str; if (!param(cmd, buffer, params, /* FIXME: parameter should be invstring now */ p_opt("bolt11", param_string, &invstring), p_opt("payment_hash", param_sha256, &rhash), - p_opt("status", param_string, &status), + p_opt("status", param_string, &status_str), NULL)) return command_param_failed(); @@ -1563,7 +1563,14 @@ static struct command_result *json_listsendpays(struct command *cmd, } } - payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, NULL); + if (status_str) { + enum wallet_payment_status status; + + if (!string_to_payment_status(status_str, &status)) + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Unrecognized status: %s", status_str); + payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, &status); + } else + payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, NULL); response = json_stream_success(cmd); diff --git a/tests/test_pay.py b/tests/test_pay.py index c701c38d4110..1f77fa8767fc 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -4304,3 +4304,26 @@ def test_pay_low_max_htlcs(node_factory): l1.daemon.wait_for_log( r'Number of pre-split HTLCs \([0-9]+\) exceeds our HTLC budget \([0-9]+\), skipping pre-splitter' ) + + +def test_listpays_with_filter_by_status(node_factory, bitcoind): + """ + This test check if the filtering by status of the command listpays + has some mistakes. + """ + + # Create the line graph l2 -> l1 with a channel of 10 ** 5 sat! + l2, l1 = node_factory.line_graph(2, fundamount=10**5, wait_for_announce=True) + + inv = l1.rpc.invoice(10 ** 5, 'inv', 'inv') + l2.rpc.pay(inv['bolt11']) + + wait_for(lambda: l2.rpc.listpays(inv['bolt11'])['pays'][0]['status'] == 'complete') + + # test if the node is still ready + payments = l2.rpc.call("listpays", {"status": 'failed'}) + + assert len(payments['pays']) == 0 + + payments = l2.rpc.listpays() + assert len(l2.rpc.listpays()['pays']) == 1