feat(upgrade): autocli query support (backport #16903) (#16921)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
mergify[bot] 2023-07-11 13:39:40 +00:00 committed by GitHub
parent 5ca5039cf2
commit 3cc94a24f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 101 additions and 527 deletions

View File

@ -13,11 +13,11 @@ require (
cosmossdk.io/tools/confix v0.0.0-20230630152705-9f4a4e416f85
cosmossdk.io/tools/rosetta v0.2.1-0.20230614114324-f368ed5c62bc
cosmossdk.io/x/circuit v0.0.0-20230710134821-641c6a79f97c
cosmossdk.io/x/evidence v0.0.0-20230710135718-3bfd00f47bde
cosmossdk.io/x/feegrant v0.0.0-20230710134821-641c6a79f97c
cosmossdk.io/x/nft v0.0.0-20230710134821-641c6a79f97c
cosmossdk.io/x/evidence v0.0.0-20230711132404-6f85267b41ff
cosmossdk.io/x/feegrant v0.0.0-20230711132404-6f85267b41ff
cosmossdk.io/x/nft v0.0.0-20230711132404-6f85267b41ff
cosmossdk.io/x/tx v0.8.0
cosmossdk.io/x/upgrade v0.0.0-20230710134821-641c6a79f97c
cosmossdk.io/x/upgrade v0.0.0-20230711132404-6f85267b41ff
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-db v1.0.0
// this version is not used as it is always replaced by the latest Cosmos SDK version

View File

@ -212,16 +212,16 @@ cosmossdk.io/tools/rosetta v0.2.1-0.20230614114324-f368ed5c62bc h1:7gFe3tRGqaA3s
cosmossdk.io/tools/rosetta v0.2.1-0.20230614114324-f368ed5c62bc/go.mod h1:l5qTTiHcPXf1m3iz7WuACKFmHW2ewAuIW/+ZcWcUm4Q=
cosmossdk.io/x/circuit v0.0.0-20230710134821-641c6a79f97c h1:oXH8E67knESVPzLdNDglffB7Ti7/P02qL8iuiTda3fA=
cosmossdk.io/x/circuit v0.0.0-20230710134821-641c6a79f97c/go.mod h1:rUBiMrg2mukTuTJCyZEicbFMH9PLyQQJxgAsQLB3UwQ=
cosmossdk.io/x/evidence v0.0.0-20230710135718-3bfd00f47bde h1:TNx2sOZSH5N9FqmUwVP52iTJVqZKRUkJC65Ff0nqWpA=
cosmossdk.io/x/evidence v0.0.0-20230710135718-3bfd00f47bde/go.mod h1:cnxLSV33Lfru9og/l3mCQBi10NHi3PJqWsKY+tKh+xc=
cosmossdk.io/x/feegrant v0.0.0-20230710134821-641c6a79f97c h1:HzPM4vJMlFArXj7tmwpV87vPiVjyPpY88/pfZgNE4FU=
cosmossdk.io/x/feegrant v0.0.0-20230710134821-641c6a79f97c/go.mod h1:TlHm+UK7zPwcQ83f24ISDzejJf56/dadAdiJf4SPgeE=
cosmossdk.io/x/nft v0.0.0-20230710134821-641c6a79f97c h1:8SKwHSXNN5kCBlRaGV2YRwoYL1wxh1A4S8Nk8eTcx/s=
cosmossdk.io/x/nft v0.0.0-20230710134821-641c6a79f97c/go.mod h1:omqWFlLcCMXsOt67tUb8uqpNA9U6J2h5Z3QQ0BRPq1M=
cosmossdk.io/x/evidence v0.0.0-20230711132404-6f85267b41ff h1:jHaIT3j6t8op9msjsm9j9AJUnzPPCtqY7Q9/i3Crj8U=
cosmossdk.io/x/evidence v0.0.0-20230711132404-6f85267b41ff/go.mod h1:NHUBoDUMg6DGc0zlpTSwUXAQznlkoCA6EJcRTfMwOWo=
cosmossdk.io/x/feegrant v0.0.0-20230711132404-6f85267b41ff h1:VqTfKSFmqGfmrBP77c2jSOpTEpN/ARNXByRkmoNxSNs=
cosmossdk.io/x/feegrant v0.0.0-20230711132404-6f85267b41ff/go.mod h1:eRhe+cGE6iTL+68FgtVIdnmtU5gRZzGq3ojyr2eJjJM=
cosmossdk.io/x/nft v0.0.0-20230711132404-6f85267b41ff h1:IufjBZ9oKrcNVWKs4j5ekpOPiaW9TXw8WozWrttitgE=
cosmossdk.io/x/nft v0.0.0-20230711132404-6f85267b41ff/go.mod h1:I1Pg8Nv5qTUP4QSQD3L00aMq1LOuJvou7XJ6kvgmwZU=
cosmossdk.io/x/tx v0.8.0 h1:gLiGRL/Fy7fs6dd0IX8jOf0PrVr56/SG6XVMGQjyvJU=
cosmossdk.io/x/tx v0.8.0/go.mod h1:T9uEumGNgKU61gJYRv1t3uzQwLnASpJGmSE229HM3xA=
cosmossdk.io/x/upgrade v0.0.0-20230710134821-641c6a79f97c h1:2TNjseXZhNKApzq6b+j0m3pnraYLG8zU356zkb6ycjM=
cosmossdk.io/x/upgrade v0.0.0-20230710134821-641c6a79f97c/go.mod h1:fQmHxVcavPTOAM0FH35txopwNhZflQ2kbSbKCKVQ/14=
cosmossdk.io/x/upgrade v0.0.0-20230711132404-6f85267b41ff h1:wPzYaNh/U6+tWjrVNQ4cGexGy9XDH4Bao24+yQa7zUA=
cosmossdk.io/x/upgrade v0.0.0-20230711132404-6f85267b41ff/go.mod h1:Td6clkz6yyD/c7gIZHKDJp8u7Ky9mbtH+l45qTXjJOk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=

View File

@ -1,26 +0,0 @@
//go:build e2e
// +build e2e
package upgrade
import (
"testing"
"github.com/stretchr/testify/suite"
"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
)
func TestE2ETestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false)
app.UpgradeKeeper.SetVersionSetter(app.BaseApp)
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
suite.Run(t, NewE2ETestSuite(cfg, app.UpgradeKeeper, ctx))
}

