From 81a9f5914ee1d2a70ace1a1ba51e099b2611b057 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 27 Jul 2022 15:49:01 +0200 Subject: [PATCH 1/4] feat: make `simapp.MakeTestEncodingConfig` private --- docs/run-node/txs.md | 2 +- simapp/app_legacy.go | 11 ++++++- simapp/encoding.go | 19 ------------ simapp/simd/cmd/genaccounts_test.go | 5 +-- simapp/simd/cmd/testnet_test.go | 5 ++- x/bank/app_test.go | 17 ++++++----- x/bank/keeper/keeper_test.go | 5 ++- x/bank/migrations/v2/json_test.go | 4 +-- x/bank/migrations/v2/store_test.go | 6 ++-- x/bank/migrations/v3/store_test.go | 6 ++-- x/genutil/gentx_test.go | 14 ++++++--- x/genutil/types/genesis_state_test.go | 20 ++++++------ x/gov/client/utils/query_test.go | 5 +-- x/gov/keeper/common_test.go | 3 +- x/gov/migrations/v043/json_test.go | 4 +-- x/gov/migrations/v043/store_test.go | 4 +-- x/gov/migrations/v046/json_test.go | 5 +-- x/gov/migrations/v046/store_test.go | 6 ++-- x/gov/simulation/decoder_test.go | 5 +-- x/slashing/app_test.go | 7 +++-- x/staking/app_test.go | 11 ++++--- x/staking/keeper/common_test.go | 43 ++++++++++++++++++++++++-- x/staking/keeper/grpc_query_test.go | 44 --------------------------- x/staking/migrations/v3/json_test.go | 6 ++-- x/staking/migrations/v3/store_test.go | 6 ++-- x/staking/simulation/decoder_test.go | 4 +-- 26 files changed, 136 insertions(+), 131 deletions(-) delete mode 100644 simapp/encoding.go diff --git a/docs/run-node/txs.md b/docs/run-node/txs.md index 9674d32f4eed..79693927afee 100644 --- a/docs/run-node/txs.md +++ b/docs/run-node/txs.md @@ -123,7 +123,7 @@ import ( func sendTx() error { // Choose your codec: Amino or Protobuf. Here, we use Protobuf, given by the // following function. - encCfg := simapp.MakeTestEncodingConfig() + encCfg := simapp.MakeEncodingConfig() // Create a new TxBuilder. txBuilder := encCfg.TxConfig.NewTxBuilder() diff --git a/simapp/app_legacy.go b/simapp/app_legacy.go index 4c53e37b3527..9d03745bc916 100644 --- a/simapp/app_legacy.go +++ b/simapp/app_legacy.go @@ -211,7 +211,7 @@ func NewSimApp( appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { - encodingConfig := MakeTestEncodingConfig() + encodingConfig := makeEncodingConfig() appCodec := encodingConfig.Codec legacyAmino := encodingConfig.Amino @@ -684,3 +684,12 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino return paramsKeeper } + +func makeEncodingConfig() simappparams.EncodingConfig { + encodingConfig := simappparams.MakeTestEncodingConfig() + std.RegisterLegacyAminoCodec(encodingConfig.Amino) + std.RegisterInterfaces(encodingConfig.InterfaceRegistry) + ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) + ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) + return encodingConfig +} diff --git a/simapp/encoding.go b/simapp/encoding.go deleted file mode 100644 index 8a90ff852478..000000000000 --- a/simapp/encoding.go +++ /dev/null @@ -1,19 +0,0 @@ -package simapp - -import ( - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" - "github.com/cosmos/cosmos-sdk/std" -) - -// MakeTestEncodingConfig creates an EncodingConfig for testing. This function -// should be used only in tests or when creating a new app instance (NewApp*()). -// App user shouldn't create new codecs - use the app.AppCodec instead. -// [DEPRECATED] -func MakeTestEncodingConfig() simappparams.EncodingConfig { - encodingConfig := simappparams.MakeTestEncodingConfig() - std.RegisterLegacyAminoCodec(encodingConfig.Amino) - std.RegisterInterfaces(encodingConfig.InterfaceRegistry) - ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) - ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) - return encodingConfig -} diff --git a/simapp/simd/cmd/genaccounts_test.go b/simapp/simd/cmd/genaccounts_test.go index ca751fc34f62..34dc5e3071ff 100644 --- a/simapp/simd/cmd/genaccounts_test.go +++ b/simapp/simd/cmd/genaccounts_test.go @@ -16,10 +16,11 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/simapp" simcmd "github.com/cosmos/cosmos-sdk/simapp/simd/cmd" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/module" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" ) @@ -73,7 +74,7 @@ func TestAddGenesisAccountCmd(t *testing.T) { cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) - appCodec := simapp.MakeTestEncodingConfig().Codec + appCodec := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}).Codec err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 09134383a16c..716e9f862b23 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -13,14 +13,17 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/auth" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/staking" ) func Test_TestnetCmd(t *testing.T) { home := t.TempDir() - encodingConfig := simapp.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModuleBasic{}, auth.AppModuleBasic{}) logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) diff --git a/x/bank/app_test.go b/x/bank/app_test.go index ef5621d34641..392728e989ab 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -10,6 +10,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -96,8 +97,8 @@ func TestSendNotEnoughBalance(t *testing.T) { sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) header := tmproto.Header{Height: app.LastBlockHeight() + 1} - txGen := simapp.MakeTestEncodingConfig().TxConfig - _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) + txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig + _, _, err := simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) require.Error(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{sdk.NewInt64Coin("foocoin", 67)}) @@ -171,8 +172,8 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { for _, tc := range testCases { header := tmproto.Header{Height: app.LastBlockHeight() + 1} - txGen := simapp.MakeTestEncodingConfig().TxConfig - _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig + _, _, err := simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) if tc.expPass { require.NoError(t, err) } else { @@ -221,8 +222,8 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { for _, tc := range testCases { header := tmproto.Header{Height: app.LastBlockHeight() + 1} - txGen := simapp.MakeTestEncodingConfig().TxConfig - _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig + _, _, err := simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { @@ -273,8 +274,8 @@ func TestMsgMultiSendDependent(t *testing.T) { for _, tc := range testCases { header := tmproto.Header{Height: app.LastBlockHeight() + 1} - txGen := simapp.MakeTestEncodingConfig().TxConfig - _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig + _, _, err := simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 63d737aa2ed0..ddc3a043cb19 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -18,10 +18,13 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/bank/exported" "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/bank/testutil" @@ -83,7 +86,7 @@ type IntegrationTestSuite struct { func (suite *IntegrationTestSuite) initKeepersWithmAccPerms(blockedAddrs map[string]bool) (authkeeper.AccountKeeper, keeper.BaseKeeper) { app := suite.app maccPerms := simapp.GetMaccPerms() - appCodec := simapp.MakeTestEncodingConfig().Codec + appCodec := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}).Codec maccPerms[holder] = nil maccPerms[authtypes.Burner] = []string{authtypes.Burner} diff --git a/x/bank/migrations/v2/json_test.go b/x/bank/migrations/v2/json_test.go index 677a211fb8e9..ddf908e01982 100644 --- a/x/bank/migrations/v2/json_test.go +++ b/x/bank/migrations/v2/json_test.go @@ -7,14 +7,14 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" v2bank "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2" "github.com/cosmos/cosmos-sdk/x/bank/types" ) func TestMigrateJSON(t *testing.T) { - encodingConfig := simapp.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig() clientCtx := client.Context{}. WithInterfaceRegistry(encodingConfig.InterfaceRegistry). WithTxConfig(encodingConfig.TxConfig). diff --git a/x/bank/migrations/v2/store_test.go b/x/bank/migrations/v2/store_test.go index 287f34626867..96bd7e15e6e3 100644 --- a/x/bank/migrations/v2/store_test.go +++ b/x/bank/migrations/v2/store_test.go @@ -6,18 +6,18 @@ import ( "cosmossdk.io/math" "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" v1bank "github.com/cosmos/cosmos-sdk/x/bank/migrations/v1" v2bank "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2" "github.com/cosmos/cosmos-sdk/x/bank/types" ) func TestSupplyMigration(t *testing.T) { - encCfg := simapp.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig() bankKey := sdk.NewKVStoreKey("bank") ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) @@ -68,7 +68,7 @@ func TestSupplyMigration(t *testing.T) { } func TestBalanceKeysMigration(t *testing.T) { - encCfg := simapp.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig() bankKey := sdk.NewKVStoreKey("bank") ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) diff --git a/x/bank/migrations/v3/store_test.go b/x/bank/migrations/v3/store_test.go index f7b790131f58..4c418ffb0d05 100644 --- a/x/bank/migrations/v3/store_test.go +++ b/x/bank/migrations/v3/store_test.go @@ -6,18 +6,18 @@ import ( "cosmossdk.io/math" "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2" v3 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v3" "github.com/cosmos/cosmos-sdk/x/bank/types" ) func TestMigrateStore(t *testing.T) { - encCfg := simapp.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig() bankKey := sdk.NewKVStoreKey("bank") ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) @@ -55,7 +55,7 @@ func TestMigrateStore(t *testing.T) { } func TestMigrateDenomMetaData(t *testing.T) { - encCfg := simapp.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig() bankKey := sdk.NewKVStoreKey("bank") ctx := testutil.DefaultContext(bankKey, sdk.NewTransientStoreKey("transient_test")) store := ctx.KVStore(bankKey) diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 0653c7b4bc32..4b0abee37b12 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -13,9 +13,9 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/bank/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -40,9 +40,8 @@ type GenTxTestSuite struct { ctx sdk.Context app *simapp.SimApp - encodingConfig simappparams.EncodingConfig - - msg1, msg2 *stakingtypes.MsgCreateValidator + encodingConfig moduletestutil.TestEncodingConfig + msg1, msg2 *stakingtypes.MsgCreateValidator } func (suite *GenTxTestSuite) SetupTest() { @@ -50,7 +49,12 @@ func (suite *GenTxTestSuite) SetupTest() { app := simapp.Setup(suite.T(), checkTx) suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) suite.app = app - suite.encodingConfig = simapp.MakeTestEncodingConfig() + suite.encodingConfig = moduletestutil.TestEncodingConfig{ + InterfaceRegistry: app.InterfaceRegistry(), + Codec: app.AppCodec(), + TxConfig: app.TxConfig(), + Amino: app.LegacyAmino(), + } var err error amount := sdk.NewInt64Coin(sdk.DefaultBondDenom, 50) diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index 20e3f64c9d49..760f593ab3cb 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -10,10 +10,12 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -46,14 +48,14 @@ func TestValidateGenesisMultipleMessages(t *testing.T) { sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, math.OneInt()) require.NoError(t, err) - txGen := simapp.MakeTestEncodingConfig().TxConfig - txBuilder := txGen.NewTxBuilder() + txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModuleBasic{}, genutil.AppModuleBasic{}).TxConfig + txBuilder := txConfig.NewTxBuilder() require.NoError(t, txBuilder.SetMsgs(msg1, msg2)) tx := txBuilder.GetTx() - genesisState := types.NewGenesisStateFromTx(txGen.TxJSONEncoder(), []sdk.Tx{tx}) + genesisState := types.NewGenesisStateFromTx(txConfig.TxJSONEncoder(), []sdk.Tx{tx}) - err = types.ValidateGenesis(genesisState, simapp.MakeTestEncodingConfig().TxConfig.TxJSONDecoder()) + err = types.ValidateGenesis(genesisState, txConfig.TxJSONDecoder()) require.Error(t, err) } @@ -62,15 +64,15 @@ func TestValidateGenesisBadMessage(t *testing.T) { msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()), desc, nil, nil) - txGen := simapp.MakeTestEncodingConfig().TxConfig - txBuilder := txGen.NewTxBuilder() + txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModuleBasic{}, genutil.AppModuleBasic{}).TxConfig + txBuilder := txConfig.NewTxBuilder() err := txBuilder.SetMsgs(msg1) require.NoError(t, err) tx := txBuilder.GetTx() - genesisState := types.NewGenesisStateFromTx(txGen.TxJSONEncoder(), []sdk.Tx{tx}) + genesisState := types.NewGenesisStateFromTx(txConfig.TxJSONEncoder(), []sdk.Tx{tx}) - err = types.ValidateGenesis(genesisState, simapp.MakeTestEncodingConfig().TxConfig.TxJSONDecoder()) + err = types.ValidateGenesis(genesisState, txConfig.TxJSONDecoder()) require.Error(t, err) } diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index 8bc1a8e42a4e..667a8831e607 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -11,9 +11,10 @@ import ( tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/client/utils" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) @@ -75,7 +76,7 @@ func (mock TxSearchMock) Block(ctx context.Context, height *int64) (*coretypes.R } func TestGetPaginatedVotes(t *testing.T) { - encCfg := simapp.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}) type testCase struct { description string diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index ab7e23d2d301..f29fa800ba44 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -9,6 +9,7 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -41,7 +42,7 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) pks := simtestutil.CreateTestPubKeys(5) - cdc := simapp.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig().Codec app.StakingKeeper = stakingkeeper.NewKeeper( cdc, diff --git a/x/gov/migrations/v043/json_test.go b/x/gov/migrations/v043/json_test.go index 4202752aada6..acde3a1b6436 100644 --- a/x/gov/migrations/v043/json_test.go +++ b/x/gov/migrations/v043/json_test.go @@ -7,14 +7,14 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" v043gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v043" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) func TestMigrateJSON(t *testing.T) { - encodingConfig := simapp.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig() clientCtx := client.Context{}. WithInterfaceRegistry(encodingConfig.InterfaceRegistry). WithTxConfig(encodingConfig.TxConfig). diff --git a/x/gov/migrations/v043/store_test.go b/x/gov/migrations/v043/store_test.go index 1ae662d818eb..104e6046f21d 100644 --- a/x/gov/migrations/v043/store_test.go +++ b/x/gov/migrations/v043/store_test.go @@ -7,10 +7,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" v042gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v042" v043gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v043" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -18,7 +18,7 @@ import ( ) func TestMigrateStore(t *testing.T) { - cdc := simapp.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig().Codec govKey := sdk.NewKVStoreKey("gov") ctx := testutil.DefaultContext(govKey, sdk.NewTransientStoreKey("transient_test")) store := ctx.KVStore(govKey) diff --git a/x/gov/migrations/v046/json_test.go b/x/gov/migrations/v046/json_test.go index 518161b9e8b5..109af562dded 100644 --- a/x/gov/migrations/v046/json_test.go +++ b/x/gov/migrations/v046/json_test.go @@ -10,9 +10,10 @@ import ( "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/gov" v046 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v046" "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -20,7 +21,7 @@ import ( ) func TestMigrateJSON(t *testing.T) { - encodingConfig := simapp.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}) clientCtx := client.Context{}. WithInterfaceRegistry(encodingConfig.InterfaceRegistry). WithTxConfig(encodingConfig.TxConfig). diff --git a/x/gov/migrations/v046/store_test.go b/x/gov/migrations/v046/store_test.go index a9318f9390a9..7241815a6ff2 100644 --- a/x/gov/migrations/v046/store_test.go +++ b/x/gov/migrations/v046/store_test.go @@ -6,18 +6,20 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/gov" v042gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v042" v046gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v046" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/cosmos/cosmos-sdk/x/upgrade" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) func TestMigrateStore(t *testing.T) { - cdc := simapp.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}, gov.AppModuleBasic{}).Codec govKey := sdk.NewKVStoreKey("gov") ctx := testutil.DefaultContext(govKey, sdk.NewTransientStoreKey("transient_test")) store := ctx.KVStore(govKey) diff --git a/x/gov/simulation/decoder_test.go b/x/gov/simulation/decoder_test.go index 10145996edcf..8f97b00afd4f 100644 --- a/x/gov/simulation/decoder_test.go +++ b/x/gov/simulation/decoder_test.go @@ -10,9 +10,10 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/simulation" "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -24,7 +25,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc := simapp.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}).Codec dec := simulation.NewDecodeStore(cdc) endTime := time.Now().UTC() diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 537571bc12eb..72b1dc14ec47 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -70,8 +71,8 @@ func TestSlashingMsgs(t *testing.T) { require.NoError(t, err) header := tmproto.Header{Height: app.LastBlockHeight() + 1} - txGen := simapp.MakeTestEncodingConfig().TxConfig - _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) + txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig + _, _, err = simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -88,7 +89,7 @@ func TestSlashingMsgs(t *testing.T) { // unjail should fail with unknown validator header = tmproto.Header{Height: app.LastBlockHeight() + 1} - _, res, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{unjailMsg}, "", []uint64{0}, []uint64{1}, false, false, priv1) + _, res, err := simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{unjailMsg}, "", []uint64{0}, []uint64{1}, false, false, priv1) require.Error(t, err) require.Nil(t, res) require.True(t, errors.Is(types.ErrValidatorNotJailed, err)) diff --git a/x/staking/app_test.go b/x/staking/app_test.go index c927ededcfa0..f7f43d8d1a46 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -71,8 +72,8 @@ func TestStakingMsgs(t *testing.T) { require.NoError(t, err) header := tmproto.Header{Height: app.LastBlockHeight() + 1} - txGen := simapp.MakeTestEncodingConfig().TxConfig - _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) + txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig + _, _, err = simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -92,7 +93,7 @@ func TestStakingMsgs(t *testing.T) { editValidatorMsg := types.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil) header = tmproto.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{editValidatorMsg}, "", []uint64{0}, []uint64{1}, true, true, priv1) + _, _, err = simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{editValidatorMsg}, "", []uint64{0}, []uint64{1}, true, true, priv1) require.NoError(t, err) validator = checkValidator(t, app, sdk.ValAddress(addr1), true) @@ -103,7 +104,7 @@ func TestStakingMsgs(t *testing.T) { delegateMsg := types.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = tmproto.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{delegateMsg}, "", []uint64{1}, []uint64{0}, true, true, priv2) + _, _, err = simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{delegateMsg}, "", []uint64{1}, []uint64{0}, true, true, priv2) require.NoError(t, err) simapp.CheckBalance(t, app, addr2, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -112,7 +113,7 @@ func TestStakingMsgs(t *testing.T) { // begin unbonding beginUnbondingMsg := types.NewMsgUndelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = tmproto.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, "", []uint64{1}, []uint64{1}, true, true, priv2) + _, _, err = simapp.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, "", []uint64{1}, []uint64{1}, true, true, priv2) require.NoError(t, err) // delegation should exist anymore diff --git a/x/staking/keeper/common_test.go b/x/staking/keeper/common_test.go index 7c270df7d958..bd99456b62db 100644 --- a/x/staking/keeper/common_test.go +++ b/x/staking/keeper/common_test.go @@ -4,16 +4,18 @@ import ( "math/big" "testing" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - + "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/cosmos/cosmos-sdk/x/staking/teststaking" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -51,3 +53,38 @@ func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int) ([]sdk return addrDels, addrVals } + +func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress, []types.Validator) { + addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, app.StakingKeeper.TokensFromConsensusPower(ctx, 300)) + valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) + pks := simtestutil.CreateTestPubKeys(5) + cdc := moduletestutil.MakeTestEncodingConfig().Codec + app.StakingKeeper = keeper.NewKeeper( + cdc, + app.GetKey(types.StoreKey), + app.AccountKeeper, + app.BankKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + val1 := teststaking.NewValidator(t, valAddrs[0], pks[0]) + val2 := teststaking.NewValidator(t, valAddrs[1], pks[1]) + vals := []types.Validator{val1, val2} + + app.StakingKeeper.SetValidator(ctx, val1) + app.StakingKeeper.SetValidator(ctx, val2) + app.StakingKeeper.SetValidatorByConsAddr(ctx, val1) + app.StakingKeeper.SetValidatorByConsAddr(ctx, val2) + app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1) + app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2) + + _, err := app.StakingKeeper.Delegate(ctx, addrs[0], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[0]), types.Unbonded, val1, true) + require.NoError(t, err) + _, err = app.StakingKeeper.Delegate(ctx, addrs[1], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[1]), types.Unbonded, val2, true) + require.NoError(t, err) + _, err = app.StakingKeeper.Delegate(ctx, addrs[0], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[2]), types.Unbonded, val2, true) + require.NoError(t, err) + applyValidatorSetUpdates(t, ctx, app.StakingKeeper, -1) + + return addrs, valAddrs, vals +} diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index 619f8d5af2bd..6217fa0c8202 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -3,19 +3,10 @@ package keeper_test import ( gocontext "context" "fmt" - "testing" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/simapp" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/teststaking" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -788,38 +779,3 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidatorUnbondingDelegations() { }) } } - -func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress, []types.Validator) { - addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, app.StakingKeeper.TokensFromConsensusPower(ctx, 300)) - valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) - pks := simtestutil.CreateTestPubKeys(5) - cdc := simapp.MakeTestEncodingConfig().Codec - app.StakingKeeper = keeper.NewKeeper( - cdc, - app.GetKey(types.StoreKey), - app.AccountKeeper, - app.BankKeeper, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) - - val1 := teststaking.NewValidator(t, valAddrs[0], pks[0]) - val2 := teststaking.NewValidator(t, valAddrs[1], pks[1]) - vals := []types.Validator{val1, val2} - - app.StakingKeeper.SetValidator(ctx, val1) - app.StakingKeeper.SetValidator(ctx, val2) - app.StakingKeeper.SetValidatorByConsAddr(ctx, val1) - app.StakingKeeper.SetValidatorByConsAddr(ctx, val2) - app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1) - app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2) - - _, err := app.StakingKeeper.Delegate(ctx, addrs[0], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[0]), types.Unbonded, val1, true) - require.NoError(t, err) - _, err = app.StakingKeeper.Delegate(ctx, addrs[1], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[1]), types.Unbonded, val2, true) - require.NoError(t, err) - _, err = app.StakingKeeper.Delegate(ctx, addrs[0], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[2]), types.Unbonded, val2, true) - require.NoError(t, err) - applyValidatorSetUpdates(t, ctx, app.StakingKeeper, -1) - - return addrs, valAddrs, vals -} diff --git a/x/staking/migrations/v3/json_test.go b/x/staking/migrations/v3/json_test.go index a52a89ad1325..c111f366515e 100644 --- a/x/staking/migrations/v3/json_test.go +++ b/x/staking/migrations/v3/json_test.go @@ -7,13 +7,13 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/x/staking/migrations/v3" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + v3 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v3" "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestMigrateJSON(t *testing.T) { - encodingConfig := simapp.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig() clientCtx := client.Context{}. WithInterfaceRegistry(encodingConfig.InterfaceRegistry). WithTxConfig(encodingConfig.TxConfig). diff --git a/x/staking/migrations/v3/store_test.go b/x/staking/migrations/v3/store_test.go index f57ce3de6c7f..24c37b595cf1 100644 --- a/x/staking/migrations/v3/store_test.go +++ b/x/staking/migrations/v3/store_test.go @@ -5,16 +5,16 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/cosmos-sdk/x/staking/migrations/v3" + v3 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v3" "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestStoreMigration(t *testing.T) { - encCfg := simapp.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig() stakingKey := sdk.NewKVStoreKey("staking") tStakingKey := sdk.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(stakingKey, tStakingKey) diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 7bc46fbbeb97..3bd7a168894f 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -11,9 +11,9 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/staking/simulation" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -33,7 +33,7 @@ func makeTestCodec() (cdc *codec.LegacyAmino) { } func TestDecodeStore(t *testing.T) { - cdc := simapp.MakeTestEncodingConfig().Codec + cdc := testutil.MakeTestEncodingConfig().Codec dec := simulation.NewDecodeStore(cdc) bondTime := time.Now().UTC() From d47b7e70ee8cbfc48c8823f8ddf88b0f01223d3b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 27 Jul 2022 15:56:56 +0200 Subject: [PATCH 2/4] fix legacy build --- simapp/app_legacy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simapp/app_legacy.go b/simapp/app_legacy.go index 9d03745bc916..2a8318363be3 100644 --- a/simapp/app_legacy.go +++ b/simapp/app_legacy.go @@ -27,6 +27,8 @@ import ( "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" From 85cc575305152e9459ea5da1a964aa1618587a9b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 27 Jul 2022 16:17:25 +0200 Subject: [PATCH 3/4] update changelog and upgrading.md --- CHANGELOG.md | 1 + UPGRADING.md | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e1ecd0042a3..412df9507f2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (simapp) [#12747](https://github.com/cosmos/cosmos-sdk/pull/12747) Remove `simapp.MakeTestEncodingConfig`. Please use `moduletestutil.MakeTestEncodingConfig` (`types/module/testutil`) in tests instead. * (x/bank) [#12648](https://github.com/cosmos/cosmos-sdk/pull/12648) `NewSendAuthorization` takes a new argument of an optional list of addresses allowed to receive bank assests via authz MsgSend grant. You can pass `nil` for the same behavior as before, i.e. any recipient is allowed. * (x/bank) [\#12593](https://github.com/cosmos/cosmos-sdk/pull/12593) Add `SpendableCoin` method to `BaseViewKeeper` * (x/slashing) [#12581](https://github.com/cosmos/cosmos-sdk/pull/12581) Remove `x/slashing` legacy querier. diff --git a/UPGRADING.md b/UPGRADING.md index 610d0245fe7a..b299ccd4f30c 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -11,8 +11,14 @@ This means that modules are injected directly into SimApp thanks to a [configura The old behavior is preserved and still can be used, without the dependency injection framework, as shows [`app_legacy.go`](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_legacy.go). The constructor, `NewSimApp` has been simplified: - - `NewSimApp` does not take encoding parameters (`encodingConfig`) as input, instead the encoding parameters are injected (when using app wiring), or directly created in the constructor. Instead, we can instantiate `SimApp` for getting the encoding configuration. - - `NewSimApp` now uses `AppOptions` for getting the home path (`homePath`) and the invariant checks period (`invCheckPeriod`). These were unnecessary given as arguments as they were already present in the `AppOptions`. + +* `NewSimApp` does not take encoding parameters (`encodingConfig`) as input, instead the encoding parameters are injected (when using app wiring), or directly created in the constructor. Instead, we can instantiate `SimApp` for getting the encoding configuration. +* `NewSimApp` now uses `AppOptions` for getting the home path (`homePath`) and the invariant checks period (`invCheckPeriod`). These were unnecessary given as arguments as they were already present in the `AppOptions`. + +### Encoding + +`simapp.MakeTestEncodingConfig()` was deprecated and has been removed. Instead you can use the `TestEncodingConfig` from the `types/module/testutil` package. +This means you can replace your usage of `simapp.MakeTestEncodingConfig` in tests to `moduletestutil.MakeTestEncodingConfig`, which takes a series of relevant `AppModuleBasic` as input (the module being tested and any potential dependencies). ## [v0.46.x](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0) From d043180d3a2d75b82f3dc0477319d19f2eb06329 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 27 Jul 2022 16:54:29 +0200 Subject: [PATCH 4/4] updates docs --- docs/run-node/txs.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/run-node/txs.md b/docs/run-node/txs.md index 79693927afee..59995a267b06 100644 --- a/docs/run-node/txs.md +++ b/docs/run-node/txs.md @@ -121,12 +121,11 @@ import ( ) func sendTx() error { - // Choose your codec: Amino or Protobuf. Here, we use Protobuf, given by the - // following function. - encCfg := simapp.MakeEncodingConfig() + // Choose your codec: Amino or Protobuf. Here, we use Protobuf, given by the following function. + app := simapp.NewSimApp(...) // Create a new TxBuilder. - txBuilder := encCfg.TxConfig.NewTxBuilder() + txBuilder := app.TxConfig().NewTxBuilder() // --snip-- }