Browse Source

pytest: Let `fail_htlcs.py` plugin generates `TEMPORARY_NODE_FAILURE` error

travis-debug
trueptolemy 6 years ago
committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent
commit
a3a0f651e3
  1. 4
      tests/plugins/fail_htlcs.py
  2. 14
      tests/test_plugin.py

4
tests/plugins/fail_htlcs.py

@ -9,7 +9,9 @@ plugin = Plugin()
def on_htlc_accepted(onion, plugin, **kwargs):
plugin.log("Failing htlc on purpose")
plugin.log("onion: %r" % (onion))
return {"result": "fail", "failure_code": 16399}
# FIXME: Define this!
WIRE_TEMPORARY_NODE_FAILURE = 0x2002
return {"result": "fail", "failure_code": WIRE_TEMPORARY_NODE_FAILURE}
plugin.run()

14
tests/test_plugin.py

@ -426,10 +426,16 @@ def test_htlc_accepted_hook_fail(node_factory):
], wait_for_announce=True)
# This must fail
inv = l2.rpc.invoice(1000, "lbl", "desc")['bolt11']
phash = l2.rpc.invoice(1000, "lbl", "desc")['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)
with pytest.raises(RpcError) as excinfo:
l1.rpc.pay(inv)
assert excinfo.value.error['data']['failcode'] == 16399
l1.rpc.waitsendpay(phash)
assert excinfo.value.error['data']['failcode'] == 0x2002
assert excinfo.value.error['data']['erring_index'] == 1
# And the invoice must still be unpaid
@ -439,7 +445,7 @@ def test_htlc_accepted_hook_fail(node_factory):
# Now try with forwarded HTLCs: l2 should still fail them
# This must fail
inv = l3.rpc.invoice(1000, "lbl", "desc")['bolt11']
with pytest.raises(RpcError) as excinfo:
with pytest.raises(RpcError):
l1.rpc.pay(inv)
# And the invoice must still be unpaid

Loading…
Cancel
Save