View File

@ -1,115 +0,0 @@
package upgrade
import (
"fmt"
"github.com/stretchr/testify/suite"
"cosmossdk.io/x/upgrade/client/cli"
"cosmossdk.io/x/upgrade/keeper"
"cosmossdk.io/x/upgrade/types"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func NewE2ETestSuite(cfg network.Config, keeper *keeper.Keeper, ctx sdk.Context) *E2ETestSuite {
return &E2ETestSuite{
cfg: cfg,
upgradeKeeper: keeper,
ctx: ctx,
}
}
type E2ETestSuite struct {
suite.Suite
upgradeKeeper *keeper.Keeper
cfg network.Config
network *network.Network
ctx sdk.Context
}
func (s *E2ETestSuite) SetupSuite() {
s.T().Log("setting up e2e test suite")
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)
}
func (s *E2ETestSuite) TearDownSuite() {
s.T().Log("tearing down e2e test suite")
s.network.Cleanup()
}
func (s *E2ETestSuite) TestModuleVersionsCLI() {
testCases := []struct {
msg string
req types.QueryModuleVersionsRequest
single bool
expPass bool
}{
{
msg: "test full query",
req: types.QueryModuleVersionsRequest{ModuleName: ""},
single: false,
expPass: true,
},
{
msg: "test single module",
req: types.QueryModuleVersionsRequest{ModuleName: "bank"},
single: true,
expPass: true,
},
{
msg: "test non-existent module",
req: types.QueryModuleVersionsRequest{ModuleName: "abcdefg"},
single: true,
expPass: false,
},
}
val := s.network.Validators[0]
clientCtx := val.ClientCtx
// avoid printing as yaml from CLI command
clientCtx.OutputFormat = "JSON"
vm, err := s.upgradeKeeper.GetModuleVersionMap(s.ctx)
s.Require().NoError(err)
s.Require().NotEmpty(vm)
mv, err := s.upgradeKeeper.GetModuleVersions(s.ctx)
s.Require().NoError(err)
for _, tc := range testCases {
s.Run(fmt.Sprintf("Case %s", tc.msg), func() {
expect := mv
if tc.expPass {
if tc.single {
expect = []*types.ModuleVersion{{Name: tc.req.ModuleName, Version: vm[tc.req.ModuleName]}}
}
// setup expected response
pm := types.QueryModuleVersionsResponse{
ModuleVersions: expect,
}
jsonVM, _ := clientCtx.Codec.MarshalJSON(&pm)
expectedRes := string(jsonVM)
// append new line to match behavior of PrintProto
expectedRes += "\n"
// get actual module versions list response from cli
cmd := cli.GetModuleVersionsCmd()
outVM, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{tc.req.ModuleName})
s.Require().NoError(err)
s.Require().Equal(expectedRes, outVM.String())
} else {
cmd := cli.GetModuleVersionsCmd()
_, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{tc.req.ModuleName})
s.Require().Error(err)
}
})
}
}

