From c4bd42af877167b6d8591e0e573ff8a0d44e2085 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 4 Jan 2021 14:14:16 +0100 Subject: [PATCH 1/4] codecs: rename MakeCodecs to MakeTestCodecs --- codec/amino_codec_test.go | 2 +- docs/basics/app-anatomy.md | 12 +++++++----- simapp/app.go | 9 --------- simapp/encoding.go | 12 +++++++++++- simapp/simd/cmd/genaccounts_test.go | 2 +- simapp/simd/cmd/root.go | 2 +- x/auth/ante/sigverify_test.go | 2 +- x/auth/keeper/keeper_test.go | 2 +- x/auth/simulation/decoder_test.go | 2 +- x/auth/types/common_test.go | 2 +- x/auth/vesting/types/common_test.go | 2 +- x/bank/keeper/keeper_test.go | 2 +- x/capability/simulation/decoder_test.go | 2 +- x/distribution/simulation/decoder_test.go | 2 +- x/evidence/keeper/querier_test.go | 8 ++++---- x/gov/keeper/common_test.go | 2 +- x/gov/simulation/decoder_test.go | 2 +- x/mint/simulation/decoder_test.go | 2 +- x/slashing/simulation/decoder_test.go | 2 +- x/staking/keeper/grpc_query_test.go | 2 +- x/staking/simulation/decoder_test.go | 2 +- 21 files changed, 39 insertions(+), 36 deletions(-) diff --git a/codec/amino_codec_test.go b/codec/amino_codec_test.go index d95ddc8d97fa..12f898b0d54c 100644 --- a/codec/amino_codec_test.go +++ b/codec/amino_codec_test.go @@ -121,7 +121,7 @@ func TestAminoCodecUnpackAnyFails(t *testing.T) { func TestAminoCodecFullDecodeAndEncode(t *testing.T) { // This tx comes from https://github.com/cosmos/cosmos-sdk/issues/8117. txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"cosmos14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"cosmosvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"tendermint/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}` - _, legacyCdc := simapp.MakeCodecs() + _, legacyCdc := simapp.MakeTestCodecs() var tx legacytx.StdTx err := legacyCdc.UnmarshalJSON([]byte(txSigned), &tx) diff --git a/docs/basics/app-anatomy.md b/docs/basics/app-anatomy.md index 9bd2256f0f6a..e7642097fdca 100644 --- a/docs/basics/app-anatomy.md +++ b/docs/basics/app-anatomy.md @@ -113,17 +113,19 @@ The `EncodingConfig` structure is the last important part of the `app.go` file. Here are descriptions of what each of the four fields means: -- `InterfaceRegistry`: The `InterfaceRegistry` is used by the Protobuf codec to handle interfaces, which are encoded and decoded (we also say "unpacked") using [`google.protobuf.Any`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). `Any` could be thought as a struct which contains a `type_url` (the concrete type of the interface) and a `value` (its encoded bytes). `InterfaceRegistry` provides a mechanism for registering interfaces and implementations that can be safely unpacked from `Any`. Each of the application's modules implements the `RegisterInterfaces` method, which can be used to register the module's own interfaces and implementations. +- `InterfaceRegistry`: The `InterfaceRegistry` is used by the Protobuf codec to handle interfaces, which are encoded and decoded (we also say "unpacked") using [`google.protobuf.Any`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). `Any` could be thought as a struct which contains a `type_url` (name of a concrete type implementing the interface) and a `value` (its encoded bytes). `InterfaceRegistry` provides a mechanism for registering interfaces and implementations that can be safely unpacked from `Any`. Each of the application's modules implements the `RegisterInterfaces` method, which can be used to register the module's own interfaces and implementations. + - You can read more about Any in [ADR-19](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-019-protobuf-state-encoding.md#usage-of-any-to-encode-interfaces). - To go more into details, the SDK uses an implementation of the Protobuf specification called [`gogoprotobuf`](https://github.com/gogo/protobuf). By default, the [gogo protobuf implementation of `Any`](https://godoc.org/github.com/gogo/protobuf/types) uses [global type registration](https://github.com/gogo/protobuf/blob/master/proto/properties.go#L540) to decode values packed in `Any` into concrete Go types. This introduces a vulnerability where any malicious module in the dependency tree could registry a type with the global protobuf registry and cause it to be loaded and unmarshaled by a transaction that referenced it in the `type_url` field. For more information, please refer to [ADR-019](../architecture/adr-019-protobuf-state-encoding.md). -- `Marshaler`: The `Marshaler` is the default codec used throughout the SDK. It is composed of a `BinaryMarshaler` used to encode and decode state, and a `JSONMarshaler` used to output data to the users (for example in the [CLI](#cli)). By default, the SDK uses Protobuf as `Marshaler`. +- `Marshaler`: the default codec used throughout the SDK. It is composed of a `BinaryMarshaler` used to encode and decode state, and a `JSONMarshaler` used to output data to the users (for example in the [CLI](#cli)). By default, the SDK uses Protobuf as `Marshaler`. - `TxConfig`: `TxConfig` defines an interface a client can utilize to generate an application-defined concrete transaction type. Currently, the SDK handles two transaction types: `SIGN_MODE_DIRECT` (which uses Protobuf binary as over-the-wire encoding) and `SIGN_MODE_LEGACY_AMINO_JSON` (which depends on Amino). Read more about transactions [here](../core/transactions.md). - `Amino`: Some legacy parts of the SDK still use Amino for backwards-compatibility. Each module exposes a `RegisterLegacyAmino` method to register the module's specific types within Amino. This `Amino` codec should not be used by app developers anymore, and will be removed in future releases. -The SDK exposes a `MakeCodecs` function used to create a `EncodingConfig`. It uses Protobuf as default `Marshaler`, and passes it down to the app's `appCodec` field. It also instantiates a legacy `Amino` codec inside the app's `legacyAmino` field. +The SDK exposes a `MakeTestEncodingConfig` function used to create a `EncodingConfig` for the app constructor (`NewApp`). It uses Protobuf as a default `Marshaler`. +NOTE: this function is market deprecated and should only be used to create an app or in tests. We are working on refactoring codec management in a post Stargate release. -See an example of a `MakeCodecs` from `simapp`: +See an example of a `MakeTestEncodingConfig` from `simapp`: -+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc3/simapp/app.go#L429-L435 ++++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc3/simapp/simd/cmd/root.go#L179-196 ## Modules diff --git a/simapp/app.go b/simapp/app.go index 02aaa2297fe8..b73538df032d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -203,7 +203,6 @@ func NewSimApp( appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { - // TODO: Remove cdc in favor of appCodec once all modules are migrated. appCodec := encodingConfig.Marshaler legacyAmino := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry @@ -441,14 +440,6 @@ func NewSimApp( return app } -// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by -// simapp. It is useful for tests and clients who do not want to construct the -// full simapp -func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) { - config := MakeTestEncodingConfig() - return config.Marshaler, config.Amino -} - // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } diff --git a/simapp/encoding.go b/simapp/encoding.go index 954f4a1175eb..4dc5e0cdd498 100644 --- a/simapp/encoding.go +++ b/simapp/encoding.go @@ -1,13 +1,14 @@ package simapp import ( + "github.com/cosmos/cosmos-sdk/codec" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/std" ) // MakeTestEncodingConfig creates an EncodingConfig for testing. // This function should be used only internally (in the SDK). -// App user should'nt create new codecs - use the app.AppCodec instead. +// App user shouldn't create new codecs - use the app.AppCodec instead. // [DEPRECATED] func MakeTestEncodingConfig() simappparams.EncodingConfig { encodingConfig := simappparams.MakeTestEncodingConfig() @@ -17,3 +18,12 @@ func MakeTestEncodingConfig() simappparams.EncodingConfig { ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) return encodingConfig } + +// MakeTestCodecs is a helper function which uses MakeTestEncodingConfig to +// construct new *std.Codec and *codec.LegacyAmino instances. +// It must not be used in non test files, instead app.AppCodec should be used. +// [DEPRECATED] +func MakeTestCodecs() (codec.Marshaler, *codec.LegacyAmino) { + config := MakeTestEncodingConfig() + return config.Marshaler, config.Amino +} diff --git a/simapp/simd/cmd/genaccounts_test.go b/simapp/simd/cmd/genaccounts_test.go index 9efc5343e7a3..03e3ef0f9291 100644 --- a/simapp/simd/cmd/genaccounts_test.go +++ b/simapp/simd/cmd/genaccounts_test.go @@ -58,7 +58,7 @@ func TestAddGenesisAccountCmd(t *testing.T) { cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) - appCodec, _ := simapp.MakeCodecs() + appCodec, _ := simapp.MakeTestCodecs() err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 534e22b0fb0d..724efcbe9c2c 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -180,7 +180,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty logger, db, traceStore, true, skipUpgradeHeights, cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), - simapp.MakeTestEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd. + simapp.MakeTestEncodingConfig(), // TODO: reuse the one created by NewRootCmd. appOpts, baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 337618fab50f..541155a1162f 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -67,7 +67,7 @@ func (suite *AnteTestSuite) TestSetPubKey() { func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() { params := types.DefaultParams() msg := []byte{1, 2, 3, 4} - _, cdc := simapp.MakeCodecs() + _, cdc := simapp.MakeTestCodecs() pkSet1, sigSet1 := generatePubKeysAndSignatures(5, msg, false) multisigKey1 := kmultisig.NewLegacyAminoPubKey(2, pkSet1) diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 87744d58c5bb..d40916c2abc0 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -129,7 +129,7 @@ func TestSupply_ValidatePermissions(t *testing.T) { maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} maccPerms[randomPerm] = []string{"random"} - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() keeper := keeper.NewAccountKeeper( cdc, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), types.ProtoBaseAccount, maccPerms, diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index c7ececcf95cc..40ed850b4ff2 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -22,7 +22,7 @@ var ( func TestDecodeStore(t *testing.T) { app := simapp.Setup(false) - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() acc := types.NewBaseAccountWithAddress(delAddr1) dec := simulation.NewDecodeStore(app.AccountKeeper) diff --git a/x/auth/types/common_test.go b/x/auth/types/common_test.go index 5c6ff0fb6488..4ec1c6d9e6fd 100644 --- a/x/auth/types/common_test.go +++ b/x/auth/types/common_test.go @@ -6,5 +6,5 @@ import ( var ( app = simapp.Setup(false) - appCodec, legacyAmino = simapp.MakeCodecs() + appCodec, legacyAmino = simapp.MakeTestCodecs() ) diff --git a/x/auth/vesting/types/common_test.go b/x/auth/vesting/types/common_test.go index 4f361059ad3c..aaaf9f9871c4 100644 --- a/x/auth/vesting/types/common_test.go +++ b/x/auth/vesting/types/common_test.go @@ -6,5 +6,5 @@ import ( var ( app = simapp.Setup(false) - appCodec, _ = simapp.MakeCodecs() + appCodec, _ = simapp.MakeTestCodecs() ) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index aea72006a45f..d4f7253f1f36 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -215,7 +215,7 @@ func (suite *IntegrationTestSuite) TestSupply_MintCoins() { func (suite *IntegrationTestSuite) TestSupply_BurnCoins() { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1}) - appCodec, _ := simapp.MakeCodecs() + appCodec, _ := simapp.MakeTestCodecs() // add module accounts to supply keeper maccPerms := simapp.GetMaccPerms() diff --git a/x/capability/simulation/decoder_test.go b/x/capability/simulation/decoder_test.go index 911580505944..fbb958028187 100644 --- a/x/capability/simulation/decoder_test.go +++ b/x/capability/simulation/decoder_test.go @@ -14,7 +14,7 @@ import ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() dec := simulation.NewDecodeStore(cdc) capOwners := types.CapabilityOwners{ diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index 7a705f97da10..cb30788268e7 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -22,7 +22,7 @@ var ( ) func TestDecodeDistributionStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() dec := simulation.NewDecodeStore(cdc) decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.OneDec())} diff --git a/x/evidence/keeper/querier_test.go b/x/evidence/keeper/querier_test.go index 58a1ff81bb3e..baca48977638 100644 --- a/x/evidence/keeper/querier_test.go +++ b/x/evidence/keeper/querier_test.go @@ -18,7 +18,7 @@ const ( func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_Existing() { ctx := suite.ctx.WithIsCheckTx(false) numEvidence := 100 - _, cdc := simapp.MakeCodecs() + _, cdc := simapp.MakeTestCodecs() evidence := suite.populateEvidence(ctx, numEvidence) query := abci.RequestQuery{ @@ -37,7 +37,7 @@ func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_Existing() { func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_NonExisting() { ctx := suite.ctx.WithIsCheckTx(false) - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() numEvidence := 100 suite.populateEvidence(ctx, numEvidence) @@ -53,7 +53,7 @@ func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_NonExisting() { func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence() { ctx := suite.ctx.WithIsCheckTx(false) - _, cdc := simapp.MakeCodecs() + _, cdc := simapp.MakeTestCodecs() numEvidence := 100 suite.populateEvidence(ctx, numEvidence) @@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence() { func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence_InvalidPagination() { ctx := suite.ctx.WithIsCheckTx(false) - _, cdc := simapp.MakeCodecs() + _, cdc := simapp.MakeTestCodecs() numEvidence := 100 suite.populateEvidence(ctx, numEvidence) diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 7ba9c5827f87..5c7478ce8404 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -22,7 +22,7 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers valAddrs := simapp.ConvertAddrsToValAddrs(addrs) pks := simapp.CreateTestPubKeys(5) - appCodec, _ := simapp.MakeCodecs() + appCodec, _ := simapp.MakeTestCodecs() app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, app.GetKey(stakingtypes.StoreKey), diff --git a/x/gov/simulation/decoder_test.go b/x/gov/simulation/decoder_test.go index 7a5b0fc1bc9d..aed40ca2558b 100644 --- a/x/gov/simulation/decoder_test.go +++ b/x/gov/simulation/decoder_test.go @@ -22,7 +22,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() dec := simulation.NewDecodeStore(cdc) endTime := time.Now().UTC() diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index 762768c07eaa..5a1ec0494fb3 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -14,7 +14,7 @@ import ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() dec := simulation.NewDecodeStore(cdc) minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15)) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index e6122f0e0a98..9084cdc8502c 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -25,7 +25,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() dec := simulation.NewDecodeStore(cdc) info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index acf6f9cb5bfb..8b52516233b4 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -733,7 +733,7 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers valAddrs := simapp.ConvertAddrsToValAddrs(addrs) pks := simapp.CreateTestPubKeys(5) - appCodec, _ := simapp.MakeCodecs() + appCodec, _ := simapp.MakeTestCodecs() app.StakingKeeper = keeper.NewKeeper( appCodec, app.GetKey(types.StoreKey), diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 60210fa89b37..bec83c366ab7 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -32,7 +32,7 @@ func makeTestCodec() (cdc *codec.LegacyAmino) { } func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _ := simapp.MakeTestCodecs() dec := simulation.NewDecodeStore(cdc) bondTime := time.Now().UTC() From 1dca29a172cccd1e35f07951bf986d0dc056c0c4 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 4 Jan 2021 14:21:13 +0100 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 382c55c16ec0..3a8ecd075e7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ + added `overwriteSig` argument to `x/auth/client.SignTx` and `client/tx.Sign` functions. + removed `x/auth/tx.go:wrapper.GetSignatures`. The `wrapper` provides `TxBuilder` functionality, and it's a private structure. That function was not used at all and it's not exposed through the `TxBuilder` interface. +* [\#8245](https://github.com/cosmos/cosmos-sdk/pull/8245) Marked deprecated `simapp.MakeCodecs` and renamed to `MakeTestCodecs`. + ### Bug Fixes From 6877082101a5bafb41732fa416a0b4c489ef0897 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 4 Jan 2021 20:32:23 +0100 Subject: [PATCH 3/4] remove MakeTestCodecs --- CHANGELOG.md | 2 +- codec/amino_codec_test.go | 3 +-- simapp/encoding.go | 14 ++------------ simapp/simd/cmd/genaccounts_test.go | 2 +- x/auth/ante/sigverify_test.go | 2 +- x/auth/keeper/keeper_test.go | 2 +- x/auth/simulation/decoder_test.go | 2 +- x/auth/types/common_test.go | 3 ++- x/auth/vesting/types/common_test.go | 4 ++-- x/bank/keeper/keeper_test.go | 2 +- x/capability/simulation/decoder_test.go | 2 +- x/distribution/simulation/decoder_test.go | 2 +- x/evidence/keeper/querier_test.go | 12 ++++++------ x/gov/keeper/common_test.go | 4 ++-- x/gov/simulation/decoder_test.go | 3 +-- x/mint/simulation/decoder_test.go | 2 +- x/slashing/simulation/decoder_test.go | 2 +- x/staking/keeper/grpc_query_test.go | 5 ++--- x/staking/simulation/decoder_test.go | 3 +-- 19 files changed, 29 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a8ecd075e7c..ba842d85f7ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,7 +95,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ + added `overwriteSig` argument to `x/auth/client.SignTx` and `client/tx.Sign` functions. + removed `x/auth/tx.go:wrapper.GetSignatures`. The `wrapper` provides `TxBuilder` functionality, and it's a private structure. That function was not used at all and it's not exposed through the `TxBuilder` interface. -* [\#8245](https://github.com/cosmos/cosmos-sdk/pull/8245) Marked deprecated `simapp.MakeCodecs` and renamed to `MakeTestCodecs`. +* [\#8245](https://github.com/cosmos/cosmos-sdk/pull/8245) Removed `simapp.MakeCodecs` and use `simapp.MakeTestEncodingConfig` instead. ### Bug Fixes diff --git a/codec/amino_codec_test.go b/codec/amino_codec_test.go index 12f898b0d54c..0526661404d5 100644 --- a/codec/amino_codec_test.go +++ b/codec/amino_codec_test.go @@ -121,8 +121,7 @@ func TestAminoCodecUnpackAnyFails(t *testing.T) { func TestAminoCodecFullDecodeAndEncode(t *testing.T) { // This tx comes from https://github.com/cosmos/cosmos-sdk/issues/8117. txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"cosmos14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"cosmosvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"tendermint/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}` - _, legacyCdc := simapp.MakeTestCodecs() - + var legacyCdc = simapp.MakeTestEncodingConfig().Amino var tx legacytx.StdTx err := legacyCdc.UnmarshalJSON([]byte(txSigned), &tx) require.NoError(t, err) diff --git a/simapp/encoding.go b/simapp/encoding.go index 4dc5e0cdd498..8a90ff852478 100644 --- a/simapp/encoding.go +++ b/simapp/encoding.go @@ -1,13 +1,12 @@ package simapp import ( - "github.com/cosmos/cosmos-sdk/codec" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/std" ) -// MakeTestEncodingConfig creates an EncodingConfig for testing. -// This function should be used only internally (in the SDK). +// MakeTestEncodingConfig creates an EncodingConfig for testing. This function +// should be used only in tests or when creating a new app instance (NewApp*()). // App user shouldn't create new codecs - use the app.AppCodec instead. // [DEPRECATED] func MakeTestEncodingConfig() simappparams.EncodingConfig { @@ -18,12 +17,3 @@ func MakeTestEncodingConfig() simappparams.EncodingConfig { ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) return encodingConfig } - -// MakeTestCodecs is a helper function which uses MakeTestEncodingConfig to -// construct new *std.Codec and *codec.LegacyAmino instances. -// It must not be used in non test files, instead app.AppCodec should be used. -// [DEPRECATED] -func MakeTestCodecs() (codec.Marshaler, *codec.LegacyAmino) { - config := MakeTestEncodingConfig() - return config.Marshaler, config.Amino -} diff --git a/simapp/simd/cmd/genaccounts_test.go b/simapp/simd/cmd/genaccounts_test.go index 03e3ef0f9291..34fda7b54aac 100644 --- a/simapp/simd/cmd/genaccounts_test.go +++ b/simapp/simd/cmd/genaccounts_test.go @@ -58,7 +58,7 @@ func TestAddGenesisAccountCmd(t *testing.T) { cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) - appCodec, _ := simapp.MakeTestCodecs() + appCodec := simapp.MakeTestEncodingConfig().Marshaler err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 541155a1162f..fa15e1f179f3 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -67,7 +67,7 @@ func (suite *AnteTestSuite) TestSetPubKey() { func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() { params := types.DefaultParams() msg := []byte{1, 2, 3, 4} - _, cdc := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Amino pkSet1, sigSet1 := generatePubKeysAndSignatures(5, msg, false) multisigKey1 := kmultisig.NewLegacyAminoPubKey(2, pkSet1) diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index d40916c2abc0..16cf53a253cf 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -129,7 +129,7 @@ func TestSupply_ValidatePermissions(t *testing.T) { maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} maccPerms[randomPerm] = []string{"random"} - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler keeper := keeper.NewAccountKeeper( cdc, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), types.ProtoBaseAccount, maccPerms, diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index 40ed850b4ff2..0caeccee0784 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -22,7 +22,7 @@ var ( func TestDecodeStore(t *testing.T) { app := simapp.Setup(false) - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler acc := types.NewBaseAccountWithAddress(delAddr1) dec := simulation.NewDecodeStore(app.AccountKeeper) diff --git a/x/auth/types/common_test.go b/x/auth/types/common_test.go index 4ec1c6d9e6fd..8588778994ec 100644 --- a/x/auth/types/common_test.go +++ b/x/auth/types/common_test.go @@ -6,5 +6,6 @@ import ( var ( app = simapp.Setup(false) - appCodec, legacyAmino = simapp.MakeTestCodecs() + ecdc = simapp.MakeTestEncodingConfig() + appCodec, legacyAmino = ecdc.Marshaler, ecdc.Amino ) diff --git a/x/auth/vesting/types/common_test.go b/x/auth/vesting/types/common_test.go index aaaf9f9871c4..8e57a28c0a62 100644 --- a/x/auth/vesting/types/common_test.go +++ b/x/auth/vesting/types/common_test.go @@ -5,6 +5,6 @@ import ( ) var ( - app = simapp.Setup(false) - appCodec, _ = simapp.MakeTestCodecs() + app = simapp.Setup(false) + appCodec = simapp.MakeTestEncodingConfig().Marshaler ) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index d4f7253f1f36..2f5c5055d2c8 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -215,7 +215,7 @@ func (suite *IntegrationTestSuite) TestSupply_MintCoins() { func (suite *IntegrationTestSuite) TestSupply_BurnCoins() { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1}) - appCodec, _ := simapp.MakeTestCodecs() + appCodec := simapp.MakeTestEncodingConfig().Marshaler // add module accounts to supply keeper maccPerms := simapp.GetMaccPerms() diff --git a/x/capability/simulation/decoder_test.go b/x/capability/simulation/decoder_test.go index fbb958028187..51232b810ab7 100644 --- a/x/capability/simulation/decoder_test.go +++ b/x/capability/simulation/decoder_test.go @@ -14,7 +14,7 @@ import ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) capOwners := types.CapabilityOwners{ diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index cb30788268e7..1032550acb10 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -22,7 +22,7 @@ var ( ) func TestDecodeDistributionStore(t *testing.T) { - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.OneDec())} diff --git a/x/evidence/keeper/querier_test.go b/x/evidence/keeper/querier_test.go index baca48977638..40a9f94e5fb0 100644 --- a/x/evidence/keeper/querier_test.go +++ b/x/evidence/keeper/querier_test.go @@ -18,12 +18,12 @@ const ( func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_Existing() { ctx := suite.ctx.WithIsCheckTx(false) numEvidence := 100 - _, cdc := simapp.MakeTestCodecs() + legacyCdc := simapp.MakeTestEncodingConfig().Amino evidence := suite.populateEvidence(ctx, numEvidence) query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryEvidence}, "/"), - Data: cdc.MustMarshalJSON(types.NewQueryEvidenceRequest(evidence[0].Hash())), + Data: legacyCdc.MustMarshalJSON(types.NewQueryEvidenceRequest(evidence[0].Hash())), } bz, err := suite.querier(ctx, []string{types.QueryEvidence}, query) @@ -31,13 +31,13 @@ func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_Existing() { suite.NotNil(bz) var e exported.Evidence - suite.Nil(cdc.UnmarshalJSON(bz, &e)) + suite.Nil(legacyCdc.UnmarshalJSON(bz, &e)) suite.Equal(evidence[0], e) } func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_NonExisting() { ctx := suite.ctx.WithIsCheckTx(false) - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler numEvidence := 100 suite.populateEvidence(ctx, numEvidence) @@ -53,7 +53,7 @@ func (suite *KeeperTestSuite) TestQuerier_QueryEvidence_NonExisting() { func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence() { ctx := suite.ctx.WithIsCheckTx(false) - _, cdc := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Amino numEvidence := 100 suite.populateEvidence(ctx, numEvidence) @@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence() { func (suite *KeeperTestSuite) TestQuerier_QueryAllEvidence_InvalidPagination() { ctx := suite.ctx.WithIsCheckTx(false) - _, cdc := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Amino numEvidence := 100 suite.populateEvidence(ctx, numEvidence) diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 5c7478ce8404..c7516eb69773 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -21,10 +21,10 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000)) valAddrs := simapp.ConvertAddrsToValAddrs(addrs) pks := simapp.CreateTestPubKeys(5) + cdc := simapp.MakeTestEncodingConfig().Marshaler - appCodec, _ := simapp.MakeTestCodecs() app.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, + cdc, app.GetKey(stakingtypes.StoreKey), app.AccountKeeper, app.BankKeeper, diff --git a/x/gov/simulation/decoder_test.go b/x/gov/simulation/decoder_test.go index aed40ca2558b..6160cdfa9f70 100644 --- a/x/gov/simulation/decoder_test.go +++ b/x/gov/simulation/decoder_test.go @@ -22,11 +22,10 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) endTime := time.Now().UTC() - content := types.ContentFromProposalType("test", "test", types.ProposalTypeText) proposal, err := types.NewProposal(content, 1, endTime, endTime.Add(24*time.Hour)) require.NoError(t, err) diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index 5a1ec0494fb3..0116108b4ed3 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -14,7 +14,7 @@ import ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15)) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 9084cdc8502c..32fb3f077408 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -25,7 +25,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index 8b52516233b4..aa3b341b0953 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -732,10 +732,9 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.TokensFromConsensusPower(300)) valAddrs := simapp.ConvertAddrsToValAddrs(addrs) pks := simapp.CreateTestPubKeys(5) - - appCodec, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler app.StakingKeeper = keeper.NewKeeper( - appCodec, + cdc, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index bec83c366ab7..36b7404fb282 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -32,9 +32,8 @@ func makeTestCodec() (cdc *codec.LegacyAmino) { } func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeTestCodecs() + cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) - bondTime := time.Now().UTC() val, err := types.NewValidator(valAddr1, delPk1, types.NewDescription("test", "test", "test", "test", "test")) From 595d9680d1c254e2a69c6e3ede1a33ff0666750e Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 7 Jan 2021 22:36:55 +0100 Subject: [PATCH 4/4] typo --- docs/basics/app-anatomy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basics/app-anatomy.md b/docs/basics/app-anatomy.md index e7642097fdca..148ba9ba5da4 100644 --- a/docs/basics/app-anatomy.md +++ b/docs/basics/app-anatomy.md @@ -121,7 +121,7 @@ Here are descriptions of what each of the four fields means: - `Amino`: Some legacy parts of the SDK still use Amino for backwards-compatibility. Each module exposes a `RegisterLegacyAmino` method to register the module's specific types within Amino. This `Amino` codec should not be used by app developers anymore, and will be removed in future releases. The SDK exposes a `MakeTestEncodingConfig` function used to create a `EncodingConfig` for the app constructor (`NewApp`). It uses Protobuf as a default `Marshaler`. -NOTE: this function is market deprecated and should only be used to create an app or in tests. We are working on refactoring codec management in a post Stargate release. +NOTE: this function is marked deprecated and should only be used to create an app or in tests. We are working on refactoring codec management in a post Stargate release. See an example of a `MakeTestEncodingConfig` from `simapp`: