Skip to content

Commit

Permalink
add unit tests for remove zeta amount
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Feb 8, 2024
1 parent 191f876 commit 2e3943d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions x/crosschain/keeper/zeta_accounting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit 2e3943d

Please sign in to comment.