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

Function test_createproof

tests/test_pay.py:7293–7339  ·  view source on GitHub ↗

Basic createproof tests: invoice string, offer string, no payment, note, include.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

7291
7292
7293def test_createproof(node_factory, bitcoind):
7294 """Basic createproof tests: invoice string, offer string, no payment, note, include."""
7295 l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True,
7296 opts=[{},
7297 {'dev-allow-localhost': None},
7298 {'dev-allow-localhost': None}])
7299
7300 offer = l3.rpc.offer('10000msat', 'test offer')
7301 inv = l1.rpc.fetchinvoice(offer['bolt12'])['invoice']
7302
7303 # No payment yet: should fail with error 1700.
7304 with pytest.raises(RpcError, match=r'1700.*No successful payment'):
7305 l1.rpc.call('createproof', {'invstring': inv})
7306
7307 l1.rpc.xpay(inv)
7308
7309 # Proof by invoice string.
7310 proof = only_one(l1.rpc.call('createproof', {'invstring': inv})['proofs'])
7311
7312 # Check returned field lists.
7313 assert 'offer_description' in proof['offer_fields_included']
7314 assert 'offer_issuer_id' in proof['offer_fields_included']
7315 assert 'invreq_payer_id' in proof['invreq_fields_included']
7316 assert 'invoice_payment_hash' in proof['invoice_fields_included']
7317 assert 'invoice_amount' in proof['invoice_fields_included']
7318 assert 'invoice_features' in proof['invoice_fields_included']
7319 assert 'invoice_node_id' in proof['invoice_fields_included']
7320 assert 'signature' in proof['invoice_fields_included']
7321
7322 # Decode the proof: must be valid.
7323 decoded = l1.rpc.decode(proof['bolt12'])
7324 assert decoded['type'] == 'bolt12 payer_proof'
7325 assert decoded['valid'] is True
7326
7327 # Proof by offer string gives the same proof.
7328 assert only_one(l1.rpc.call('createproof', {'invstring': offer['bolt12']})['proofs'])['bolt12'] == proof['bolt12']
7329
7330 # Second payment to same offer gives two proofs.
7331 inv2 = l1.rpc.fetchinvoice(offer['bolt12'])['invoice']
7332 l1.rpc.xpay(inv2)
7333 ret3 = l1.rpc.call('createproof', {'invstring': offer['bolt12']})
7334 assert len(ret3['proofs']) == 2
7335
7336 # Both decode as valid.
7337 for p in ret3['proofs']:
7338 d = l1.rpc.decode(p['bolt12'])
7339 assert d['valid'] is True
7340
7341
7342def test_createproof_note(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 7

only_oneFunction · 0.90
line_graphMethod · 0.80
fetchinvoiceMethod · 0.80
offerMethod · 0.45
callMethod · 0.45
xpayMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected