mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
JSONRPC: listpayments not return a naked array.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
361fdccfca
commit
34a994c7db
2 changed files with 29 additions and 16 deletions
|
@ -485,7 +485,8 @@ static void json_listpayments(struct command *cmd, const char *buffer,
|
||||||
|
|
||||||
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash);
|
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash);
|
||||||
|
|
||||||
json_array_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
|
json_array_start(response, "payments");
|
||||||
for (int i=0; i<tal_count(payments); i++) {
|
for (int i=0; i<tal_count(payments); i++) {
|
||||||
const struct wallet_payment *t = payments[i];
|
const struct wallet_payment *t = payments[i];
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
|
@ -514,6 +515,7 @@ static void json_listpayments(struct command *cmd, const char *buffer,
|
||||||
json_object_end(response);
|
json_object_end(response);
|
||||||
}
|
}
|
||||||
json_array_end(response);
|
json_array_end(response);
|
||||||
|
json_object_end(response);
|
||||||
command_success(cmd, response);
|
command_success(cmd, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -707,13 +707,24 @@ class LightningDTests(BaseLightningDTests):
|
||||||
preimage3 = l1.rpc.sendpay(to_json([routestep]), rhash)
|
preimage3 = l1.rpc.sendpay(to_json([routestep]), rhash)
|
||||||
assert l2.rpc.listinvoice('testpayment3')[0]['complete'] == True
|
assert l2.rpc.listinvoice('testpayment3')[0]['complete'] == True
|
||||||
assert l2.rpc.listinvoice('testpayment3')[0]['msatoshi_received'] == amt*2
|
assert l2.rpc.listinvoice('testpayment3')[0]['msatoshi_received'] == amt*2
|
||||||
|
|
||||||
# Test listpayments
|
# Test listpayments
|
||||||
assert len(l1.rpc.listpayments()) == 2
|
payments = l1.rpc.listpayments()['payments']
|
||||||
assert len(l1.rpc.listpayments(None, l2.rpc.listinvoice('testpayment2')[0]['payment_hash'])) == 1
|
assert len(payments) == 2
|
||||||
assert l1.rpc.listpayments(None, l2.rpc.listinvoice('testpayment2')[0]['payment_hash'])[0]['status'] == 'complete'
|
|
||||||
assert l1.rpc.listpayments(None, l2.rpc.listinvoice('testpayment2')[0]['payment_hash'])[0]['payment_preimage'] == preimage2['preimage']
|
invoice2 = l2.rpc.listinvoice('testpayment2')[0]
|
||||||
assert l1.rpc.listpayments(None, l2.rpc.listinvoice('testpayment3')[0]['payment_hash'])[0]['status'] == 'complete'
|
payments = l1.rpc.listpayments(None, invoice2['payment_hash'])['payments']
|
||||||
assert l1.rpc.listpayments(None, l2.rpc.listinvoice('testpayment3')[0]['payment_hash'])[0]['payment_preimage'] == preimage3['preimage']
|
assert len(payments) == 1
|
||||||
|
print(payments)
|
||||||
|
assert payments[0]['status'] == 'complete'
|
||||||
|
assert payments[0]['payment_preimage'] == preimage2['preimage']
|
||||||
|
|
||||||
|
invoice3 = l2.rpc.listinvoice('testpayment3')[0]
|
||||||
|
payments = l1.rpc.listpayments(None, invoice3['payment_hash'])['payments']
|
||||||
|
assert len(payments) == 1
|
||||||
|
print(payments)
|
||||||
|
assert payments[0]['status'] == 'complete'
|
||||||
|
assert payments[0]['payment_preimage'] == preimage3['preimage']
|
||||||
|
|
||||||
def test_sendpay_cant_afford(self):
|
def test_sendpay_cant_afford(self):
|
||||||
l1,l2 = self.connect()
|
l1,l2 = self.connect()
|
||||||
|
@ -779,11 +790,11 @@ class LightningDTests(BaseLightningDTests):
|
||||||
l1.rpc.pay(inv2, random.randint(1000, 999999))
|
l1.rpc.pay(inv2, random.randint(1000, 999999))
|
||||||
|
|
||||||
# Should see 6 completed payments
|
# Should see 6 completed payments
|
||||||
assert len(l1.rpc.listpayments()) == 6
|
assert len(l1.rpc.listpayments()['payments']) == 6
|
||||||
|
|
||||||
# Test listpayments indexed by bolt11.
|
# Test listpayments indexed by bolt11.
|
||||||
assert len(l1.rpc.listpayments(inv)) == 1
|
assert len(l1.rpc.listpayments(inv)['payments']) == 1
|
||||||
assert l1.rpc.listpayments(inv)[0]['payment_preimage'] == preimage['preimage']
|
assert l1.rpc.listpayments(inv)['payments'][0]['payment_preimage'] == preimage['preimage']
|
||||||
|
|
||||||
def test_bad_opening(self):
|
def test_bad_opening(self):
|
||||||
# l1 asks for a too-long locktime
|
# l1 asks for a too-long locktime
|
||||||
|
@ -2610,9 +2621,9 @@ class LightningDTests(BaseLightningDTests):
|
||||||
# Should reconnect, and sort the payment out.
|
# Should reconnect, and sort the payment out.
|
||||||
l1.daemon.start()
|
l1.daemon.start()
|
||||||
|
|
||||||
wait_for(lambda: l1.rpc.listpayments()[0]['status'] != 'pending')
|
wait_for(lambda: l1.rpc.listpayments()['payments'][0]['status'] != 'pending')
|
||||||
|
|
||||||
assert l1.rpc.listpayments()[0]['status'] == 'complete'
|
assert l1.rpc.listpayments()['payments'][0]['status'] == 'complete'
|
||||||
assert l2.rpc.listinvoice('inv1')[0]['complete'] == True
|
assert l2.rpc.listinvoice('inv1')[0]['complete'] == True
|
||||||
|
|
||||||
# FIXME: We should re-add pre-announced routes on startup!
|
# FIXME: We should re-add pre-announced routes on startup!
|
||||||
|
@ -2654,10 +2665,10 @@ class LightningDTests(BaseLightningDTests):
|
||||||
# Should reconnect, and fail the payment
|
# Should reconnect, and fail the payment
|
||||||
l1.daemon.start()
|
l1.daemon.start()
|
||||||
|
|
||||||
wait_for(lambda: l1.rpc.listpayments()[0]['status'] != 'pending')
|
wait_for(lambda: l1.rpc.listpayments()['payments'][0]['status'] != 'pending')
|
||||||
|
|
||||||
assert l2.rpc.listinvoice('inv1')[0]['complete'] == False
|
assert l2.rpc.listinvoice('inv1')[0]['complete'] == False
|
||||||
assert l1.rpc.listpayments()[0]['status'] == 'failed'
|
assert l1.rpc.listpayments()['payments'][0]['status'] == 'failed'
|
||||||
|
|
||||||
# Another attempt should also fail.
|
# Another attempt should also fail.
|
||||||
self.assertRaises(ValueError, l1.rpc.pay, inv1['bolt11'])
|
self.assertRaises(ValueError, l1.rpc.pay, inv1['bolt11'])
|
||||||
|
@ -2681,8 +2692,8 @@ class LightningDTests(BaseLightningDTests):
|
||||||
l1.daemon.wait_for_log('dev_disconnect: =WIRE_UPDATE_ADD_HTLC-nocommit')
|
l1.daemon.wait_for_log('dev_disconnect: =WIRE_UPDATE_ADD_HTLC-nocommit')
|
||||||
|
|
||||||
# We should see it in listpayments
|
# We should see it in listpayments
|
||||||
assert l1.rpc.listpayments()[0]['status'] == 'pending'
|
assert l1.rpc.listpayments()['payments'][0]['status'] == 'pending'
|
||||||
assert l1.rpc.listpayments()[0]['payment_hash'] == inv1['payment_hash']
|
assert l1.rpc.listpayments()['payments'][0]['payment_hash'] == inv1['payment_hash']
|
||||||
|
|
||||||
# Second one should fail.
|
# Second one should fail.
|
||||||
self.assertRaises(ValueError, l1.rpc.pay, inv1['bolt11'])
|
self.assertRaises(ValueError, l1.rpc.pay, inv1['bolt11'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue