@@ -467,167 +467,6 @@ pub fn fund_taproot_taker(
467467 balances. spendable
468468}
469469
470- /// Verifies the results of a coinswap for the taker and makers after performing a swap.
471- #[ allow( dead_code) ]
472- pub fn verify_swap_results (
473- taker : & Taker ,
474- makers : & [ Arc < Maker > ] ,
475- org_taker_spend_balance : Amount ,
476- org_maker_spend_balances : Vec < Amount > ,
477- ) {
478- // Check Taker balances
479- {
480- let wallet = taker. get_wallet ( ) ;
481- let balances = wallet. get_balances ( ) . unwrap ( ) ;
482-
483- // Debug logging for taker
484- log:: info!(
485- "🔍 DEBUG Taker - Regular: {}, Swap: {}, Spendable: {}" ,
486- balances. regular. to_btc( ) ,
487- balances. swap. to_btc( ) ,
488- balances. spendable. to_btc( )
489- ) ;
490- assert_in_range ! (
491- balances. regular. to_sat( ) ,
492- [
493- 14499696 , // Successful coinswap
494- 14999142 , // Recovery via timelock (abort2_case 1, 2, 3)(abort3_case 1, 2)
495- 14940090 , // Recovery via Hashlock
496- 15000000 , // No spending
497- ] ,
498- "Taker seed balance mismatch"
499- ) ;
500-
501- assert_in_range ! (
502- balances. swap. to_sat( ) ,
503- [
504- 443633 , // Successful coinswap
505- 442714 , // Recovery via timelock
506- 0 , // Unsuccessful coinswap (abort2_case 1, 2, 3)(abort3_case 1, 2)
507- 443339 , // Recovery via hashlock
508- ] ,
509- "Taker swapcoin balance mismatch"
510- ) ;
511-
512- assert_in_range ! ( balances. contract. to_sat( ) , [ 0 ] , "Contract balance mismatch" ) ;
513- assert_eq ! ( balances. fidelity, Amount :: ZERO ) ;
514-
515- // Check balance difference
516- let balance_diff = org_taker_spend_balance
517- . checked_sub ( balances. spendable )
518- . unwrap ( ) ;
519-
520- log:: info!(
521- "🔍 DEBUG Taker balance diff: {} sats" ,
522- balance_diff. to_sat( )
523- ) ;
524-
525- assert_in_range ! (
526- balance_diff. to_sat( ) ,
527- [
528- 56671 , // Successful coinswap
529- 56965 , // Recovery via timelock
530- 500304 , // Spent swapcoin
531- 858 , // Recovery via timelock (new fee system) (abort2_case 1, 2, 3)(abort3_case 1, 2)
532- 59910 , // Recovery via Hashlock (abort3_case3)
533- 500912 , // Recovery via Hashlock(abort3_case1)
534- 0 // No spending
535- ] ,
536- "Taker spendable balance change mismatch"
537- ) ;
538- }
539-
540- // Check Maker balances
541- makers
542- . iter ( )
543- . zip ( org_maker_spend_balances. iter ( ) )
544- . enumerate ( )
545- . for_each ( |( maker_index, ( maker, org_spend_balance) ) | {
546- let mut wallet = maker. get_wallet ( ) . write ( ) . unwrap ( ) ;
547- wallet. sync_and_save ( ) . unwrap ( ) ;
548- let balances = wallet. get_balances ( ) . unwrap ( ) ;
549-
550- // Debug logging for makers
551- log:: info!(
552- "🔍 DEBUG Maker {} - Regular: {}, Swap: {}, Contract: {}, Spendable: {}" ,
553- maker_index,
554- balances. regular. to_btc( ) ,
555- balances. swap. to_btc( ) ,
556- balances. contract. to_btc( ) ,
557- balances. spendable. to_btc( )
558- ) ;
559-
560- assert_in_range ! (
561- balances. regular. to_sat( ) ,
562- [
563- 14555287 , // First maker on successful coinswap
564- 14555285 , // First maker (with slight fee variance)
565- 14533002 , // Second maker on successful coinswap
566- 14532998 , // Second maker (with slight fee variance)
567- 14999500 , // No spending (abort2_case 2, 3)(abort3_case 1, 2)
568- 14999518 , // No spending (with slight fee variance)
569- 14998646 , // Recovery via timelock (abort2_case 1, 2)(abort3_case 1, 2)
570- 24999502 , // Multi-taker scenario
571- 14998642
572- ] ,
573- "Maker seed balance mismatch"
574- ) ;
575-
576- assert_in_range ! (
577- balances. swap. to_sat( ) ,
578- [
579- 465918 , // First maker
580- 499724 , // Second maker
581- 442712 , // Taker swap amount
582- 465624 , // One of the maker in recovery via hashlock (abort3_case3)
583- 0 , // No swap or funding tx missing + recovery via timelock (abort2_case 1, 2, 3)(abort3_case 1, 2)
584- ] ,
585- "Maker swapcoin balance mismatch"
586- ) ;
587-
588- assert_eq ! ( balances. fidelity, Amount :: from_btc( 0.05 ) . unwrap( ) ) ;
589-
590- //TODO-: Debug why in every test run malice2 test case gives different contract balance while recovering via hashlock
591- // Live contract balance can be non-zero, if a maker shuts down in middle of recovery.
592- /* assert!(
593- balances.contract == Amount::ZERO
594- || balances.contract == Amount::from_btc(0.00441812).unwrap() // Contract balance in recovery scenarios
595- );
596- */
597-
598- // Check spendable balance difference.
599- let balance_diff = match org_spend_balance. checked_sub ( balances. spendable ) {
600- None => balances. spendable . checked_sub ( * org_spend_balance) . unwrap ( ) , // Successful swap as Makers balance increase by Coinswap fee.
601- Some ( diff) => diff, // No spending or unsuccessful swap
602- } ;
603-
604- log:: info!(
605- "🔍 DEBUG Maker {} balance diff: {} sats" ,
606- maker_index,
607- balance_diff. to_sat( )
608- ) ;
609-
610- assert_in_range ! (
611- balance_diff. to_sat( ) ,
612- [
613- 21705 , // First maker fee
614- 33226 , // Second maker fee
615- 0 , // No Swap (abort2_case 1, 2, 3)(abort3_case 1, 2)
616- 858 , // Recovery via timelock (abort2_case 1, 2, 3)(abort3_case 1, 2)
617- 444213 , // Taker abort after setup - first maker recovery cost (abort1 test case)
618- 443624 , // Taker abort after setup - second maker recovery cost (abort1 test case)
619- 466498 , // Maker abort after setup(abort3_case3)
620- 410176 , // Multi-taker first maker (previous run)
621- 410118 , // Multi-taker first maker (current run)
622- 21411 // Recovery via hashlock (abort3_case3)
623- ] ,
624- "Maker spendable balance change mismatch"
625- ) ;
626- } ) ;
627-
628- log:: info!( "✅ Swap results verification complete" ) ;
629- }
630-
631470#[ allow( dead_code) ]
632471pub fn verify_maker_pre_swap_balances ( balances : & Balances , assert_regular_balance : u64 ) {
633472 assert_in_range ! (
0 commit comments