-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for aborted zeta amount keeper functions
- Loading branch information
Showing
9 changed files
with
186 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/spf13/cobra" | ||
"github.com/zeta-chain/zetacore/x/crosschain/types" | ||
) | ||
|
||
func CmdGetAbortedZetaAmount() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get-aborted-zeta-amount", | ||
Short: "Query current tss address", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
params := &types.QueryAbortedZetaAmountRequest{} | ||
res, err := queryClient.AbortedZetaAmount(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
flags.AddQueryFlagsToCmd(cmd) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
"github.com/stretchr/testify/require" | ||
keepertest "github.com/zeta-chain/zetacore/testutil/keeper" | ||
"github.com/zeta-chain/zetacore/x/crosschain/types" | ||
) | ||
|
||
func TestKeeper_AddAbortedZetaAmount(t *testing.T) { | ||
|
||
t.Run("should add aborted zeta amount", func(t *testing.T) { | ||
k, ctx, _, _ := keepertest.CrosschainKeeper(t) | ||
originalAmount := sdkmath.NewUint(rand.Uint64()) | ||
k.SetAbortedZetaAmount(ctx, types.AbortedZetaAmount{ | ||
originalAmount, | ||
}) | ||
val, found := k.GetAbortedZetaAmount(ctx) | ||
require.True(t, found) | ||
require.Equal(t, originalAmount, val.Amount) | ||
addAmount := sdkmath.NewUint(rand.Uint64()) | ||
k.AddAbortedZetaAmount(ctx, addAmount) | ||
val, found = k.GetAbortedZetaAmount(ctx) | ||
require.True(t, found) | ||
require.Equal(t, originalAmount.Add(addAmount), val.Amount) | ||
}) | ||
|
||
t.Run("cant find aborted amount", func(t *testing.T) { | ||
k, ctx, _, _ := keepertest.CrosschainKeeper(t) | ||
val, found := k.GetAbortedZetaAmount(ctx) | ||
require.False(t, found) | ||
require.Equal(t, types.AbortedZetaAmount{}, val) | ||
}) | ||
|
||
t.Run("add very high zeta amount", func(t *testing.T) { | ||
k, ctx, _, _ := keepertest.CrosschainKeeper(t) | ||
highAmount := sdkmath.NewUintFromString("100000000000000000000000000000000000000000000000") | ||
k.SetAbortedZetaAmount(ctx, types.AbortedZetaAmount{ | ||
highAmount, | ||
}) | ||
val, found := k.GetAbortedZetaAmount(ctx) | ||
require.True(t, found) | ||
require.Equal(t, highAmount, val.Amount) | ||
}) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters