diff --git a/tests/e2e/upgrade/client/testutil/cli_test.go b/tests/e2e/upgrade/cli_test.go similarity index 79% rename from tests/e2e/upgrade/client/testutil/cli_test.go rename to tests/e2e/upgrade/cli_test.go index 6e431b1378..e9f19e69c6 100644 --- a/tests/e2e/upgrade/client/testutil/cli_test.go +++ b/tests/e2e/upgrade/cli_test.go @@ -1,7 +1,7 @@ //go:build e2e // +build e2e -package testutil +package upgrade import ( "testing" @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/x/upgrade/client/testutil" ) func TestIntegrationTestSuite(t *testing.T) { @@ -24,5 +23,5 @@ func TestIntegrationTestSuite(t *testing.T) { app.UpgradeKeeper.SetVersionSetter(app.BaseApp) app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) - suite.Run(t, testutil.NewIntegrationTestSuite(cfg, app.UpgradeKeeper, ctx)) + suite.Run(t, NewIntegrationTestSuite(cfg, app.UpgradeKeeper, ctx)) } diff --git a/x/upgrade/client/testutil/suite.go b/tests/e2e/upgrade/suite.go similarity index 99% rename from x/upgrade/client/testutil/suite.go rename to tests/e2e/upgrade/suite.go index 37b356f4aa..59c463f1aa 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/tests/e2e/upgrade/suite.go @@ -1,4 +1,4 @@ -package testutil +package upgrade import ( "fmt" diff --git a/x/upgrade/client/cli/tx_test.go b/x/upgrade/client/cli/tx_test.go new file mode 100644 index 0000000000..0daf658ccd --- /dev/null +++ b/x/upgrade/client/cli/tx_test.go @@ -0,0 +1,111 @@ +package cli_test + +import ( + "context" + "fmt" + "io" + "testing" + + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/bytes" + tmcli "github.com/tendermint/tendermint/libs/cli" + rpcclient "github.com/tendermint/tendermint/rpc/client" + rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" + coretypes "github.com/tendermint/tendermint/rpc/core/types" + tmtypes "github.com/tendermint/tendermint/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" + svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/upgrade" + upgradecli "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" +) + +var _ client.TendermintRPC = (*mockTendermintRPC)(nil) + +type mockTendermintRPC struct { + rpcclientmock.Client + + responseQuery abci.ResponseQuery +} + +func (_ mockTendermintRPC) BroadcastTxCommit(_ context.Context, _ tmtypes.Tx) (*coretypes.ResultBroadcastTxCommit, error) { + return &coretypes.ResultBroadcastTxCommit{}, nil +} + +func (m mockTendermintRPC) ABCIQueryWithOptions( + _ context.Context, + _ string, _ bytes.HexBytes, + _ rpcclient.ABCIQueryOptions, +) (*coretypes.ResultABCIQuery, error) { + return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil +} + +func TestModuleVersionsCLI(t *testing.T) { + cmd := upgradecli.GetModuleVersionsCmd() + cmd.SetOut(io.Discard) + require.NotNil(t, cmd) + + encCfg := testutilmod.MakeTestEncodingConfig(upgrade.AppModuleBasic{}) + kr := keyring.NewInMemory(encCfg.Codec) + baseCtx := client.Context{}. + WithKeyring(kr). + WithTxConfig(encCfg.TxConfig). + WithCodec(encCfg.Codec). + WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithAccountRetriever(client.MockAccountRetriever{}). + WithOutput(io.Discard). + WithChainID("test-chain") + + testCases := []struct { + msg string + args []string + expCmdOuptut string + }{ + { + msg: "test full query with json output", + args: []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}, + expCmdOuptut: `--height=1 --output=json`, + }, + { + msg: "test full query with text output", + args: []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", tmcli.OutputFlag)}, + expCmdOuptut: `--height=1 --output=text`, + }, + { + msg: "test single module", + args: []string{"bank", fmt.Sprintf("--%s=1", flags.FlagHeight)}, + expCmdOuptut: `bank --height=1`, + }, + { + msg: "test non-existent module", + args: []string{"abcdefg", fmt.Sprintf("--%s=1", flags.FlagHeight)}, + expCmdOuptut: `abcdefg --height=1`, + }, + } + + for _, tc := range testCases { + tc := tc + + t.Run(tc.msg, func(t *testing.T) { + ctx := svrcmd.CreateExecuteContext(context.Background()) + + cmd.SetOut(io.Discard) + require.NotNil(t, cmd) + + cmd.SetContext(ctx) + cmd.SetArgs(tc.args) + + require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd)) + + if len(tc.args) != 0 { + require.Contains(t, fmt.Sprint(cmd), tc.expCmdOuptut) + } + }) + } + +}