Skip to content

Commit 883626f

Browse files
committed
Add unit test coverage for package::weight_received_htlc
1 parent a938df6 commit 883626f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lightning/src/chain/package.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ fn feerate_bump<F: Deref, L: Deref>(predicted_weight: usize, input_amounts: u64,
842842

843843
#[cfg(test)]
844844
mod tests {
845-
use chain::package::{CounterpartyReceivedHTLCOutput, HolderHTLCOutput, PackageTemplate, PackageSolvingData, RevokedOutput, WEIGHT_REVOKED_OUTPUT};
845+
use chain::package::{CounterpartyReceivedHTLCOutput, HolderHTLCOutput, PackageTemplate, PackageSolvingData, RevokedOutput, WEIGHT_REVOKED_OUTPUT, weight_received_htlc};
846846
use chain::Txid;
847847
use ln::chan_utils::HTLCOutputInCommitment;
848848
use ln::{PaymentPreimage, PaymentHash};
@@ -1042,13 +1042,25 @@ mod tests {
10421042
fn test_package_weight() {
10431043
let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
10441044
let secp_ctx = Secp256k1::new();
1045-
let revk_outp = dumb_revk_output!(secp_ctx);
10461045

1047-
let package = PackageTemplate::build_package(txid, 0, revk_outp, 0, true, 100);
1048-
// (nVersion (4) + nLocktime (4) + count_tx_in (1) + prevout (36) + sequence (4) + script_length (1) + count_tx_out (1) + value (8) + var_int (1)) * WITNESS_SCALE_FACTOR
1049-
// + witness marker (2) + WEIGHT_REVOKED_OUTPUT
1050-
for &opt_anchors in [false, true].iter() {
1051-
assert_eq!(package.package_weight(&Script::new(), opt_anchors), (4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1) * WITNESS_SCALE_FACTOR + 2 + WEIGHT_REVOKED_OUTPUT as usize);
1046+
{
1047+
let revk_outp = dumb_revk_output!(secp_ctx);
1048+
let package = PackageTemplate::build_package(txid, 0, revk_outp, 0, true, 100);
1049+
// (nVersion (4) + nLocktime (4) + count_tx_in (1) + prevout (36) + sequence (4) + script_length (1) + count_tx_out (1) + value (8) + var_int (1)) * WITNESS_SCALE_FACTOR
1050+
// + witness marker (2) + WEIGHT_REVOKED_OUTPUT
1051+
for &opt_anchors in [false, true].iter() {
1052+
assert_eq!(package.package_weight(&Script::new(), opt_anchors), (4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1) * WITNESS_SCALE_FACTOR + 2 + WEIGHT_REVOKED_OUTPUT as usize);
1053+
}
1054+
}
1055+
1056+
{
1057+
let counterparty_outp = dumb_counterparty_output!(secp_ctx, 1_000_000);
1058+
let package = PackageTemplate::build_package(txid, 0, counterparty_outp, 1000, true, 100);
1059+
// (nVersion (4) + nLocktime (4) + count_tx_in (1) + prevout (36) + sequence (4) + script_length (1) + count_tx_out (1) + value (8) + var_int (1)) * WITNESS_SCALE_FACTOR
1060+
// + witness marker (2) + weight_received_htlc(opt_anchors)
1061+
for &opt_anchors in [false, true].iter() {
1062+
assert_eq!(package.package_weight(&Script::new(), opt_anchors), (4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1) * WITNESS_SCALE_FACTOR + 2 + weight_received_htlc(opt_anchors) as usize);
1063+
}
10521064
}
10531065
}
10541066
}

0 commit comments

Comments
 (0)