@@ -732,7 +732,7 @@ impl SimulationResult {
732732 self . total_payment_obligations
733733 }
734734
735- pub fn precentage_of_payment_obligations_missed ( & self ) -> f64 {
735+ pub fn percentage_of_payment_obligations_missed ( & self ) -> f64 {
736736 let total_payment_obligations = self . total_payment_obligations ( ) ;
737737 self . missed_payment_obligations
738738 . iter ( )
@@ -786,22 +786,20 @@ mod tests {
786786 let result = sim. run ( ) ;
787787 sim. assert_invariants ( ) ;
788788
789- println ! ( "{}" , sim) ;
790- result. save_tx_graph ( "graph.svg" ) ;
791- // Lets check the simulation state after the run
792- // Specifically how many payment obligations we're missed
793- // And how many were created in a cospend
794- println ! (
795- "Total payment obligations: {}" ,
796- result. total_payment_obligations( )
789+ // Assert simulation completed successfully
790+ assert ! (
791+ result. total_payment_obligations( ) > 0 ,
792+ "Simulation should create payment obligations"
797793 ) ;
798- println ! (
799- "Missed payment obligations: {:?}" ,
800- result . missed_payment_obligations
794+ assert ! (
795+ result . percentage_of_payment_obligations_missed ( ) < 1.0 ,
796+ "Not all obligations should be missed"
801797 ) ;
802- println ! (
803- "Missed payment obligations percentage: {:?}" ,
804- result. precentage_of_payment_obligations_missed( )
798+
799+ assert_eq ! (
800+ result. percentage_of_payment_obligations_missed( ) ,
801+ 0.5384615384615384 ,
802+ "With seed 42, missed percentage should be deterministic"
805803 ) ;
806804 }
807805
@@ -983,8 +981,33 @@ mod tests {
983981
984982 assert ! ( bob. with( & sim) . info( ) . received_transactions. contains( & spend) ) ;
985983
986- // TODO mine another block, check wallet utxos, et
984+ // Mine another block to confirm the transaction
985+ let miner_addr = alice. with_mut ( & mut sim) . new_address ( ) ;
986+ let block_bx = BroadcastSetHandleMut {
987+ id : BroadcastSetId ( sim. broadcast_set_data . len ( ) - 1 ) ,
988+ sim : & mut sim,
989+ } ;
990+
991+ let _block = block_bx
992+ . construct_block_template ( Weight :: MAX_BLOCK )
993+ . mine ( miner_addr, & mut sim) ;
994+
995+ sim. assert_invariants ( ) ;
987996
988- println ! ( "{:?}" , sim) ;
997+ // Verify transaction is now confirmed and UTXOs are updated
998+ assert ! ( alice
999+ . with( & sim)
1000+ . info( )
1001+ . confirmed_utxos
1002+ . contains( & spend. with( & sim) . outpoints( ) . nth( 1 ) . unwrap( ) ) ) ;
1003+ assert ! ( bob
1004+ . with( & sim)
1005+ . info( )
1006+ . confirmed_utxos
1007+ . contains( & spend. with( & sim) . outpoints( ) . nth( 0 ) . unwrap( ) ) ) ;
1008+
1009+ // Verify the spend transaction is no longer unconfirmed
1010+ assert ! ( alice. with( & sim) . info( ) . unconfirmed_txos. is_empty( ) ) ;
1011+ assert ! ( bob. with( & sim) . info( ) . unconfirmed_txos. is_empty( ) ) ;
9891012 }
9901013}
0 commit comments