MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_preapprove

Function test_preapprove

tests/test_misc.py:5041–5102  ·  view source on GitHub ↗
(node_factory, bitcoind, preapprove)

Source from the content-addressed store, hash-verified

5039
5040@pytest.mark.parametrize("preapprove", [False, True])
5041def test_preapprove(node_factory, bitcoind, preapprove):
5042 # l1 uses old routine which doesn't support check.
5043 opts = [{'dev-hsmd-no-preapprove-check': None}, {}]
5044 if preapprove is False:
5045 opts[0]['dev-hsmd-fail-preapprove'] = None
5046 opts[1]['dev-hsmd-fail-preapprove'] = None
5047
5048 l1, l2 = node_factory.line_graph(2, opts=opts)
5049
5050 inv = l1.rpc.invoice(123000, 'label', 'description', 3700)['bolt11']
5051 if preapprove:
5052 l2.rpc.check('preapproveinvoice', bolt11=inv)
5053 else:
5054 with pytest.raises(RpcError, match='invoice was declined'):
5055 l2.rpc.check('preapproveinvoice', bolt11=inv)
5056
5057 l2.daemon.wait_for_log("preapprove_invoice: check_only=1")
5058
5059 # But l1 can't check properly, will always pass.
5060 inv = l2.rpc.invoice(123000, 'label', 'description', 3700)['bolt11']
5061 l1.rpc.check('preapproveinvoice', bolt11=inv)
5062
5063 assert not l1.daemon.is_in_log("preapprove_invoice: check_only=1")
5064
5065 # But if we try to actually preapprove we fail if told.
5066 if preapprove:
5067 l1.rpc.preapproveinvoice(inv)
5068 else:
5069 with pytest.raises(RpcError, match='invoice was declined'):
5070 l1.rpc.preapproveinvoice(bolt11=inv)
5071 l1.daemon.wait_for_log("preapprove_invoice: check_only=0")
5072
5073 # Same for keysend
5074 if preapprove:
5075 l2.rpc.check('preapprovekeysend',
5076 destination=l1.info['id'],
5077 payment_hash='00' * 32,
5078 amount_msat=1000)
5079 else:
5080 with pytest.raises(RpcError, match='keysend was declined'):
5081 l2.rpc.check('preapprovekeysend',
5082 destination=l1.info['id'],
5083 payment_hash='00' * 32,
5084 amount_msat=1000)
5085
5086 l2.daemon.wait_for_log("preapprove_keysend: check_only=1")
5087
5088 # But l1 can't check properly, will always pass.
5089 l1.rpc.check('preapprovekeysend',
5090 destination=l2.info['id'],
5091 payment_hash='00' * 32,
5092 amount_msat=1000)
5093
5094 assert not l1.daemon.is_in_log("preapprove_keysend: check_only=1")
5095
5096 # But if we try to actually preapprove we fail if told.
5097 if preapprove:
5098 l1.rpc.preapprovekeysend(l2.info['id'], '00' * 32, 1000)

Callers

nothing calls this directly

Calls 5

line_graphMethod · 0.80
wait_for_logMethod · 0.80
is_in_logMethod · 0.80
invoiceMethod · 0.45
checkMethod · 0.45

Tested by

no test coverage detected