pytest: always provide payment_secret when making payments.

They're about to become compulsory.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-07-12 16:19:19 +09:30
committed by neil saitug
parent 3f5d5a1de5
commit 4e881e56ce
7 changed files with 212 additions and 164 deletions

View File

@@ -1001,13 +1001,14 @@ def test_htlc_accepted_hook_fail(node_factory):
], wait_for_announce=True)
# This must fail
phash = l2.rpc.invoice(1000, "lbl", "desc")['payment_hash']
inv = l2.rpc.invoice(1000, "lbl", "desc")
phash = inv['payment_hash']
route = l1.rpc.getroute(l2.info['id'], 1000, 1)['route']
# Here shouldn't use `pay` command because l2 rejects with WIRE_TEMPORARY_NODE_FAILURE,
# then it will be excluded when l1 try another pay attempt.
# Note if the destination is excluded, the route result is undefined.
l1.rpc.sendpay(route, phash)
l1.rpc.sendpay(route, phash, payment_secret=inv['payment_secret'])
with pytest.raises(RpcError) as excinfo:
l1.rpc.waitsendpay(phash)
assert excinfo.value.error['data']['failcode'] == 0x2002
@@ -1231,22 +1232,24 @@ def test_forward_event_notification(node_factory, bitcoind, executor):
wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 8)
payment_hash13 = l3.rpc.invoice(amount, "first", "desc")['payment_hash']
inv = l3.rpc.invoice(amount, "first", "desc")
payment_hash13 = inv['payment_hash']
route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
# status: offered -> settled
l1.rpc.sendpay(route, payment_hash13)
l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret'])
l1.rpc.waitsendpay(payment_hash13)
# status: offered -> failed
route = l1.rpc.getroute(l4.info['id'], amount, 1)['route']
payment_hash14 = "f" * 64
with pytest.raises(RpcError):
l1.rpc.sendpay(route, payment_hash14)
l1.rpc.sendpay(route, payment_hash14, payment_secret="f" * 64)
l1.rpc.waitsendpay(payment_hash14)
# status: offered -> local_failed
payment_hash15 = l5.rpc.invoice(amount, 'onchain_timeout', 'desc')['payment_hash']
inv = l5.rpc.invoice(amount, 'onchain_timeout', 'desc')
payment_hash15 = inv['payment_hash']
fee = amount * 10 // 1000000 + 1
c12 = l1.get_channel_scid(l2)
c25 = l2.get_channel_scid(l5)
@@ -1259,7 +1262,7 @@ def test_forward_event_notification(node_factory, bitcoind, executor):
'delay': 5,
'channel': c25}]
executor.submit(l1.rpc.sendpay, route, payment_hash15)
executor.submit(l1.rpc.sendpay, route, payment_hash15, payment_secret=inv['payment_secret'])
l5.daemon.wait_for_log('permfail')
l5.wait_for_channel_onchain(l2.info['id'])
@@ -1320,16 +1323,18 @@ def test_sendpay_notifications(node_factory, bitcoind):
l1, l2, l3 = node_factory.line_graph(3, opts=opts, wait_for_announce=True)
chanid23 = l2.get_channel_scid(l3)
payment_hash1 = l3.rpc.invoice(amount, "first", "desc")['payment_hash']
payment_hash2 = l3.rpc.invoice(amount, "second", "desc")['payment_hash']
inv1 = l3.rpc.invoice(amount, "first", "desc")
payment_hash1 = inv1['payment_hash']
inv2 = l3.rpc.invoice(amount, "second", "desc")
payment_hash2 = inv2['payment_hash']
route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
l1.rpc.sendpay(route, payment_hash1)
l1.rpc.sendpay(route, payment_hash1, payment_secret=inv1['payment_secret'])
response1 = l1.rpc.waitsendpay(payment_hash1)
l2.rpc.close(chanid23, 1)
l1.rpc.sendpay(route, payment_hash2)
l1.rpc.sendpay(route, payment_hash2, payment_secret=inv2['payment_secret'])
with pytest.raises(RpcError) as err:
l1.rpc.waitsendpay(payment_hash2)
@@ -1349,16 +1354,18 @@ def test_sendpay_notifications_nowaiter(node_factory):
chanid23 = l2.get_channel_scid(l3)
amount = 10**8
payment_hash1 = l3.rpc.invoice(amount, "first", "desc")['payment_hash']
payment_hash2 = l3.rpc.invoice(amount, "second", "desc")['payment_hash']
inv1 = l3.rpc.invoice(amount, "first", "desc")
payment_hash1 = inv1['payment_hash']
inv2 = l3.rpc.invoice(amount, "second", "desc")
payment_hash2 = inv2['payment_hash']
route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
l1.rpc.sendpay(route, payment_hash1)
l1.rpc.sendpay(route, payment_hash1, payment_secret=inv1['payment_secret'])
l1.daemon.wait_for_log(r'Received a sendpay_success')
l2.rpc.close(chanid23, 1)
l1.rpc.sendpay(route, payment_hash2)
l1.rpc.sendpay(route, payment_hash2, payment_secret=inv2['payment_secret'])
l1.daemon.wait_for_log(r'Received a sendpay_failure')
results = l1.rpc.call('listsendpays_plugin')
@@ -1980,36 +1987,40 @@ def test_coin_movement_notices(node_factory, bitcoind, chainparams):
wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4)
amount = 10**8
payment_hash13 = l3.rpc.invoice(amount, "first", "desc")['payment_hash']
inv = l3.rpc.invoice(amount, "first", "desc")
payment_hash13 = inv['payment_hash']
route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
# status: offered -> settled
l1.rpc.sendpay(route, payment_hash13)
l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret'])
l1.rpc.waitsendpay(payment_hash13)
# status: offered -> failed
route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
payment_hash13 = "f" * 64
with pytest.raises(RpcError):
l1.rpc.sendpay(route, payment_hash13)
l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret'])
l1.rpc.waitsendpay(payment_hash13)
# go the other direction
payment_hash31 = l1.rpc.invoice(amount // 2, "first", "desc")['payment_hash']
inv = l1.rpc.invoice(amount // 2, "first", "desc")
payment_hash31 = inv['payment_hash']
route = l3.rpc.getroute(l1.info['id'], amount // 2, 1)['route']
l3.rpc.sendpay(route, payment_hash31)
l3.rpc.sendpay(route, payment_hash31, payment_secret=inv['payment_secret'])
l3.rpc.waitsendpay(payment_hash31)
# receive a payment (endpoint)
payment_hash12 = l2.rpc.invoice(amount, "first", "desc")['payment_hash']
inv = l2.rpc.invoice(amount, "first", "desc")
payment_hash12 = inv['payment_hash']
route = l1.rpc.getroute(l2.info['id'], amount, 1)['route']
l1.rpc.sendpay(route, payment_hash12)
l1.rpc.sendpay(route, payment_hash12, payment_secret=inv['payment_secret'])
l1.rpc.waitsendpay(payment_hash12)
# send a payment (originator)
payment_hash21 = l1.rpc.invoice(amount // 2, "second", "desc")['payment_hash']
inv = l1.rpc.invoice(amount // 2, "second", "desc")
payment_hash21 = inv['payment_hash']
route = l2.rpc.getroute(l1.info['id'], amount // 2, 1)['route']
l2.rpc.sendpay(route, payment_hash21)
l2.rpc.sendpay(route, payment_hash21, payment_secret=inv['payment_secret'])
l2.rpc.waitsendpay(payment_hash21)
# restart to test index