@@ -812,12 +812,13 @@ impl ChannelMonitor {
812
812
mod tests {
813
813
use bitcoin:: util:: misc:: hex_bytes;
814
814
use bitcoin:: blockdata:: script:: Script ;
815
- use bitcoin:: util:: hash:: Hash160 ;
815
+ use bitcoin:: util:: hash:: { Hash160 , Sha256dHash } ;
816
+ use bitcoin:: blockdata:: transaction:: Transaction ;
816
817
use ln:: channelmonitor:: ChannelMonitor ;
817
818
use ln:: channelmonitor:: LocalSignedTx ;
818
819
use ln:: chan_utils:: HTLCOutputInCommitment ;
819
820
use secp256k1:: key:: { SecretKey , PublicKey } ;
820
- use secp256k1:: Secp256k1 ;
821
+ use secp256k1:: { Secp256k1 , Signature } ;
821
822
use rand:: { thread_rng, Rng } ;
822
823
823
824
#[ test]
@@ -1173,7 +1174,30 @@ mod tests {
1173
1174
"Previous secret did not match new one" ) ;
1174
1175
}
1175
1176
}
1176
- // pub gen_rn_tx
1177
+
1178
+ fn gen_zeroed_local_signed_tx ( hash : & [ u8 ; 32 ] ) -> Option < LocalSignedTx > {
1179
+ Some ( LocalSignedTx {
1180
+ txid : Sha256dHash :: from_data ( & [ ] ) ,
1181
+ tx : Transaction {
1182
+ version : 0 ,
1183
+ lock_time : 0 ,
1184
+ input : Vec :: new ( ) ,
1185
+ output : Vec :: new ( ) ,
1186
+ } ,
1187
+ revocation_key : PublicKey :: new ( ) ,
1188
+ a_htlc_key : PublicKey :: new ( ) ,
1189
+ b_htlc_key : PublicKey :: new ( ) ,
1190
+ delayed_payment_key : PublicKey :: new ( ) ,
1191
+ feerate_per_kw : 0 ,
1192
+ htlc_outputs : vec ! [ ( HTLCOutputInCommitment {
1193
+ offered : true ,
1194
+ amount_msat: 0 ,
1195
+ cltv_expiry : 0 ,
1196
+ payment_hash : hash. clone( ) ,
1197
+ transaction_output_index : 0 ,
1198
+ } , Signature :: from_der( & Secp256k1 :: new( ) , & [ ] ) . unwrap( ) , Signature :: from_der( & Secp256k1 :: new( ) , & [ ] ) . unwrap( ) ) ] ,
1199
+ } )
1200
+ }
1177
1201
1178
1202
#[ test]
1179
1203
fn test_prune_preimages ( ) {
@@ -1188,28 +1212,23 @@ mod tests {
1188
1212
preimage. push ( [ 0 ; 32 ] ) ;
1189
1213
hash. push ( [ 0 ; 32 ] ) ;
1190
1214
1191
- // should use rng.fill byutes for hash
1192
- for i in 0 ..100 {
1215
+ for _i in 0 ..100 {
1193
1216
rng. fill_bytes ( preimage. last_mut ( ) . unwrap ( ) ) ;
1194
1217
hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1195
1218
monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1196
1219
}
1197
1220
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
- //});
1211
-
1212
- monitor. provide_secret ( 0 , [ 0 ; 32 ] , None ) ;
1221
+ // signatures are falses
1222
+ rng. fill_bytes ( preimage. last_mut ( ) . unwrap ( ) ) ;
1223
+ hash. last_mut ( ) . unwrap ( ) [ 0 ..20 ] . clone_from_slice ( & Hash160 :: from_data ( preimage. last_mut ( ) . unwrap ( ) ) [ 0 ..20 ] ) ;
1224
+ monitor. provide_payment_preimage ( hash. last_mut ( ) . unwrap ( ) , preimage. last_mut ( ) . unwrap ( ) ) ;
1225
+ monitor. current_local_signed_commitment_tx = gen_zeroed_local_signed_tx ( hash. last_mut ( ) . unwrap ( ) ) ;
1226
+ //remote_claimable_outpoints
1227
+ // provide valid signatures + monitor.payment_preimages.keys().next().unwrap()
1228
+ // macro rules for both gen_tx + gen_htlcoutputs
1229
+ // managed this assert_eq!
1230
+
1231
+ //monitor.provide_secret(0, [0;32], None);
1213
1232
// #1 5 preimages : 2 commit tx, 5 htlc each
1214
1233
// #2 5 preimages : remote commit tx, 3 htlc
1215
1234
// #3 5 preimages : local commit tx, 3 htlc
0 commit comments