Skip to content

Commit 7e96793

Browse files
author
Antoine Riard
committed
test_prune_image uncomplete lightningdevkit#2
1 parent cbd5a1c commit 7e96793

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

src/ln/channelmonitor.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,11 @@ mod tests {
814814
use bitcoin::blockdata::script::Script;
815815
use bitcoin::util::hash::Hash160;
816816
use ln::channelmonitor::ChannelMonitor;
817+
use ln::channelmonitor::LocalSignedTx;
818+
use ln::chan_utils::HTLCOutputInCommitment;
817819
use secp256k1::key::{SecretKey,PublicKey};
818820
use secp256k1::Secp256k1;
821+
use rand::{thread_rng,Rng};
819822

820823
#[test]
821824
fn test_per_commitment_storage() {
@@ -1170,6 +1173,7 @@ mod tests {
11701173
"Previous secret did not match new one");
11711174
}
11721175
}
1176+
// pub gen_rn_tx
11731177

11741178
#[test]
11751179
fn test_prune_preimages() {
@@ -1178,36 +1182,40 @@ mod tests {
11781182
let secp_ctx = Secp256k1::new();
11791183
let mut preimage : Vec<[u8; 32]> = Vec::new();
11801184
let mut hash : Vec<[u8;32]> = Vec::new();
1185+
let mut rng = thread_rng();
11811186

11821187
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-
//
11851188
preimage.push([0;32]);
11861189
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());
11981190

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+
}
12021197

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+
//});
12061211

12071212
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!
12111219
}
12121220

12131221

0 commit comments

Comments
 (0)