diff --git a/go/cli/crisis_tx_test.go b/go/cli/crisis_tx_test.go new file mode 100644 index 00000000..7f4363d6 --- /dev/null +++ b/go/cli/crisis_tx_test.go @@ -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) + } + }) + } +}