@@ -196,3 +196,42 @@ fn realize_yield_should_work_when_pending_unstakes_exist() {
196196 assert_eq ! ( yield_realized_amount( ALICE ) , Some ( 150 * ONE ) ) ;
197197 } ) ;
198198}
199+
200+ #[ test]
201+ fn realize_yield_should_reconcile_pure_gigahdx_when_no_pending_unstakes ( ) {
202+ // Reach the "GIGAHDX with zero underlying hdx AND no pending unstakes"
203+ // state: over-active partial unstake drains principal to 0, then `unlock`
204+ // after cooldown clears the pending position (record survives because
205+ // gigahdx > 0). realize_yield must still fold the full current value in.
206+ ExtBuilder :: default ( )
207+ . with_pot_balance ( 200 * ONE )
208+ . build ( )
209+ . execute_with ( || {
210+ assert_ok ! ( GigaHdx :: giga_stake( RawOrigin :: Signed ( ALICE ) . into( ) , 100 * ONE ) ) ;
211+ assert_ok ! ( GigaHdx :: giga_unstake( RawOrigin :: Signed ( ALICE ) . into( ) , 50 * ONE ) ) ;
212+
213+ let p = only_pending ( ALICE ) ;
214+ System :: set_block_number ( p. expires_at ) ;
215+ assert_ok ! ( GigaHdx :: unlock( RawOrigin :: Signed ( ALICE ) . into( ) , p. id) ) ;
216+
217+ // Pure GIGAHDX: no principal, no pending, record still alive.
218+ let s = Stakes :: < Test > :: get ( ALICE ) . unwrap ( ) ;
219+ assert_eq ! ( s. hdx, 0 ) ;
220+ assert_eq ! ( s. gigahdx, 50 * ONE ) ;
221+ assert_eq ! ( s. unstaking, 0 ) ;
222+ assert_eq ! ( s. unstaking_count, 0 ) ;
223+ assert_eq ! ( locked_under_ghdx( ALICE ) , 0 ) ;
224+
225+ assert_ok ! ( GigaHdx :: realize_yield( RawOrigin :: Signed ( ALICE ) . into( ) ) ) ;
226+
227+ let s = Stakes :: < Test > :: get ( ALICE ) . unwrap ( ) ;
228+ assert_eq ! ( s. gigahdx, 50 * ONE ) ; // unchanged
229+ assert_eq ! ( s. hdx, 150 * ONE ) ; // full current value folded in
230+ assert_eq ! ( s. unstaking, 0 ) ;
231+ assert_eq ! ( s. unstaking_count, 0 ) ;
232+ assert_eq ! ( TotalLocked :: <Test >:: get( ) , 150 * ONE ) ;
233+ assert_eq ! ( locked_under_ghdx( ALICE ) , 150 * ONE ) ;
234+ assert_eq ! ( gigapot_balance( ) , 0 ) ;
235+ assert_eq ! ( yield_realized_amount( ALICE ) , Some ( 150 * ONE ) ) ;
236+ } ) ;
237+ }
0 commit comments