@@ -1481,4 +1481,82 @@ mod tests {
14811481 assert_eq ! ( out. accepted_event, 5 ) ;
14821482 assert_eq ! ( out. remaining, 0 ) ;
14831483 }
1484+
1485+ #[ rstest]
1486+ fn stop_and_exit_payout_refunds_and_idle (
1487+ mut c : Contract ,
1488+ owner : AccountId ,
1489+ receiver : AccountId ,
1490+ ) {
1491+ use near_sdk_contract_tools:: ft:: Nep141Controller as _;
1492+ let escrow: u128 = 10 ;
1493+
1494+ // Seed escrowed shares into the vault's own account
1495+ c. deposit_unchecked ( & near_sdk:: env:: current_account_id ( ) , escrow)
1496+ . unwrap_or_else ( |e| near_sdk:: env:: panic_str ( & e. to_string ( ) ) ) ;
1497+
1498+ // Enter Payout with non-zero escrow
1499+ c. op_state = OpState :: Payout {
1500+ op_id : 123 ,
1501+ receiver : receiver. clone ( ) ,
1502+ amount : 77 ,
1503+ owner : owner. clone ( ) ,
1504+ escrow_shares : escrow,
1505+ burn_shares : escrow,
1506+ } ;
1507+
1508+ let supply_before = c. total_supply ( ) ;
1509+ let vault_before = c. balance_of ( & near_sdk:: env:: current_account_id ( ) ) ;
1510+ let owner_before = c. balance_of ( & owner) ;
1511+ let idle_before = c. idle_balance ;
1512+
1513+ c. stop_and_exit_payout :: < & str > ( Some ( & "reason" ) ) ;
1514+
1515+ // Escrow refunded, no burn, vault goes Idle
1516+ assert ! ( matches!( c. op_state, OpState :: Idle ) ) ;
1517+ assert_eq ! ( c. total_supply( ) , supply_before, "No burn/mint on stop" ) ;
1518+ assert_eq ! (
1519+ c. balance_of( & near_sdk:: env:: current_account_id( ) ) ,
1520+ vault_before. saturating_sub( escrow) ,
1521+ "Vault should transfer escrow to owner"
1522+ ) ;
1523+ assert_eq ! (
1524+ c. balance_of( & owner) ,
1525+ owner_before. saturating_add( escrow) ,
1526+ "Owner should receive escrow refund"
1527+ ) ;
1528+ assert_eq ! ( c. idle_balance, idle_before, "Idle balance unchanged" ) ;
1529+ }
1530+
1531+ #[ rstest]
1532+ fn stop_and_exit_payout_zero_escrow_just_idle (
1533+ mut c : Contract ,
1534+ owner : AccountId ,
1535+ receiver : AccountId ,
1536+ ) {
1537+ // Enter Payout with zero escrow; no transfers should occur
1538+ c. op_state = OpState :: Payout {
1539+ op_id : 7 ,
1540+ receiver,
1541+ amount : 1 ,
1542+ owner : owner. clone ( ) ,
1543+ escrow_shares : 0 ,
1544+ burn_shares : 0 ,
1545+ } ;
1546+
1547+ let supply_before = c. total_supply ( ) ;
1548+ let vault_before = c. balance_of ( & near_sdk:: env:: current_account_id ( ) ) ;
1549+ let owner_before = c. balance_of ( & owner) ;
1550+
1551+ c. stop_and_exit_payout :: < & str > ( None ) ;
1552+
1553+ assert ! ( matches!( c. op_state, OpState :: Idle ) ) ;
1554+ assert_eq ! ( c. total_supply( ) , supply_before, "No supply change" ) ;
1555+ assert_eq ! (
1556+ c. balance_of( & near_sdk:: env:: current_account_id( ) ) ,
1557+ vault_before,
1558+ "Vault balance unchanged"
1559+ ) ;
1560+ assert_eq ! ( c. balance_of( & owner) , owner_before, "Owner balance unchanged" ) ;
1561+ }
14841562}
0 commit comments