From 30b9967c194e4ecc003a57433d739f0063c1ff66 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 15 Feb 2024 15:09:32 +0100 Subject: [PATCH 01/19] del: global config from x/auth client/keys --- baseapp/abci_utils_test.go | 4 ++-- baseapp/baseapp_test.go | 4 ++-- baseapp/msg_service_router_test.go | 2 +- client/context.go | 16 ++++++++++++++ client/keys/add.go | 2 +- client/keys/parse.go | 34 +++++++++++++++++------------- client/keys/parse_test.go | 6 +----- client/keys/show.go | 2 +- client/tx/tx_test.go | 2 +- crypto/ledger/ledger_test.go | 2 +- simapp/app.go | 4 +++- simapp/simd/cmd/root.go | 6 +++++- simapp/simd/cmd/root_v2.go | 4 +++- testutil/integration/router.go | 2 +- types/address.go | 25 ++++++++++++++++++++++ types/config.go | 10 --------- types/module/testutil/codec.go | 4 ++-- x/auth/ante/feegrant_test.go | 2 +- x/auth/tx/config.go | 26 ++++++++++++++--------- x/auth/tx/config/depinject.go | 6 ++++++ x/auth/tx/config_test.go | 2 +- 21 files changed, 108 insertions(+), 57 deletions(-) diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index 9d1cbac1aa85..944353baef78 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -327,7 +327,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) // create a baseapp along with a tx config for tx generation - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), dbm.NewMemDB(), txConfig.TxDecoder()) // create a proposal handler @@ -422,7 +422,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSelection() { cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") var ( secret1 = []byte("secret1") diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 68bea9795016..3913d2003b26 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -66,7 +66,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") db := dbm.NewMemDB() logBuffer := new(bytes.Buffer) logger := log.NewLogger(logBuffer, log.ColorOption(false)) @@ -503,7 +503,7 @@ func TestTxDecoder(t *testing.T) { baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") tx := newTxCounter(t, txConfig, 1, 0) txBytes, err := txConfig.TxEncoder()(tx) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 2f9807997e25..cd7d3b9c4552 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -138,7 +138,7 @@ func TestMsgService(t *testing.T) { app := appBuilder.Build(dbm.NewMemDB(), nil) // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") // set the TxDecoder in the BaseApp for minimal tx simulations app.SetTxDecoder(txConfig.TxDecoder()) diff --git a/client/context.go b/client/context.go index b93fab97840c..6cd51b71045a 100644 --- a/client/context.go +++ b/client/context.go @@ -79,6 +79,10 @@ type Context struct { AddressCodec address.Codec ValidatorAddressCodec address.Codec ConsensusAddressCodec address.Codec + + // Bech32 address prefixes + AddressPrefix string + ValidatorPrefix string } // WithCmdContext returns a copy of the context with an updated context.Context, @@ -337,6 +341,18 @@ func (ctx Context) WithConsensusAddressCodec(consensusAddressCodec address.Codec return ctx } +// WithAddressPrefix returns the context with the provided address bech32 prefix. +func (ctx Context) WithAddressPrefix(addressPrefix string) Context { + ctx.AddressPrefix = addressPrefix + return ctx +} + +// WithValidatorPrefix returns the context with the provided validator bech32 prefix. +func (ctx Context) WithValidatorPrefix(validatorPrefix string) Context { + ctx.ValidatorPrefix = validatorPrefix + return ctx +} + // PrintString prints the raw string to ctx.Output if it's defined, otherwise to os.Stdout func (ctx Context) PrintString(str string) error { return ctx.PrintBytes([]byte(str)) diff --git a/client/keys/add.go b/client/keys/add.go index 4e6e4f27f756..e61715f37399 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -269,7 +269,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf // If we're using ledger, only thing we need is the path and the bech32 prefix. if useLedger { - bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix() + bech32PrefixAccAddr := ctx.AddressPrefix k, err := kb.SaveLedgerKey(name, hd.Secp256k1, bech32PrefixAccAddr, coinType, account, index) if err != nil { return err diff --git a/client/keys/parse.go b/client/keys/parse.go index 5fb34935c477..aa468e089281 100644 --- a/client/keys/parse.go +++ b/client/keys/parse.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/cosmos/cosmos-sdk/client" "io" "strings" @@ -16,14 +17,14 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" ) -func bech32Prefixes(config *sdk.Config) []string { +func bech32Prefixes(mainBech32Prefix string) []string { return []string{ - config.GetBech32AccountAddrPrefix(), - config.GetBech32AccountPubPrefix(), - config.GetBech32ValidatorAddrPrefix(), - config.GetBech32ValidatorPubPrefix(), - config.GetBech32ConsensusAddrPrefix(), - config.GetBech32ConsensusPubPrefix(), + mainBech32Prefix, + sdk.GetBech32PrefixAccPub(mainBech32Prefix), + sdk.GetBech32PrefixValAddr(mainBech32Prefix), + sdk.GetBech32PrefixValPub(mainBech32Prefix), + sdk.GetBech32PrefixConsAddr(mainBech32Prefix), + sdk.GetBech32PrefixConsPub(mainBech32Prefix), } } @@ -44,8 +45,8 @@ type bech32Output struct { Formats []string `json:"formats"` } -func newBech32Output(config *sdk.Config, bs []byte) bech32Output { - bech32Prefixes := bech32Prefixes(config) +func newBech32Output(bech32Prefix string, bs []byte) bech32Output { + bech32Prefixes := bech32Prefixes(bech32Prefix) out := bech32Output{Formats: make([]string, len(bech32Prefixes))} for i, prefix := range bech32Prefixes { @@ -80,15 +81,18 @@ hexadecimal into bech32 cosmos prefixed format and vice versa. `, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - config, _ := sdk.GetSealedConfig(cmd.Context()) - return doParseKey(cmd, config, args) + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + return doParseKey(cmd, clientCtx.AddressPrefix, args) }, } return cmd } -func doParseKey(cmd *cobra.Command, config *sdk.Config, args []string) error { +func doParseKey(cmd *cobra.Command, bech32Prefix string, args []string) error { addr := strings.TrimSpace(args[0]) outstream := cmd.OutOrStdout() @@ -97,7 +101,7 @@ func doParseKey(cmd *cobra.Command, config *sdk.Config, args []string) error { } output, _ := cmd.Flags().GetString(flags.FlagOutput) - if !(runFromBech32(outstream, addr, output) || runFromHex(config, outstream, addr, output)) { + if !(runFromBech32(outstream, addr, output) || runFromHex(bech32Prefix, outstream, addr, output)) { return errors.New("couldn't find valid bech32 nor hex data") } @@ -117,13 +121,13 @@ func runFromBech32(w io.Writer, bech32str, output string) bool { } // print info from hex -func runFromHex(config *sdk.Config, w io.Writer, hexstr, output string) bool { +func runFromHex(bech32Prefix string, w io.Writer, hexstr, output string) bool { bz, err := hex.DecodeString(hexstr) if err != nil { return false } - displayParseKeyInfo(w, newBech32Output(config, bz), output) + displayParseKeyInfo(w, newBech32Output(bech32Prefix, bz), output) return true } diff --git a/client/keys/parse_test.go b/client/keys/parse_test.go index 687922db3c6c..650cb7c501f0 100644 --- a/client/keys/parse_test.go +++ b/client/keys/parse_test.go @@ -4,16 +4,12 @@ import ( "testing" "github.com/stretchr/testify/require" - - sdk "github.com/cosmos/cosmos-sdk/types" ) func TestParseKey(t *testing.T) { bech32str := "cosmos104ytdpvrx9284zd50v9ep8c6j7pua7dkk0x3ek" hexstr := "EB5AE9872103497EC092EF901027049E4F39200C60040D3562CD7F104A39F62E6E5A39A818F4" - config := sdk.NewConfig() - tests := []struct { name string args []string @@ -27,7 +23,7 @@ func TestParseKey(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.wantErr, doParseKey(ParseKeyStringCommand(), config, tt.args) != nil) + require.Equal(t, tt.wantErr, doParseKey(ParseKeyStringCommand(), "cosmos", tt.args) != nil) }) } } diff --git a/client/keys/show.go b/client/keys/show.go index fd2abe33b720..22c14ddaeb58 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -175,7 +175,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) { return err } - return ledger.ShowAddress(*ledgerItem.Path, pk, sdk.GetConfig().GetBech32AccountAddrPrefix()) + return ledger.ShowAddress(*ledgerItem.Path, pk, clientCtx.AddressPrefix) } return nil diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 42553a4835f5..cc4a21dbf4ed 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -29,7 +29,7 @@ import ( func newTestTxConfig() (client.TxConfig, codec.Codec) { encodingConfig := moduletestutil.MakeTestEncodingConfig() - return authtx.NewTxConfig(codec.NewProtoCodec(encodingConfig.InterfaceRegistry), authtx.DefaultSignModes), encodingConfig.Codec + return authtx.NewTxConfig(codec.NewProtoCodec(encodingConfig.InterfaceRegistry), authtx.DefaultSignModes, "cosmos", "cosmosvaloper"), encodingConfig.Codec } // mockContext is a mock client.Context to return arbitrary simulation response, used to diff --git a/crypto/ledger/ledger_test.go b/crypto/ledger/ledger_test.go index 1c742791a35f..a0ff890b935c 100644 --- a/crypto/ledger/ledger_test.go +++ b/crypto/ledger/ledger_test.go @@ -95,7 +95,7 @@ func TestPublicKeySafe(t *testing.T) { require.NoError(t, err) require.NotNil(t, priv) - require.Nil(t, ShowAddress(path, priv.PubKey(), sdk.GetConfig().GetBech32AccountAddrPrefix())) + require.Nil(t, ShowAddress(path, priv.PubKey(), "cosmos")) checkDefaultPubKey(t, priv) addr2 := sdk.AccAddress(priv.PubKey().Address()).String() diff --git a/simapp/app.go b/simapp/app.go index 66c216eaa939..38160ab8c23f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -211,7 +211,7 @@ func NewSimApp( }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() - txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes, sdk.GetConfig().GetBech32AccountAddrPrefix(), sdk.GetConfig().GetBech32ValidatorAddrPrefix()) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) @@ -322,6 +322,8 @@ func NewSimApp( txConfigOpts := authtx.ConfigOptions{ EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + AddressPrefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + ValidatorPrefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), } txConfig, err = authtx.NewTxConfigWithOptions( appCodec, diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 24ed158ee4b6..d94dedd2fdeb 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -49,7 +49,9 @@ func NewRootCmd() *cobra.Command { WithValidatorAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix())). WithConsensusAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix())). WithHomeDir(simapp.DefaultNodeHome). - WithViper("") // uses by default the binary name as prefix + WithViper(""). // uses by default the binary name as prefix + WithAddressPrefix(sdk.GetConfig().GetBech32AccountAddrPrefix()). + WithValidatorPrefix(sdk.GetConfig().GetBech32ValidatorAddrPrefix()) rootCmd := &cobra.Command{ Use: "simd", @@ -80,6 +82,8 @@ func NewRootCmd() *cobra.Command { txConfigOpts := tx.ConfigOptions{ EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx), + AddressPrefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + ValidatorPrefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), } txConfig, err := tx.NewTxConfigWithOptions( initClientCtx.Codec, diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 3b207a1a0155..f3b8a37ca3c8 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -116,7 +116,9 @@ func ProvideClientContext( WithValidatorAddressCodec(validatorAddressCodec). WithConsensusAddressCodec(consensusAddressCodec). WithHomeDir(simapp.DefaultNodeHome). - WithViper("") // uses by default the binary name as prefix + WithViper(""). // uses by default the binary name as prefix + WithAddressPrefix(txConfigOpts.AddressPrefix). + WithValidatorPrefix(txConfigOpts.ValidatorPrefix) // Read the config to overwrite the default values with the values from the config file customClientTemplate, customClientConfig := initClientConfig() diff --git a/testutil/integration/router.go b/testutil/integration/router.go index cbb579823207..07f56e829dea 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -55,7 +55,7 @@ func NewIntegrationApp( basicModuleManager := module.NewBasicManagerFromManager(moduleManager, nil) basicModuleManager.RegisterInterfaces(interfaceRegistry) - txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes, "cosmos", "cosmosvaloper") bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName)) bApp.MountKVStores(keys) diff --git a/types/address.go b/types/address.go index 3cafd383eb87..8bb0d56fc4c8 100644 --- a/types/address.go +++ b/types/address.go @@ -71,6 +71,31 @@ const ( Bech32PrefixConsPub = Bech32MainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic ) +// GetBech32PrefixAccPub returns the Bech32 prefix of an account's public key. +func GetBech32PrefixAccPub(mainPrefix string) string { + return mainPrefix + PrefixPublic +} + +// GetBech32PrefixValAddr returns the Bech32 prefix of a validator's operator address. +func GetBech32PrefixValAddr(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixOperator +} + +// GetBech32PrefixValPub returns the Bech32 prefix of a validator's operator public key. +func GetBech32PrefixValPub(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixOperator + PrefixPublic +} + +// GetBech32PrefixConsAddr returns the Bech32 prefix of a consensus node address. +func GetBech32PrefixConsAddr(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixConsensus +} + +// GetBech32PrefixConsPub returns the Bech32 prefix of a consensus node public key. +func GetBech32PrefixConsPub(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic +} + // cache variables var ( // AccAddress.String() is expensive and if unoptimized dominantly showed up in profiles, diff --git a/types/config.go b/types/config.go index 7f638f255e34..7089ceaff74b 100644 --- a/types/config.go +++ b/types/config.go @@ -13,7 +13,6 @@ const DefaultKeyringServiceName = "cosmos" // Config is the structure that holds the SDK configuration parameters. // This could be used to initialize certain configuration parameters for the SDK. type Config struct { - fullFundraiserPath string bech32AddressPrefix map[string]string mtx sync.RWMutex @@ -39,7 +38,6 @@ func NewConfig() *Config { "validator_pub": Bech32PrefixValPub, "consensus_pub": Bech32PrefixConsPub, }, - fullFundraiserPath: FullFundraiserPath, } } @@ -96,14 +94,6 @@ func (config *Config) SetBech32PrefixForConsensusNode(addressPrefix, pubKeyPrefi config.bech32AddressPrefix["consensus_pub"] = pubKeyPrefix } -// Set the FullFundraiserPath (BIP44Prefix) on the config. -// -// Deprecated: This method is supported for backward compatibility only and will be removed in a future release. Use SetPurpose and SetCoinType instead. -func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) { - config.assertNotSealed() - config.fullFundraiserPath = fullFundraiserPath -} - // Seal seals the config such that the config state could not be modified further func (config *Config) Seal() *Config { config.mtx.Lock() diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index cd3ddf206214..abf8ecb01334 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -30,7 +30,7 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig encCfg := TestEncodingConfig{ InterfaceRegistry: interfaceRegistry, Codec: codec, - TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes), + TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes, "cosmos", "cosmosvaloper"), Amino: aminoCodec, } @@ -47,7 +47,7 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig func MakeTestTxConfig() client.TxConfig { interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) - return tx.NewTxConfig(cdc, tx.DefaultSignModes) + return tx.NewTxConfig(cdc, tx.DefaultSignModes, "cosmos", "cosmosvaloper") } type TestBuilderTxConfig struct { diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 3a0f60c1f690..37e41e7004af 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -145,7 +145,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { tc := stc // to make scopelint happy t.Run(name, func(t *testing.T) { suite := SetupTestSuite(t, false) - protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), tx.DefaultSignModes) + protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), tx.DefaultSignModes, "cosmos", "cosmosvaloper") // this just tests our handler dfd := ante.NewDeductFeeDecorator(suite.accountKeeper, suite.bankKeeper, suite.feeGrantKeeper, nil) feeAnteHandler := sdk.ChainAnteDecorators(dfd) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 858851b1c693..efc5c13c89bc 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -9,7 +9,6 @@ import ( "cosmossdk.io/x/tx/signing/direct" "cosmossdk.io/x/tx/signing/directaux" "cosmossdk.io/x/tx/signing/textual" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -54,6 +53,10 @@ type ConfigOptions struct { JSONDecoder sdk.TxDecoder // JSONEncoder is the encoder that will be used to encode json transactions. JSONEncoder sdk.TxEncoder + // AddressPredix is the bech32 address prefix. + AddressPrefix string + // ValidatorPrefix is the bech32 validator prefix. + ValidatorPrefix string } // DefaultSignModes are the default sign modes enabled for protobuf transactions. @@ -73,12 +76,14 @@ var DefaultSignModes = []signingtypes.SignMode{ // We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK, // this constructor is primarily used in tests, but also sees usage in app chains like: // https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37 -func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, - customSignModes ...txsigning.SignModeHandler, +func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, addressPrefix, + validatorPrefix string, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{ EnabledSignModes: enabledSignModes, CustomSignModes: customSignModes, + AddressPrefix: addressPrefix, + ValidatorPrefix: validatorPrefix, }) if err != nil { panic(err) @@ -86,13 +91,12 @@ func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMod return txConfig } -// NewDefaultSigningOptions returns the sdk default signing options used by x/tx. This includes account and +// NewSigningOptions returns signing options used by x/tx. This includes account and // validator address prefix enabled codecs. -func NewDefaultSigningOptions() (*txsigning.Options, error) { - sdkConfig := sdk.GetConfig() +func NewSigningOptions(addressPrefix, validatorPrefix string) (*txsigning.Options, error) { return &txsigning.Options{ - AddressCodec: authcodec.NewBech32Codec(sdkConfig.GetBech32AccountAddrPrefix()), - ValidatorAddressCodec: authcodec.NewBech32Codec(sdkConfig.GetBech32ValidatorAddrPrefix()), + AddressCodec: authcodec.NewBech32Codec(addressPrefix), + ValidatorAddressCodec: authcodec.NewBech32Codec(validatorPrefix), }, nil } @@ -102,7 +106,8 @@ func NewDefaultSigningOptions() (*txsigning.Options, error) { func NewSigningHandlerMap(configOpts ConfigOptions) (*txsigning.HandlerMap, error) { var err error if configOpts.SigningOptions == nil { - configOpts.SigningOptions, err = NewDefaultSigningOptions() + //configOpts.SigningOptions, err = NewDefaultSigningOptions() + configOpts.SigningOptions, err = NewSigningOptions(configOpts.AddressPrefix, configOpts.ValidatorPrefix) if err != nil { return nil, err } @@ -188,7 +193,8 @@ func NewTxConfigWithOptions(protoCodec codec.Codec, configOptions ConfigOptions) var err error if configOptions.SigningContext == nil { if configOptions.SigningOptions == nil { - configOptions.SigningOptions, err = NewDefaultSigningOptions() + //configOptions.SigningOptions, err = NewDefaultSigningOptions() + configOptions.SigningOptions, err = NewSigningOptions(configOptions.AddressPrefix, configOptions.ValidatorPrefix) if err != nil { return nil, err } diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index dff980a5a790..1893cda74265 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -2,6 +2,8 @@ package tx import ( "context" + authv1 "cosmossdk.io/api/cosmos/auth/module/v1" + stakingv1 "cosmossdk.io/api/cosmos/staking/module/v1" "fmt" "google.golang.org/grpc" @@ -44,6 +46,8 @@ type ModuleInputs struct { ValidatorAddressCodec runtime.ValidatorAddressCodec Codec codec.Codec ProtoFileResolver txsigning.ProtoFileResolver + AuthConfig *authv1.Module + StakingConfig *stakingv1.Module // BankKeeper is the expected bank keeper to be passed to AnteHandlers BankKeeper authtypes.BankKeeper `optional:"true"` MetadataBankKeeper BankKeeper `optional:"true"` @@ -78,6 +82,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { ValidatorAddressCodec: in.ValidatorAddressCodec, }, CustomSignModes: customSignModeHandlers, + AddressPrefix: in.AuthConfig.Bech32Prefix, + ValidatorPrefix: in.StakingConfig.Bech32PrefixValidator, } // enable SIGN_MODE_TEXTUAL only if bank keeper is available diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index e109f69f1e03..86fe0c6ab9cc 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -22,7 +22,7 @@ func TestGenerator(t *testing.T) { std.RegisterInterfaces(interfaceRegistry) interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}) protoCodec := codec.NewProtoCodec(interfaceRegistry) - suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, tx.DefaultSignModes))) + suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, tx.DefaultSignModes, "cosmos", "cosmosvaloper"))) } func TestConfigOptions(t *testing.T) { From 515f295af2c872dbbdcc0cb38f8852370b780d02 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 15 Feb 2024 16:32:43 +0100 Subject: [PATCH 02/19] fix: lint --- client/keys/parse.go | 2 +- x/auth/tx/config.go | 3 +-- x/auth/tx/config/depinject.go | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/client/keys/parse.go b/client/keys/parse.go index aa468e089281..62bb5f75011a 100644 --- a/client/keys/parse.go +++ b/client/keys/parse.go @@ -5,13 +5,13 @@ import ( "encoding/json" "errors" "fmt" - "github.com/cosmos/cosmos-sdk/client" "io" "strings" "github.com/spf13/cobra" "sigs.k8s.io/yaml" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index efc5c13c89bc..7ba46939f0fd 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -9,6 +9,7 @@ import ( "cosmossdk.io/x/tx/signing/direct" "cosmossdk.io/x/tx/signing/directaux" "cosmossdk.io/x/tx/signing/textual" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -106,7 +107,6 @@ func NewSigningOptions(addressPrefix, validatorPrefix string) (*txsigning.Option func NewSigningHandlerMap(configOpts ConfigOptions) (*txsigning.HandlerMap, error) { var err error if configOpts.SigningOptions == nil { - //configOpts.SigningOptions, err = NewDefaultSigningOptions() configOpts.SigningOptions, err = NewSigningOptions(configOpts.AddressPrefix, configOpts.ValidatorPrefix) if err != nil { return nil, err @@ -193,7 +193,6 @@ func NewTxConfigWithOptions(protoCodec codec.Codec, configOptions ConfigOptions) var err error if configOptions.SigningContext == nil { if configOptions.SigningOptions == nil { - //configOptions.SigningOptions, err = NewDefaultSigningOptions() configOptions.SigningOptions, err = NewSigningOptions(configOptions.AddressPrefix, configOptions.ValidatorPrefix) if err != nil { return nil, err diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index 1893cda74265..d4651e2579f2 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -2,15 +2,14 @@ package tx import ( "context" - authv1 "cosmossdk.io/api/cosmos/auth/module/v1" - stakingv1 "cosmossdk.io/api/cosmos/staking/module/v1" "fmt" - "google.golang.org/grpc" "google.golang.org/grpc/codes" grpcstatus "google.golang.org/grpc/status" + authv1 "cosmossdk.io/api/cosmos/auth/module/v1" bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + stakingv1 "cosmossdk.io/api/cosmos/staking/module/v1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/address" "cosmossdk.io/depinject" From dd03da772f158166104cb72ce712e40c557fc3ba Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 27 Feb 2024 09:54:44 +0100 Subject: [PATCH 03/19] fix: lint --- x/auth/tx/config/depinject.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index d4651e2579f2..5a92e4b2c7b6 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -3,6 +3,7 @@ package tx import ( "context" "fmt" + "google.golang.org/grpc" "google.golang.org/grpc/codes" grpcstatus "google.golang.org/grpc/status" From bfdc12b9c19a609a5df0508dcdac54a11042b059 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 27 Feb 2024 10:14:06 +0100 Subject: [PATCH 04/19] fix: test --- testutil/sims/simulation_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index a1147231c64b..f3774be12f08 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -55,7 +55,7 @@ func SimulationOperations(app runtime.AppSimI, cdc codec.Codec, config simtypes. simState := module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, - TxConfig: authtx.NewTxConfig(cdc, authtx.DefaultSignModes), // TODO(tip): we should extract this from app + TxConfig: authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper"), // TODO(tip): we should extract this from app BondDenom: sdk.DefaultBondDenom, } From 03b9b0f2901919d345607bdbeba3cd36cb9f761d Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 27 Feb 2024 12:52:47 +0100 Subject: [PATCH 05/19] fix: TestSigVerification --- x/auth/ante/sigverify_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index d157866e0d10..db7c0a7e30df 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -102,6 +102,8 @@ func TestSigVerification(t *testing.T) { txConfigOpts := authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx), EnabledSignModes: enabledSignModes, + AddressPrefix: "cosmos", + ValidatorPrefix: "cosmosvaloper", } var err error suite.clientCtx.TxConfig, err = authtx.NewTxConfigWithOptions( From 99b6d5796825218fc6b6c698725cbeb3a407f591 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 29 Feb 2024 11:50:44 +0100 Subject: [PATCH 06/19] update: NewTxConfig --- baseapp/abci_utils_test.go | 6 ++++-- baseapp/baseapp_test.go | 9 +++++---- baseapp/msg_service_router_test.go | 3 ++- client/context.go | 2 +- client/tx/tx_test.go | 4 +++- simapp/app.go | 9 ++++++--- simapp/simd/cmd/root.go | 7 +++++-- simapp/simd/cmd/root_v2.go | 8 ++++++-- testutil/integration/router.go | 3 ++- testutil/sims/simulation_helpers.go | 3 ++- types/module/testutil/codec.go | 10 ++++++---- x/auth/tx/config.go | 24 ++++++++---------------- x/auth/tx/config/depinject.go | 6 ------ 13 files changed, 50 insertions(+), 44 deletions(-) diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index 4c3f41882ae2..949d4d52d5d8 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -325,9 +325,10 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() // create a codec for marshaling cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() // create a baseapp along with a tx config for tx generation - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), dbm.NewMemDB(), txConfig.TxDecoder()) // create a proposal handler @@ -422,7 +423,8 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSelection() { cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") + signingCtx := cdc.InterfaceRegistry().SigningContext() + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) var ( secret1 = []byte("secret1") diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 3913d2003b26..910be1a93e84 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -29,7 +29,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -65,8 +64,9 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite t.Helper() cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) db := dbm.NewMemDB() logBuffer := new(bytes.Buffer) logger := log.NewLogger(logBuffer, log.ColorOption(false)) @@ -499,11 +499,12 @@ func TestBaseAppOptionSeal(t *testing.T) { } func TestTxDecoder(t *testing.T) { - cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) tx := newTxCounter(t, txConfig, 1, 0) txBytes, err := txConfig.TxEncoder()(tx) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index cd7d3b9c4552..725e90d79264 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -136,9 +136,10 @@ func TestMsgService(t *testing.T) { ), &appBuilder, &cdc, &interfaceRegistry) require.NoError(t, err) app := appBuilder.Build(dbm.NewMemDB(), nil) + signingCtx := interfaceRegistry.SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper") + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) // set the TxDecoder in the BaseApp for minimal tx simulations app.SetTxDecoder(txConfig.TxDecoder()) diff --git a/client/context.go b/client/context.go index 6cd51b71045a..b4f8e54fe024 100644 --- a/client/context.go +++ b/client/context.go @@ -80,7 +80,7 @@ type Context struct { ValidatorAddressCodec address.Codec ConsensusAddressCodec address.Codec - // Bech32 address prefixes + // Bech32 address prefixes. AddressPrefix string ValidatorPrefix string } diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index e53d28842737..5d8b12efac42 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -29,7 +29,9 @@ import ( func newTestTxConfig() (client.TxConfig, codec.Codec) { encodingConfig := moduletestutil.MakeTestEncodingConfig() - return authtx.NewTxConfig(codec.NewProtoCodec(encodingConfig.InterfaceRegistry), authtx.DefaultSignModes, "cosmos", "cosmosvaloper"), encodingConfig.Codec + cdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) + signingCtx := cdc.InterfaceRegistry().SigningContext() + return authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), encodingConfig.Codec } // mockContext is a mock client.Context to return arbitrary simulation response, used to diff --git a/simapp/app.go b/simapp/app.go index 79dc76fd5947..1ff00556a52d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -207,7 +207,8 @@ func NewSimApp( }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() - txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes, sdk.GetConfig().GetBech32AccountAddrPrefix(), sdk.GetConfig().GetBech32ValidatorAddrPrefix()) + signingCtx := interfaceRegistry.SigningContext() + txConfig := authtx.NewTxConfig(appCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) @@ -315,8 +316,10 @@ func NewSimApp( txConfigOpts := authtx.ConfigOptions{ EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), - AddressPrefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), - ValidatorPrefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + SigningOptions: &signing.Options{ + AddressCodec: signingCtx.AddressCodec(), + ValidatorAddressCodec: signingCtx.ValidatorAddressCodec(), + }, } txConfig, err = authtx.NewTxConfigWithOptions( appCodec, diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 3a864cb05f36..e2c0fec47604 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/x/auth/tx" authtxconfig "cosmossdk.io/x/auth/tx/config" "cosmossdk.io/x/auth/types" + txsigning "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -82,8 +83,10 @@ func NewRootCmd() *cobra.Command { txConfigOpts := tx.ConfigOptions{ EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx), - AddressPrefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), - ValidatorPrefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + SigningOptions: &txsigning.Options{ + AddressCodec: initClientCtx.InterfaceRegistry.SigningContext().AddressCodec(), + ValidatorAddressCodec: initClientCtx.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + }, } txConfig, err := tx.NewTxConfigWithOptions( initClientCtx.Codec, diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 2d0f23f04768..796a4ce85ff2 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -7,6 +7,8 @@ import ( "github.com/spf13/cobra" + authv1 "cosmossdk.io/api/cosmos/auth/module/v1" + stakingv1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/client/v2/autocli" clientv2keyring "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/core/address" @@ -103,6 +105,8 @@ func ProvideClientContext( addressCodec address.Codec, validatorAddressCodec runtime.ValidatorAddressCodec, consensusAddressCodec runtime.ConsensusAddressCodec, + authConfig *authv1.Module, + stakingConfig *stakingv1.Module, ) client.Context { var err error @@ -117,8 +121,8 @@ func ProvideClientContext( WithConsensusAddressCodec(consensusAddressCodec). WithHomeDir(simapp.DefaultNodeHome). WithViper(""). // uses by default the binary name as prefix - WithAddressPrefix(txConfigOpts.AddressPrefix). - WithValidatorPrefix(txConfigOpts.ValidatorPrefix) + WithAddressPrefix(authConfig.Bech32Prefix). + WithValidatorPrefix(stakingConfig.Bech32PrefixValidator) // Read the config to overwrite the default values with the values from the config file customClientTemplate, customClientConfig := initClientConfig() diff --git a/testutil/integration/router.go b/testutil/integration/router.go index cf97a62fd0bf..8bc3989fae47 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -53,8 +53,9 @@ func NewIntegrationApp( interfaceRegistry := codectypes.NewInterfaceRegistry() moduleManager := module.NewManagerFromMap(modules) moduleManager.RegisterInterfaces(interfaceRegistry) + signingCtx := interfaceRegistry.SigningContext() - txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes, "cosmos", "cosmosvaloper") + txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName)) bApp.MountKVStores(keys) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index f3774be12f08..ac2d5b871cf7 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -52,10 +52,11 @@ func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose, // SimulationOperations retrieves the simulation params from the provided file path // and returns all the modules weighted operations func SimulationOperations(app runtime.AppSimI, cdc codec.Codec, config simtypes.Config) []simtypes.WeightedOperation { + signingCtx := cdc.InterfaceRegistry().SigningContext() simState := module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, - TxConfig: authtx.NewTxConfig(cdc, authtx.DefaultSignModes, "cosmos", "cosmosvaloper"), // TODO(tip): we should extract this from app + TxConfig: authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), // TODO(tip): we should extract this from app BondDenom: sdk.DefaultBondDenom, } diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index adac6f410f08..34bffae69830 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -25,12 +25,13 @@ type TestEncodingConfig struct { func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { aminoCodec := codec.NewLegacyAmino() interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() - codec := codec.NewProtoCodec(interfaceRegistry) + cdc := codec.NewProtoCodec(interfaceRegistry) + signingCtx := interfaceRegistry.SigningContext() encCfg := TestEncodingConfig{ InterfaceRegistry: interfaceRegistry, - Codec: codec, - TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes, "cosmos", "cosmosvaloper"), + Codec: cdc, + TxConfig: tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes), Amino: aminoCodec, } @@ -46,7 +47,8 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { func MakeTestTxConfig() client.TxConfig { interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) - return tx.NewTxConfig(cdc, tx.DefaultSignModes, "cosmos", "cosmosvaloper") + signingCtx := interfaceRegistry.SigningContext() + return tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) } type TestBuilderTxConfig struct { diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 79f94784caa1..dc0bf3c31e75 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -1,6 +1,7 @@ package tx import ( + "errors" "fmt" "cosmossdk.io/core/address" @@ -57,10 +58,6 @@ type ConfigOptions struct { JSONDecoder sdk.TxDecoder // JSONEncoder is the encoder that will be used to encode json transactions. JSONEncoder sdk.TxEncoder - // AddressPredix is the bech32 address prefix. - AddressPrefix string - // ValidatorPrefix is the bech32 validator prefix. - ValidatorPrefix string } // DefaultSignModes are the default sign modes enabled for protobuf transactions. @@ -80,14 +77,15 @@ var DefaultSignModes = []signingtypes.SignMode{ // We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK, // this constructor is primarily used in tests, but also sees usage in app chains like: // https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37 -func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, addressPrefix, - validatorPrefix string, customSignModes ...txsigning.SignModeHandler, +func NewTxConfig(protoCodec codec.Codec, addressCodec, validatorAddressCodec address.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{ EnabledSignModes: enabledSignModes, CustomSignModes: customSignModes, - AddressPrefix: addressPrefix, - ValidatorPrefix: validatorPrefix, + SigningOptions: &txsigning.Options{ + AddressCodec: addressCodec, + ValidatorAddressCodec: validatorAddressCodec, + }, }) if err != nil { panic(err) @@ -110,10 +108,7 @@ func NewSigningOptions(addressPrefix, validatorPrefix string) (*txsigning.Option func NewSigningHandlerMap(configOpts ConfigOptions) (*txsigning.HandlerMap, error) { var err error if configOpts.SigningOptions == nil { - configOpts.SigningOptions, err = NewSigningOptions(configOpts.AddressPrefix, configOpts.ValidatorPrefix) - if err != nil { - return nil, err - } + return nil, errors.New("not signing options not provided") } if configOpts.SigningContext == nil { configOpts.SigningContext, err = txsigning.NewContext(*configOpts.SigningOptions) @@ -184,10 +179,7 @@ func NewTxConfigWithOptions(protoCodec codec.Codec, configOptions ConfigOptions) var err error if configOptions.SigningContext == nil { if configOptions.SigningOptions == nil { - configOptions.SigningOptions, err = NewSigningOptions(configOptions.AddressPrefix, configOptions.ValidatorPrefix) - if err != nil { - return nil, err - } + return nil, errors.New("signing options not provided") } if configOptions.SigningOptions.FileResolver == nil { configOptions.SigningOptions.FileResolver = protoCodec.InterfaceRegistry() diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index 32eb667a84ee..85ce366c9b7c 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -10,9 +10,7 @@ import ( grpcstatus "google.golang.org/grpc/status" "google.golang.org/protobuf/reflect/protoreflect" - authv1 "cosmossdk.io/api/cosmos/auth/module/v1" bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - stakingv1 "cosmossdk.io/api/cosmos/staking/module/v1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/address" "cosmossdk.io/depinject" @@ -47,8 +45,6 @@ type ModuleInputs struct { ValidatorAddressCodec runtime.ValidatorAddressCodec Codec codec.Codec ProtoFileResolver txsigning.ProtoFileResolver - AuthConfig *authv1.Module - StakingConfig *stakingv1.Module // BankKeeper is the expected bank keeper to be passed to AnteHandlers BankKeeper authtypes.BankKeeper `optional:"true"` MetadataBankKeeper BankKeeper `optional:"true"` @@ -85,8 +81,6 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { CustomGetSigners: make(map[protoreflect.FullName]txsigning.GetSignersFunc), }, CustomSignModes: customSignModeHandlers, - AddressPrefix: in.AuthConfig.Bech32Prefix, - ValidatorPrefix: in.StakingConfig.Bech32PrefixValidator, } for _, mode := range in.CustomGetSigners { From b3a92760ece5995103a33553d63a653583f31044 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 29 Feb 2024 12:16:58 +0100 Subject: [PATCH 07/19] fix: x/auth tests --- x/auth/ante/feegrant_test.go | 4 +++- x/auth/ante/sigverify_test.go | 21 +++++++++++++++++---- x/auth/tx/config.go | 2 +- x/auth/tx/config_test.go | 3 ++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 37e41e7004af..51c6f349f72c 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -145,7 +145,9 @@ func TestDeductFeesNoDelegation(t *testing.T) { tc := stc // to make scopelint happy t.Run(name, func(t *testing.T) { suite := SetupTestSuite(t, false) - protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), tx.DefaultSignModes, "cosmos", "cosmosvaloper") + cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) + signingCtx := cdc.InterfaceRegistry().SigningContext() + protoTxCfg := tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) // this just tests our handler dfd := ante.NewDeductFeeDecorator(suite.accountKeeper, suite.bankKeeper, suite.feeGrantKeeper, nil) feeAnteHandler := sdk.ChainAnteDecorators(dfd) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index db7c0a7e30df..ab21482b48c8 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -15,6 +15,7 @@ import ( authtx "cosmossdk.io/x/auth/tx" txmodule "cosmossdk.io/x/auth/tx/config" "cosmossdk.io/x/auth/types" + txsigning "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -99,15 +100,18 @@ func TestSigVerification(t *testing.T) { enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} // Since TEXTUAL is not enabled by default, we create a custom TxConfig // here which includes it. + cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) txConfigOpts := authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx), EnabledSignModes: enabledSignModes, - AddressPrefix: "cosmos", - ValidatorPrefix: "cosmosvaloper", + SigningOptions: &txsigning.Options{ + AddressCodec: cdc.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + }, } var err error suite.clientCtx.TxConfig, err = authtx.NewTxConfigWithOptions( - codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), + cdc, txConfigOpts, ) require.NoError(t, err) @@ -140,6 +144,10 @@ func TestSigVerification(t *testing.T) { txConfigOpts = authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(suite.txBankKeeper), EnabledSignModes: enabledSignModes, + SigningOptions: &txsigning.Options{ + AddressCodec: cdc.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + }, } anteTxConfig, err := authtx.NewTxConfigWithOptions( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), @@ -305,13 +313,18 @@ func TestAnteHandlerChecks(t *testing.T) { enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} // Since TEXTUAL is not enabled by default, we create a custom TxConfig // here which includes it. + cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) txConfigOpts := authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx), EnabledSignModes: enabledSignModes, + SigningOptions: &txsigning.Options{ + AddressCodec: cdc.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + }, } anteTxConfig, err := authtx.NewTxConfigWithOptions( - codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), + cdc, txConfigOpts, ) require.NoError(t, err) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index dc0bf3c31e75..ce29e8e01c63 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -108,7 +108,7 @@ func NewSigningOptions(addressPrefix, validatorPrefix string) (*txsigning.Option func NewSigningHandlerMap(configOpts ConfigOptions) (*txsigning.HandlerMap, error) { var err error if configOpts.SigningOptions == nil { - return nil, errors.New("not signing options not provided") + return nil, errors.New("signing options not provided") } if configOpts.SigningContext == nil { configOpts.SigningContext, err = txsigning.NewContext(*configOpts.SigningOptions) diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index 9c88643f1fe8..fc94f5b44863 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -23,7 +23,8 @@ func TestGenerator(t *testing.T) { std.RegisterInterfaces(interfaceRegistry) interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}) protoCodec := codec.NewProtoCodec(interfaceRegistry) - suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, tx.DefaultSignModes, "cosmos", "cosmosvaloper"))) + signingCtx := interfaceRegistry.SigningContext() + suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes))) } func TestConfigOptions(t *testing.T) { From 7b757c156f3a6012aa2f431cdb4e17e19f56c886 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 29 Feb 2024 12:51:16 +0100 Subject: [PATCH 08/19] fix: TestConfigOptions --- x/auth/tx/config_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index fc94f5b44863..47809828dfbd 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -1,6 +1,7 @@ package tx_test import ( + "cosmossdk.io/x/tx/signing" "testing" "github.com/stretchr/testify/require" @@ -30,7 +31,10 @@ func TestGenerator(t *testing.T) { func TestConfigOptions(t *testing.T) { interfaceRegistry := types.NewInterfaceRegistry() protoCodec := codec.NewProtoCodec(interfaceRegistry) - configOptions := tx.ConfigOptions{} + configOptions := tx.ConfigOptions{SigningOptions: &signing.Options{ + AddressCodec: protoCodec.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: protoCodec.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + }} txConfig, err := tx.NewTxConfigWithOptions(protoCodec, configOptions) require.NoError(t, err) require.NotNil(t, txConfig) From deab53ee2d013a989e40059e5cda81089889f9b3 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 29 Feb 2024 13:40:02 +0100 Subject: [PATCH 09/19] lint happy --- x/auth/tx/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index 47809828dfbd..1fc215a4e868 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -1,7 +1,6 @@ package tx_test import ( - "cosmossdk.io/x/tx/signing" "testing" "github.com/stretchr/testify/require" @@ -10,6 +9,7 @@ import ( _ "cosmossdk.io/api/cosmos/crypto/secp256k1" "cosmossdk.io/x/auth/tx" txtestutil "cosmossdk.io/x/auth/tx/testutil" + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/testutil" From e5a743ed77ad352b058e149f1212c3eb74eb8fee Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 29 Feb 2024 17:15:24 +0100 Subject: [PATCH 10/19] update: NewTxConfig uses codec ir --- baseapp/abci_utils_test.go | 6 ++---- baseapp/baseapp_test.go | 6 ++---- baseapp/msg_service_router_test.go | 3 +-- client/tx/tx_test.go | 3 +-- simapp/app.go | 2 +- testutil/integration/router.go | 3 +-- testutil/sims/simulation_helpers.go | 3 +-- types/module/testutil/codec.go | 7 ++----- x/auth/ante/feegrant_test.go | 3 +-- x/auth/tx/config.go | 6 +++--- x/auth/tx/config_test.go | 3 +-- 11 files changed, 16 insertions(+), 29 deletions(-) diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index 949d4d52d5d8..d0845c51040d 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -325,10 +325,9 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() // create a codec for marshaling cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - signingCtx := cdc.InterfaceRegistry().SigningContext() // create a baseapp along with a tx config for tx generation - txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), dbm.NewMemDB(), txConfig.TxDecoder()) // create a proposal handler @@ -423,8 +422,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSelection() { cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - signingCtx := cdc.InterfaceRegistry().SigningContext() - txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) var ( secret1 = []byte("secret1") diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 910be1a93e84..3ce4726d1c08 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -64,9 +64,8 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite t.Helper() cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - signingCtx := cdc.InterfaceRegistry().SigningContext() - txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) db := dbm.NewMemDB() logBuffer := new(bytes.Buffer) logger := log.NewLogger(logBuffer, log.ColorOption(false)) @@ -501,10 +500,9 @@ func TestBaseAppOptionSeal(t *testing.T) { func TestTxDecoder(t *testing.T) { cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - signingCtx := cdc.InterfaceRegistry().SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) tx := newTxCounter(t, txConfig, 1, 0) txBytes, err := txConfig.TxEncoder()(tx) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 725e90d79264..2f9807997e25 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -136,10 +136,9 @@ func TestMsgService(t *testing.T) { ), &appBuilder, &cdc, &interfaceRegistry) require.NoError(t, err) app := appBuilder.Build(dbm.NewMemDB(), nil) - signingCtx := interfaceRegistry.SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) // set the TxDecoder in the BaseApp for minimal tx simulations app.SetTxDecoder(txConfig.TxDecoder()) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 5d8b12efac42..257fdcab272d 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -30,8 +30,7 @@ import ( func newTestTxConfig() (client.TxConfig, codec.Codec) { encodingConfig := moduletestutil.MakeTestEncodingConfig() cdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) - signingCtx := cdc.InterfaceRegistry().SigningContext() - return authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), encodingConfig.Codec + return authtx.NewTxConfig(cdc, authtx.DefaultSignModes), encodingConfig.Codec } // mockContext is a mock client.Context to return arbitrary simulation response, used to diff --git a/simapp/app.go b/simapp/app.go index 1ff00556a52d..eb8ee7fc239a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -208,7 +208,7 @@ func NewSimApp( appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() signingCtx := interfaceRegistry.SigningContext() - txConfig := authtx.NewTxConfig(appCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) diff --git a/testutil/integration/router.go b/testutil/integration/router.go index 8bc3989fae47..2784118eb2a2 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -53,9 +53,8 @@ func NewIntegrationApp( interfaceRegistry := codectypes.NewInterfaceRegistry() moduleManager := module.NewManagerFromMap(modules) moduleManager.RegisterInterfaces(interfaceRegistry) - signingCtx := interfaceRegistry.SigningContext() - txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes) bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName)) bApp.MountKVStores(keys) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index ac2d5b871cf7..a1147231c64b 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -52,11 +52,10 @@ func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose, // SimulationOperations retrieves the simulation params from the provided file path // and returns all the modules weighted operations func SimulationOperations(app runtime.AppSimI, cdc codec.Codec, config simtypes.Config) []simtypes.WeightedOperation { - signingCtx := cdc.InterfaceRegistry().SigningContext() simState := module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, - TxConfig: authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), // TODO(tip): we should extract this from app + TxConfig: authtx.NewTxConfig(cdc, authtx.DefaultSignModes), // TODO(tip): we should extract this from app BondDenom: sdk.DefaultBondDenom, } diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 34bffae69830..73a57820c48e 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -26,12 +26,11 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { aminoCodec := codec.NewLegacyAmino() interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) - signingCtx := interfaceRegistry.SigningContext() encCfg := TestEncodingConfig{ InterfaceRegistry: interfaceRegistry, Codec: cdc, - TxConfig: tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes), + TxConfig: tx.NewTxConfig(cdc, tx.DefaultSignModes), Amino: aminoCodec, } @@ -46,9 +45,7 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { func MakeTestTxConfig() client.TxConfig { interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(interfaceRegistry) - signingCtx := interfaceRegistry.SigningContext() - return tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) + return tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), tx.DefaultSignModes) } type TestBuilderTxConfig struct { diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 51c6f349f72c..d662a4a59ab1 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -146,8 +146,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { t.Run(name, func(t *testing.T) { suite := SetupTestSuite(t, false) cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) - signingCtx := cdc.InterfaceRegistry().SigningContext() - protoTxCfg := tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) + protoTxCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes) // this just tests our handler dfd := ante.NewDeductFeeDecorator(suite.accountKeeper, suite.bankKeeper, suite.feeGrantKeeper, nil) feeAnteHandler := sdk.ChainAnteDecorators(dfd) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index ce29e8e01c63..fee46430eeba 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -77,14 +77,14 @@ var DefaultSignModes = []signingtypes.SignMode{ // We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK, // this constructor is primarily used in tests, but also sees usage in app chains like: // https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37 -func NewTxConfig(protoCodec codec.Codec, addressCodec, validatorAddressCodec address.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, +func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{ EnabledSignModes: enabledSignModes, CustomSignModes: customSignModes, SigningOptions: &txsigning.Options{ - AddressCodec: addressCodec, - ValidatorAddressCodec: validatorAddressCodec, + AddressCodec: protoCodec.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: protoCodec.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), }, }) if err != nil { diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index 1fc215a4e868..b84e79267be5 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -24,8 +24,7 @@ func TestGenerator(t *testing.T) { std.RegisterInterfaces(interfaceRegistry) interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}) protoCodec := codec.NewProtoCodec(interfaceRegistry) - signingCtx := interfaceRegistry.SigningContext() - suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes))) + suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, tx.DefaultSignModes))) } func TestConfigOptions(t *testing.T) { From 4d50ffffc0ef53c3bb7b159f7054ebbc71ee7687 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 1 Mar 2024 09:31:51 +0100 Subject: [PATCH 11/19] update: NewTxConfig takes address.Codec --- baseapp/abci_utils_test.go | 6 ++++-- baseapp/baseapp_test.go | 6 ++++-- baseapp/msg_service_router_test.go | 3 ++- client/tx/tx_test.go | 3 ++- simapp/app.go | 2 +- testutil/integration/router.go | 3 ++- testutil/sims/simulation_helpers.go | 3 ++- types/module/testutil/codec.go | 7 +++++-- x/auth/ante/feegrant_test.go | 3 ++- x/auth/tx/config.go | 13 ++++++------- x/auth/tx/config_test.go | 10 +++++----- 11 files changed, 35 insertions(+), 24 deletions(-) diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index d0845c51040d..949d4d52d5d8 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -325,9 +325,10 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() // create a codec for marshaling cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() // create a baseapp along with a tx config for tx generation - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), dbm.NewMemDB(), txConfig.TxDecoder()) // create a proposal handler @@ -422,7 +423,8 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSelection() { cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + signingCtx := cdc.InterfaceRegistry().SigningContext() + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) var ( secret1 = []byte("secret1") diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 3ce4726d1c08..910be1a93e84 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -64,8 +64,9 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite t.Helper() cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) db := dbm.NewMemDB() logBuffer := new(bytes.Buffer) logger := log.NewLogger(logBuffer, log.ColorOption(false)) @@ -500,9 +501,10 @@ func TestBaseAppOptionSeal(t *testing.T) { func TestTxDecoder(t *testing.T) { cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) tx := newTxCounter(t, txConfig, 1, 0) txBytes, err := txConfig.TxEncoder()(tx) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 2f9807997e25..725e90d79264 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -136,9 +136,10 @@ func TestMsgService(t *testing.T) { ), &appBuilder, &cdc, &interfaceRegistry) require.NoError(t, err) app := appBuilder.Build(dbm.NewMemDB(), nil) + signingCtx := interfaceRegistry.SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) // set the TxDecoder in the BaseApp for minimal tx simulations app.SetTxDecoder(txConfig.TxDecoder()) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 257fdcab272d..976a75d49b42 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -30,7 +30,8 @@ import ( func newTestTxConfig() (client.TxConfig, codec.Codec) { encodingConfig := moduletestutil.MakeTestEncodingConfig() cdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) - return authtx.NewTxConfig(cdc, authtx.DefaultSignModes), encodingConfig.Codec + signingCtx := encodingConfig.InterfaceRegistry.SigningContext() + return authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), encodingConfig.Codec } // mockContext is a mock client.Context to return arbitrary simulation response, used to diff --git a/simapp/app.go b/simapp/app.go index eb8ee7fc239a..1ff00556a52d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -208,7 +208,7 @@ func NewSimApp( appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() signingCtx := interfaceRegistry.SigningContext() - txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(appCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) diff --git a/testutil/integration/router.go b/testutil/integration/router.go index 2784118eb2a2..8bc3989fae47 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -53,8 +53,9 @@ func NewIntegrationApp( interfaceRegistry := codectypes.NewInterfaceRegistry() moduleManager := module.NewManagerFromMap(modules) moduleManager.RegisterInterfaces(interfaceRegistry) + signingCtx := interfaceRegistry.SigningContext() - txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName)) bApp.MountKVStores(keys) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index a1147231c64b..ac2d5b871cf7 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -52,10 +52,11 @@ func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose, // SimulationOperations retrieves the simulation params from the provided file path // and returns all the modules weighted operations func SimulationOperations(app runtime.AppSimI, cdc codec.Codec, config simtypes.Config) []simtypes.WeightedOperation { + signingCtx := cdc.InterfaceRegistry().SigningContext() simState := module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, - TxConfig: authtx.NewTxConfig(cdc, authtx.DefaultSignModes), // TODO(tip): we should extract this from app + TxConfig: authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), // TODO(tip): we should extract this from app BondDenom: sdk.DefaultBondDenom, } diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 73a57820c48e..872babea6214 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -26,11 +26,12 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { aminoCodec := codec.NewLegacyAmino() interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) + signingCtx := cdc.InterfaceRegistry().SigningContext() encCfg := TestEncodingConfig{ InterfaceRegistry: interfaceRegistry, Codec: cdc, - TxConfig: tx.NewTxConfig(cdc, tx.DefaultSignModes), + TxConfig: tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes), Amino: aminoCodec, } @@ -45,7 +46,9 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { func MakeTestTxConfig() client.TxConfig { interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() - return tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), tx.DefaultSignModes) + cdc := codec.NewProtoCodec(interfaceRegistry) + signingCtx := interfaceRegistry.SigningContext() + return tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) } type TestBuilderTxConfig struct { diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index d662a4a59ab1..80f858b042f6 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -146,7 +146,8 @@ func TestDeductFeesNoDelegation(t *testing.T) { t.Run(name, func(t *testing.T) { suite := SetupTestSuite(t, false) cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) - protoTxCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes) + signingCtx := suite.encCfg.InterfaceRegistry.SigningContext() + protoTxCfg := tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) // this just tests our handler dfd := ante.NewDeductFeeDecorator(suite.accountKeeper, suite.bankKeeper, suite.feeGrantKeeper, nil) feeAnteHandler := sdk.ChainAnteDecorators(dfd) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index fee46430eeba..90fbb8e39f27 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -5,7 +5,6 @@ import ( "fmt" "cosmossdk.io/core/address" - authcodec "cosmossdk.io/x/auth/codec" txdecode "cosmossdk.io/x/tx/decode" txsigning "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/aminojson" @@ -77,14 +76,14 @@ var DefaultSignModes = []signingtypes.SignMode{ // We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK, // this constructor is primarily used in tests, but also sees usage in app chains like: // https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37 -func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, +func NewTxConfig(protoCodec codec.Codec, addressCodec, validatorAddressCodec address.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{ EnabledSignModes: enabledSignModes, CustomSignModes: customSignModes, SigningOptions: &txsigning.Options{ - AddressCodec: protoCodec.InterfaceRegistry().SigningContext().AddressCodec(), - ValidatorAddressCodec: protoCodec.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + AddressCodec: addressCodec, + ValidatorAddressCodec: validatorAddressCodec, }, }) if err != nil { @@ -95,10 +94,10 @@ func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMod // NewSigningOptions returns signing options used by x/tx. This includes account and // validator address prefix enabled codecs. -func NewSigningOptions(addressPrefix, validatorPrefix string) (*txsigning.Options, error) { +func NewSigningOptions(addressCodec, validatorAddressCodec address.Codec) (*txsigning.Options, error) { return &txsigning.Options{ - AddressCodec: authcodec.NewBech32Codec(addressPrefix), - ValidatorAddressCodec: authcodec.NewBech32Codec(validatorPrefix), + AddressCodec: addressCodec, + ValidatorAddressCodec: validatorAddressCodec, }, nil } diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index b84e79267be5..888bf0eda5d0 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/testutil" - "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,15 +23,16 @@ func TestGenerator(t *testing.T) { std.RegisterInterfaces(interfaceRegistry) interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}) protoCodec := codec.NewProtoCodec(interfaceRegistry) - suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, tx.DefaultSignModes))) + signingCtx := protoCodec.InterfaceRegistry().SigningContext() + suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes))) } func TestConfigOptions(t *testing.T) { - interfaceRegistry := types.NewInterfaceRegistry() + interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() protoCodec := codec.NewProtoCodec(interfaceRegistry) configOptions := tx.ConfigOptions{SigningOptions: &signing.Options{ - AddressCodec: protoCodec.InterfaceRegistry().SigningContext().AddressCodec(), - ValidatorAddressCodec: protoCodec.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + AddressCodec: interfaceRegistry.SigningContext().AddressCodec(), + ValidatorAddressCodec: interfaceRegistry.SigningContext().ValidatorAddressCodec(), }} txConfig, err := tx.NewTxConfigWithOptions(protoCodec, configOptions) require.NoError(t, err) From 65b76a4c806065f9f61ebaadbaf5b32c4c7d571e Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 1 Mar 2024 16:50:22 +0100 Subject: [PATCH 12/19] update: use same codecs in app.go --- simapp/app.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 1ff00556a52d..27241c328455 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -279,13 +279,11 @@ func NewSimApp( app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger), authtypes.NewModuleAddress(govtypes.ModuleName).String()) bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) - addressCodec := authcodec.NewBech32Codec(sdk.Bech32MainPrefix) - // add keepers accountsKeeper, err := accounts.NewKeeper( appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger), - addressCodec, + signingCtx.AddressCodec(), appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter(), @@ -301,7 +299,7 @@ func NewSimApp( } app.AccountsKeeper = accountsKeeper - app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, addressCodec, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.BankKeeper = bankkeeper.NewBaseKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), logger), @@ -331,7 +329,7 @@ func NewSimApp( app.txConfig = txConfig app.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), signingCtx.ValidatorAddressCodec(), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), ) app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[minttypes.StoreKey]), logger), app.StakingKeeper, app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) From ef36e359c5c404855ea5e34551b773b8e36001be Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 1 Mar 2024 17:08:47 +0100 Subject: [PATCH 13/19] update: codecs as arguments in NewIntegrationApp --- .../bank/keeper/deterministic_test.go | 14 ++++++++----- .../distribution/keeper/msg_server_test.go | 20 +++++++++++-------- .../evidence/keeper/infraction_test.go | 20 +++++++++++-------- tests/integration/example/example_test.go | 6 ++++++ tests/integration/gov/keeper/keeper_test.go | 18 ++++++++++------- .../slashing/keeper/keeper_test.go | 16 +++++++++------ .../integration/staking/keeper/common_test.go | 16 +++++++++------ .../staking/keeper/deterministic_test.go | 16 +++++++++------ testutil/integration/router.go | 6 ++++-- 9 files changed, 84 insertions(+), 48 deletions(-) diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 3023f5f9248f..89c633395b11 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -63,7 +63,8 @@ type deterministicFixture struct { func initDeterministicFixture(t *testing.T) *deterministicFixture { t.Helper() keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) @@ -101,10 +102,13 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index ac6197269770..0f4ab883ed8c 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -66,7 +66,8 @@ func initFixture(t *testing.T) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, pooltypes.StoreKey, stakingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}, protocolpool.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) @@ -138,13 +139,16 @@ func initFixture(t *testing.T) *fixture { }, }) - integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - distrtypes.ModuleName: distrModule, - pooltypes.ModuleName: poolModule, - }) + integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + distrtypes.ModuleName: distrModule, + pooltypes.ModuleName: poolModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 1b0241ff87f8..5ea7d2e4e65c 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -87,7 +87,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, consensusparamtypes.StoreKey, evidencetypes.StoreKey, stakingtypes.StoreKey, slashingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, evidence.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -141,13 +142,16 @@ func initFixture(tb testing.TB) *fixture { slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry()) evidenceModule := evidence.NewAppModule(*evidenceKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - slashingtypes.ModuleName: slashingModule, - evidencetypes.ModuleName: evidenceModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + slashingtypes.ModuleName: slashingModule, + evidencetypes.ModuleName: evidenceModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/example/example_test.go b/tests/integration/example/example_test.go index 71a9acb8770c..2002a3807c3a 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -30,6 +30,8 @@ func Example() { // in this example we are testing the integration of the following modules: // - mint, which directly depends on auth, bank and staking encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, mint.AppModule{}) + signingCtx := encodingCfg.InterfaceRegistry.SigningContext() + keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, minttypes.StoreKey) authority := authtypes.NewModuleAddress("gov").String() @@ -63,6 +65,8 @@ func Example() { logger, keys, encodingCfg.Codec, + signingCtx.AddressCodec(), + signingCtx.ValidatorAddressCodec(), map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, minttypes.ModuleName: mintModule, @@ -147,6 +151,8 @@ func Example_oneModule() { logger, keys, encodingCfg.Codec, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, }, diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 39756b834f34..124cea99c37c 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -52,7 +52,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, pooltypes.StoreKey, types.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -127,12 +128,15 @@ func initFixture(tb testing.TB) *fixture { stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) govModule := gov.NewAppModule(cdc, govKeeper, accountKeeper, bankKeeper, poolKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - types.ModuleName: govModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + types.ModuleName: govModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 14936367c4a8..2d6aadaf6ff4 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -56,7 +56,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -100,11 +101,14 @@ func initFixture(tb testing.TB) *fixture { stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry()) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - slashingtypes.ModuleName: slashingModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + slashingtypes.ModuleName: slashingModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 35f617450db3..6955c5e23591 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -103,7 +103,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, types.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -147,11 +148,14 @@ func initFixture(tb testing.TB) *fixture { bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - types.ModuleName: stakingModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + types.ModuleName: stakingModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index b8b9d134196d..fe705a793639 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -68,7 +68,8 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) @@ -111,11 +112,14 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + }) ctx := integrationApp.Context() diff --git a/testutil/integration/router.go b/testutil/integration/router.go index 8bc3989fae47..ae3daaa64e73 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -2,6 +2,7 @@ package integration import ( "context" + "cosmossdk.io/core/address" "fmt" cmtabcitypes "github.com/cometbft/cometbft/abci/types" @@ -46,6 +47,8 @@ func NewIntegrationApp( logger log.Logger, keys map[string]*storetypes.KVStoreKey, appCodec codec.Codec, + addressCodec address.Codec, + validatorCodec address.Codec, modules map[string]appmodule.AppModule, ) *App { db := dbm.NewMemDB() @@ -53,9 +56,8 @@ func NewIntegrationApp( interfaceRegistry := codectypes.NewInterfaceRegistry() moduleManager := module.NewManagerFromMap(modules) moduleManager.RegisterInterfaces(interfaceRegistry) - signingCtx := interfaceRegistry.SigningContext() - txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), addressCodec, validatorCodec, authtx.DefaultSignModes) bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName)) bApp.MountKVStores(keys) From e8fd0c3d4782c38108ac855b4fd125d5daf36bc6 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 4 Mar 2024 11:14:08 +0100 Subject: [PATCH 14/19] update: CodecOptios as argument in MakeTestEncodingConfig --- client/context_test.go | 3 ++- client/grpc_query_test.go | 3 ++- client/keys/add_ledger_test.go | 7 ++++--- client/keys/add_test.go | 9 +++++---- client/keys/delete_test.go | 3 ++- client/keys/export_test.go | 3 ++- client/keys/import_test.go | 7 ++++--- client/keys/list_test.go | 5 +++-- client/keys/migrate_test.go | 3 ++- client/keys/rename_test.go | 3 ++- client/keys/show_test.go | 3 ++- client/tx/aux_builder_test.go | 3 ++- client/tx/tx_test.go | 5 +++-- client/v2/autocli/common_test.go | 3 ++- codec/any_test.go | 5 +++-- codec/unknownproto/regression_test.go | 3 ++- server/util_test.go | 3 ++- simapp/simd/cmd/testnet_test.go | 3 ++- .../integration/auth/client/cli/suite_test.go | 3 ++- tests/integration/bank/app_test.go | 9 +++++---- tests/integration/bank/bench_test.go | 5 +++-- .../bank/keeper/deterministic_test.go | 3 ++- tests/integration/distribution/cli_tx_test.go | 3 ++- .../distribution/keeper/msg_server_test.go | 3 ++- .../evidence/keeper/infraction_test.go | 3 ++- tests/integration/example/example_test.go | 5 +++-- tests/integration/gov/keeper/keeper_test.go | 3 ++- .../slashing/keeper/keeper_test.go | 3 ++- .../integration/staking/keeper/common_test.go | 3 ++- .../staking/keeper/deterministic_test.go | 3 ++- .../tx/aminojson/aminojson_test.go | 11 ++++++----- tests/integration/tx/decode_test.go | 5 +++-- testutil/integration/router.go | 2 +- testutil/key_test.go | 7 ++++--- types/mempool/mempool_test.go | 3 ++- types/module/testutil/codec.go | 12 ++++++------ x/auth/ante/testutil_test.go | 3 ++- x/auth/client/cli/encode_test.go | 5 +++-- x/auth/client/tx_test.go | 7 ++++--- x/auth/keeper/deterministic_test.go | 3 ++- x/auth/keeper/keeper_test.go | 3 ++- x/auth/tx/aux_test.go | 3 ++- x/auth/types/genesis_test.go | 3 ++- x/auth/vesting/types/vesting_account_test.go | 3 ++- x/authz/client/cli/tx_test.go | 3 ++- x/authz/keeper/genesis_test.go | 3 ++- x/authz/keeper/keeper_test.go | 3 ++- x/authz/migrations/v2/store_test.go | 3 ++- x/authz/module/abci_test.go | 3 ++- x/authz/simulation/decoder_test.go | 3 ++- x/authz/simulation/genesis_test.go | 3 ++- x/bank/client/cli/tx_test.go | 3 ++- x/bank/keeper/collections_test.go | 3 ++- x/bank/keeper/keeper_test.go | 5 +++-- x/circuit/ante/circuit_test.go | 3 ++- x/circuit/keeper/genesis_test.go | 3 ++- x/circuit/keeper/keeper_test.go | 3 ++- x/consensus/keeper/keeper_test.go | 3 ++- x/crisis/keeper/genesis_test.go | 3 ++- x/crisis/keeper/keeper_test.go | 7 ++++--- x/crisis/keeper/msg_server_test.go | 5 +++-- x/distribution/keeper/allocation_test.go | 7 ++++--- x/distribution/keeper/delegation_test.go | 19 ++++++++++--------- x/distribution/keeper/keeper_test.go | 3 ++- .../migrations/v4/migrate_funds_test.go | 3 ++- x/distribution/migrations/v4/migrate_test.go | 3 ++- x/distribution/simulation/decoder_test.go | 3 ++- x/evidence/keeper/keeper_test.go | 5 +++-- x/feegrant/client/cli/tx_test.go | 3 ++- x/feegrant/filtered_fee_test.go | 3 ++- x/feegrant/grant_test.go | 3 ++- x/feegrant/keeper/genesis_test.go | 3 ++- x/feegrant/keeper/keeper_test.go | 3 ++- x/feegrant/migrations/v2/store_test.go | 3 ++- x/feegrant/module/abci_test.go | 3 ++- x/feegrant/simulation/decoder_test.go | 3 ++- x/feegrant/simulation/genesis_test.go | 3 ++- x/genutil/client/cli/genaccount_test.go | 3 ++- x/genutil/client/cli/gentx_test.go | 3 ++- x/genutil/client/cli/migrate_test.go | 3 ++- x/genutil/gentx_test.go | 3 ++- x/genutil/types/genesis_state_test.go | 5 +++-- x/gov/client/cli/tx_test.go | 3 ++- x/gov/client/utils/query_test.go | 3 ++- x/gov/keeper/common_test.go | 3 ++- x/gov/migrations/v5/store_test.go | 3 ++- x/gov/migrations/v6/store_test.go | 3 ++- x/group/client/cli/tx_test.go | 3 ++- x/group/keeper/genesis_test.go | 3 ++- x/group/keeper/grpc_query_test.go | 3 ++- x/group/keeper/keeper_test.go | 3 ++- x/group/migrations/v2/migrate_test.go | 3 ++- x/group/proposal_test.go | 3 ++- x/group/simulation/decoder_test.go | 3 ++- x/group/simulation/genesis_test.go | 3 ++- x/mint/keeper/genesis_test.go | 3 ++- x/mint/keeper/grpc_query_test.go | 3 ++- x/mint/keeper/keeper_test.go | 3 ++- x/mint/simulation/genesis_test.go | 5 +++-- x/nft/keeper/keeper_test.go | 3 ++- x/nft/simulation/decoder_test.go | 3 ++- x/nft/simulation/genesis_test.go | 3 ++- x/params/keeper/common_test.go | 3 ++- x/params/keeper/keeper_test.go | 3 ++- x/params/types/subspace_test.go | 3 ++- x/protocolpool/keeper/keeper_test.go | 3 ++- x/slashing/keeper/keeper_test.go | 3 ++- x/slashing/migrations/v4/migrate_test.go | 3 ++- x/slashing/simulation/decoder_test.go | 3 ++- x/staking/client/cli/tx_test.go | 3 ++- x/staking/keeper/keeper_test.go | 3 ++- x/staking/migrations/v5/migrations_test.go | 5 +++-- x/staking/simulation/decoder_test.go | 3 ++- x/upgrade/keeper/abci_test.go | 5 +++-- x/upgrade/keeper/grpc_query_test.go | 3 ++- x/upgrade/keeper/keeper_test.go | 3 ++- 116 files changed, 279 insertions(+), 165 deletions(-) diff --git a/client/context_test.go b/client/context_test.go index 7c0397540c50..98c6d9f76752 100644 --- a/client/context_test.go +++ b/client/context_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -98,7 +99,7 @@ x: "10" } func TestGetFromFields(t *testing.T) { - cfg := testutil.MakeTestEncodingConfig() + cfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) path := hd.CreateHDPath(118, 0, 0).String() testCases := []struct { diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index 7aaf78a85445..8a302f2e3f30 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -39,7 +40,7 @@ func (s *IntegrationTestSuite) SetupSuite() { keys := storetypes.NewKVStoreKeys(countertypes.StoreKey) cms := integration.CreateMultiStore(keys, logger) s.ctx = sdk.NewContext(cms, true, logger) - cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModule{}) + cfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, counter.AppModule{}) s.cdc = cfg.Codec queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, cfg.InterfaceRegistry) diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index 2e1865823c30..3d04cc5e3b92 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -39,7 +40,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { // Prepare a keybase kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec clientCtx := client.Context{}. WithKeyringDir(kbHome). WithCodec(cdc). @@ -97,7 +98,7 @@ func Test_runAddCmdLedger(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec clientCtx := client.Context{}. WithKeyringDir(kbHome). @@ -144,7 +145,7 @@ func Test_runAddCmdLedger(t *testing.T) { } func Test_runAddCmdLedgerDryRun(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testData := []struct { name string args []string diff --git a/client/keys/add_test.go b/client/keys/add_test.go index 95cf3347810a..687aff609235 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -28,7 +29,7 @@ func Test_runAddCmdBasic(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) @@ -149,7 +150,7 @@ func Test_runAddCmdMultisigDupKeys(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) @@ -217,7 +218,7 @@ func Test_runAddCmdDryRun(t *testing.T) { pubkey1 := `{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AtObiFVE4s+9+RX5SP8TN9r2mxpoaT4eGj9CJfK7VRzN"}` pubkey2 := `{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/se1vkqgdQ7VJQCM4mxN+L+ciGhnnJ4XYsQCRBMrdRi"}` b64Pubkey := "QWhnOHhpdXBJcGZ2UlR2ak5la1ExclROUThTOW96YjdHK2RYQmFLVjl4aUo=" - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testData := []struct { name string @@ -349,7 +350,7 @@ func Test_runAddCmdDryRun(t *testing.T) { func TestAddRecoverFileBackend(t *testing.T) { cmd := AddKeyCommand() cmd.Flags().AddFlagSet(Commands().PersistentFlags()) - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() diff --git a/client/keys/delete_test.go b/client/keys/delete_test.go index dd1a38bd875b..69a5b8571207 100644 --- a/client/keys/delete_test.go +++ b/client/keys/delete_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -34,7 +35,7 @@ func Test_runDeleteCmd(t *testing.T) { fakeKeyName2 := "runDeleteCmd_Key2" path := sdk.GetFullBIP44Path() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec cmd.SetArgs([]string{"blah", fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome)}) kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) diff --git a/client/keys/export_test.go b/client/keys/export_test.go index db49eb5b8c37..8da6922ca908 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -19,7 +20,7 @@ import ( ) func Test_runExportCmd(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testCases := []struct { name string keyringBackend string diff --git a/client/keys/import_test.go b/client/keys/import_test.go index 006f8ce672b2..bc9c5d34abb7 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,7 +19,7 @@ import ( ) func Test_runImportCmd(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testCases := []struct { name string keyringBackend string @@ -122,7 +123,7 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO } func Test_runImportHexCmd(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testCases := []struct { name string keyringBackend string @@ -184,7 +185,7 @@ func Test_runImportCmdWithEmptyName(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) // Now add a temporary keybase kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) diff --git a/client/keys/list_test.go b/client/keys/list_test.go index b81a9d9aabaa..8f2752e5af9f 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -39,7 +40,7 @@ func Test_runListCmd(t *testing.T) { kbHome2 := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome2, mockIn, cdc) assert.NilError(t, err) @@ -92,7 +93,7 @@ func Test_runListCmd(t *testing.T) { func Test_runListKeyTypeCmd(t *testing.T) { cmd := ListKeyTypesCmd() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kbHome := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) diff --git a/client/keys/migrate_test.go b/client/keys/migrate_test.go index 4d3abe0007da..0e7adb4e6ca1 100644 --- a/client/keys/migrate_test.go +++ b/client/keys/migrate_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -41,7 +42,7 @@ func TestMigrateTestSuite(t *testing.T) { func (s *MigrateTestSuite) SetupSuite() { s.dir = s.T().TempDir() - s.cdc = moduletestutil.MakeTestEncodingConfig().Codec + s.cdc = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec s.appName = "cosmos" s.priv = cryptotypes.PrivKey(secp256k1.GenPrivKey()) s.pub = s.priv.PubKey() diff --git a/client/keys/rename_test.go b/client/keys/rename_test.go index 62253d382be5..e67d0df8d4c8 100644 --- a/client/keys/rename_test.go +++ b/client/keys/rename_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -33,7 +34,7 @@ func Test_runRenameCmd(t *testing.T) { path := sdk.GetFullBIP44Path() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) diff --git a/client/keys/show_test.go b/client/keys/show_test.go index 5d7f9c033263..ac6c162b5076 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -56,7 +57,7 @@ func Test_runShowCmd(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) diff --git a/client/tx/aux_builder_test.go b/client/tx/aux_builder_test.go index f177ba730a89..b0c7e3e874eb 100644 --- a/client/tx/aux_builder_test.go +++ b/client/tx/aux_builder_test.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -33,7 +34,7 @@ var ( func TestAuxTxBuilder(t *testing.T) { counterModule := counter.AppModule{} - cdc := moduletestutil.MakeTestEncodingConfig(counterModule).Codec + cdc := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, counterModule).Codec reg := codectypes.NewInterfaceRegistry() testdata.RegisterInterfaces(reg) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 976a75d49b42..8859531dbdd2 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -28,7 +29,7 @@ import ( ) func newTestTxConfig() (client.TxConfig, codec.Codec) { - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}) cdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) signingCtx := encodingConfig.InterfaceRegistry.SigningContext() return authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), encodingConfig.Codec @@ -155,7 +156,7 @@ func TestBuildUnsignedTx(t *testing.T) { } func TestBuildUnsignedTxWithWithExtensionOptions(t *testing.T) { - txCfg := moduletestutil.MakeBuilderTestTxConfig() + txCfg := moduletestutil.MakeBuilderTestTxConfig(testutil.CodecOptions{}) extOpts := []*codectypes.Any{ { TypeUrl: "/test", diff --git a/client/v2/autocli/common_test.go b/client/v2/autocli/common_test.go index c75eaa5b17a4..2a5203fca9d9 100644 --- a/client/v2/autocli/common_test.go +++ b/client/v2/autocli/common_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/codec/testutil" sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -51,7 +52,7 @@ func initFixture(t *testing.T) *fixture { clientConn, err := grpc.Dial(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) assert.NilError(t, err) - encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, bank.AppModule{}) kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendMemory, home, nil, encodingConfig.Codec) assert.NilError(t, err) diff --git a/codec/any_test.go b/codec/any_test.go index ccb63f129682..d9996ec3d3c4 100644 --- a/codec/any_test.go +++ b/codec/any_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -71,7 +72,7 @@ func TestMarshalAny(t *testing.T) { func TestMarshalProtoPubKey(t *testing.T) { require := require.New(t) - ccfg := testutil.MakeTestEncodingConfig() + ccfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) privKey := ed25519.GenPrivKey() pk := privKey.PubKey() @@ -111,7 +112,7 @@ func TestMarshalProtoPubKey(t *testing.T) { // helper functions func TestMarshalProtoInterfacePubKey(t *testing.T) { require := require.New(t) - ccfg := testutil.MakeTestEncodingConfig() + ccfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) privKey := ed25519.GenPrivKey() pk := privKey.PubKey() diff --git a/codec/unknownproto/regression_test.go b/codec/unknownproto/regression_test.go index 3473e6481c14..84ee71cc5838 100644 --- a/codec/unknownproto/regression_test.go +++ b/codec/unknownproto/regression_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -14,7 +15,7 @@ import ( // protowire.ConsumeFieldValue. Discovered from fuzzing. func TestBadBytesPassedIntoDecoder(t *testing.T) { data, _ := hex.DecodeString("0A9F010A9C200A2D2F6962632E636F72652E636F6E6E656374696F6E2E76312E4D7367436F6E6E656374696F584F75656E496E6974126B0A0D6962637A65726F636C69656E74120B6962637A65726F636F6E6E1A1C0A0C6962636F6E65636C69656E74120A6962636F6E65636F6E6E00002205312E302E302A283235454635364341373935313335453430393336384536444238313130463232413442453035433212080A0612040A0208011A40143342993E25DA936CDDC7BE3D8F603CA6E9661518D536D0C482E18A0154AA096E438A6B9BCADFCFC2F0D689DCCAF55B96399D67A8361B70F5DA13091E2F929") - cfg := testutil.MakeTestEncodingConfig() + cfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) decoder := cfg.TxConfig.TxDecoder() tx, err := decoder(data) diff --git a/server/util_test.go b/server/util_test.go index 2ec1a27bc6e7..11f5cbb208c9 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -450,7 +451,7 @@ func TestEmptyMinGasPrices(t *testing.T) { tempDir := t.TempDir() err := os.Mkdir(filepath.Join(tempDir, "config"), os.ModePerm) require.NoError(t, err) - encCfg := testutil.MakeTestEncodingConfig() + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) // Run InitCmd to create necessary config files. clientCtx := client.Context{}.WithHomeDir(tempDir).WithCodec(encCfg.Codec) diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 60ba6126fb97..c78f3408dc9c 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/testutil/configurator" "github.com/cosmos/cosmos-sdk/types/module" @@ -46,7 +47,7 @@ func Test_TestnetCmd(t *testing.T) { require.Len(t, moduleManager.Modules, 7) home := t.TempDir() - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, staking.AppModule{}) logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) diff --git a/tests/integration/auth/client/cli/suite_test.go b/tests/integration/auth/client/cli/suite_test.go index 454ff4e1b82e..963a313045c5 100644 --- a/tests/integration/auth/client/cli/suite_test.go +++ b/tests/integration/auth/client/cli/suite_test.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -56,7 +57,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index e51ad0137323..eeca54284fff 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -26,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + cdctestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -175,7 +176,7 @@ func TestSendNotEnoughBalance(t *testing.T) { require.NoError(t, err) sendMsg := types.NewMsgSend(addr1Str, addr2Str, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) require.Error(t, err) @@ -255,7 +256,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) if tc.expPass { require.NoError(t, err) @@ -308,7 +309,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { for _, tc := range testCases { header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) @@ -363,7 +364,7 @@ func TestMsgMultiSendDependent(t *testing.T) { for _, tc := range testCases { header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) diff --git a/tests/integration/bank/bench_test.go b/tests/integration/bank/bench_test.go index 628d85a50eeb..b953a3f39ec9 100644 --- a/tests/integration/bank/bench_test.go +++ b/tests/integration/bank/bench_test.go @@ -15,6 +15,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -82,7 +83,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) { _, err = baseApp.Commit() require.NoError(b, err) - txGen := moduletestutil.MakeTestTxConfig() + txGen := moduletestutil.MakeTestTxConfig(codectestutil.CodecOptions{}) txEncoder := txGen.TxEncoder() // pre-compute all txs @@ -140,7 +141,7 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) { _, err = baseApp.Commit() require.NoError(b, err) - txGen := moduletestutil.MakeTestTxConfig() + txGen := moduletestutil.MakeTestTxConfig(codectestutil.CodecOptions{}) txEncoder := txGen.TxEncoder() // pre-compute all txs diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 89c633395b11..54d51b0e20b3 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -23,6 +23,7 @@ import ( _ "cosmossdk.io/x/staking" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -63,7 +64,7 @@ type deterministicFixture struct { func initDeterministicFixture(t *testing.T) *deterministicFixture { t.Helper() keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey) - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(t) diff --git a/tests/integration/distribution/cli_tx_test.go b/tests/integration/distribution/cli_tx_test.go index e45c228a032b..f7e6767558e8 100644 --- a/tests/integration/distribution/cli_tx_test.go +++ b/tests/integration/distribution/cli_tx_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -38,7 +39,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig() + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 0f4ab883ed8c..7d4dcf8d3871 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -33,6 +33,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -66,7 +67,7 @@ func initFixture(t *testing.T) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, pooltypes.StoreKey, stakingtypes.StoreKey, ) - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(t) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 5ea7d2e4e65c..9ef9d498361b 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -41,6 +41,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -87,7 +88,7 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, consensusparamtypes.StoreKey, evidencetypes.StoreKey, stakingtypes.StoreKey, slashingtypes.StoreKey, ) - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) diff --git a/tests/integration/example/example_test.go b/tests/integration/example/example_test.go index 2002a3807c3a..e921c175021b 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -18,6 +18,7 @@ import ( minttypes "cosmossdk.io/x/mint/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,7 +30,7 @@ import ( func Example() { // in this example we are testing the integration of the following modules: // - mint, which directly depends on auth, bank and staking - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, mint.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, mint.AppModule{}) signingCtx := encodingCfg.InterfaceRegistry.SigningContext() keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, minttypes.StoreKey) @@ -122,7 +123,7 @@ func Example() { // That module has no dependency on other modules. func Example_oneModule() { // in this example we are testing the integration of the auth module: - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) keys := storetypes.NewKVStoreKeys(authtypes.StoreKey) authority := authtypes.NewModuleAddress("gov").String() diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 124cea99c37c..2a10d9b8e313 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -29,6 +29,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -52,7 +53,7 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, pooltypes.StoreKey, types.StoreKey, ) - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 2d6aadaf6ff4..a74665167221 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -30,6 +30,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -56,7 +57,7 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey, ) - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 6955c5e23591..f864019603c0 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -26,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -103,7 +104,7 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, types.StoreKey, ) - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, staking.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index fe705a793639..961059c272f1 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -27,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" @@ -68,7 +69,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, ) - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, distribution.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(t) diff --git a/tests/integration/tx/aminojson/aminojson_test.go b/tests/integration/tx/aminojson/aminojson_test.go index c66d43e7c991..c28ce9c0994f 100644 --- a/tests/integration/tx/aminojson/aminojson_test.go +++ b/tests/integration/tx/aminojson/aminojson_test.go @@ -61,6 +61,7 @@ import ( signing_testutil "cosmossdk.io/x/tx/signing/testutil" "cosmossdk.io/x/upgrade" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" ed25519types "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -92,8 +93,8 @@ import ( // by the mutation of genOpts passed to the generator. func TestAminoJSON_Equivalence(t *testing.T) { encCfg := testutil.MakeTestEncodingConfig( - auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, consensus.AppModule{}, - distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, + codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, + consensus.AppModule{}, distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, gov.AppModule{}, groupmodule.AppModule{}, mint.AppModule{}, slashing.AppModule{}, staking.AppModule{}, upgrade.AppModule{}, vesting.AppModule{}) legacytx.RegressionTestingAminoCodec = encCfg.Amino @@ -208,7 +209,7 @@ func newAny(t *testing.T, msg proto.Message) *anypb.Any { // TestAminoJSON_LegacyParity tests that the Encoder encoder produces the same output as the Encoder encoder. func TestAminoJSON_LegacyParity(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(auth.AppModule{}, authzmodule.AppModule{}, + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, distribution.AppModule{}, slashing.AppModule{}, staking.AppModule{}, vesting.AppModule{}, gov.AppModule{}) legacytx.RegressionTestingAminoCodec = encCfg.Amino @@ -512,7 +513,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) { } func TestSendAuthorization(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(auth.AppModule{}, authzmodule.AppModule{}, + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, distribution.AppModule{}, bank.AppModule{}) aj := aminojson.NewEncoder(aminojson.EncoderOptions{}) @@ -562,7 +563,7 @@ func TestSendAuthorization(t *testing.T) { } func TestDecimalMutation(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(staking.AppModule{}) + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}) rates := &stakingtypes.CommissionRates{} rateBz, _ := encCfg.Amino.MarshalJSON(rates) require.Equal(t, `{"rate":"0","max_rate":"0","max_change_rate":"0"}`, string(rateBz)) diff --git a/tests/integration/tx/decode_test.go b/tests/integration/tx/decode_test.go index 8e228951823f..fae669f89f61 100644 --- a/tests/integration/tx/decode_test.go +++ b/tests/integration/tx/decode_test.go @@ -30,6 +30,7 @@ import ( "cosmossdk.io/x/upgrade" "github.com/cosmos/cosmos-sdk/codec/legacy" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/tests/integration/rapidgen" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -43,8 +44,8 @@ import ( // TestDecode tests that the tx decoder can decode all the txs in the test suite. func TestDecode(t *testing.T) { encCfg := testutil.MakeTestEncodingConfig( - auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, consensus.AppModule{}, - distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, + codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, + consensus.AppModule{}, distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, gov.AppModule{}, groupmodule.AppModule{}, mint.AppModule{}, slashing.AppModule{}, staking.AppModule{}, upgrade.AppModule{}, vesting.AppModule{}) legacytx.RegressionTestingAminoCodec = encCfg.Amino diff --git a/testutil/integration/router.go b/testutil/integration/router.go index ae3daaa64e73..f6bf8db260d9 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -2,13 +2,13 @@ package integration import ( "context" - "cosmossdk.io/core/address" "fmt" cmtabcitypes "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/log" "cosmossdk.io/store" diff --git a/testutil/key_test.go b/testutil/key_test.go index 26847d764752..4a44bb4a6b75 100644 --- a/testutil/key_test.go +++ b/testutil/key_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/types" @@ -13,7 +14,7 @@ import ( func TestGenerateCoinKey(t *testing.T) { t.Parallel() - cdc := testutil.MakeTestEncodingConfig().Codec + cdc := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec addr, mnemonic, err := GenerateCoinKey(hd.Secp256k1, cdc) require.NoError(t, err) @@ -28,7 +29,7 @@ func TestGenerateCoinKey(t *testing.T) { func TestGenerateSaveCoinKey(t *testing.T) { t.Parallel() - encCfg := testutil.MakeTestEncodingConfig() + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) kb, err := keyring.New(t.Name(), "test", t.TempDir(), nil, encCfg.Codec) require.NoError(t, err) @@ -53,7 +54,7 @@ func TestGenerateSaveCoinKey(t *testing.T) { func TestGenerateSaveCoinKeyOverwriteFlag(t *testing.T) { t.Parallel() - encCfg := testutil.MakeTestEncodingConfig() + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) kb, err := keyring.New(t.Name(), "test", t.TempDir(), nil, encCfg.Codec) require.NoError(t, err) diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index bab941ae611b..3dbd5f1349b0 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/log" "cosmossdk.io/x/auth/signing" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" @@ -236,7 +237,7 @@ func (s *MempoolTestSuite) TestSampleTxs() { } func unmarshalTx(txBytes []byte) (sdk.Tx, error) { - cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModule{}) + cfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, counter.AppModule{}) return cfg.TxConfig.TxJSONDecoder()(txBytes) } diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 872babea6214..c6753e6b271e 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -22,9 +22,9 @@ type TestEncodingConfig struct { Amino *codec.LegacyAmino } -func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { +func MakeTestEncodingConfig(codecOpt testutil.CodecOptions, modules ...module.AppModule) TestEncodingConfig { aminoCodec := codec.NewLegacyAmino() - interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() + interfaceRegistry := codecOpt.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) signingCtx := cdc.InterfaceRegistry().SigningContext() @@ -44,8 +44,8 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { return encCfg } -func MakeTestTxConfig() client.TxConfig { - interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() +func MakeTestTxConfig(codecOpt testutil.CodecOptions) client.TxConfig { + interfaceRegistry := codecOpt.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) signingCtx := interfaceRegistry.SigningContext() return tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) @@ -56,9 +56,9 @@ type TestBuilderTxConfig struct { TxBuilder *TestTxBuilder } -func MakeBuilderTestTxConfig() TestBuilderTxConfig { +func MakeBuilderTestTxConfig(codecOpt testutil.CodecOptions) TestBuilderTxConfig { return TestBuilderTxConfig{ - TxConfig: MakeTestTxConfig(), + TxConfig: MakeTestTxConfig(codecOpt), } } diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index c49cebdcdf5e..1814e94f2b29 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -67,7 +68,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithIsCheckTx(isCheckTx).WithBlockHeight(1) - suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) maccPerms := map[string][]string{ "fee_collector": nil, diff --git a/x/auth/client/cli/encode_test.go b/x/auth/client/cli/encode_test.go index d5b116ca733c..1234de797ac9 100644 --- a/x/auth/client/cli/encode_test.go +++ b/x/auth/client/cli/encode_test.go @@ -11,13 +11,14 @@ import ( "cosmossdk.io/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestGetCommandEncode(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) txConfig := encodingConfig.TxConfig cdc := encodingConfig.Codec @@ -47,7 +48,7 @@ func TestGetCommandEncode(t *testing.T) { } func TestGetCommandDecode(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) txConfig := encodingConfig.TxConfig cdc := encodingConfig.Codec diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 130e8af7e564..61ab3349a094 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -38,7 +39,7 @@ func TestParseQueryResponse(t *testing.T) { func TestReadTxFromFile(t *testing.T) { t.Parallel() - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig @@ -74,7 +75,7 @@ func TestReadTxFromFile(t *testing.T) { func TestReadTxsFromFile(t *testing.T) { t.Parallel() - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig @@ -138,7 +139,7 @@ func TestReadTxsFromFile(t *testing.T) { func TestBatchScanner_Scan(t *testing.T) { t.Parallel() - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) txConfig := encodingConfig.TxConfig clientCtx := client.Context{} diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index 95bbef98b4ee..61baa01c2835 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -19,6 +19,7 @@ import ( "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -52,7 +53,7 @@ func TestDeterministicTestSuite(t *testing.T) { } func (suite *DeterministicTestSuite) SetupTest() { - suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) suite.Require() key := storetypes.NewKVStoreKey(types.StoreKey) diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 8ed4c8d00de2..02a25bb6ec83 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" @@ -46,7 +47,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 7321464f054c..4d1ae10b3271 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -9,6 +9,7 @@ import ( authsigning "cosmossdk.io/x/auth/signing" clienttx "github.com/cosmos/cosmos-sdk/client/tx" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" _ "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" @@ -39,7 +40,7 @@ var ( // client.TxBuilder created by the fee payer. func TestBuilderWithAux(t *testing.T) { t.Skip("restore when we re-enable aux on the TX builder") - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index 8a3bf204bad2..c8be155e8ffa 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/x/auth" "cosmossdk.io/x/auth/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -54,7 +55,7 @@ func TestValidateGenesisDuplicateAccounts(t *testing.T) { } func TestGenesisAccountIterator(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) cdc := encodingConfig.Codec acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index ba1b289f2474..83273f32bbad 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/auth/vesting" "cosmossdk.io/x/auth/vesting/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -38,7 +39,7 @@ type VestingAccountTestSuite struct { } func (s *VestingAccountTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(vesting.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, vesting.AppModule{}) key := storetypes.NewKVStoreKey(authtypes.StoreKey) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index 2b7df03f8052..d4b2b5f0aa9f 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -51,7 +52,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModule{}, authz.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, bank.AppModule{}, authz.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index e3ced43a0eb5..ed7903049757 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -49,7 +50,7 @@ func (suite *GenesisTestSuite) SetupTest() { suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) - suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) // gomock initializations ctrl := gomock.NewController(suite.T()) diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index b984aeac2a1a..cf9cfa7dbde9 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -51,7 +52,7 @@ func (s *TestSuite) SetupTest() { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now().Round(0).UTC()}) - s.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) s.baseApp = baseapp.NewBaseApp( diff --git a/x/authz/migrations/v2/store_test.go b/x/authz/migrations/v2/store_test.go index 00cdc53071ea..4440ae5b4fbe 100644 --- a/x/authz/migrations/v2/store_test.go +++ b/x/authz/migrations/v2/store_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/bank" banktypes "cosmossdk.io/x/bank/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" @@ -25,7 +26,7 @@ import ( ) func TestMigration(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}, bank.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}, bank.AppModule{}) cdc := encodingConfig.Codec authzKey := storetypes.NewKVStoreKey("authz") diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index f0494f267c84..1dc8a7f8088d 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -30,7 +31,7 @@ func TestExpiredGrantsQueue(t *testing.T) { key := storetypes.NewKVStoreKey(keeper.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) ctx := testCtx.Ctx env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/authz/simulation/decoder_test.go b/x/authz/simulation/decoder_test.go index 5e9697443908..dbeee176732a 100644 --- a/x/authz/simulation/decoder_test.go +++ b/x/authz/simulation/decoder_test.go @@ -13,13 +13,14 @@ import ( "cosmossdk.io/x/authz/simulation" banktypes "cosmossdk.io/x/bank/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestDecodeStore(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) dec := simulation.NewDecodeStore(encCfg.Codec) diff --git a/x/authz/simulation/genesis_test.go b/x/authz/simulation/genesis_test.go index 19c0508de678..6578c21644f3 100644 --- a/x/authz/simulation/genesis_test.go +++ b/x/authz/simulation/genesis_test.go @@ -13,13 +13,14 @@ import ( "cosmossdk.io/x/authz/simulation" banktypes "cosmossdk.io/x/bank/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) s := rand.NewSource(1) diff --git a/x/bank/client/cli/tx_test.go b/x/bank/client/cli/tx_test.go index 17a73e5f6725..e73d59bb32f2 100644 --- a/x/bank/client/cli/tx_test.go +++ b/x/bank/client/cli/tx_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" @@ -37,7 +38,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, bank.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/bank/keeper/collections_test.go b/x/bank/keeper/collections_test.go index b372f4edc84b..8e77b664f395 100644 --- a/x/bank/keeper/collections_test.go +++ b/x/bank/keeper/collections_test.go @@ -18,6 +18,7 @@ import ( banktypes "cosmossdk.io/x/bank/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -28,7 +29,7 @@ func TestBankStateCompatibility(t *testing.T) { key := storetypes.NewKVStoreKey(banktypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 7d5e90ccac4b..e44423e352ff 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -27,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -129,7 +130,7 @@ func (suite *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(banktypes.StoreKey) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) @@ -303,7 +304,7 @@ func (suite *KeeperTestSuite) TestGetAuthority() { NewKeeperWithAuthority := func(authority string) keeper.BaseKeeper { return keeper.NewBaseKeeper( env, - moduletestutil.MakeTestEncodingConfig().Codec, + moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec, suite.authKeeper, nil, authority, diff --git a/x/circuit/ante/circuit_test.go b/x/circuit/ante/circuit_test.go index 6c1e8693f135..9bf328a3466c 100644 --- a/x/circuit/ante/circuit_test.go +++ b/x/circuit/ante/circuit_test.go @@ -12,6 +12,7 @@ import ( cbtypes "cosmossdk.io/x/circuit/types" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,7 +38,7 @@ func (m MockCircuitBreaker) IsAllowed(ctx context.Context, typeURL string) (bool func initFixture(t *testing.T) *fixture { t.Helper() mockStoreKey := storetypes.NewKVStoreKey("test") - encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) mockclientCtx := client.Context{}. WithTxConfig(encCfg.TxConfig) diff --git a/x/circuit/keeper/genesis_test.go b/x/circuit/keeper/genesis_test.go index 16f8362ba239..cc4e3b6cbaad 100644 --- a/x/circuit/keeper/genesis_test.go +++ b/x/circuit/keeper/genesis_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,7 +38,7 @@ func TestGenesisTestSuite(t *testing.T) { func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.ModuleName) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, circuit.AppModule{}) sdkCtx := testCtx.Ctx s.ctx = sdkCtx diff --git a/x/circuit/keeper/keeper_test.go b/x/circuit/keeper/keeper_test.go index 29464b66b72f..38ce34b1e14a 100644 --- a/x/circuit/keeper/keeper_test.go +++ b/x/circuit/keeper/keeper_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/circuit/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -40,7 +41,7 @@ type fixture struct { func initFixture(t *testing.T) *fixture { t.Helper() - encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, circuit.AppModule{}) ac := addresscodec.NewBech32Codec("cosmos") mockStoreKey := storetypes.NewKVStoreKey("test") diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 3ab63dc3cf61..64edfe1018f4 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( authtypes "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,7 +33,7 @@ func (s *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(consensusparamkeeper.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, env, authtypes.NewModuleAddress("gov").String()) diff --git a/x/crisis/keeper/genesis_test.go b/x/crisis/keeper/genesis_test.go index d111beebafe0..a2b392c3a6a0 100644 --- a/x/crisis/keeper/genesis_test.go +++ b/x/crisis/keeper/genesis_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,7 +38,7 @@ func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/crisis/keeper/keeper_test.go b/x/crisis/keeper/keeper_test.go index 4a9237d3e92f..84910f934568 100644 --- a/x/crisis/keeper/keeper_test.go +++ b/x/crisis/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( storetypes "cosmossdk.io/store/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,7 +27,7 @@ func TestLogger(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) require.Equal(t, @@ -40,7 +41,7 @@ func TestInvariants(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) require.Equal(t, keeper.InvCheckPeriod(), uint(5)) @@ -57,7 +58,7 @@ func TestAssertInvariants(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) keeper.RegisterRoute("testModule", "testRoute1", func(sdk.Context) (string, bool) { return "", false }) diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index b86fbf724528..ea60b9ac9fe8 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -10,6 +10,7 @@ import ( storetypes "cosmossdk.io/store/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -37,7 +38,7 @@ func (s *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", sdk.AccAddress([]byte("addr1_______________")).String(), addresscodec.NewBech32Codec("cosmos")) s.ctx = testCtx.Ctx @@ -51,7 +52,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() { err := s.keeper.ConstantFee.Set(s.ctx, constantFee) s.Require().NoError(err) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) kr := keyring.NewInMemory(encCfg.Codec) testutil.CreateKeyringAccounts(s.T(), kr, 1) diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index f067964415d9..90e0d9afe6e5 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -20,6 +20,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,7 +32,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -90,7 +91,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -221,7 +222,7 @@ func TestAllocateTokensTruncation(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index 140249e62741..715ffc9f572d 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -18,6 +18,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,7 +30,7 @@ func TestCalculateRewardsBasic(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -131,7 +132,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -236,7 +237,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -362,7 +363,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -461,7 +462,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -538,7 +539,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -656,7 +657,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -795,7 +796,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -996,7 +997,7 @@ func Test100PercentCommissionReward(t *testing.T) { key := storetypes.NewKVStoreKey(disttypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 65acdccab18e..38f1bdc9ecbf 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -17,6 +17,7 @@ import ( "cosmossdk.io/x/distribution/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -38,7 +39,7 @@ func initFixture(t *testing.T) (sdk.Context, []sdk.AccAddress, keeper.Keeper, de key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) addrs := simtestutil.CreateIncrementalAccounts(2) diff --git a/x/distribution/migrations/v4/migrate_funds_test.go b/x/distribution/migrations/v4/migrate_funds_test.go index 2267e6bba292..6bf290755362 100644 --- a/x/distribution/migrations/v4/migrate_funds_test.go +++ b/x/distribution/migrations/v4/migrate_funds_test.go @@ -22,6 +22,7 @@ import ( pooltypes "cosmossdk.io/x/protocolpool/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -34,7 +35,7 @@ func TestFundsMigration(t *testing.T) { ) logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) - encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}, distribution.AppModule{}) ctx := sdk.NewContext(cms, true, logger) maccPerms := map[string][]string{ diff --git a/x/distribution/migrations/v4/migrate_test.go b/x/distribution/migrations/v4/migrate_test.go index 86001ccd12ac..f3d6075a61dd 100644 --- a/x/distribution/migrations/v4/migrate_test.go +++ b/x/distribution/migrations/v4/migrate_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/x/distribution" v4 "cosmossdk.io/x/distribution/migrations/v4" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -19,7 +20,7 @@ import ( ) func TestMigration(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey("distribution") storeService := runtime.NewKVStoreService(storeKey) tKey := storetypes.NewTransientStoreKey("transient_test") diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index 71eb414442cb..98a5c91fe317 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/x/distribution/simulation" "cosmossdk.io/x/distribution/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -24,7 +25,7 @@ var ( ) func TestDecodeDistributionStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 6513aa581a11..61f9eb0ef4a2 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -84,7 +85,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(evidence.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, evidence.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) tkey := storetypes.NewTransientStoreKey("evidence_transient_store") @@ -115,7 +116,7 @@ func (suite *KeeperTestSuite) SetupTest() { evidenceKeeper.SetRouter(router) suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) - suite.encCfg = moduletestutil.MakeTestEncodingConfig(evidence.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, evidence.AppModule{}) suite.accountKeeper = accountKeeper diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index d691821f26ec..ffdbcbb584f2 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -61,7 +62,7 @@ func TestCLITestSuite(t *testing.T) { func (s *CLITestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.encCfg = testutilmod.MakeTestEncodingConfig(module.AppModule{}, gov.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}, gov.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/feegrant/filtered_fee_test.go b/x/feegrant/filtered_fee_test.go index f5deee9e3d96..d8e3fe81684a 100644 --- a/x/feegrant/filtered_fee_test.go +++ b/x/feegrant/filtered_fee_test.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/x/feegrant/module" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -22,7 +23,7 @@ import ( func TestFilteredFeeValidAllow(t *testing.T) { key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index 0dcad40a7379..a333a51e7756 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/feegrant/module" codecaddress "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -21,7 +22,7 @@ func TestGrant(t *testing.T) { addressCodec := codecaddress.NewBech32Codec("cosmos") key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index eb2eff20d467..9d321fe11518 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -17,6 +17,7 @@ import ( feegranttestutil "cosmossdk.io/x/feegrant/testutil" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" @@ -43,7 +44,7 @@ func initFixture(t *testing.T) *genesisFixture { t.Helper() key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctrl := gomock.NewController(t) accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index e68f798d94d2..64e3dd711a54 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -17,6 +17,7 @@ import ( feegranttestutil "cosmossdk.io/x/feegrant/testutil" codecaddress "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -44,7 +45,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.addrs = simtestutil.CreateIncrementalAccounts(20) key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) // setup gomock and initialize some globally expected executions ctrl := gomock.NewController(suite.T()) diff --git a/x/feegrant/migrations/v2/store_test.go b/x/feegrant/migrations/v2/store_test.go index 747e6f74fb6f..2d8bca9b8c9c 100644 --- a/x/feegrant/migrations/v2/store_test.go +++ b/x/feegrant/migrations/v2/store_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/x/feegrant/module" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -23,7 +24,7 @@ import ( ) func TestMigration(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec ac := addresscodec.NewBech32Codec("cosmos") diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 1fb1685aa3c9..9676ae4ffd83 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -28,7 +29,7 @@ import ( func TestFeegrantPruning(t *testing.T) { key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) addrs := simtestutil.CreateIncrementalAccounts(4) granter1 := addrs[0] diff --git a/x/feegrant/simulation/decoder_test.go b/x/feegrant/simulation/decoder_test.go index 37526f596526..f29fa98977ad 100644 --- a/x/feegrant/simulation/decoder_test.go +++ b/x/feegrant/simulation/decoder_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/feegrant/simulation" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -25,7 +26,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) ac := addresscodec.NewBech32Codec("cosmos") diff --git a/x/feegrant/simulation/genesis_test.go b/x/feegrant/simulation/genesis_test.go index 1271cd5bb001..7bdd29c2e38f 100644 --- a/x/feegrant/simulation/genesis_test.go +++ b/x/feegrant/simulation/genesis_test.go @@ -12,13 +12,14 @@ import ( "cosmossdk.io/x/feegrant/module" "cosmossdk.io/x/feegrant/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" moduletypes "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index 2c5b8a923b33..f269ca7d6537 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" @@ -69,7 +70,7 @@ func TestAddGenesisAccountCmd(t *testing.T) { cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - appCodec := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}).Codec + appCodec := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}).Codec err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) diff --git a/x/genutil/client/cli/gentx_test.go b/x/genutil/client/cli/gentx_test.go index 76ea4856d592..a4c698398805 100644 --- a/x/genutil/client/cli/gentx_test.go +++ b/x/genutil/client/cli/gentx_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -42,7 +43,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(genutil.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, genutil.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/genutil/client/cli/migrate_test.go b/x/genutil/client/cli/migrate_test.go index 55a97fa079d5..7e84b491b132 100644 --- a/x/genutil/client/cli/migrate_test.go +++ b/x/genutil/client/cli/migrate_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -54,7 +55,7 @@ func TestMigrateGenesis(t *testing.T) { genesisFile := testutil.WriteToNewTempFile(t, tc.genesis) jsonOutput, err := clitestutil.ExecTestCLICmd( // the codec does not contain any modules so that genutil does not bring unnecessary dependencies in the test - client.Context{Codec: moduletestutil.MakeTestEncodingConfig().Codec}, + client.Context{Codec: moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec}, cli.MigrateGenesisCmd(cli.MigrationMap), []string{tc.target, genesisFile.Name()}, ) diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 4ce47e3a3dfd..862e19042364 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -19,6 +19,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -52,7 +53,7 @@ type GenTxTestSuite struct { } func (suite *GenTxTestSuite) SetupTest() { - suite.encodingConfig = moduletestutil.MakeTestEncodingConfig(genutil.AppModule{}) + suite.encodingConfig = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, genutil.AppModule{}) key := storetypes.NewKVStoreKey("a_Store_Key") tkey := storetypes.NewTransientStoreKey("a_transient_store") suite.ctx = testutil.DefaultContext(key, tkey) diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index 95a6aef6d2d4..bb97c2f00c85 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -13,6 +13,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -48,7 +49,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) { sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, math.OneInt()) require.NoError(t, err) - txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModule{}, genutil.AppModule{}).TxConfig + txConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}, genutil.AppModule{}).TxConfig txBuilder := txConfig.NewTxBuilder() require.NoError(t, txBuilder.SetMsgs(msg1, msg2)) @@ -64,7 +65,7 @@ func TestValidateGenesisBadMessage(t *testing.T) { msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()).String(), desc, nil, nil) - txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModule{}, genutil.AppModule{}).TxConfig + txConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}, genutil.AppModule{}).TxConfig txBuilder := txConfig.NewTxBuilder() err := txBuilder.SetMsgs(msg1) require.NoError(t, err) diff --git a/x/gov/client/cli/tx_test.go b/x/gov/client/cli/tx_test.go index 05ffcb92d806..4cbaf6972d96 100644 --- a/x/gov/client/cli/tx_test.go +++ b/x/gov/client/cli/tx_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -43,7 +44,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(gov.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index 3e539f71b4c5..5c0aed3ac7fa 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -15,6 +15,7 @@ import ( v1 "cosmossdk.io/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -54,7 +55,7 @@ func (mock TxSearchMock) Block(ctx context.Context, height *int64) (*coretypes.R } func TestGetPaginatedVotes(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(gov.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}) type testCase struct { description string diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index be8d44ea20c9..e2dda210d6a8 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -98,7 +99,7 @@ func setupGovKeeper(t *testing.T, expectations ...func(sdk.Context, mocks)) ( storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) v1.RegisterInterfaces(encCfg.InterfaceRegistry) v1beta1.RegisterInterfaces(encCfg.InterfaceRegistry) banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) diff --git a/x/gov/migrations/v5/store_test.go b/x/gov/migrations/v5/store_test.go index c84ee38e0a34..b790aaf971ae 100644 --- a/x/gov/migrations/v5/store_test.go +++ b/x/gov/migrations/v5/store_test.go @@ -13,13 +13,14 @@ import ( v5 "cosmossdk.io/x/gov/migrations/v5" v1 "cosmossdk.io/x/gov/types/v1" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestMigrateStore(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModule{}, bank.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}, bank.AppModule{}).Codec govKey := storetypes.NewKVStoreKey("gov") ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(govKey) diff --git a/x/gov/migrations/v6/store_test.go b/x/gov/migrations/v6/store_test.go index f356f59cca43..76a6aa654e6a 100644 --- a/x/gov/migrations/v6/store_test.go +++ b/x/gov/migrations/v6/store_test.go @@ -13,13 +13,14 @@ import ( v1 "cosmossdk.io/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestMigrateStore(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}).Codec govKey := storetypes.NewKVStoreKey("gov") ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) storeService := runtime.NewKVStoreService(govKey) diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index d46599c17634..dbc768f2d4e7 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" @@ -49,7 +50,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(groupmodule.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, groupmodule.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/group/keeper/genesis_test.go b/x/group/keeper/genesis_test.go index 412f5db64cb3..4b9a3236f19f 100644 --- a/x/group/keeper/genesis_test.go +++ b/x/group/keeper/genesis_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -52,7 +53,7 @@ func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(group.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) ctrl := gomock.NewController(s.T()) diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index 4754d73e5703..0be863e07359 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -45,7 +46,7 @@ func initKeeper(t *testing.T) *fixture { key := storetypes.NewKVStoreKey(group.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctx := testCtx.Ctx diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 7fde6bd60109..77cea1cbc9b1 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -24,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -55,7 +56,7 @@ func (s *TestSuite) SetupTest() { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}, bank.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}, bank.AppModule{}) s.addrs = simtestutil.CreateIncrementalAccounts(6) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/group/migrations/v2/migrate_test.go b/x/group/migrations/v2/migrate_test.go index 098586580620..c06b975c826c 100644 --- a/x/group/migrations/v2/migrate_test.go +++ b/x/group/migrations/v2/migrate_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -34,7 +35,7 @@ var ( ) func TestMigrate(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, groupmodule.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, groupmodule.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey(v2.ModuleName) storeService := runtime.NewKVStoreService(storeKey) tKey := storetypes.NewTransientStoreKey("transient_test") diff --git a/x/group/proposal_test.go b/x/group/proposal_test.go index d7a5748d5f53..eff18529ff7d 100644 --- a/x/group/proposal_test.go +++ b/x/group/proposal_test.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/x/group" "cosmossdk.io/x/group/module" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -16,7 +17,7 @@ import ( // This test serves as a showcase that we need to be careful when unmarshalling // multiple times into the same reference. func TestGogoUnmarshalProposal(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec p1 := group.Proposal{Proposers: []string{"foo"}} diff --git a/x/group/simulation/decoder_test.go b/x/group/simulation/decoder_test.go index 303490e02b8a..6eee5a2fbd63 100644 --- a/x/group/simulation/decoder_test.go +++ b/x/group/simulation/decoder_test.go @@ -12,13 +12,14 @@ import ( "cosmossdk.io/x/group/module" "cosmossdk.io/x/group/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestDecodeStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) diff --git a/x/group/simulation/genesis_test.go b/x/group/simulation/genesis_test.go index 7bc06aa2ccc7..9d129fca7af7 100644 --- a/x/group/simulation/genesis_test.go +++ b/x/group/simulation/genesis_test.go @@ -13,13 +13,14 @@ import ( groupmodule "cosmossdk.io/x/group/module" "cosmossdk.io/x/group/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(groupmodule.AppModule{}, bank.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, groupmodule.AppModule{}, bank.AppModule{}) cdc := encodingConfig.Codec s := rand.NewSource(1) diff --git a/x/mint/keeper/genesis_test.go b/x/mint/keeper/genesis_test.go index c21dbc4fc421..5fc6e9e03678 100644 --- a/x/mint/keeper/genesis_test.go +++ b/x/mint/keeper/genesis_test.go @@ -17,6 +17,7 @@ import ( "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,7 +43,7 @@ func TestGenesisTestSuite(t *testing.T) { func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/mint/keeper/grpc_query_test.go b/x/mint/keeper/grpc_query_test.go index 5b190ae5d444..f2f80689b759 100644 --- a/x/mint/keeper/grpc_query_test.go +++ b/x/mint/keeper/grpc_query_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,7 +32,7 @@ type MintTestSuite struct { } func (suite *MintTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index 0f22cb763ae1..fb4fa58c1827 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -15,6 +15,7 @@ import ( minttestutil "cosmossdk.io/x/mint/testutil" "cosmossdk.io/x/mint/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -38,7 +39,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (s *IntegrationTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index a4a79ef3f31b..8a3858e3d293 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/mint/simulation" "cosmossdk.io/x/mint/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -21,7 +22,7 @@ import ( // TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. // Abonormal scenarios are not tested here. func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) s := rand.NewSource(1) r := rand.New(s) @@ -60,7 +61,7 @@ func TestRandomizedGenState(t *testing.T) { // TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. func TestRandomizedGenState1(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 2332a68b38e1..823553727bd5 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -52,7 +53,7 @@ type TestSuite struct { func (s *TestSuite) SetupTest() { // suite setup s.addrs = simtestutil.CreateIncrementalAccounts(3) - s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) key := storetypes.NewKVStoreKey(nft.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) diff --git a/x/nft/simulation/decoder_test.go b/x/nft/simulation/decoder_test.go index 4c4b4a9941ec..7498ee7e8f58 100644 --- a/x/nft/simulation/decoder_test.go +++ b/x/nft/simulation/decoder_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/x/nft/module" "cosmossdk.io/x/nft/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -23,7 +24,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) dec := simulation.NewDecodeStore(encCfg.Codec) class := nft.Class{ diff --git a/x/nft/simulation/genesis_test.go b/x/nft/simulation/genesis_test.go index cd82052df323..3aa6928943c0 100644 --- a/x/nft/simulation/genesis_test.go +++ b/x/nft/simulation/genesis_test.go @@ -13,13 +13,14 @@ import ( "cosmossdk.io/x/nft/simulation" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(nftmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, nftmodule.AppModule{}) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index 2511b1e77eb3..5a577e51b649 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -6,13 +6,14 @@ import ( paramskeeper "cosmossdk.io/x/params/keeper" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdktestutil "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func testComponents() (*codec.LegacyAmino, sdk.Context, storetypes.StoreKey, storetypes.StoreKey, paramskeeper.Keeper) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(params.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, params.AppModule{}) cdc := encodingConfig.Codec legacyAmino := createTestCodec() diff --git a/x/params/keeper/keeper_test.go b/x/params/keeper/keeper_test.go index 382b5ed9e8f0..d82db839dd35 100644 --- a/x/params/keeper/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -30,7 +31,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - encodingCfg := moduletestutil.MakeTestEncodingConfig(params.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, params.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) tkey := storetypes.NewTransientStoreKey("params_transient_test") diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index f7aeeca28ca6..34f384922924 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -17,6 +17,7 @@ import ( "cosmossdk.io/x/params/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -38,7 +39,7 @@ func (suite *SubspaceTestSuite) SetupTest() { ms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) - encodingConfig := moduletestutil.MakeTestEncodingConfig(paramsmodule.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, paramsmodule.AppModule{}) suite.cdc = encodingConfig.Codec suite.amino = encodingConfig.Amino diff --git a/x/protocolpool/keeper/keeper_test.go b/x/protocolpool/keeper/keeper_test.go index 30df28d01a3c..fec0abd80cbc 100644 --- a/x/protocolpool/keeper/keeper_test.go +++ b/x/protocolpool/keeper/keeper_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -50,7 +51,7 @@ func (s *KeeperTestSuite) SetupTest() { environment := runtime.NewEnvironment(storeService, log.NewNopLogger()) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index 9e22a710e5e0..b78f42b8dc96 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -20,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" sdktestutil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -48,7 +49,7 @@ func (s *KeeperTestSuite) SetupTest() { env := runtime.NewEnvironment(storeService, log.NewNopLogger()) testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now().Round(0).UTC()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/slashing/migrations/v4/migrate_test.go b/x/slashing/migrations/v4/migrate_test.go index de31d92e3e5e..41d8995af6e4 100644 --- a/x/slashing/migrations/v4/migrate_test.go +++ b/x/slashing/migrations/v4/migrate_test.go @@ -12,6 +12,7 @@ import ( v4 "cosmossdk.io/x/slashing/migrations/v4" slashingtypes "cosmossdk.io/x/slashing/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -20,7 +21,7 @@ import ( var consAddr = sdk.ConsAddress(sdk.AccAddress([]byte("addr1_______________"))) func TestMigrate(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(slashing.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, slashing.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey(slashingtypes.ModuleName) tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index d786b64de306..50d9887a491d 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/slashing/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -24,7 +25,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(slashing.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, slashing.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) diff --git a/x/staking/client/cli/tx_test.go b/x/staking/client/cli/tx_test.go index 10edb4c1344c..39d8957bc640 100644 --- a/x/staking/client/cli/tx_test.go +++ b/x/staking/client/cli/tx_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -44,7 +45,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(staking.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 16b87cbbeec1..de6cfe138b5f 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -58,7 +59,7 @@ func (s *KeeperTestSuite) SetupTest() { testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.key = key ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) s.cdc = encCfg.Codec ctrl := gomock.NewController(s.T()) diff --git a/x/staking/migrations/v5/migrations_test.go b/x/staking/migrations/v5/migrations_test.go index 1f731415f342..07e19b3fcb8e 100644 --- a/x/staking/migrations/v5/migrations_test.go +++ b/x/staking/migrations/v5/migrations_test.go @@ -18,6 +18,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -50,7 +51,7 @@ func TestHistoricalKeysMigration(t *testing.T) { testCases[int64(height)] = testCase{} } - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec for height := range testCases { testCases[height] = testCase{ oldKey: v5.GetLegacyHistoricalInfoKey(height), @@ -80,7 +81,7 @@ func createHistoricalInfo(height int64, chainID string) *stakingtypes.Historical } func TestDelegationsByValidatorMigrations(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(staking.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey(v5.ModuleName) tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 308d054220bb..897219b86cce 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/x/staking/simulation" "cosmossdk.io/x/staking/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -22,7 +23,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc := testutil.MakeTestEncodingConfig().Codec + cdc := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec dec := simulation.NewDecodeStore(cdc) oneIntBz, err := math.OneInt().Marshal() diff --git a/x/upgrade/keeper/abci_test.go b/x/upgrade/keeper/abci_test.go index e74005dd8949..831d39cf1957 100644 --- a/x/upgrade/keeper/abci_test.go +++ b/x/upgrade/keeper/abci_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -111,7 +112,7 @@ func (s *TestSuite) VerifySet(t *testing.T, skipUpgradeHeights map[int64]bool) { func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { t.Helper() s := TestSuite{} - s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) @@ -458,7 +459,7 @@ func TestBinaryVersion(t *testing.T) { func TestDowngradeVerification(t *testing.T) { // could not use setupTest() here, because we have to use the same key // for the two keepers. - encCfg := moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 2911f11380c7..c866df64e767 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,7 +36,7 @@ type UpgradeTestSuite struct { } func (suite *UpgradeTestSuite) SetupTest() { - suite.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 798c93d9ce99..f17d6ae870d8 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -43,7 +44,7 @@ type KeeperTestSuite struct { } func (s *KeeperTestSuite) SetupTest() { - s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) From 2c4b397acf9806a2bc12d72764ade274013d855d Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 4 Mar 2024 11:26:20 +0100 Subject: [PATCH 15/19] CHANGELOG & UPGRADING --- CHANGELOG.md | 1 + UPGRADING.md | 9 ++++++--- x/auth/CHANGELOG.md | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e9939c7bd8d..c23c2c1e985b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### API Breaking Changes +* (types) [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) `module.testutil.MakeTestEncodingConfig` now takes `CodecOptions` as argument. * (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) Remove basic manager and all related functions (`module.BasicManager`, `module.NewBasicManager`, `module.NewBasicManagerFromManager`, `NewGenesisOnlyAppModule`). * The module manager now can do everything that the basic manager was doing. * When using runtime, just inject the module manager when needed using your app config. diff --git a/UPGRADING.md b/UPGRADING.md index 8ed75edacba2..46efd2176644 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -12,16 +12,19 @@ In this section we describe the changes made in Cosmos SDK' SimApp. #### Client (`root.go`) -The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.). +The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.) +and address bech32 prefixes (address and validator address). This is part of the work of abstracting the SDK from the global bech32 config. -This means the address codecs must be provided in the `client.Context` in the application client (usually `root.go`). +This means the address codecs and prefixes must be provided in the `client.Context` in the application client (usually `root.go`). ```diff clientCtx = clientCtx. + WithAddressCodec(addressCodec). + WithValidatorAddressCodec(validatorAddressCodec). -+ WithConsensusAddressCodec(consensusAddressCodec) ++ WithConsensusAddressCodec(consensusAddressCodec). ++ WithAddressPrefix("cosmos"). ++ WithValidatorPrefix("cosmosvaloper") ``` **When using `depinject` / `app v2`, the client codecs can be provided directly from application config.** diff --git a/x/auth/CHANGELOG.md b/x/auth/CHANGELOG.md index 33c4017bf38e..585075a9d39e 100644 --- a/x/auth/CHANGELOG.md +++ b/x/auth/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) Address and validator address codecs are now arguments of `NewTxConfig`. `NewDefaultSigningOptions` has been replaced with `NewSigningOptions` which takes address and validator address codecs as arguments. * [#17985](https://github.com/cosmos/cosmos-sdk/pull/17985) Remove `StdTxConfig` * [#19161](https://github.com/cosmos/cosmos-sdk/pull/19161) Remove `simulate` from `SetGasMeter` * [#19363](https://github.com/cosmos/cosmos-sdk/pull/19363) Remove `IterateAccounts` and `GetAllAccounts` methods from the AccountKeeper interface and Keeper. From 0323d2d54935ee4f12da2b193076acc4d83a97a0 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 4 Mar 2024 12:39:17 +0100 Subject: [PATCH 16/19] fix: integration tests --- tests/integration/evidence/keeper/infraction_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 9ef9d498361b..5c9977d6c7c6 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -88,7 +88,7 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, consensusparamtypes.StoreKey, evidencetypes.StoreKey, stakingtypes.StoreKey, slashingtypes.StoreKey, ) - encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, evidence.AppModule{}) cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) From 48465bc6bf01466b35f738d668d1dea96d953f0e Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 4 Mar 2024 16:04:27 +0100 Subject: [PATCH 17/19] fix: autocli test --- client/v2/autocli/common_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/v2/autocli/common_test.go b/client/v2/autocli/common_test.go index 2a5203fca9d9..2850abc226f3 100644 --- a/client/v2/autocli/common_test.go +++ b/client/v2/autocli/common_test.go @@ -63,8 +63,8 @@ func initFixture(t *testing.T) *fixture { banktypes.RegisterInterfaces(interfaceRegistry) clientCtx := client.Context{}. - WithAddressCodec(addresscodec.NewBech32Codec("cosmos")). - WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")). + WithAddressCodec(interfaceRegistry.SigningContext().AddressCodec()). + WithValidatorAddressCodec(interfaceRegistry.SigningContext().ValidatorAddressCodec()). WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons")). WithKeyring(kr). WithKeyringDir(home). From 5a50d81a4969a88a4ac7952a525aa9afd0f7ea87 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 6 Mar 2024 10:30:38 +0100 Subject: [PATCH 18/19] update: CodecOptions with codecs --- codec/testutil/codec.go | 64 ++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/codec/testutil/codec.go b/codec/testutil/codec.go index 4887aa2727b5..c3c14ee1f40e 100644 --- a/codec/testutil/codec.go +++ b/codec/testutil/codec.go @@ -3,6 +3,7 @@ package testutil import ( "github.com/cosmos/gogoproto/proto" + coreaddress "cosmossdk.io/core/address" "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" @@ -10,34 +11,45 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) -// CodecOptions are options for creating a test codec. +// CodecOptions are options for creating a test codec. If set, provided address codecs will be prioritized when +// building the InterfaceRegistry and ProtoCodec. If not set, new address bech32 codecs will be created using +// the provided prefixes. type CodecOptions struct { AccAddressPrefix string ValAddressPrefix string + AddressCodec coreaddress.Codec + ValidatorCodec coreaddress.Codec } -// NewInterfaceRegistry returns a new InterfaceRegistry with the given options. -func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { - accAddressPrefix := o.AccAddressPrefix - if accAddressPrefix == "" { - accAddressPrefix = "cosmos" +// NewCodecOptionsWithPrefixes returns CodecOptions with provided prefixes. +func NewCodecOptionsWithPrefixes(addressPrefix, validatorPrefix string) CodecOptions { + return CodecOptions{ + AccAddressPrefix: addressPrefix, + ValAddressPrefix: validatorPrefix, } +} - valAddressPrefix := o.ValAddressPrefix - if valAddressPrefix == "" { - valAddressPrefix = "cosmosvaloper" +// NewCodecOptionsWithCodecs returns CodecOptions with provided address codecs. +func NewCodecOptionsWithCodecs(addressCodec, validatorCodec coreaddress.Codec) CodecOptions { + return CodecOptions{ + AddressCodec: addressCodec, + ValidatorCodec: validatorCodec, } +} +// NewInterfaceRegistry returns a new InterfaceRegistry with the given options. +func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { ir, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ ProtoFiles: proto.HybridResolver, SigningOptions: signing.Options{ - AddressCodec: address.NewBech32Codec(accAddressPrefix), - ValidatorAddressCodec: address.NewBech32Codec(valAddressPrefix), + AddressCodec: o.GetAddressCodec(), + ValidatorAddressCodec: o.GetValidatorCodec(), }, }) if err != nil { panic(err) } + return ir } @@ -45,3 +57,33 @@ func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { func (o CodecOptions) NewCodec() *codec.ProtoCodec { return codec.NewProtoCodec(o.NewInterfaceRegistry()) } + +// GetAddressCodec returns the address codec. If not address codec was provided it'll create a new one based on the +// bech32 prefix. +func (o CodecOptions) GetAddressCodec() coreaddress.Codec { + if o.AddressCodec != nil { + return o.AddressCodec + } + + accAddressPrefix := o.AccAddressPrefix + if accAddressPrefix == "" { + accAddressPrefix = "cosmos" + } + + return address.NewBech32Codec(accAddressPrefix) +} + +// GetValidatorCodec returns the validator address codec. If not validator codec was provided it'll create a new one +// based on the bech32 prefix. +func (o CodecOptions) GetValidatorCodec() coreaddress.Codec { + if o.ValidatorCodec != nil { + return o.ValidatorCodec + } + + valAddressPrefix := o.ValAddressPrefix + if valAddressPrefix == "" { + valAddressPrefix = "cosmosvaloper" + } + + return address.NewBech32Codec(valAddressPrefix) +} From db3486ad37b723d550a2beaba55016537418954d Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 6 Mar 2024 14:01:12 +0100 Subject: [PATCH 19/19] fix2 --- x/auth/signing/adapter_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/auth/signing/adapter_test.go b/x/auth/signing/adapter_test.go index 2a90b7030a36..432a0194ba77 100644 --- a/x/auth/signing/adapter_test.go +++ b/x/auth/signing/adapter_test.go @@ -8,13 +8,14 @@ import ( authsign "cosmossdk.io/x/auth/signing" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/types/tx/signing" ) func TestGetSignBytesAdapterNoPublicKey(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) txConfig := encodingConfig.TxConfig _, _, addr := testdata.KeyTestPubAddr() signerData := authsign.SignerData{