Skip to content

Commit

Permalink
feat(go/cli): add crisis tests
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Sep 9, 2024
1 parent 79de572 commit 47faeed
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions go/cli/crisis_tx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package cli_test

import (
"context"
"io"
"testing"

sdkmath "cosmossdk.io/math"
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/crisis"

"pkg.akt.dev/go/cli"
cflags "pkg.akt.dev/go/cli/flags"
clitestutil "pkg.akt.dev/go/cli/testutil"
)

func TestNewMsgVerifyInvariantTxCmd(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(crisis.AppModuleBasic{})
kr := keyring.NewInMemory(encCfg.Codec)
baseCtx := client.Context{}.
WithKeyring(kr).
WithTxConfig(encCfg.TxConfig).
WithCodec(encCfg.Codec).
WithLegacyAmino(encCfg.Amino).
WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}).
WithAccountRetriever(client.MockAccountRetriever{}).
WithOutput(io.Discard).
WithChainID("test-chain").
WithSignModeStr(cflags.SignModeDirect)

accounts := testutil.CreateKeyringAccounts(t, kr, 1)
testCases := []struct {
name string
args []string
expectErr bool
errString string
expectedCode uint32
}{
{
"missing module",
cli.TestFlags().
With(
"",
"total-supply",
).
WithFrom(accounts[0].Address.String()).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10)))),
true, "invalid module name", 0,
},
{
"missing invariant route",
cli.TestFlags().
With(
"bank",
"",
).
WithFrom(accounts[0].Address.String()).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10)))),
true, "invalid invariant route", 0,
},
{
"valid transaction",
cli.TestFlags().
With(
"bank",
"total-supply",
).
WithFrom(accounts[0].Address.String()).
WithSkipConfirm().
WithBroadcastModeSync().
WithFees(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10)))),
false, "", 0,
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
cmd := cli.GetTxCrisisVerifyInvariantTxCmd()

_, err := clitestutil.ExecTestCLICmd(context.Background(), baseCtx, cmd, tc.args...)
if tc.expectErr {
require.Error(t, err)
require.Contains(t, err.Error(), tc.errString)
} else {
require.NoError(t, err)
}
})
}
}

0 comments on commit 47faeed

Please sign in to comment.