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

Function test_bad_onion_immediate_peer

tests/test_misc.py:2181–2225  ·  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

2179
2180
2181def test_bad_onion_immediate_peer(node_factory, bitcoind):
2182 """Test that we handle the malformed msg when we're the origin"""
2183 l1, l2 = node_factory.line_graph(2, opts=[{}, {'dev-fail-process-onionpacket': None}])
2184
2185 inv = l2.rpc.invoice(123000, 'test_bad_onion_immediate_peer', 'description')
2186 route = l1.single_route(l2.info['id'], 123000)
2187 assert len(route) == 1
2188
2189 l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
2190 with pytest.raises(RpcError) as err:
2191 l1.rpc.waitsendpay(inv['payment_hash'])
2192
2193 # FIXME: #define PAY_UNPARSEABLE_ONION 202
2194 PAY_UNPARSEABLE_ONION = 202
2195 assert err.value.error['code'] == PAY_UNPARSEABLE_ONION
2196 # FIXME: WIRE_INVALID_ONION_HMAC = BADONION|PERM|5
2197 WIRE_INVALID_ONION_HMAC = 0x8000 | 0x4000 | 5
2198 assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC
2199
2200 # Asking again about the same payment should give same result.
2201 with pytest.raises(RpcError) as err:
2202 l1.rpc.waitsendpay(inv['payment_hash'])
2203
2204 assert err.value.error['code'] == PAY_UNPARSEABLE_ONION
2205 assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC
2206
2207 # Same, but using injectpaymentonion with corrupt onion.
2208 blockheight = l1.rpc.getinfo()['blockheight']
2209 hops = [{'pubkey': l1.info['id'],
2210 'payload': serialize_payload_tlv(123000, 18 + 6, first_scid(l1, l2), blockheight).hex()},
2211 {'pubkey': l2.info['id'],
2212 'payload': serialize_payload_final_tlv(123000, 18, 123000, blockheight, inv['payment_secret']).hex()}]
2213 onion = l1.rpc.createonion(hops=hops, assocdata=inv['payment_hash'])
2214
2215 with pytest.raises(RpcError) as err:
2216 l1.rpc.injectpaymentonion(onion=onion['onion'],
2217 payment_hash=inv['payment_hash'],
2218 amount_msat=123000,
2219 cltv_expiry=blockheight + 18 + 6,
2220 partid=1,
2221 groupid=0)
2222 # FIXME: PAY_INJECTPAYMENTONION_FAILED = 218
2223 PAY_INJECTPAYMENTONION_FAILED = 218
2224 assert err.value.error['code'] == PAY_INJECTPAYMENTONION_FAILED
2225 assert 'onionreply' in err.value.error['data']
2226
2227
2228def 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