diff --git a/CHANGELOG.md b/CHANGELOG.md index 88cad893b975..8530c78e8fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,10 +37,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] - -### API Breaking Changes - -* (types) [\#12355](https://github.com/cosmos/cosmos-sdk/pull/12355) Remove the compile-time `types.DBbackend` variable. Removes usage of the same in server/util.go ### Features * (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration. @@ -65,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (types) [\#12355](https://github.com/cosmos/cosmos-sdk/pull/12355) Remove the compile-time `types.DBbackend` variable. Removes usage of the same in server/util.go * (x/gov) [#12368](https://github.com/cosmos/cosmos-sdk/pull/12369) Gov keeper is now passed by reference instead of copy to make post-construction mutation of Hooks and Proposal Handlers possible at a framework level. * (simapp) [#12270](https://github.com/cosmos/cosmos-sdk/pull/12270) Remove `invCheckPeriod uint` attribute from `SimApp` struct as per migration of `x/crisis` to app wiring * (simapp) [#12334](https://github.com/cosmos/cosmos-sdk/pull/12334) Move `simapp.ConvertAddrsToValAddrs` and `simapp.CreateTestPubKeys ` to respectively `simtestutil.ConvertAddrsToValAddrs` and `simtestutil.CreateTestPubKeys` (`testutil/sims`) @@ -77,6 +74,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/distribution) [#12434](https://github.com/cosmos/cosmos-sdk/pull/12434) `x/distribution` module `SetParams` keeper method definition is now updated to return `error`. * (x/crisis) [#12445](https://github.com/cosmos/cosmos-sdk/pull/12445) `x/crisis` module `SetConstantFee` keeper method definition is now updated to return `error`. +### CLI Breaking Changes + +* (x/group) [#12551](https://github.com/cosmos/cosmos-sdk/pull/12551) read the decision policy from disk in group CLI commands. ### Bug Fixes @@ -242,7 +242,7 @@ empty coins slice before it is used to create `banktype.MsgSend`. * [\#11797](https://github.com/cosmos/cosmos-sdk/pull/11797) Remove all RegisterRESTRoutes (previously deprecated) * [\#11089](https://github.com/cosmos/cosmos-sdk/pull/11089]) interacting with the node through `grpc.Dial` requires clients to pass a codec refer to [doc](docs/run-node/interact-node.md). -* [\#9594](https://github.com/cosmos/cosmos-sdk/pull/9594) Remove legacy REST API. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/master/migrations/rest.html) to migrate to the new REST endpoints. +* [\#9594](https://github.com/cosmos/cosmos-sdk/pull/9594) Remove legacy REST API. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/v0.45/migrations/rest.html) to migrate to the new REST endpoints. * [\#9995](https://github.com/cosmos/cosmos-sdk/pull/9995) Increased gas cost for creating proposals. * [\#11029](https://github.com/cosmos/cosmos-sdk/pull/11029) The deprecated Vote Option field is removed in gov v1beta2 and nil in v1beta1. Use Options instead. * [\#11013](https://github.com/cosmos/cosmos-sdk/pull/11013) The `tx gov submit-proposal` command has changed syntax to support the new Msg-based gov proposals. To access the old CLI command, please use `tx gov submit-legacy-proposal`. @@ -665,7 +665,7 @@ Security Release. No breaking changes related to 0.44.x. ### Client Breaking Changes -* [\#10041](https://github.com/cosmos/cosmos-sdk/pull/10041) Remove broadcast & encode legacy REST endpoints. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/master/migrations/rest.html) to migrate to the new REST endpoints. +* [\#10041](https://github.com/cosmos/cosmos-sdk/pull/10041) Remove broadcast & encode legacy REST endpoints. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/v0.45/migrations/rest.html) to migrate to the new REST endpoints. ## [v0.43.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) - 2021-08-10 diff --git a/api/go.mod b/api/go.mod index c108b7b207de..6d4f2617d6a2 100644 --- a/api/go.mod +++ b/api/go.mod @@ -6,7 +6,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-alpha7 github.com/gogo/protobuf v1.3.2 google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb - google.golang.org/grpc v1.47.0 + google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 ) diff --git a/api/go.sum b/api/go.sum index 0cd7aec7c24f..8ba0ac9ae851 100644 --- a/api/go.sum +++ b/api/go.sum @@ -137,8 +137,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= -google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/client/v2/go.mod b/client/v2/go.mod index 36046a0f2b6a..ab9d299b54b0 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -8,7 +8,7 @@ require ( github.com/iancoleman/strcase v0.2.0 github.com/spf13/cobra v1.5.0 github.com/spf13/pflag v1.0.5 - google.golang.org/grpc v1.47.0 + google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 gotest.tools/v3 v3.3.0 ) diff --git a/client/v2/go.sum b/client/v2/go.sum index 6c2fb1e99987..1f611995b44a 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -151,8 +151,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= -google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/errors/go.mod b/errors/go.mod index 9103e9e48be2..17c27da29364 100644 --- a/errors/go.mod +++ b/errors/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.0 - google.golang.org/grpc v1.47.0 + google.golang.org/grpc v1.48.0 ) require ( diff --git a/errors/go.sum b/errors/go.sum index 05c58bf14f79..c21cee931ab8 100644 --- a/errors/go.sum +++ b/errors/go.sum @@ -113,8 +113,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= -google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/go.mod b/go.mod index d4f170f203bd..33c2ab7416c9 100644 --- a/go.mod +++ b/go.mod @@ -60,7 +60,7 @@ require ( golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 golang.org/x/exp v0.0.0-20220428152302-39d4317da171 google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd - google.golang.org/grpc v1.47.0 + google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 pgregory.net/rapid v0.4.7 sigs.k8s.io/yaml v1.3.0 diff --git a/go.sum b/go.sum index a733d703ad77..6d2050b79006 100644 --- a/go.sum +++ b/go.sum @@ -2016,8 +2016,9 @@ google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ5 google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= -google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= diff --git a/orm/go.mod b/orm/go.mod index a1820e889bdb..23f885bcb48f 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -12,7 +12,7 @@ require ( github.com/regen-network/gocuke v0.6.2 github.com/stretchr/testify v1.8.0 github.com/tendermint/tm-db v0.6.7 - google.golang.org/grpc v1.47.0 + google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 gotest.tools/v3 v3.3.0 pgregory.net/rapid v0.4.7 diff --git a/orm/go.sum b/orm/go.sum index 130a3ef6c107..3511cbd7368b 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -271,8 +271,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= -google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh index f7bf4cefc76d..a8f814464592 100755 --- a/scripts/mockgen.sh +++ b/scripts/mockgen.sh @@ -14,3 +14,4 @@ $mockgen_cmd -source=x/nft/expected_keepers.go -package testutil -destination x/ $mockgen_cmd -source=x/feegrant/expected_keepers.go -package testutil -destination x/feegrant/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/mint/types/expected_keepers.go -package testutil -destination x/mint/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/params/proposal_handler_test.go -package testutil -destination x/params/testutil/staking_keeper_mock.go +$mockgen_cmd -source=x/crisis/types/expected_keepers.go -package testutil -destination x/crisis/testutil/expected_keepers_mocks.go diff --git a/x/capability/keeper/keeper_test.go b/x/capability/keeper/keeper_test.go index 0d6a5f06552e..c859032013bc 100644 --- a/x/capability/keeper/keeper_test.go +++ b/x/capability/keeper/keeper_test.go @@ -5,15 +5,18 @@ import ( "testing" "github.com/stretchr/testify/suite" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/capability/keeper" - "github.com/cosmos/cosmos-sdk/x/capability/testutil" "github.com/cosmos/cosmos-sdk/x/capability/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +var ( + stakingModuleName string = "staking" + bankModuleName string = "bank" ) type KeeperTestSuite struct { @@ -24,16 +27,15 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - app, err := simtestutil.Setup(testutil.AppConfig, - &suite.keeper, - ) - suite.Require().NoError(err) - - suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: 1}) + key := sdk.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) + suite.ctx = testCtx.Ctx + encCfg := moduletestutil.MakeTestEncodingConfig(capability.AppModuleBasic{}) + suite.keeper = keeper.NewKeeper(encCfg.Codec, key, key) } func (suite *KeeperTestSuite) TestSeal() { - sk := suite.keeper.ScopeToModule(banktypes.ModuleName) + sk := suite.keeper.ScopeToModule(bankModuleName) suite.Require().Panics(func() { suite.keeper.ScopeToModule(" ") }) @@ -67,12 +69,12 @@ func (suite *KeeperTestSuite) TestSeal() { }) suite.Require().Panics(func() { - _ = suite.keeper.ScopeToModule(stakingtypes.ModuleName) + _ = suite.keeper.ScopeToModule(stakingModuleName) }) } func (suite *KeeperTestSuite) TestNewCapability() { - sk := suite.keeper.ScopeToModule(banktypes.ModuleName) + sk := suite.keeper.ScopeToModule(bankModuleName) got, ok := sk.GetCapability(suite.ctx, "transfer") suite.Require().False(ok) @@ -111,8 +113,8 @@ func (suite *KeeperTestSuite) TestNewCapability() { } func (suite *KeeperTestSuite) TestAuthenticateCapability() { - sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName) - sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) + sk1 := suite.keeper.ScopeToModule(bankModuleName) + sk2 := suite.keeper.ScopeToModule(stakingModuleName) cap1, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) @@ -150,8 +152,8 @@ func (suite *KeeperTestSuite) TestAuthenticateCapability() { } func (suite *KeeperTestSuite) TestClaimCapability() { - sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName) - sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) + sk1 := suite.keeper.ScopeToModule(bankModuleName) + sk2 := suite.keeper.ScopeToModule(stakingModuleName) sk3 := suite.keeper.ScopeToModule("foo") cap, err := sk1.NewCapability(suite.ctx, "transfer") @@ -174,8 +176,8 @@ func (suite *KeeperTestSuite) TestClaimCapability() { } func (suite *KeeperTestSuite) TestGetOwners() { - sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName) - sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) + sk1 := suite.keeper.ScopeToModule(bankModuleName) + sk2 := suite.keeper.ScopeToModule(stakingModuleName) sk3 := suite.keeper.ScopeToModule("foo") sks := []keeper.ScopedKeeper{sk1, sk2, sk3} @@ -187,7 +189,7 @@ func (suite *KeeperTestSuite) TestGetOwners() { suite.Require().NoError(sk2.ClaimCapability(suite.ctx, cap, "transfer")) suite.Require().NoError(sk3.ClaimCapability(suite.ctx, cap, "transfer")) - expectedOrder := []string{banktypes.ModuleName, "foo", stakingtypes.ModuleName} + expectedOrder := []string{bankModuleName, "foo", stakingModuleName} // Ensure all scoped keepers can get owners for _, sk := range sks { owners, ok := sk.GetOwners(suite.ctx, "transfer") @@ -214,7 +216,7 @@ func (suite *KeeperTestSuite) TestGetOwners() { suite.Require().Nil(err, "could not release capability") // new expected order and scoped capabilities - expectedOrder = []string{banktypes.ModuleName, stakingtypes.ModuleName} + expectedOrder = []string{bankModuleName, stakingModuleName} sks = []keeper.ScopedKeeper{sk1, sk2} // Ensure all scoped keepers can get owners @@ -242,8 +244,8 @@ func (suite *KeeperTestSuite) TestGetOwners() { } func (suite *KeeperTestSuite) TestReleaseCapability() { - sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName) - sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) + sk1 := suite.keeper.ScopeToModule(bankModuleName) + sk2 := suite.keeper.ScopeToModule(stakingModuleName) cap1, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) @@ -271,7 +273,7 @@ func (suite *KeeperTestSuite) TestReleaseCapability() { } func (suite KeeperTestSuite) TestRevertCapability() { - sk := suite.keeper.ScopeToModule(banktypes.ModuleName) + sk := suite.keeper.ScopeToModule(bankModuleName) ms := suite.ctx.MultiStore() diff --git a/x/crisis/keeper/keeper_test.go b/x/crisis/keeper/keeper_test.go index f710a166a35e..905cb99aee7b 100644 --- a/x/crisis/keeper/keeper_test.go +++ b/x/crisis/keeper/keeper_test.go @@ -3,48 +3,58 @@ package keeper_test import ( "testing" + "github.com/cosmos/cosmos-sdk/testutil" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/crisis" + "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistestutil "github.com/cosmos/cosmos-sdk/x/crisis/testutil" "github.com/cosmos/cosmos-sdk/x/crisis/types" ) func TestLogger(t *testing.T) { - app := simapp.Setup(t, false) + ctrl := gomock.NewController(t) + supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - ctx := app.NewContext(true, tmproto.Header{}) + key := sdk.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") require.Equal(t, - ctx.Logger().With("module", "x/"+types.ModuleName), - app.CrisisKeeper.Logger(ctx)) + testCtx.Ctx.Logger().With("module", "x/"+types.ModuleName), + keeper.Logger(testCtx.Ctx)) } func TestInvariants(t *testing.T) { - app := simapp.Setup(t, false) - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) + ctrl := gomock.NewController(t) + supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - require.Equal(t, app.CrisisKeeper.InvCheckPeriod(), uint(5)) + key := sdk.NewKVStoreKey(types.StoreKey) + encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") + require.Equal(t, keeper.InvCheckPeriod(), uint(5)) - // SimApp has 11 registered invariants - orgInvRoutes := app.CrisisKeeper.Routes() - app.CrisisKeeper.RegisterRoute("testModule", "testRoute", func(sdk.Context) (string, bool) { return "", false }) - require.Equal(t, len(app.CrisisKeeper.Routes()), len(orgInvRoutes)+1) + orgInvRoutes := keeper.Routes() + keeper.RegisterRoute("testModule", "testRoute", func(sdk.Context) (string, bool) { return "", false }) + require.Equal(t, len(keeper.Routes()), len(orgInvRoutes)+1) } func TestAssertInvariants(t *testing.T) { - app := simapp.Setup(t, false) - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) + ctrl := gomock.NewController(t) + supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - ctx := app.NewContext(true, tmproto.Header{}) + key := sdk.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") - app.CrisisKeeper.RegisterRoute("testModule", "testRoute1", func(sdk.Context) (string, bool) { return "", false }) - require.NotPanics(t, func() { app.CrisisKeeper.AssertInvariants(ctx) }) + keeper.RegisterRoute("testModule", "testRoute1", func(sdk.Context) (string, bool) { return "", false }) + require.NotPanics(t, func() { keeper.AssertInvariants(testCtx.Ctx) }) - app.CrisisKeeper.RegisterRoute("testModule", "testRoute2", func(sdk.Context) (string, bool) { return "", true }) - require.Panics(t, func() { app.CrisisKeeper.AssertInvariants(ctx) }) + keeper.RegisterRoute("testModule", "testRoute2", func(sdk.Context) (string, bool) { return "", true }) + require.Panics(t, func() { keeper.AssertInvariants(testCtx.Ctx) }) } diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index 6d4ba8e546f1..2c2ac3ebebbd 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -3,13 +3,15 @@ package keeper_test import ( "testing" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/crisis" "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistestutil "github.com/cosmos/cosmos-sdk/x/crisis/testutil" "github.com/cosmos/cosmos-sdk/x/crisis/types" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) type KeeperTestSuite struct { @@ -20,13 +22,16 @@ type KeeperTestSuite struct { } func (s *KeeperTestSuite) SetupTest() { - app := simapp.Setup(s.T(), false) - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) - ctx := app.NewContext(true, tmproto.Header{}) + ctrl := gomock.NewController(s.T()) + supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - s.ctx = ctx - s.keeper = app.CrisisKeeper + key := sdk.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") + + s.ctx = testCtx.Ctx + s.keeper = keeper } func (s *KeeperTestSuite) TestMsgUpdateParams() { diff --git a/x/crisis/testutil/expected_keepers_mocks.go b/x/crisis/testutil/expected_keepers_mocks.go new file mode 100644 index 000000000000..152ee6dce37d --- /dev/null +++ b/x/crisis/testutil/expected_keepers_mocks.go @@ -0,0 +1,49 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/crisis/types/expected_keepers.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" +) + +// MockSupplyKeeper is a mock of SupplyKeeper interface. +type MockSupplyKeeper struct { + ctrl *gomock.Controller + recorder *MockSupplyKeeperMockRecorder +} + +// MockSupplyKeeperMockRecorder is the mock recorder for MockSupplyKeeper. +type MockSupplyKeeperMockRecorder struct { + mock *MockSupplyKeeper +} + +// NewMockSupplyKeeper creates a new mock instance. +func NewMockSupplyKeeper(ctrl *gomock.Controller) *MockSupplyKeeper { + mock := &MockSupplyKeeper{ctrl: ctrl} + mock.recorder = &MockSupplyKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSupplyKeeper) EXPECT() *MockSupplyKeeperMockRecorder { + return m.recorder +} + +// SendCoinsFromAccountToModule mocks base method. +func (m *MockSupplyKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockSupplyKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockSupplyKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} diff --git a/x/group/client/cli/tx.go b/x/group/client/cli/tx.go index 6cff34a5c19c..d5dfbadfe8ab 100644 --- a/x/group/client/cli/tx.go +++ b/x/group/client/cli/tx.go @@ -3,7 +3,6 @@ package cli import ( "fmt" "strconv" - "strings" "github.com/spf13/cobra" @@ -53,18 +52,12 @@ func TxCmd(name string) *cobra.Command { // MsgCreateGroupCmd creates a CLI command for Msg/CreateGroup. func MsgCreateGroupCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "create-group [admin] [metadata] [members-json-file]", - Short: "Create a group which is an aggregation " + - "of member accounts with associated weights and " + - "an administrator account. Note, the '--from' flag is " + - "ignored as it is implied from [admin].", - Long: strings.TrimSpace( - fmt.Sprintf(`Create a group which is an aggregation of member accounts with associated weights and -an administrator account. Note, the '--from' flag is ignored as it is implied from [admin]. -Members accounts can be given through a members JSON file that contains an array of members. - -Example: -$ %s tx group create-group [admin] [metadata] [members-json-file] + Use: "create-group [admin] [metadata] [members-json-file]", + Short: "Create a group which is an aggregation of member accounts with associated weights and an administrator account.", + Long: `Create a group which is an aggregation of member accounts with associated weights and an administrator account. +Note, the '--from' flag is ignored as it is implied from [admin]. Members accounts can be given through a members JSON file that contains an array of members.`, + Example: fmt.Sprintf(` +%s tx group create-group [admin] [metadata] [members-json-file] Where members.json contains: @@ -81,11 +74,7 @@ Where members.json contains: "metadata": "some metadata" } ] -} -`, - version.AppName, - ), - ), +}`, version.AppName), Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) @@ -126,11 +115,8 @@ func MsgUpdateGroupMembersCmd() *cobra.Command { cmd := &cobra.Command{ Use: "update-group-members [admin] [group-id] [members-json-file]", Short: "Update a group's members. Set a member's weight to \"0\" to delete it.", - Long: strings.TrimSpace( - fmt.Sprintf(`Update a group's members - -Example: -$ %s tx group update-group-members [admin] [group-id] [members-json-file] + Example: fmt.Sprintf(` +%s tx group update-group-members [admin] [group-id] [members-json-file] Where members.json contains: @@ -150,10 +136,7 @@ Where members.json contains: } Set a member's weight to "0" to delete it. -`, - version.AppName, - ), - ), +`, version.AppName), Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) @@ -277,21 +260,14 @@ func MsgUpdateGroupMetadataCmd() *cobra.Command { // MsgCreateGroupWithPolicyCmd creates a CLI command for Msg/CreateGroupWithPolicy. func MsgCreateGroupWithPolicyCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "create-group-with-policy [admin] [group-metadata] [group-policy-metadata] [members-json-file] [decision-policy]", - Short: "Create a group with policy which is an aggregation " + - "of member accounts with associated weights, " + - "an administrator account and a decision policy. Note, the '--from' flag is " + - "ignored as it is implied from [admin].", - Long: strings.TrimSpace( - fmt.Sprintf(`Create a group with policy which is an aggregation of member accounts with associated weights, + Use: "create-group-with-policy [admin] [group-metadata] [group-policy-metadata] [members-json-file] [decision-policy-json-file]", + Short: "Create a group with policy which is an aggregation of member accounts with associated weights, an administrator account and decision policy.", + Long: `Create a group with policy which is an aggregation of member accounts with associated weights, an administrator account and decision policy. Note, the '--from' flag is ignored as it is implied from [admin]. Members accounts can be given through a members JSON file that contains an array of members. -If group-policy-as-admin flag is set to true, the admin of the newly created group and group policy is set with the group policy address itself. - -Example: -$ %s tx group create-group-with-policy [admin] [group-metadata] [group-policy-metadata] [members-json-file] \ -'{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"1", \ -"windows": {"voting_period": "120h", "min_execution_period": "0s"}}' +If group-policy-as-admin flag is set to true, the admin of the newly created group and group policy is set with the group policy address itself.`, + Example: fmt.Sprintf(` +%s tx group create-group-with-policy [admin] [group-metadata] [group-policy-metadata] members.json policy.json where members.json contains: @@ -309,10 +285,18 @@ where members.json contains: } ] } -`, - version.AppName, - ), - ), + +and policy.json contains: + +{ + "@type": "/cosmos.group.v1.ThresholdDecisionPolicy", + "threshold": "1", + "windows": { + "voting_period": "120h", + "min_execution_period": "0s" + } +} +`, version.AppName), Args: cobra.MinimumNArgs(5), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) @@ -335,8 +319,8 @@ where members.json contains: return err } - var policy group.DecisionPolicy - if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(args[4]), &policy); err != nil { + policy, err := parseDecisionPolicy(clientCtx.Codec, args[4]) + if err != nil { return err } @@ -368,26 +352,32 @@ where members.json contains: // MsgCreateGroupPolicyCmd creates a CLI command for Msg/CreateGroupPolicy. func MsgCreateGroupPolicyCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "create-group-policy [admin] [group-id] [metadata] [decision-policy]", - Short: "Create a group policy which is an account " + - "associated with a group and a decision policy. " + - "Note, the '--from' flag is " + - "ignored as it is implied from [admin].", - Long: strings.TrimSpace( - fmt.Sprintf(`Create a group policy which is an account associated with a group and a decision policy. -Note, the '--from' flag is ignored as it is implied from [admin]. - -Example: -$ %s tx group create-group-policy [admin] [group-id] [metadata] \ -'{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"1", \ -"windows": {"voting_period": "120h", "min_execution_period": "0s"}}' - -Here, we can use percentage decision policy when needed, where 0 < percentage <= 1. -Ex: '{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"0.5", "windows": {"voting_period": "120h", "min_execution_period": "0s"}} -`, - version.AppName, - ), - ), + Use: "create-group-policy [admin] [group-id] [metadata] [decision-policy-json-file]", + Short: `Create a group policy which is an account associated with a group and a decision policy. Note, the '--from' flag is ignored as it is implied from [admin].`, + Example: fmt.Sprintf(` +%s tx group create-group-policy [admin] [group-id] [metadata] policy.json + +where policy.json contains: + +{ + "@type": "/cosmos.group.v1.ThresholdDecisionPolicy", + "threshold": "1", + "windows": { + "voting_period": "120h", + "min_execution_period": "0s" + } +} + +Here, we can use percentage decision policy when needed, where 0 < percentage <= 1: + +{ + "@type": "/cosmos.group.v1.PercentageDecisionPolicy", + "percentage": "0.5", + "windows": { + "voting_period": "120h", + "min_execution_period": "0s" + } +}`, version.AppName), Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Flags().Set(flags.FlagFrom, args[0]) @@ -405,8 +395,8 @@ Ex: '{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"0.5", " return err } - var policy group.DecisionPolicy - if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(args[3]), &policy); err != nil { + policy, err := parseDecisionPolicy(clientCtx.Codec, args[3]) + if err != nil { return err } @@ -470,7 +460,7 @@ func MsgUpdateGroupPolicyAdminCmd() *cobra.Command { // MsgUpdateGroupPolicyDecisionPolicyCmd creates a CLI command for Msg/UpdateGroupPolicyDecisionPolicy. func MsgUpdateGroupPolicyDecisionPolicyCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "update-group-policy-decision-policy [admin] [group-policy-account] [decision-policy]", + Use: "update-group-policy-decision-policy [admin] [group-policy-account] [decision-policy-json-file]", Short: "Update a group policy's decision policy", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { @@ -484,8 +474,8 @@ func MsgUpdateGroupPolicyDecisionPolicyCmd() *cobra.Command { return err } - var policy group.DecisionPolicy - if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(args[2]), &policy); err != nil { + policy, err := parseDecisionPolicy(clientCtx.Codec, args[2]) + if err != nil { return err } @@ -556,13 +546,11 @@ func MsgSubmitProposalCmd() *cobra.Command { cmd := &cobra.Command{ Use: "submit-proposal [proposal_json_file]", Short: "Submit a new proposal", - Long: fmt.Sprintf(`Submit a new proposal. - + Long: `Submit a new proposal. Parameters: - msg_tx_json_file: path to json file with messages that will be executed if the proposal is accepted. - -Example: - $ %s tx group submit-proposal path/to/proposal.json + msg_tx_json_file: path to json file with messages that will be executed if the proposal is accepted.`, + Example: fmt.Sprintf(` +%s tx group submit-proposal path/to/proposal.json Where proposal.json contains: @@ -638,7 +626,7 @@ func MsgWithdrawProposalCmd() *cobra.Command { Parameters: proposal-id: unique ID of the proposal. group-policy-admin-or-proposer: either admin of the group policy or one the proposer of the proposal. - (note: --from flag will be ignored here) + Note: --from flag will be ignored here. `, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -788,14 +776,13 @@ func MsgExecCmd() *cobra.Command { func MsgLeaveGroupCmd() *cobra.Command { cmd := &cobra.Command{ Use: "leave-group [member-address] [group-id]", - Short: "remove member from the group", - Long: ` remove member from the group + Short: "Remove member from the group", + Long: `Remove member from the group Parameters: group-id: unique id of the group member-address: account address of the group member - Note, the '--from' flag is - ignored as it is implied from [member-address] + Note, the '--from' flag is ignored as it is implied from [member-address] `, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/x/group/client/cli/util.go b/x/group/client/cli/util.go index 377c26d9c7c7..fccf7626a2df 100644 --- a/x/group/client/cli/util.go +++ b/x/group/client/cli/util.go @@ -2,6 +2,7 @@ package cli import ( "encoding/json" + "fmt" "io/ioutil" "os" @@ -10,6 +11,24 @@ import ( "github.com/cosmos/cosmos-sdk/x/group" ) +func parseDecisionPolicy(cdc codec.Codec, decisionPolicyFile string) (group.DecisionPolicy, error) { + if decisionPolicyFile == "" { + return nil, fmt.Errorf("decision policy is required") + } + + contents, err := ioutil.ReadFile(decisionPolicyFile) + if err != nil { + return nil, err + } + + var policy group.DecisionPolicy + if err := cdc.UnmarshalInterfaceJSON(contents, &policy); err != nil { + return nil, fmt.Errorf("failed to parse decision policy: %w", err) + } + + return policy, nil +} + func parseMembers(membersFile string) ([]group.MemberRequest, error) { members := group.MemberRequests{} diff --git a/x/group/client/testutil/tx.go b/x/group/client/testutil/tx.go index b30830cf5b4e..3e0954e1fcea 100644 --- a/x/group/client/testutil/tx.go +++ b/x/group/client/testutil/tx.go @@ -134,7 +134,7 @@ func (s *IntegrationTestSuite) SetupSuite() { val.Address.String(), "1", validMetadata, - fmt.Sprintf("{\"@type\":\"/cosmos.group.v1.PercentageDecisionPolicy\", \"percentage\":\"%f\", \"windows\":{\"voting_period\":\"30000s\"}}", percentage), + testutil.WriteToNewTempFile(s.T(), fmt.Sprintf(`{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"%f", "windows":{"voting_period":"30000s"}}`, percentage)).Name(), }, s.commonFlags..., ), @@ -713,6 +713,8 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { }]}`, val.Address.String(), tooLongMetadata) invalidMembersMetadataFile := testutil.WriteToNewTempFile(s.T(), invalidMembersMetadata) + thresholdDecisionPolicyFile := testutil.WriteToNewTempFile(s.T(), `{"@type": "/cosmos.group.v1.ThresholdDecisionPolicy","threshold": "1","windows": {"voting_period":"1s"}}`) + testCases := []struct { name string args []string @@ -729,7 +731,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { validMetadata, validMetadata, validMembersFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, false), }, s.commonFlags..., @@ -747,7 +749,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { validMetadata, validMetadata, validMembersFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, true), }, s.commonFlags..., @@ -765,7 +767,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { validMetadata, validMetadata, validMembersFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, false), fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), }, @@ -784,7 +786,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { strings.Repeat("a", 256), validMetadata, validMembersFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, false), }, s.commonFlags..., @@ -802,7 +804,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { validMetadata, strings.Repeat("a", 256), validMembersFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, false), }, s.commonFlags..., @@ -820,7 +822,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { validMetadata, validMetadata, invalidMembersAddressFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, false), }, s.commonFlags..., @@ -838,7 +840,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { validMetadata, validMetadata, invalidMembersWeightFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, false), }, s.commonFlags..., @@ -856,7 +858,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { validMetadata, validMetadata, invalidMembersMetadataFile.Name(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%v", client.FlagGroupPolicyAsAdmin, false), }, s.commonFlags..., @@ -894,6 +896,8 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { groupID := s.group.Id + thresholdDecisionPolicyFile := testutil.WriteToNewTempFile(s.T(), `{"@type": "/cosmos.group.v1.ThresholdDecisionPolicy","threshold": "1","windows": {"voting_period":"1s"}}`) + testCases := []struct { name string args []string @@ -909,7 +913,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { val.Address.String(), fmt.Sprintf("%v", groupID), validMetadata, - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), }, s.commonFlags..., ), @@ -925,7 +929,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { val.Address.String(), fmt.Sprintf("%v", groupID), validMetadata, - "{\"@type\":\"/cosmos.group.v1.PercentageDecisionPolicy\", \"percentage\":\"0.5\", \"windows\":{\"voting_period\":\"1s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"0.5", "windows":{"voting_period":"1s"}}`).Name(), }, s.commonFlags..., ), @@ -941,7 +945,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { val.Address.String(), fmt.Sprintf("%v", groupID), validMetadata, - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), }, s.commonFlags..., @@ -958,7 +962,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { wrongAdmin.String(), fmt.Sprintf("%v", groupID), validMetadata, - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), }, s.commonFlags..., ), @@ -974,7 +978,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { val.Address.String(), fmt.Sprintf("%v", groupID), strings.Repeat("a", 500), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), }, s.commonFlags..., ), @@ -990,7 +994,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { val.Address.String(), "10", validMetadata, - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + thresholdDecisionPolicyFile.Name(), }, s.commonFlags..., ), @@ -1006,7 +1010,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { val.Address.String(), fmt.Sprintf("%v", groupID), validMetadata, - "{\"@type\":\"/cosmos.group.v1.PercentageDecisionPolicy\", \"percentage\":\"-0.5\", \"windows\":{\"voting_period\":\"1s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"-0.5", "windows":{"voting_period":"1s"}}`).Name(), }, s.commonFlags..., ), @@ -1022,7 +1026,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { val.Address.String(), fmt.Sprintf("%v", groupID), validMetadata, - "{\"@type\":\"/cosmos.group.v1.PercentageDecisionPolicy\", \"percentage\":\"2\", \"windows\":{\"voting_period\":\"1s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"2", "windows":{"voting_period":"1s"}}`).Name(), }, s.commonFlags..., ), @@ -1176,7 +1180,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { []string{ groupPolicy.Admin, groupPolicy.Address, - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"40000s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"1", "windows":{"voting_period":"40000s"}}`).Name(), }, commonFlags..., ), @@ -1191,7 +1195,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { []string{ groupPolicy.Admin, groupPolicy.Address, - "{\"@type\":\"/cosmos.group.v1.PercentageDecisionPolicy\", \"percentage\":\"0.5\", \"windows\":{\"voting_period\":\"40000s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"0.5", "windows":{"voting_period":"40000s"}}`).Name(), }, commonFlags..., ), @@ -1206,7 +1210,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { []string{ groupPolicy.Admin, groupPolicy.Address, - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"50000s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"1", "windows":{"voting_period":"50000s"}}`).Name(), fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), }, commonFlags..., @@ -1222,7 +1226,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { []string{ newAdmin.String(), groupPolicy.Address, - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"1", "windows":{"voting_period":"1s"}}`).Name(), }, commonFlags..., ), @@ -1237,7 +1241,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { []string{ groupPolicy.Admin, newAdmin.String(), - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"1\", \"windows\":{\"voting_period\":\"1s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"1", "windows":{"voting_period":"1s"}}`).Name(), }, commonFlags..., ), @@ -1252,7 +1256,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { []string{ groupPolicy.Admin, groupPolicy.Address, - "{\"@type\":\"/cosmos.group.v1.PercentageDecisionPolicy\", \"percentage\":\"-0.5\", \"windows\":{\"voting_period\":\"1s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"-0.5", "windows":{"voting_period":"1s"}}`).Name(), }, commonFlags..., ), @@ -1267,7 +1271,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { []string{ groupPolicy.Admin, groupPolicy.Address, - "{\"@type\":\"/cosmos.group.v1.PercentageDecisionPolicy\", \"percentage\":\"2\", \"windows\":{\"voting_period\":\"40000s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"2", "windows":{"voting_period":"40000s"}}`).Name(), }, commonFlags..., ), @@ -2109,7 +2113,7 @@ func (s *IntegrationTestSuite) TestTxLeaveGroup() { val.Address.String(), groupID, "AQ==", - "{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"3\", \"windows\":{\"voting_period\":\"1s\"}}", + testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"3", "windows":{"voting_period":"1s"}}`).Name(), }, s.commonFlags..., ), @@ -2529,7 +2533,7 @@ func (s *IntegrationTestSuite) createGroupThresholdPolicyWithBalance(adminAddres adminAddress, groupID, validMetadata, - fmt.Sprintf("{\"@type\":\"/cosmos.group.v1.ThresholdDecisionPolicy\", \"threshold\":\"%d\", \"windows\":{\"voting_period\":\"30000s\"}}", threshold), + testutil.WriteToNewTempFile(s.T(), fmt.Sprintf(`{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"%d", "windows":{"voting_period":"30000s"}}`, threshold)).Name(), }, s.commonFlags..., ), diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index 22f699366119..867ca04a7099 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -250,7 +250,7 @@ func (k Keeper) unbondedToBonded(ctx sdk.Context, validator types.Validator) (ty // UnbondingToUnbonded switches a validator from unbonding state to unbonded state func (k Keeper) UnbondingToUnbonded(ctx sdk.Context, validator types.Validator) types.Validator { if !validator.IsUnbonding() { - panic(fmt.Sprintf("bad state transition unbondingToBonded, validator: %v\n", validator)) + panic(fmt.Sprintf("bad state transition unbondingToUnbonded, validator: %v\n", validator)) } return k.completeUnbondingValidator(ctx, validator)