@@ -2419,6 +2419,48 @@ def test_htlc_accepted_hook_failmsg(node_factory):
2419
2419
l1 .rpc .pay (inv )
2420
2420
2421
2421
2422
+ def test_htlc_accepted_hook_customtlvs (node_factory ):
2423
+ """ Passes an custom extra tlv field to the hooks return that should be set
2424
+ as the `update_add_htlc_tlvs` in the `update_add_htlc` message on
2425
+ forwards.
2426
+ """
2427
+ plugin = os .path .join (os .path .dirname (__file__ ), 'plugins/htlc_accepted-customtlv.py' )
2428
+ l1 , l2 , l3 = node_factory .line_graph (3 , opts = [{}, {'plugin' : plugin }, {'plugin' : plugin }], wait_for_announce = True )
2429
+
2430
+ # Single tlv - Check that we receive the extra tlv at l3 attached by l2.
2431
+ single_tlv = "fe00010001012a" # represents type: 65537, lenght: 1, value: 42
2432
+ l2 .rpc .setcustomtlvs (tlvs = single_tlv )
2433
+ inv = l3 .rpc .invoice (1000 , 'customtlvs-singletlv' , '' )['bolt11' ]
2434
+ l1 .rpc .pay (inv )
2435
+ l3 .daemon .wait_for_log (f"called htlc accepted hook with extra_tlvs: { single_tlv } " )
2436
+
2437
+ # Mutliple tlvs - Check that we recieve multiple extra tlvs at l3 attached by l2.
2438
+ multi_tlv = "fdffff012afe00010001020539" # represents type: 65535, length: 1, value: 42 and type: 65537, length: 2, value: 1337
2439
+ l2 .rpc .setcustomtlvs (tlvs = multi_tlv )
2440
+ inv = l3 .rpc .invoice (1000 , 'customtlvs-multitlvs' , '' )['bolt11' ]
2441
+ l1 .rpc .pay (inv )
2442
+ l3 .daemon .wait_for_log (f"called htlc accepted hook with extra_tlvs: { multi_tlv } " )
2443
+
2444
+
2445
+ def test_htlc_accepted_hook_malformedtlvs (node_factory ):
2446
+ """ Passes an custom extra tlv field to the hooks return that is malformed
2447
+ and should cause a broken log.
2448
+ l1 -- l2 -- l3
2449
+ """
2450
+ plugin = os .path .join (os .path .dirname (__file__ ), 'plugins/htlc_accepted-customtlv.py' )
2451
+ l1 , l2 , l3 = node_factory .line_graph (3 , opts = [{}, {'plugin' : plugin , 'broken_log' : "lightningd: " , 'may_fail' : True }, {}], wait_for_announce = True )
2452
+
2453
+ mal_tlv = "fe00010001020539fdffff012a" # is malformed, types are 65537 and 65535 not in asc order.
2454
+ l2 .rpc .setcustomtlvs (tlvs = mal_tlv )
2455
+ inv = l3 .rpc .invoice (1000 , 'customtlvs-maltlvs' , '' )
2456
+ phash = inv ['payment_hash' ]
2457
+ route = l1 .rpc .getroute (l3 .info ['id' ], 1000 , 1 )['route' ]
2458
+
2459
+ # Here shouldn't use `pay` command because l2 should fail with a broken log.
2460
+ l1 .rpc .sendpay (route , phash , payment_secret = inv ['payment_secret' ])
2461
+ assert l2 .daemon .wait_for_log ("BROKEN.*htlc_accepted_hook returned bad extra_tlvs" )
2462
+
2463
+
2422
2464
def test_hook_dep (node_factory ):
2423
2465
dep_a = os .path .join (os .path .dirname (__file__ ), 'plugins/dep_a.py' )
2424
2466
dep_b = os .path .join (os .path .dirname (__file__ ), 'plugins/dep_b.py' )
0 commit comments