@@ -814,8 +814,11 @@ mod tests {
814
814
use bitcoin:: blockdata:: script:: Script ;
815
815
use bitcoin:: util:: hash:: Hash160 ;
816
816
use ln:: channelmonitor:: ChannelMonitor ;
817
+ use ln:: channelmonitor:: LocalSignedTx ;
818
+ use ln:: chan_utils:: HTLCOutputInCommitment ;
817
819
use secp256k1:: key:: { SecretKey , PublicKey } ;
818
820
use secp256k1:: Secp256k1 ;
821
+ use rand:: { thread_rng, Rng } ;
819
822
820
823
#[ test]
821
824
fn test_per_commitment_storage ( ) {
@@ -1170,6 +1173,7 @@ mod tests {
1170
1173
"Previous secret did not match new one" ) ;
1171
1174
}
1172
1175
}
1176
+ // pub gen_rn_tx
1173
1177
1174
1178
#[ test]
1175
1179
fn test_prune_preimages ( ) {
@@ -1178,36 +1182,40 @@ mod tests {
1178
1182
let secp_ctx = Secp256k1 :: new ( ) ;
1179
1183
let mut preimage : Vec < [ u8 ; 32 ] > = Vec :: new ( ) ;
1180
1184
let mut hash : Vec < [ u8 ; 32 ] > = Vec :: new ( ) ;
1185
+ let mut rng = thread_rng ( ) ;
1181
1186
1182
1187
monitor = ChannelMonitor :: new ( & SecretKey :: from_slice ( & secp_ctx, & [ 42 ; 32 ] ) . unwrap ( ) , & PublicKey :: new ( ) , & SecretKey :: from_slice ( & secp_ctx, & [ 43 ; 32 ] ) . unwrap ( ) , 0 , Script :: new ( ) ) ;
1183
-
1184
- //
1185
1188
preimage. push ( [ 0 ; 32 ] ) ;
1186
1189
hash. push ( [ 0 ; 32 ] ) ;
1187
- preimage. last_mut ( ) . unwrap ( ) [ 0 ..32 ] . clone_from_slice ( & hex_bytes ( "7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc" ) . unwrap ( ) ) ;
1188
- hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1189
- monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1190
-
1191
- preimage. last_mut ( ) . unwrap ( ) [ 0 ..32 ] . clone_from_slice ( & hex_bytes ( "c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964" ) . unwrap ( ) ) ;
1192
- hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1193
- monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1194
-
1195
- preimage. last_mut ( ) . unwrap ( ) [ 0 ..32 ] . clone_from_slice ( & hex_bytes ( "2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8" ) . unwrap ( ) ) ;
1196
- hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1197
- monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1198
1190
1199
- preimage. last_mut ( ) . unwrap ( ) [ 0 ..32 ] . clone_from_slice ( & hex_bytes ( "27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116" ) . unwrap ( ) ) ;
1200
- hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1201
- monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1191
+ // should use rng.fill byutes for hash
1192
+ for i in 0 ..100 {
1193
+ rng. fill_bytes ( preimage. last_mut ( ) . unwrap ( ) ) ;
1194
+ hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1195
+ monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1196
+ }
1202
1197
1203
- preimage. last_mut ( ) . unwrap ( ) [ 0 ..32 ] . clone_from_slice ( & hex_bytes ( "a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32" ) . unwrap ( ) ) ;
1204
- hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1205
- monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1198
+ monitor. current_local_signed_commitment_tx = gen_rn_tx ( ) ;
1199
+ //monitor.current_local_signed_commitment_tx = Some(LocalSignedTx {
1200
+ // txid: Default:default();
1201
+ // tx: None,
1202
+ // revocation_key: None,
1203
+ // a_htlc_key: None,
1204
+ // b_htlc_key: None,
1205
+ // delayed_payment_key: None,
1206
+ // feerate_per_kw: 0,
1207
+ // htlc_outputs: None, //HTLCOutputInCommitment {
1208
+ // // payment_hash: hash.clone()
1209
+ // //}
1210
+ //});
1206
1211
1207
1212
monitor. provide_secret ( 0 , [ 0 ; 32 ] , None ) ;
1208
- // #1 5 preimages : 2 commit tx
1209
- // #2 5 preimages : remote commit tx
1210
- // #3 5 preimages : local commit tx
1213
+ // #1 5 preimages : 2 commit tx, 5 htlc each
1214
+ // #2 5 preimages : remote commit tx, 3 htlc
1215
+ // #3 5 preimages : local commit tx, 3 htlc
1216
+ // #4 30 preimages : all
1217
+
1218
+ //assert_eq!
1211
1219
}
1212
1220
1213
1221
0 commit comments