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

Function test_xpay_simple

tests/test_xpay.py:147–215  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

145
146
147def test_xpay_simple(node_factory):
148 l1, l2, l3, l4 = node_factory.get_nodes(4, opts={'may_reconnect': True})
149 node_factory.join_nodes([l1, l2, l3], wait_for_announce=True)
150 node_factory.join_nodes([l3, l4], announce_channels=False)
151
152 # BOLT-11, direct peer
153 b11 = l2.rpc.invoice('10000msat', 'test_xpay_simple', 'test_xpay_simple bolt11')['bolt11']
154 ret = l1.rpc.xpay(b11)
155 assert ret['failed_parts'] == 0
156 assert ret['successful_parts'] == 1
157 assert ret['amount_msat'] == 10000
158 assert ret['amount_sent_msat'] == 10000
159
160 PAY_INJECTPAYMENTONION_ALREADY_PAID = 219
161 # Fails if we try to pay again
162 b11_paid = b11
163 with pytest.raises(RpcError, match="Already paid") as err:
164 l1.rpc.xpay(b11_paid)
165 assert err.value.error['code'] == PAY_INJECTPAYMENTONION_ALREADY_PAID
166
167 # BOLT-11, indirect peer
168 b11 = l3.rpc.invoice('10000msat', 'test_xpay_simple', 'test_xpay_simple bolt11')['bolt11']
169 ret = l1.rpc.xpay(b11)
170 assert ret['failed_parts'] == 0
171 assert ret['successful_parts'] == 1
172 assert ret['amount_msat'] == 10000
173 assert ret['amount_sent_msat'] == 10001
174
175 # BOLT-11, routehint
176 b11 = l4.rpc.invoice('10000msat', 'test_xpay_simple', 'test_xpay_simple bolt11')['bolt11']
177 l1.rpc.xpay(b11)
178
179 # BOLT-12 (with payer_note specified).
180 offer = l3.rpc.offer('any')['bolt12']
181 b12 = l1.rpc.fetchinvoice(offer, '100000msat')['invoice']
182 l1.rpc.xpay(invstring=b12, payer_note="Payment for a cup of coffee")
183
184 # BOLT-12, direct peer
185 offer = l2.rpc.offer('any')['bolt12']
186 b12 = l1.rpc.fetchinvoice(offer, '10000msat')['invoice']
187 ret = l1.rpc.xpay(invstring=b12)
188 assert ret['failed_parts'] == 0
189 assert ret['successful_parts'] == 1
190 assert ret['amount_msat'] == 10000
191 assert ret['amount_sent_msat'] == 10000
192
193 # Failure from l4.
194 b11 = l4.rpc.invoice('10000msat', 'test_xpay_simple2', 'test_xpay_simple2 bolt11')['bolt11']
195 l4.rpc.delinvoice('test_xpay_simple2', 'unpaid')
196 with pytest.raises(RpcError, match="Destination said it doesn't know invoice"):
197 l1.rpc.xpay(b11)
198
199 offer = l4.rpc.offer('any')['bolt12']
200 b12 = l1.rpc.fetchinvoice(offer, '100000msat')['invoice']
201
202 # Failure from l3 (with routehint)
203 l4.stop()
204 with pytest.raises(RpcError, match=r"Failed after 1 attempts\. We got temporary_channel_failure for the invoice's route hint \([0-9x]*/[01]\), assuming it can't carry 10000msat\. Then routing failed: We could not find a usable set of paths\. The shortest path is [0-9x]*->[0-9x]*->[0-9x]*, but [0-9x]*/[01]\ layer xpay-15 says max is 9999msat"):

Callers

nothing calls this directly

Calls 10

get_nodesMethod · 0.80
join_nodesMethod · 0.80
fetchinvoiceMethod · 0.80
delinvoiceMethod · 0.80
restartMethod · 0.80
invoiceMethod · 0.45
xpayMethod · 0.45
offerMethod · 0.45
stopMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected