77from threading import Event
88from pyln .testing .utils import (
99 TIMEOUT , VALGRIND , sync_blockheight , only_one ,
10- wait_for , TailableProc , env , mine_funding_to_announce
10+ wait_for , TailableProc , env , mine_funding_to_announce ,
1111)
1212from utils import (
13- account_balance , scriptpubkey_addr , check_coin_moves , first_scid
13+ account_balance , scriptpubkey_addr , check_coin_moves , first_scid ,
14+ serialize_payload_tlv , serialize_payload_final_tlv ,
1415)
1516
1617import copy
@@ -2115,9 +2116,10 @@ def test_bad_onion(node_factory, bitcoind):
21152116 assert err .value .error ['data' ]['erring_channel' ] == route [1 ]['channel' ]
21162117
21172118
2119+ @pytest .mark .xfail (strict = True )
21182120def test_bad_onion_immediate_peer (node_factory , bitcoind ):
21192121 """Test that we handle the malformed msg when we're the origin"""
2120- l1 , l2 = node_factory .line_graph (2 , opts = { 'dev-fail-process-onionpacket' : None })
2122+ l1 , l2 = node_factory .line_graph (2 , opts = [{}, { 'dev-fail-process-onionpacket' : None }] )
21212123
21222124 inv = l2 .rpc .invoice (123000 , 'test_bad_onion_immediate_peer' , 'description' )
21232125 route = l1 .rpc .getroute (l2 .info ['id' ], 123000 , 1 )['route' ]
@@ -2134,6 +2136,26 @@ def test_bad_onion_immediate_peer(node_factory, bitcoind):
21342136 WIRE_INVALID_ONION_HMAC = 0x8000 | 0x4000 | 5
21352137 assert err .value .error ['data' ]['failcode' ] == WIRE_INVALID_ONION_HMAC
21362138
2139+ # Same, but using injectpaymentonion with corrupt onion.
2140+ blockheight = l1 .rpc .getinfo ()['blockheight' ]
2141+ hops = [{'pubkey' : l1 .info ['id' ],
2142+ 'payload' : serialize_payload_tlv (123000 , 18 + 6 , first_scid (l1 , l2 ), blockheight ).hex ()},
2143+ {'pubkey' : l2 .info ['id' ],
2144+ 'payload' : serialize_payload_final_tlv (123000 , 18 , 123000 , blockheight , inv ['payment_secret' ]).hex ()}]
2145+ onion = l1 .rpc .createonion (hops = hops , assocdata = inv ['payment_hash' ])
2146+
2147+ with pytest .raises (RpcError ) as err :
2148+ l1 .rpc .injectpaymentonion (onion = onion ['onion' ],
2149+ payment_hash = inv ['payment_hash' ],
2150+ amount_msat = 123000 ,
2151+ cltv_expiry = blockheight + 18 + 6 ,
2152+ partid = 1 ,
2153+ groupid = 0 )
2154+ # FIXME: PAY_INJECTPAYMENTONION_FAILED = 218
2155+ PAY_INJECTPAYMENTONION_FAILED = 218
2156+ assert err .value .error ['code' ] == PAY_INJECTPAYMENTONION_FAILED
2157+ assert 'onionreply' in err .value .error ['data' ]
2158+
21372159
21382160def test_newaddr (node_factory , chainparams ):
21392161 l1 = node_factory .get_node ()
0 commit comments