diff --git a/tests/plugins/hold_invoice.py b/tests/plugins/hold_invoice.py new file mode 100755 index 000000000..ec11d18bf --- /dev/null +++ b/tests/plugins/hold_invoice.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +"""Simple plugin to allow testing while closing of HTLC is delayed. +""" + +from lightning import Plugin +import time + +plugin = Plugin() + + +@plugin.hook('invoice_payment') +def on_payment(payment, plugin): + time.sleep(float(plugin.get_option('holdtime'))) + return {} + + +plugin.add_option('holdtime', '10', 'The time to hold invoice for.') +plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 4278097e7..3fdcac285 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2,7 +2,7 @@ from collections import OrderedDict from fixtures import * # noqa: F401,F403 from flaky import flaky # noqa: F401 from lightning import RpcError, Millisatoshi -from utils import only_one, wait_for +from utils import only_one, wait_for, TIMEOUT import os import pytest @@ -293,6 +293,16 @@ def test_invoice_payment_hook(node_factory): l2.daemon.wait_for_log('preimage=' + '0' * 64) +def test_invoice_payment_hook_hold(node_factory): + """ l1 uses the hold_invoice plugin to delay invoice payment. + """ + opts = [{}, {'plugin': 'tests/plugins/hold_invoice.py', 'holdtime': TIMEOUT / 2}] + l1, l2 = node_factory.line_graph(2, opts=opts) + + inv1 = l2.rpc.invoice(123000, 'label', 'description', preimage='1' * 64) + l1.rpc.pay(inv1['bolt11']) + + def test_openchannel_hook(node_factory, bitcoind): """ l2 uses the reject_odd_funding_amounts plugin to reject some openings. """