From a1a0b335770f9833ad49a887731c10f64e16d793 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 13 Jan 2018 21:50:38 +1030 Subject: [PATCH] pay: allow 'null' msatoshi field. Since most callers use positional arguments, we should allow a 'null' literal where we require no value at all. Also adds some more value tests. Signed-off-by: Rusty Russell --- lightningd/pay.c | 2 +- tests/test_lightningd.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index ebcef51cb..5d6fc7bb1 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -444,7 +444,7 @@ static void json_pay(struct command *cmd, if (b11->msatoshi) { msatoshi = *b11->msatoshi; - if (msatoshitok) { + if (msatoshitok && !json_tok_is_null(buffer, msatoshitok)) { command_fail(cmd, "msatoshi parameter unnecessary"); return; } diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index dc748eb40..eac02d887 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -744,6 +744,12 @@ class LightningDTests(BaseLightningDTests): l1.rpc.pay(inv) assert l2.rpc.listinvoice('test_pay')[0]['complete'] == True + # Repeat payments are NOPs (if valid): we can hand null. + l1.rpc.pay(inv, None) + # This won't work: can't provide an amount (even if correct!) + self.assertRaises(ValueError, l1.rpc.pay, inv, 123000) + self.assertRaises(ValueError, l1.rpc.pay, inv, 122000) + # Check pay_index is not null outputs = l2.db_query('SELECT pay_index IS NOT NULL AS q FROM invoices WHERE label="label";') assert len(outputs) == 1 and outputs[0]['q'] != 0 @@ -752,6 +758,9 @@ class LightningDTests(BaseLightningDTests): for i in range(5): label = "any{}".format(i) inv = l2.rpc.invoice("any", label, 'description')['bolt11'] + # Must provide an amount! + self.assertRaises(ValueError, l1.rpc.pay, inv) + self.assertRaises(ValueError, l1.rpc.pay, inv, None) l1.rpc.pay(inv, random.randint(1000, 999999)) def test_bad_opening(self):