@@ -228,6 +228,17 @@ fn sorted_vec<T: Ord>(mut v: Vec<T>) -> Vec<T> {
228
228
v
229
229
}
230
230
231
+ /// Asserts that `a` and `b` are close, but maybe off by up to 5.
232
+ /// This is useful when checking fees and weights on transactions as things may vary by a few based
233
+ /// on signature size and signature size estimation being non-exact.
234
+ fn fuzzy_assert_eq < V : core:: convert:: TryInto < u64 > > ( a : V , b : V ) {
235
+ let a_u64 = a. try_into ( ) . map_err ( |_| ( ) ) . unwrap ( ) ;
236
+ let b_u64 = b. try_into ( ) . map_err ( |_| ( ) ) . unwrap ( ) ;
237
+ eprintln ! ( "Checking {} and {} for fuzzy equality" , a_u64, b_u64) ;
238
+ assert ! ( a_u64 >= b_u64 - 5 ) ;
239
+ assert ! ( b_u64 >= a_u64 - 5 ) ;
240
+ }
241
+
231
242
fn do_test_claim_value_force_close ( prev_commitment_tx : bool ) {
232
243
// Tests `get_claimable_balances` with an HTLC across a force-close.
233
244
// We build a channel with an HTLC pending, then force close the channel and check that the
@@ -496,11 +507,14 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
496
507
let node_b_htlc_claimable = nodes[ 1 ] . best_block_info ( ) . 1 + BREAKDOWN_TIMEOUT as u32 ;
497
508
mine_transaction ( & nodes[ 1 ] , & b_broadcast_txn[ 0 ] ) ;
498
509
510
+ fuzzy_assert_eq ( b_broadcast_txn[ 0 ] . output [ 0 ] . value ,
511
+ 3_000 - chan_feerate * b_broadcast_txn[ 0 ] . weight ( ) as u64 / 1_000 ) ;
512
+
499
513
assert_eq ! ( sorted_vec( vec![ Balance :: ClaimableAwaitingConfirmations {
500
514
claimable_amount_satoshis: 1_000 ,
501
515
confirmation_height: node_b_commitment_claimable,
502
516
} , Balance :: ClaimableAwaitingConfirmations {
503
- claimable_amount_satoshis: 3_000 ,
517
+ claimable_amount_satoshis: b_broadcast_txn [ 0 ] . output [ 0 ] . value ,
504
518
confirmation_height: node_b_htlc_claimable,
505
519
} , Balance :: ContentiousClaimable {
506
520
claimable_amount_satoshis: 4_000 ,
@@ -514,7 +528,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
514
528
test_spendable_output ( & nodes[ 1 ] , & remote_txn[ 0 ] ) ;
515
529
516
530
assert_eq ! ( sorted_vec( vec![ Balance :: ClaimableAwaitingConfirmations {
517
- claimable_amount_satoshis: 3_000 ,
531
+ claimable_amount_satoshis: b_broadcast_txn [ 0 ] . output [ 0 ] . value ,
518
532
confirmation_height: node_b_htlc_claimable,
519
533
} , Balance :: ContentiousClaimable {
520
534
claimable_amount_satoshis: 4_000 ,
0 commit comments