View File

@ -12,11 +12,11 @@ require (
cosmossdk.io/math v1.0.1
cosmossdk.io/simapp v0.0.0-20230620040119-e078f1a49e8b
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
cosmossdk.io/x/evidence v0.0.0-20230710135718-3bfd00f47bde
cosmossdk.io/x/feegrant v0.0.0-20230710134821-641c6a79f97c
cosmossdk.io/x/nft v0.0.0-20230710134821-641c6a79f97c // indirect
cosmossdk.io/x/evidence v0.0.0-20230711132404-6f85267b41ff
cosmossdk.io/x/feegrant v0.0.0-20230711132404-6f85267b41ff
cosmossdk.io/x/nft v0.0.0-20230711132404-6f85267b41ff // indirect
cosmossdk.io/x/tx v0.8.0
cosmossdk.io/x/upgrade v0.0.0-20230710134821-641c6a79f97c
cosmossdk.io/x/upgrade v0.0.0-20230711132404-6f85267b41ff
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3

View File

@ -208,16 +208,16 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c h1:A+FMPW9GtfcPB
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c/go.mod h1:RbYGvXCbz8uNBCXrwS9Z8SyydeWi+W5x5MZ33muyzMw=
cosmossdk.io/x/circuit v0.0.0-20230710134821-641c6a79f97c h1:oXH8E67knESVPzLdNDglffB7Ti7/P02qL8iuiTda3fA=
cosmossdk.io/x/circuit v0.0.0-20230710134821-641c6a79f97c/go.mod h1:rUBiMrg2mukTuTJCyZEicbFMH9PLyQQJxgAsQLB3UwQ=
cosmossdk.io/x/evidence v0.0.0-20230710135718-3bfd00f47bde h1:TNx2sOZSH5N9FqmUwVP52iTJVqZKRUkJC65Ff0nqWpA=
cosmossdk.io/x/evidence v0.0.0-20230710135718-3bfd00f47bde/go.mod h1:cnxLSV33Lfru9og/l3mCQBi10NHi3PJqWsKY+tKh+xc=
cosmossdk.io/x/feegrant v0.0.0-20230710134821-641c6a79f97c h1:HzPM4vJMlFArXj7tmwpV87vPiVjyPpY88/pfZgNE4FU=
cosmossdk.io/x/feegrant v0.0.0-20230710134821-641c6a79f97c/go.mod h1:TlHm+UK7zPwcQ83f24ISDzejJf56/dadAdiJf4SPgeE=
cosmossdk.io/x/nft v0.0.0-20230710134821-641c6a79f97c h1:8SKwHSXNN5kCBlRaGV2YRwoYL1wxh1A4S8Nk8eTcx/s=
cosmossdk.io/x/nft v0.0.0-20230710134821-641c6a79f97c/go.mod h1:omqWFlLcCMXsOt67tUb8uqpNA9U6J2h5Z3QQ0BRPq1M=
cosmossdk.io/x/evidence v0.0.0-20230711132404-6f85267b41ff h1:jHaIT3j6t8op9msjsm9j9AJUnzPPCtqY7Q9/i3Crj8U=
cosmossdk.io/x/evidence v0.0.0-20230711132404-6f85267b41ff/go.mod h1:NHUBoDUMg6DGc0zlpTSwUXAQznlkoCA6EJcRTfMwOWo=
cosmossdk.io/x/feegrant v0.0.0-20230711132404-6f85267b41ff h1:VqTfKSFmqGfmrBP77c2jSOpTEpN/ARNXByRkmoNxSNs=
cosmossdk.io/x/feegrant v0.0.0-20230711132404-6f85267b41ff/go.mod h1:eRhe+cGE6iTL+68FgtVIdnmtU5gRZzGq3ojyr2eJjJM=
cosmossdk.io/x/nft v0.0.0-20230711132404-6f85267b41ff h1:IufjBZ9oKrcNVWKs4j5ekpOPiaW9TXw8WozWrttitgE=
cosmossdk.io/x/nft v0.0.0-20230711132404-6f85267b41ff/go.mod h1:I1Pg8Nv5qTUP4QSQD3L00aMq1LOuJvou7XJ6kvgmwZU=
cosmossdk.io/x/tx v0.8.0 h1:gLiGRL/Fy7fs6dd0IX8jOf0PrVr56/SG6XVMGQjyvJU=
cosmossdk.io/x/tx v0.8.0/go.mod h1:T9uEumGNgKU61gJYRv1t3uzQwLnASpJGmSE229HM3xA=
cosmossdk.io/x/upgrade v0.0.0-20230710134821-641c6a79f97c h1:2TNjseXZhNKApzq6b+j0m3pnraYLG8zU356zkb6ycjM=
cosmossdk.io/x/upgrade v0.0.0-20230710134821-641c6a79f97c/go.mod h1:fQmHxVcavPTOAM0FH35txopwNhZflQ2kbSbKCKVQ/14=
cosmossdk.io/x/upgrade v0.0.0-20230711132404-6f85267b41ff h1:wPzYaNh/U6+tWjrVNQ4cGexGy9XDH4Bao24+yQa7zUA=
cosmossdk.io/x/upgrade v0.0.0-20230711132404-6f85267b41ff/go.mod h1:Td6clkz6yyD/c7gIZHKDJp8u7Ky9mbtH+l45qTXjJOk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=

View File

@ -13,7 +13,7 @@ require (
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c
github.com/cosmos/gogoproto v1.4.10
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3

View File

@ -177,8 +177,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb h1:8QuN6QiOvE03D8DYnlVIfgyy/fTjQHoEDMsDPtSeXVk=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb/go.mod h1:ipTpaQLbn9S35e+b6gWm6OB9Lwr1mYy/47cX+owKnE4=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c h1:5Plp4fx0NKn/mSVxEc5G2QsXQ6O0q3n7P5nS2ETEAEI=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c/go.mod h1:ipTpaQLbn9S35e+b6gWm6OB9Lwr1mYy/47cX+owKnE4=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=

View File

@ -12,7 +12,7 @@ require (
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c
github.com/cosmos/gogoproto v1.4.10
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3

View File

@ -175,8 +175,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb h1:8QuN6QiOvE03D8DYnlVIfgyy/fTjQHoEDMsDPtSeXVk=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb/go.mod h1:ipTpaQLbn9S35e+b6gWm6OB9Lwr1mYy/47cX+owKnE4=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c h1:5Plp4fx0NKn/mSVxEc5G2QsXQ6O0q3n7P5nS2ETEAEI=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c/go.mod h1:ipTpaQLbn9S35e+b6gWm6OB9Lwr1mYy/47cX+owKnE4=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=

View File

@ -12,7 +12,7 @@ require (
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c
github.com/cosmos/gogoproto v1.4.10
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3

View File

@ -176,8 +176,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb h1:8QuN6QiOvE03D8DYnlVIfgyy/fTjQHoEDMsDPtSeXVk=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230710133933-d4f661321afb/go.mod h1:ipTpaQLbn9S35e+b6gWm6OB9Lwr1mYy/47cX+owKnE4=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c h1:5Plp4fx0NKn/mSVxEc5G2QsXQ6O0q3n7P5nS2ETEAEI=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c/go.mod h1:ipTpaQLbn9S35e+b6gWm6OB9Lwr1mYy/47cX+owKnE4=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=

View File

@ -30,6 +30,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#14880](https://github.com/cosmos/cosmos-sdk/pull/14880) Switch from using gov v1beta1 to gov v1 in upgrade CLIs.
* [#14764](https://github.com/cosmos/cosmos-sdk/pull/14764) The `x/upgrade` module is extracted to have a separate go.mod file which allows it be a standalone module.
### Improvements
* [#16903](https://github.com/cosmos/cosmos-sdk/pull/16903) Use AutoCLI for upgrade querying commands.
### API Breaking Changes
* [#16845](https://github.com/cosmos/cosmos-sdk/pull/16845) Remove gov v1beta1 handler. Use gov v1 proposals directly, or replicate the handler in your app.

View File

@ -8,7 +8,6 @@ import (
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/header"
@ -31,8 +30,6 @@ import (
)
type TestSuite struct {
suite.Suite
module appmodule.HasBeginBlocker
keeper *keeper.Keeper
ctx sdk.Context
@ -115,7 +112,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite {
s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{})
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
s.baseApp = baseapp.NewBaseApp(
"upgrade",

53
x/upgrade/autocli.go Normal file
View File

@ -0,0 +1,53 @@
package upgrade
import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
upgradev1beta1 "cosmossdk.io/api/cosmos/upgrade/v1beta1"
)
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: upgradev1beta1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "CurrentPlan",
Use: "plan",
Short: "Query the upgrade plan (if one exists)",
Long: "Gets the currently scheduled upgrade plan, if one exists",
},
{
RpcMethod: "AppliedPlan",
Use: "applied [upgrade-name]",
Short: "Query the block header for height at which a completed upgrade was applied",
Long: "If upgrade-name was previously executed on the chain, this returns the header for the block at which it was applied. This helps a client determine which binary was valid over a given range of blocks, as well as more context to understand past migrations.",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "name"},
},
},
{
RpcMethod: "ModuleVersions",
Use: "module-versions [optional module_name]",
Alias: []string{"module_versions"},
Short: "Query the list of module versions",
Long: "Gets a list of module names and their respective consensus versions. Following the command with a specific module name will return only that module's information.",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "module_name", Optional: true},
},
},
{
RpcMethod: "Authority",
Use: "authority",
Short: "Get the upgrade authority address",
},
{
RpcMethod: "UpgradedConsensusState",
Skip: true, // Skipping this command as the query is deprecated.
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: upgradev1beta1.Query_ServiceDesc.ServiceName,
},
}
}

View File

@ -1,157 +0,0 @@
package cli
import (
"fmt"
"github.com/spf13/cobra"
"cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/types/errors"
)
// GetQueryCmd returns the parent command for all x/upgrade CLI query commands.
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the upgrade module",
}
cmd.AddCommand(
GetCurrentPlanCmd(),
GetAppliedPlanCmd(),
GetModuleVersionsCmd(),
)
return cmd
}
// GetCurrentPlanCmd returns the query upgrade plan command.
func GetCurrentPlanCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "plan",
Short: "get upgrade plan (if one exists)",
Long: "Gets the currently scheduled upgrade plan, if one exists",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
req := types.QueryCurrentPlanRequest{}
res, err := queryClient.CurrentPlan(cmd.Context(), &req)
if err != nil {
return err
}
if res.Plan == nil {
return fmt.Errorf("no upgrade scheduled")
}
return clientCtx.PrintProto(res.GetPlan())
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetAppliedPlanCmd returns information about the block at which a completed
// upgrade was applied.
func GetAppliedPlanCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "applied [upgrade-name]",
Short: "block header for height at which a completed upgrade was applied",
Long: "If upgrade-name was previously executed on the chain, this returns the header for the block at which it was applied.\n" +
"This helps a client determine which binary was valid over a given range of blocks, as well as more context to understand past migrations.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
ctx := cmd.Context()
req := types.QueryAppliedPlanRequest{Name: args[0]}
res, err := queryClient.AppliedPlan(ctx, &req)
if err != nil {
return err
}
if res.Height == 0 {
return fmt.Errorf("no upgrade found")
}
// we got the height, now let's return the headers
node, err := clientCtx.GetNode()
if err != nil {
return err
}
headers, err := node.BlockchainInfo(ctx, res.Height, res.Height)
if err != nil {
return err
}
if len(headers.BlockMetas) == 0 {
return fmt.Errorf("no headers returned for height %d", res.Height)
}
// always output json as Header is unreable in toml ([]byte is a long list of numbers)
bz, err := clientCtx.LegacyAmino.MarshalJSONIndent(headers.BlockMetas[0], "", " ")
if err != nil {
return err
}
return clientCtx.PrintString(fmt.Sprintf("%s\n", bz))
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetModuleVersionsCmd returns the module version list from state
func GetModuleVersionsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "module_versions [optional module_name]",
Short: "get the list of module versions",
Long: "Gets a list of module names and their respective consensus versions.\n" +
"Following the command with a specific module name will return only\n" +
"that module's information.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
var req types.QueryModuleVersionsRequest
if len(args) == 1 {
req = types.QueryModuleVersionsRequest{ModuleName: args[0]}
} else {
req = types.QueryModuleVersionsRequest{}
}
res, err := queryClient.ModuleVersions(cmd.Context(), &req)
if err != nil {
return err
}
if res.ModuleVersions == nil {
return errors.ErrNotFound
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@ -1,177 +0,0 @@
package cli_test
import (
"context"
"fmt"
"io"
"testing"
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/stretchr/testify/require"
"cosmossdk.io/x/upgrade"
upgradecli "cosmossdk.io/x/upgrade/client/cli"
"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"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
)
func TestGetCurrentPlanCmd(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(upgrade.AppModuleBasic{})
kr := keyring.NewInMemory(encCfg.Codec)
baseCtx := client.Context{}.
WithKeyring(kr).
WithTxConfig(encCfg.TxConfig).
WithCodec(encCfg.Codec).
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
WithAccountRetriever(client.MockAccountRetriever{}).
WithOutput(io.Discard).
WithChainID("test-chain")
testCases := []struct {
name string
args []string
expCmdOutput string
}{
{
name: "json output",
args: []string{fmt.Sprintf("--%s=json", flags.FlagOutput)},
expCmdOutput: `[--output=json]`,
},
{
name: "text output",
args: []string{fmt.Sprintf("--%s=text", flags.FlagOutput)},
expCmdOutput: `[--output=text]`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())
cmd := upgradecli.GetCurrentPlanCmd()
cmd.SetOut(io.Discard)
require.NotNil(t, cmd)
cmd.SetContext(ctx)
cmd.SetArgs(tc.args)
require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))
require.Contains(t, fmt.Sprint(cmd), "plan [] [] get upgrade plan (if one exists)")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
})
}
}
func TestGetAppliedPlanCmd(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(upgrade.AppModuleBasic{})
kr := keyring.NewInMemory(encCfg.Codec)
baseCtx := client.Context{}.
WithKeyring(kr).
WithTxConfig(encCfg.TxConfig).
WithCodec(encCfg.Codec).
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
WithAccountRetriever(client.MockAccountRetriever{}).
WithOutput(io.Discard).
WithChainID("test-chain")
testCases := []struct {
name string
args []string
expCmdOutput string
}{
{
name: "json output",
args: []string{"test-upgrade", fmt.Sprintf("--%s=json", flags.FlagOutput)},
expCmdOutput: `[test-upgrade --output=json]`,
},
{
name: "text output",
args: []string{"test-upgrade", fmt.Sprintf("--%s=text", flags.FlagOutput)},
expCmdOutput: `[test-upgrade --output=text]`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())
cmd := upgradecli.GetAppliedPlanCmd()
cmd.SetOut(io.Discard)
require.NotNil(t, cmd)
cmd.SetContext(ctx)
cmd.SetArgs(tc.args)
require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))
require.Contains(t, fmt.Sprint(cmd), "applied [upgrade-name] [] [] block header for height at which a completed upgrade was applied")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
})
}
}
func TestGetModuleVersionsCmd(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(upgrade.AppModuleBasic{})
kr := keyring.NewInMemory(encCfg.Codec)
baseCtx := client.Context{}.
WithKeyring(kr).
WithTxConfig(encCfg.TxConfig).
WithCodec(encCfg.Codec).
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
WithAccountRetriever(client.MockAccountRetriever{}).
WithOutput(io.Discard).
WithChainID("test-chain")
testCases := []struct {
msg string
args []string
expCmdOutput string
}{
{
msg: "test full query with json output",
args: []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)},
expCmdOutput: `--height=1 --output=json`,
},
{
msg: "test full query with text output",
args: []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", flags.FlagOutput)},
expCmdOutput: `--height=1 --output=text`,
},
{
msg: "test single module",
args: []string{"bank", fmt.Sprintf("--%s=1", flags.FlagHeight)},
expCmdOutput: `bank --height=1`,
},
{
msg: "test non-existent module",
args: []string{"abcdefg", fmt.Sprintf("--%s=1", flags.FlagHeight)},
expCmdOutput: `abcdefg --height=1`,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.msg, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())
cmd := upgradecli.GetModuleVersionsCmd()
cmd.SetOut(io.Discard)
require.NotNil(t, cmd)
cmd.SetContext(ctx)
cmd.SetArgs(tc.args)
require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))
require.Contains(t, fmt.Sprint(cmd), "module_versions [optional module_name] [] [] get the list of module versions")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
})
}
}

