@@ -32,12 +32,6 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
3232 } } ;
3333 }
3434
35- macro_rules! get_u8 {
36- ( ) => {
37- get_slice!( 1 ) [ 0 ]
38- } ;
39- }
40-
4135 macro_rules! get_u16 {
4236 ( ) => {
4337 match get_slice!( 2 ) . try_into( ) {
@@ -47,92 +41,73 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
4741 } ;
4842 }
4943
50- macro_rules! get_u32 {
44+ macro_rules! get_bool {
5145 ( ) => {
52- match get_slice!( 4 ) . try_into( ) {
53- Ok ( val) => u32 :: from_be_bytes( val) ,
54- Err ( _) => return ,
55- }
46+ get_slice!( 1 ) [ 0 ] & 1 != 0
5647 } ;
5748 }
5849
59- macro_rules! get_u64 {
60- ( ) => {
61- match get_slice!( 8 ) . try_into( ) {
62- Ok ( val) => u64 :: from_be_bytes( val) ,
63- Err ( _) => return ,
64- }
65- } ;
50+ fn usize_to_32_bytes ( input : usize ) -> [ u8 ; 32 ] {
51+ let mut bytes = [ 0u8 ; 32 ] ;
52+ let input_bytes = input. to_be_bytes ( ) ;
53+ bytes[ ..input_bytes. len ( ) ] . copy_from_slice ( & input_bytes) ;
54+ bytes
6655 }
6756
68- macro_rules! get_bool {
69- ( ) => {
70- get_slice!( 1 ) [ 0 ] != 0
71- } ;
72- }
57+ fn usize_to_pubkey ( input : usize ) -> PublicKey {
58+ let bytes = usize_to_32_bytes ( 1 + input) ;
7359
74- macro_rules! get_pubkey {
75- ( ) => {
76- match PublicKey :: from_slice( get_slice!( 33 ) ) {
77- Ok ( val) => val,
78- Err ( _) => return ,
79- }
80- } ;
60+ let secp_ctx = Secp256k1 :: new ( ) ;
61+ let secret_key = SecretKey :: from_slice ( & bytes) . unwrap ( ) ;
62+ secret_key. public_key ( & secp_ctx)
8163 }
8264
8365 let secp_ctx = Secp256k1 :: new ( ) ;
8466 let logger: Arc < dyn Logger > = Arc :: new ( test_logger:: TestLogger :: new ( "" . to_owned ( ) , out) ) ;
8567
86- let session_priv = match SecretKey :: from_slice ( get_slice ! ( 32 ) ) {
87- Ok ( val) => val,
88- Err ( _) => return ,
89- } ;
90-
91- let payment_id = match get_slice ! ( 32 ) . try_into ( ) {
92- Ok ( val) => PaymentId ( val) ,
93- Err ( _) => return ,
94- } ;
68+ let session_priv = SecretKey :: from_slice ( & usize_to_32_bytes ( 213127 ) ) . unwrap ( ) ;
69+ let payment_id = PaymentId ( usize_to_32_bytes ( 232299 ) ) ;
9570
9671 let mut hops = Vec :: < RouteHop > :: new ( ) ;
97- let hop_count = get_slice ! ( 1 ) [ 0 ] as usize ;
98- for _ in 0 ..hop_count {
72+ let hop_count = get_slice ! ( 1 ) [ 0 ] as usize % 30 ;
73+ for i in 0 ..hop_count {
9974 hops. push ( RouteHop {
100- pubkey : get_pubkey ! ( ) ,
75+ pubkey : usize_to_pubkey ( i ) ,
10176 node_features : NodeFeatures :: empty ( ) ,
102- short_channel_id : get_u64 ! ( ) ,
77+ short_channel_id : i as u64 ,
10378 channel_features : ChannelFeatures :: empty ( ) ,
104- fee_msat : get_u64 ! ( ) ,
105- cltv_expiry_delta : get_u32 ! ( ) ,
106- maybe_announced_channel : get_bool ! ( ) ,
79+ fee_msat : 0 ,
80+ cltv_expiry_delta : 0 ,
81+ maybe_announced_channel : false ,
10782 } ) ;
10883 }
10984
11085 let blinded_tail = match get_bool ! ( ) {
11186 true => {
11287 let mut trampoline_hops = Vec :: < TrampolineHop > :: new ( ) ;
113- let trampoline_hop_count = get_slice ! ( 1 ) [ 0 ] as usize ;
114- for _ in 0 ..trampoline_hop_count {
88+ let trampoline_hop_count = get_slice ! ( 1 ) [ 0 ] as usize % 30 ;
89+ for i in 0 ..trampoline_hop_count {
11590 trampoline_hops. push ( TrampolineHop {
116- pubkey : get_pubkey ! ( ) ,
91+ pubkey : usize_to_pubkey ( 1000 + i ) ,
11792 node_features : NodeFeatures :: empty ( ) ,
118- fee_msat : get_u64 ! ( ) ,
119- cltv_expiry_delta : get_u32 ! ( ) ,
93+ fee_msat : 0 ,
94+ cltv_expiry_delta : 0 ,
12095 } ) ;
12196 }
12297 let mut blinded_hops = Vec :: < BlindedHop > :: new ( ) ;
123- let blinded_hop_count = get_slice ! ( 1 ) [ 0 ] as usize ;
124- for _ in 0 ..blinded_hop_count {
98+ let blinded_hop_count = get_slice ! ( 1 ) [ 0 ] as usize % 30 ;
99+ for i in 0 ..blinded_hop_count {
125100 blinded_hops. push ( BlindedHop {
126- blinded_node_id : get_pubkey ! ( ) ,
127- encrypted_payload : get_slice ! ( get_u8 !( ) ) . to_vec ( ) ,
101+ blinded_node_id : usize_to_pubkey ( 2000 + i ) ,
102+ encrypted_payload : get_slice ! ( get_u16 !( ) ) . to_vec ( ) ,
128103 } ) ;
129104 }
130105 Some ( BlindedTail {
131106 trampoline_hops,
132107 hops : blinded_hops,
133- blinding_point : get_pubkey ! ( ) ,
134- excess_final_cltv_expiry_delta : get_u32 ! ( ) ,
135- final_value_msat : get_u64 ! ( ) ,
108+ blinding_point : usize_to_pubkey ( 64354334 ) ,
109+ excess_final_cltv_expiry_delta : 0 ,
110+ final_value_msat : 0 ,
136111 } )
137112 } ,
138113 false => None ,
@@ -143,7 +118,7 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
143118 let htlc_source = HTLCSource :: OutboundRoute {
144119 path,
145120 session_priv,
146- first_hop_htlc_msat : get_u64 ! ( ) ,
121+ first_hop_htlc_msat : 0 ,
147122 payment_id,
148123 } ;
149124
0 commit comments