@@ -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
@@ -501,11 +512,14 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
501
512
let node_b_htlc_claimable = nodes[ 1 ] . best_block_info ( ) . 1 + BREAKDOWN_TIMEOUT as u32 ;
502
513
mine_transaction ( & nodes[ 1 ] , & b_broadcast_txn[ 0 ] ) ;
503
514
515
+ fuzzy_assert_eq ( b_broadcast_txn[ 0 ] . output [ 0 ] . value ,
516
+ 3_000 - chan_feerate * b_broadcast_txn[ 0 ] . weight ( ) as u64 / 1_000 ) ;
517
+
504
518
assert_eq ! ( sorted_vec( vec![ Balance :: ClaimableAwaitingConfirmations {
505
519
claimable_amount_satoshis: 1_000 ,
506
520
confirmation_height: node_b_commitment_claimable,
507
521
} , Balance :: ClaimableAwaitingConfirmations {
508
- claimable_amount_satoshis: 3_000 ,
522
+ claimable_amount_satoshis: b_broadcast_txn [ 0 ] . output [ 0 ] . value ,
509
523
confirmation_height: node_b_htlc_claimable,
510
524
} , Balance :: ContentiousClaimable {
511
525
claimable_amount_satoshis: 4_000 ,
@@ -519,7 +533,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
519
533
test_spendable_output ( & nodes[ 1 ] , & remote_txn[ 0 ] ) ;
520
534
521
535
assert_eq ! ( sorted_vec( vec![ Balance :: ClaimableAwaitingConfirmations {
522
- claimable_amount_satoshis: 3_000 ,
536
+ claimable_amount_satoshis: b_broadcast_txn [ 0 ] . output [ 0 ] . value ,
523
537
confirmation_height: node_b_htlc_claimable,
524
538
} , Balance :: ContentiousClaimable {
525
539
claimable_amount_satoshis: 4_000 ,
0 commit comments