View File

@ -7,12 +7,12 @@ require (
cosmossdk.io/core v0.9.0
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741
cosmossdk.io/log v1.1.0
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c
github.com/cosmos/gogoproto v1.4.10
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-gateway v1.16.0
@ -174,7 +174,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.4.0 // indirect
gotest.tools/v3 v3.5.0 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v1.0.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect

View File

@ -198,8 +198,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z
cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU=
cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741 h1:BCRz06fvddw7cKGiEGDiSox3qMsjQ97f92K+PDZDHdc=
cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741/go.mod h1:TB05o6YXkZkzsc+6bZFAV5kZRBtoCU9tUkbeMIqEg0w=
cosmossdk.io/log v1.1.0 h1:v0ogPHYeTzPcBTcPR1A3j1hkei4pZama8kz8LKlCMv0=
cosmossdk.io/log v1.1.0/go.mod h1:6zjroETlcDs+mm62gd8Ig7mZ+N+fVOZS91V17H+M4N4=
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca h1:msenprh2BLLRwNT7zN56TbBHOGk/7ARQckXHxXyvjoQ=
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca/go.mod h1:PkIAKXZvaxrTRc++z53XMRvFk8AcGGWYHcMIPzVYX9c=
cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg=
cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c h1:A+FMPW9GtfcPBDQNtFeDFN27h1SAP6OVjnGgPLlYXmI=
@ -341,8 +341,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1 h1:7ERS+ZW1tTly/DLfUwjMB6h80wtlNGBcFjI2Eb9eZIU=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1/go.mod h1:xee+suLR+WgtzSQBr0jjXQsvb1FIteMfnEzbr2Lk+4w=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c h1:5Plp4fx0NKn/mSVxEc5G2QsXQ6O0q3n7P5nS2ETEAEI=
github.com/cosmos/cosmos-sdk v0.50.0-alpha.1.0.20230711130522-37cf56dff23c/go.mod h1:ipTpaQLbn9S35e+b6gWm6OB9Lwr1mYy/47cX+owKnE4=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
@ -1679,8 +1679,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@ -41,7 +41,7 @@ func (suite *UpgradeTestSuite) SetupTest() {
skipUpgradeHeights := make(map[int64]bool)
suite.upgradeKeeper = keeper.NewKeeper(skipUpgradeHeights, storeService, suite.encCfg.Codec, "", nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
suite.upgradeKeeper = keeper.NewKeeper(skipUpgradeHeights, storeService, suite.encCfg.Codec, suite.T().TempDir(), nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
suite.upgradeKeeper.SetModuleVersionMap(suite.ctx, module.VersionMap{
"bank": 0,
})

View File

@ -64,11 +64,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
}
}
// GetQueryCmd returns the CLI query commands for this module
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
// GetTxCmd returns the CLI transaction commands for this module
func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd(ab.ac)