diff --git a/x/crosschain/keeper/zeta_accounting_test.go b/x/crosschain/keeper/zeta_accounting_test.go index 1d5e1f7921..8a20b4ee4b 100644 --- a/x/crosschain/keeper/zeta_accounting_test.go +++ b/x/crosschain/keeper/zeta_accounting_test.go @@ -47,3 +47,43 @@ func TestKeeper_AddZetaAccounting(t *testing.T) { }) } + +func TestKeeper_RemoveZetaAbortedAmount(t *testing.T) { + t.Run("should remove aborted zeta amount", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeper(t) + originalAmount := sdkmath.NewUint(100) + k.SetZetaAccounting(ctx, types.ZetaAccounting{ + AbortedZetaAmount: originalAmount, + }) + val, found := k.GetZetaAccounting(ctx) + require.True(t, found) + require.Equal(t, originalAmount, val.AbortedZetaAmount) + removeAmount := originalAmount.Sub(sdkmath.NewUint(50)) + err := k.RemoveZetaAbortedAmount(ctx, removeAmount) + require.NoError(t, err) + val, found = k.GetZetaAccounting(ctx) + require.True(t, found) + require.Equal(t, originalAmount.Sub(removeAmount), val.AbortedZetaAmount) + }) + t.Run("fail remove aborted zeta amount if accounting not set", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeper(t) + err := k.RemoveZetaAbortedAmount(ctx, sdkmath.OneUint()) + require.ErrorIs(t, err, types.ErrUnableToFindZetaAccounting) + }) + t.Run("fail remove aborted zeta amount if insufficient amount", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeper(t) + originalAmount := sdkmath.NewUint(100) + k.SetZetaAccounting(ctx, types.ZetaAccounting{ + AbortedZetaAmount: originalAmount, + }) + val, found := k.GetZetaAccounting(ctx) + require.True(t, found) + require.Equal(t, originalAmount, val.AbortedZetaAmount) + removeAmount := originalAmount.Add(sdkmath.NewUint(500)) + err := k.RemoveZetaAbortedAmount(ctx, removeAmount) + require.ErrorIs(t, err, types.ErrInsufficientZetaAmount) + val, found = k.GetZetaAccounting(ctx) + require.True(t, found) + require.Equal(t, originalAmount, val.AbortedZetaAmount) + }) +}