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

Function test_bad_onion_immediate_peer

tests/test_misc.py:2211–2255  ·  view source on GitHub ↗

Test that we handle the malformed msg when we're the origin

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2209
2210
2211def test_bad_onion_immediate_peer(node_factory, bitcoind):
2212 """Test that we handle the malformed msg when we're the origin"""
2213 l1, l2 = node_factory.line_graph(2, opts=[{}, {'dev-fail-process-onionpacket': None}])
2214
2215 inv = l2.rpc.invoice(123000, 'test_bad_onion_immediate_peer', 'description')
2216 route = l1.single_route(l2.info['id'], 123000)
2217 assert len(route) == 1
2218
2219 l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
2220 with pytest.raises(RpcError) as err:
2221 l1.rpc.waitsendpay(inv['payment_hash'])
2222
2223 # FIXME: #define PAY_UNPARSEABLE_ONION 202
2224 PAY_UNPARSEABLE_ONION = 202
2225 assert err.value.error['code'] == PAY_UNPARSEABLE_ONION
2226 # FIXME: WIRE_INVALID_ONION_HMAC = BADONION|PERM|5
2227 WIRE_INVALID_ONION_HMAC = 0x8000 | 0x4000 | 5
2228 assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC
2229
2230 # Asking again about the same payment should give same result.
2231 with pytest.raises(RpcError) as err:
2232 l1.rpc.waitsendpay(inv['payment_hash'])
2233
2234 assert err.value.error['code'] == PAY_UNPARSEABLE_ONION
2235 assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC
2236
2237 # Same, but using injectpaymentonion with corrupt onion.
2238 blockheight = l1.rpc.getinfo()['blockheight']
2239 hops = [{'pubkey': l1.info['id'],
2240 'payload': serialize_payload_tlv(123000, 18 + 6, first_scid(l1, l2), blockheight).hex()},
2241 {'pubkey': l2.info['id'],
2242 'payload': serialize_payload_final_tlv(123000, 18, 123000, blockheight, inv['payment_secret']).hex()}]
2243 onion = l1.rpc.createonion(hops=hops, assocdata=inv['payment_hash'])
2244
2245 with pytest.raises(RpcError) as err:
2246 l1.rpc.injectpaymentonion(onion=onion['onion'],
2247 payment_hash=inv['payment_hash'],
2248 amount_msat=123000,
2249 cltv_expiry=blockheight + 18 + 6,
2250 partid=1,
2251 groupid=0)
2252 # FIXME: PAY_INJECTPAYMENTONION_FAILED = 218
2253 PAY_INJECTPAYMENTONION_FAILED = 218
2254 assert err.value.error['code'] == PAY_INJECTPAYMENTONION_FAILED
2255 assert 'onionreply' in err.value.error['data']
2256
2257
2258def test_newaddr(node_factory, chainparams):

Callers

nothing calls this directly

Calls 9

serialize_payload_tlvFunction · 0.90
first_scidFunction · 0.90
line_graphMethod · 0.80
single_routeMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
invoiceMethod · 0.45
getinfoMethod · 0.45

Tested by

no test coverage detected