Skip to content

Commit 630c9aa

Browse files
author
Antoine Riard
committed
test prune_payment_preimages uncomplte lightningdevkit#3
1 parent 7e96793 commit 630c9aa

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

src/ln/channelmonitor.rs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -812,12 +812,13 @@ impl ChannelMonitor {
812812
mod tests {
813813
use bitcoin::util::misc::hex_bytes;
814814
use bitcoin::blockdata::script::Script;
815-
use bitcoin::util::hash::Hash160;
815+
use bitcoin::util::hash::{Hash160,Sha256dHash};
816+
use bitcoin::blockdata::transaction::Transaction;
816817
use ln::channelmonitor::ChannelMonitor;
817818
use ln::channelmonitor::LocalSignedTx;
818819
use ln::chan_utils::HTLCOutputInCommitment;
819820
use secp256k1::key::{SecretKey,PublicKey};
820-
use secp256k1::Secp256k1;
821+
use secp256k1::{Secp256k1, Signature};
821822
use rand::{thread_rng,Rng};
822823

823824
#[test]
@@ -1173,7 +1174,30 @@ mod tests {
11731174
"Previous secret did not match new one");
11741175
}
11751176
}
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+
}
11771201

11781202
#[test]
11791203
fn test_prune_preimages() {
@@ -1188,28 +1212,23 @@ mod tests {
11881212
preimage.push([0;32]);
11891213
hash.push([0;32]);
11901214

1191-
// should use rng.fill byutes for hash
1192-
for i in 0..100 {
1215+
for _i in 0..100 {
11931216
rng.fill_bytes(preimage.last_mut().unwrap());
11941217
hash.last_mut().unwrap()[0..20].clone_from_slice(&Hash160::from_data(preimage.last_mut().unwrap())[0..20]);
11951218
monitor.provide_payment_preimage(hash.last_mut().unwrap(), preimage.last_mut().unwrap());
11961219
}
11971220

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);
12131232
// #1 5 preimages : 2 commit tx, 5 htlc each
12141233
// #2 5 preimages : remote commit tx, 3 htlc
12151234
// #3 5 preimages : local commit tx, 3 htlc

0 commit comments

Comments
 (0)