mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
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 <rusty@rustcorp.com.au>
This commit is contained in:
parent
e83f8594c9
commit
78adf0b673
@ -444,7 +444,7 @@ static void json_pay(struct command *cmd,
|
|||||||
|
|
||||||
if (b11->msatoshi) {
|
if (b11->msatoshi) {
|
||||||
msatoshi = *b11->msatoshi;
|
msatoshi = *b11->msatoshi;
|
||||||
if (msatoshitok) {
|
if (msatoshitok && !json_tok_is_null(buffer, msatoshitok)) {
|
||||||
command_fail(cmd, "msatoshi parameter unnecessary");
|
command_fail(cmd, "msatoshi parameter unnecessary");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -744,6 +744,12 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
l1.rpc.pay(inv)
|
l1.rpc.pay(inv)
|
||||||
assert l2.rpc.listinvoice('test_pay')[0]['complete'] == True
|
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
|
# Check pay_index is not null
|
||||||
outputs = l2.db_query('SELECT pay_index IS NOT NULL AS q FROM invoices WHERE label="label";')
|
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
|
assert len(outputs) == 1 and outputs[0]['q'] != 0
|
||||||
@ -752,6 +758,9 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
for i in range(5):
|
for i in range(5):
|
||||||
label = "any{}".format(i)
|
label = "any{}".format(i)
|
||||||
inv = l2.rpc.invoice("any", label, 'description')['bolt11']
|
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))
|
l1.rpc.pay(inv, random.randint(1000, 999999))
|
||||||
|
|
||||||
def test_bad_opening(self):
|
def test_bad_opening(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user