Skip to content

Commit

Permalink
Add fee check to v2_splice_in test
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Apr 24, 2024
1 parent c5c9e59 commit fd22952
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lightning/src/ln/functional_tests_splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,13 @@ fn test_channel_open_v2_and_close() {
let total_output = broadcasted_funding_tx.output[0].value + broadcasted_funding_tx.output[1].value;
assert!(total_input > total_output);
let fee = total_input - total_output;
let fee_rate = chanmon_cfgs[0].fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee); // target is irrelevant
assert_eq!(fee_rate, 253);
let target_fee_rate = chanmon_cfgs[0].fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee); // target is irrelevant
assert_eq!(target_fee_rate, 253);
assert_eq!(broadcasted_funding_tx.weight().to_wu(), 576);
let expected_minimum_fee = (broadcasted_funding_tx.weight().to_wu() as f64 * fee_rate as f64 / 1000 as f64).ceil() as u64;
let expected_minimum_fee = (broadcasted_funding_tx.weight().to_wu() as f64 * target_fee_rate as f64 / 1000 as f64).ceil() as u64;
let expected_maximum_fee = expected_minimum_fee * 3;
assert!(fee >= expected_minimum_fee);
assert!(fee <= expected_maximum_fee);

// Simulate confirmation of the funding tx
confirm_transaction(&initiator_node, &broadcasted_funding_tx);
Expand Down Expand Up @@ -1128,6 +1130,22 @@ fn test_v2_splice_in() {
assert_eq!(broadcasted_splice_tx_acc.encode().len(), 389);
assert_eq!(broadcasted_splice_tx_acc.encode().as_hex().to_string(), expected_funding_tx);

println!("{:?}", broadcasted_splice_tx); // TODO remove

// check fees
let total_input = channel_value_sat + extra_splice_funding_input_sats;
assert_eq!(broadcasted_splice_tx.output.len(), 2);
let total_output = broadcasted_splice_tx.output[0].value + broadcasted_splice_tx.output[1].value;
assert!(total_input > total_output);
let fee = total_input - total_output;
let target_fee_rate = chanmon_cfgs[0].fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee); // target is irrelevant
assert_eq!(target_fee_rate, 253);
assert_eq!(broadcasted_splice_tx.weight().to_wu(), 887);
let expected_minimum_fee = (broadcasted_splice_tx.weight().to_wu() as f64 * target_fee_rate as f64 / 1000 as f64).ceil() as u64;
let expected_maximum_fee = expected_minimum_fee * 5; // TODO lower tolerance, e.g. 3
assert!(fee >= expected_minimum_fee);
assert!(fee <= expected_maximum_fee);

// Simulate confirmation of the funding tx
confirm_transaction(&initiator_node, &broadcasted_splice_tx);
let channel_ready_message = get_event_msg!(initiator_node, MessageSendEvent::SendChannelReady, acceptor_node.node.get_our_node_id());
Expand Down

0 comments on commit fd22952

Please sign in to comment.