From 3d11bfdbd40d050e3ad50b2cf3aec0cc2b17d24d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 23 Mar 2023 15:08:39 +0100 Subject: [PATCH 1/4] refactor: remove some depinject usage --- client/keys/add_ledger_test.go | 8 +++--- client/keys/add_test.go | 9 +++---- client/keys/delete_test.go | 4 +-- client/keys/export_test.go | 4 +-- client/keys/import_test.go | 4 +-- client/keys/list_test.go | 6 ++--- client/keys/migrate_test.go | 4 +-- client/keys/rename_test.go | 4 +-- client/keys/show_test.go | 4 +-- client/testutil/util.go | 32 ----------------------- client/tx/aux_builder_test.go | 12 +++------ client/tx/tx_test.go | 12 +++------ types/module/testutil/codec.go | 4 +-- x/auth/types/genesis_test.go | 9 +++---- x/authz/migrations/v2/store_test.go | 10 +++---- x/distribution/simulation/decoder_test.go | 10 +++---- x/evidence/simulation/decoder_test.go | 1 - x/group/proposal_test.go | 10 +++---- x/group/simulation/decoder_test.go | 10 +++---- x/group/simulation/genesis_test.go | 11 ++++---- x/params/keeper/common_test.go | 10 +++---- x/params/testutil/app_config.go | 23 ---------------- x/params/types/subspace_test.go | 12 ++++----- x/slashing/simulation/decoder_test.go | 9 +++---- x/slashing/simulation/genesis_test.go | 8 ++---- 25 files changed, 72 insertions(+), 158 deletions(-) delete mode 100644 client/testutil/util.go delete mode 100644 x/params/testutil/app_config.go diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index 19602fce42a5..1bcc62aa5654 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -15,11 +15,11 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { @@ -44,7 +44,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { // Prepare a keybase kbHome := t.TempDir() - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec clientCtx := client.Context{}.WithKeyringDir(kbHome).WithCodec(cdc) ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) @@ -96,7 +96,7 @@ func Test_runAddCmdLedger(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec clientCtx := client.Context{}.WithKeyringDir(kbHome).WithCodec(cdc) ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) @@ -137,7 +137,7 @@ func Test_runAddCmdLedger(t *testing.T) { } func Test_runAddCmdLedgerDryRun(t *testing.T) { - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec testData := []struct { name string args []string diff --git a/client/keys/add_test.go b/client/keys/add_test.go index 3fe04f447bd0..1f28fcddbc3a 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -12,12 +12,12 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "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" "github.com/cosmos/go-bip39" ) @@ -28,8 +28,7 @@ func Test_runAddCmdBasic(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := clienttestutil.MakeTestCodec(t) - + cdc := moduletestutil.MakeTestEncodingConfig().Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) @@ -124,7 +123,7 @@ func Test_runAddCmdBasic(t *testing.T) { 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"}` - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec testData := []struct { name string @@ -235,7 +234,7 @@ func Test_runAddCmdDryRun(t *testing.T) { func TestAddRecoverFileBackend(t *testing.T) { cmd := AddKeyCommand() cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() diff --git a/client/keys/delete_test.go b/client/keys/delete_test.go index c3799b00249a..49f897aece41 100644 --- a/client/keys/delete_test.go +++ b/client/keys/delete_test.go @@ -9,12 +9,12 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "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" ) func Test_runDeleteCmd(t *testing.T) { @@ -34,7 +34,7 @@ func Test_runDeleteCmd(t *testing.T) { fakeKeyName2 := "runDeleteCmd_Key2" path := sdk.GetConfig().GetFullBIP44Path() - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec cmd.SetArgs([]string{"blah", fmt.Sprintf("--%s=%s", flags.FlagHome, 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 4af52288d2a7..cd4dc98049c0 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -20,7 +20,7 @@ import ( ) func Test_runExportCmd(t *testing.T) { - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec testCases := []struct { name string keyringBackend string diff --git a/client/keys/import_test.go b/client/keys/import_test.go index 93027be6e57d..59cdf044d9cf 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -11,14 +11,14 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func Test_runImportCmd(t *testing.T) { - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec testCases := []struct { name string keyringBackend string diff --git a/client/keys/list_test.go b/client/keys/list_test.go index 22e33399cfa4..9fd0b70fb276 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -10,13 +10,13 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func cleanupKeys(t *testing.T, kb keyring.Keyring, keys ...string) func() { @@ -37,7 +37,7 @@ func Test_runListCmd(t *testing.T) { kbHome2 := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome2, mockIn, cdc) assert.NilError(t, err) @@ -85,7 +85,7 @@ func Test_runListCmd(t *testing.T) { func Test_runListKeyTypeCmd(t *testing.T) { cmd := ListKeyTypesCmd() - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec kbHome := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) diff --git a/client/keys/migrate_test.go b/client/keys/migrate_test.go index a53745c4457d..8878f61755c0 100644 --- a/client/keys/migrate_test.go +++ b/client/keys/migrate_test.go @@ -11,13 +11,13 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) type setter interface { @@ -36,7 +36,7 @@ type MigrateTestSuite struct { func (s *MigrateTestSuite) SetupSuite() { s.dir = s.T().TempDir() - s.cdc = clienttestutil.MakeTestCodec(s.T()) + s.cdc = moduletestutil.MakeTestEncodingConfig().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 b78c8f48e6dc..40d7d579330b 100644 --- a/client/keys/rename_test.go +++ b/client/keys/rename_test.go @@ -9,12 +9,12 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "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" ) func Test_runRenameCmd(t *testing.T) { @@ -32,7 +32,7 @@ func Test_runRenameCmd(t *testing.T) { path := sdk.GetConfig().GetFullBIP44Path() - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().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 701df6803665..7a180c1a10c5 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -18,6 +17,7 @@ import ( "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" ) func Test_multiSigKey_Properties(t *testing.T) { @@ -53,7 +53,7 @@ func Test_runShowCmd(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := clienttestutil.MakeTestCodec(t) + cdc := moduletestutil.MakeTestEncodingConfig().Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) diff --git a/client/testutil/util.go b/client/testutil/util.go deleted file mode 100644 index a26d11ad231e..000000000000 --- a/client/testutil/util.go +++ /dev/null @@ -1,32 +0,0 @@ -package testutil - -import ( - "testing" - - "github.com/stretchr/testify/require" - - runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" - appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" - "cosmossdk.io/core/appconfig" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/codec" - _ "github.com/cosmos/cosmos-sdk/runtime" // Register runtime module -) - -var TestConfig = appconfig.Compose(&appv1alpha1.Config{ - Modules: []*appv1alpha1.ModuleConfig{ - { - Name: "runtime", - Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "clientTest", - }), - }, - }, -}) - -func MakeTestCodec(t *testing.T) codec.Codec { - var cdc codec.Codec - err := depinject.Inject(TestConfig, &cdc) - require.NoError(t, err) - return cdc -} diff --git a/client/tx/aux_builder_test.go b/client/tx/aux_builder_test.go index 5f183c4a9d09..9a967192e50b 100644 --- a/client/tx/aux_builder_test.go +++ b/client/tx/aux_builder_test.go @@ -5,29 +5,23 @@ import ( "github.com/stretchr/testify/require" - _ "cosmossdk.io/api/cosmos/bank/v1beta1" - "cosmossdk.io/depinject" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" typestx "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/bank" ) func TestAuxTxBuilder(t *testing.T) { - var ( - reg codectypes.InterfaceRegistry - cdc codec.Codec - ) - err := depinject.Inject(clienttestutil.TestConfig, ®, &cdc) bankModule := bank.AppModuleBasic{} + cdc := moduletestutil.MakeTestEncodingConfig(bankModule).Codec + reg := codectypes.NewInterfaceRegistry() - require.NoError(t, err) testdata.RegisterInterfaces(reg) // required for test case: "GetAuxSignerData works for DIRECT_AUX" bankModule.RegisterInterfaces(reg) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 25bc03a28470..788b96c2f2f3 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -6,13 +6,11 @@ import ( "strings" "testing" - "cosmossdk.io/depinject" sdkmath "cosmossdk.io/math" "github.com/stretchr/testify/require" "google.golang.org/grpc" "github.com/cosmos/cosmos-sdk/client" - clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -21,6 +19,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" txtypes "github.com/cosmos/cosmos-sdk/types/tx" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" ante "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -30,13 +29,8 @@ import ( ) func newTestTxConfig(t *testing.T) (client.TxConfig, codec.Codec) { - var ( - pcdc codec.ProtoCodecMarshaler - cdc codec.Codec - ) - err := depinject.Inject(clienttestutil.TestConfig, &pcdc, &cdc) - require.NoError(t, err) - return authtx.NewTxConfig(pcdc, authtx.DefaultSignModes), cdc + encodingConfig := moduletestutil.MakeTestEncodingConfig() + return authtx.NewTxConfig(codec.NewProtoCodec(encodingConfig.InterfaceRegistry), authtx.DefaultSignModes), encodingConfig.Codec } // mockContext is a mock client.Context to return abitrary simulation response, used to diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index b54085c584e7..cbb51dc68565 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -21,7 +21,7 @@ type TestEncodingConfig struct { } func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig { - cdc := codec.NewLegacyAmino() + aminoCodec := codec.NewLegacyAmino() interfaceRegistry := types.NewInterfaceRegistry() codec := codec.NewProtoCodec(interfaceRegistry) @@ -29,7 +29,7 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig InterfaceRegistry: interfaceRegistry, Codec: codec, TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes), - Amino: cdc, + Amino: aminoCodec, } mb := module.NewBasicManager(modules...) diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index 99931a3a99d0..f1e1e6443c70 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -4,15 +4,14 @@ import ( "encoding/json" "testing" - "cosmossdk.io/depinject" proto "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/testutil" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -54,8 +53,8 @@ func TestValidateGenesisDuplicateAccounts(t *testing.T) { } func TestGenesisAccountIterator(t *testing.T) { - var cdc codec.Codec - depinject.Inject(testutil.AppConfig, &cdc) + encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) + cdc := encodingConfig.Codec acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) acc2 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) diff --git a/x/authz/migrations/v2/store_test.go b/x/authz/migrations/v2/store_test.go index 4442b1985d1c..fd2a266fb3db 100644 --- a/x/authz/migrations/v2/store_test.go +++ b/x/authz/migrations/v2/store_test.go @@ -4,25 +4,25 @@ import ( "testing" "time" - "cosmossdk.io/depinject" storetypes "cosmossdk.io/store/types" "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "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/authz" v2 "github.com/cosmos/cosmos-sdk/x/authz/migrations/v2" - authztestutil "github.com/cosmos/cosmos-sdk/x/authz/testutil" + authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) func TestMigration(t *testing.T) { - var cdc codec.Codec - depinject.Inject(authztestutil.AppConfig, &cdc) + encodingConfig := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}, bank.AppModuleBasic{}) + cdc := encodingConfig.Codec authzKey := storetypes.NewKVStoreKey("authz") ctx := testutil.DefaultContext(authzKey, storetypes.NewTransientStoreKey("transient_test")) diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index 6667f169333f..9d599213a436 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -6,14 +6,13 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" 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/distribution" "github.com/cosmos/cosmos-sdk/x/distribution/simulation" - "github.com/cosmos/cosmos-sdk/x/distribution/testutil" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -25,9 +24,8 @@ var ( ) func TestDecodeDistributionStore(t *testing.T) { - var cdc codec.Codec - err := depinject.Inject(testutil.AppConfig, &cdc) - require.NoError(t, err) + encodingConfig := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) diff --git a/x/evidence/simulation/decoder_test.go b/x/evidence/simulation/decoder_test.go index 709cc99d7da9..c9dddff69c5f 100644 --- a/x/evidence/simulation/decoder_test.go +++ b/x/evidence/simulation/decoder_test.go @@ -19,7 +19,6 @@ import ( func TestDecodeStore(t *testing.T) { var evidenceKeeper keeper.Keeper - err := depinject.Inject(testutil.AppConfig, &evidenceKeeper) require.NoError(t, err) diff --git a/x/group/proposal_test.go b/x/group/proposal_test.go index 9162a70815eb..b84804788042 100644 --- a/x/group/proposal_test.go +++ b/x/group/proposal_test.go @@ -5,10 +5,9 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/codec" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/group" - "github.com/cosmos/cosmos-sdk/x/group/testutil" + "github.com/cosmos/cosmos-sdk/x/group/module" ) // TestGogoUnmarshalProposal tests some weird behavior in gogoproto @@ -16,9 +15,8 @@ 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) { - var cdc codec.Codec - err := depinject.Inject(testutil.AppConfig, &cdc) - require.NoError(t, err) + encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + cdc := encodingConfig.Codec p1 := group.Proposal{Proposers: []string{"foo"}} p2 := group.Proposal{Proposers: []string{"bar"}} diff --git a/x/group/simulation/decoder_test.go b/x/group/simulation/decoder_test.go index 74106303f6ba..12c9bb305570 100644 --- a/x/group/simulation/decoder_test.go +++ b/x/group/simulation/decoder_test.go @@ -6,21 +6,19 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/kv" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/group" "github.com/cosmos/cosmos-sdk/x/group/internal/orm" "github.com/cosmos/cosmos-sdk/x/group/keeper" + "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/group/simulation" - grouptestutil "github.com/cosmos/cosmos-sdk/x/group/testutil" ) func TestDecodeStore(t *testing.T) { - var cdc codec.Codec - err := depinject.Inject(grouptestutil.AppConfig, &cdc) - require.NoError(t, err) + encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) g := group.GroupInfo{Id: 1} diff --git a/x/group/simulation/genesis_test.go b/x/group/simulation/genesis_test.go index db09434920ac..58cc6c09b5b3 100644 --- a/x/group/simulation/genesis_test.go +++ b/x/group/simulation/genesis_test.go @@ -7,20 +7,19 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" sdkmath "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/group" + groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/group/simulation" - "github.com/cosmos/cosmos-sdk/x/group/testutil" ) func TestRandomizedGenState(t *testing.T) { - var cdc codec.Codec - err := depinject.Inject(testutil.AppConfig, &cdc) - require.NoError(t, err) + encodingConfig := moduletestutil.MakeTestEncodingConfig(groupmodule.AppModuleBasic{}, bank.AppModuleBasic{}) + cdc := encodingConfig.Codec 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 cebd3b142b7f..7f5e0fbd9e9c 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -1,21 +1,19 @@ package keeper_test import ( - "cosmossdk.io/depinject" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdktestutil "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/params" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - "github.com/cosmos/cosmos-sdk/x/params/testutil" ) func testComponents() (*codec.LegacyAmino, sdk.Context, storetypes.StoreKey, storetypes.StoreKey, paramskeeper.Keeper) { - var cdc codec.Codec - if err := depinject.Inject(testutil.AppConfig, &cdc); err != nil { - panic(err) - } + encodingConfig := moduletestutil.MakeTestEncodingConfig(params.AppModuleBasic{}) + cdc := encodingConfig.Codec legacyAmino := createTestCodec() mkey := storetypes.NewKVStoreKey("test") diff --git a/x/params/testutil/app_config.go b/x/params/testutil/app_config.go deleted file mode 100644 index 415c01e0553f..000000000000 --- a/x/params/testutil/app_config.go +++ /dev/null @@ -1,23 +0,0 @@ -package testutil - -import ( - "github.com/cosmos/cosmos-sdk/testutil/configurator" - - _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring -) - -var AppConfig = configurator.NewAppConfig( - configurator.AuthModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.ParamsModule(), - configurator.GenutilModule(), -) diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index 28fe1897ceea..ac2b4951f456 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -11,14 +11,14 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/suite" - "cosmossdk.io/depinject" "cosmossdk.io/store" "cosmossdk.io/store/metrics" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params/testutil" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + paramsmodule "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -39,11 +39,9 @@ func (suite *SubspaceTestSuite) SetupTest() { ms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) - err := depinject.Inject(testutil.AppConfig, - &suite.cdc, - &suite.amino, - ) - suite.NoError(err) + encodingConfig := moduletestutil.MakeTestEncodingConfig(paramsmodule.AppModuleBasic{}) + suite.cdc = encodingConfig.Codec + suite.amino = encodingConfig.Amino ss := types.NewSubspace(suite.cdc, suite.amino, key, tkey, "testsubspace") suite.ctx = sdk.NewContext(ms, cmtproto.Header{}, false, log.NewNopLogger()) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 4d99fa16af30..974defe4a258 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -8,13 +8,12 @@ import ( gogotypes "github.com/cosmos/gogoproto/types" "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" 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/slashing" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/testutil" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -26,8 +25,8 @@ var ( ) func TestDecodeStore(t *testing.T) { - var cdc codec.Codec - depinject.Inject(testutil.AppConfig, &cdc) + encodingConfig := moduletestutil.MakeTestEncodingConfig(slashing.AppModuleBasic{}) + cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) diff --git a/x/slashing/simulation/genesis_test.go b/x/slashing/simulation/genesis_test.go index 6cf18bb751b8..55bce42a84a6 100644 --- a/x/slashing/simulation/genesis_test.go +++ b/x/slashing/simulation/genesis_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -16,15 +15,13 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/testutil" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. // Abonormal scenarios are not tested here. func TestRandomizedGenState(t *testing.T) { - var interfaceRegistry codectypes.InterfaceRegistry - depinject.Inject(testutil.AppConfig, &interfaceRegistry) + interfaceRegistry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) s := rand.NewSource(1) @@ -60,8 +57,7 @@ func TestRandomizedGenState(t *testing.T) { // TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. func TestRandomizedGenState1(t *testing.T) { - var interfaceRegistry codectypes.InterfaceRegistry - depinject.Inject(testutil.AppConfig, &interfaceRegistry) + interfaceRegistry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) s := rand.NewSource(1) From 94e902a80547bf93651c2b51bfe373a095778bb6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 23 Mar 2023 15:33:57 +0100 Subject: [PATCH 2/4] updates --- .../bank/keeper/deterministic_test.go | 4 +- .../distribution/keeper/allocation_test.go | 4 +- x/auth/client/cli/encode_test.go | 53 ++++++------------- x/auth/client/tx_test.go | 43 ++++++--------- x/auth/tx/aux_test.go | 17 ++---- x/auth/types/account_test.go | 2 +- x/feegrant/migrations/v2/store_test.go | 14 +++-- x/feegrant/simulation/decoder_test.go | 9 ++-- x/feegrant/simulation/operations_test.go | 23 +++++++- x/feegrant/testutil/app_config.go | 28 ---------- 10 files changed, 72 insertions(+), 125 deletions(-) delete mode 100644 x/feegrant/testutil/app_config.go diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 1f419eeaba22..394727f776d6 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/configurator" - "github.com/cosmos/cosmos-sdk/testutil/sims" + simstestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -61,7 +61,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { var interfaceRegistry codectypes.InterfaceRegistry - app, err := sims.Setup( + app, err := simstestutil.Setup( configurator.NewAppConfig( configurator.AuthModule(), configurator.TxModule(), diff --git a/tests/integration/distribution/keeper/allocation_test.go b/tests/integration/distribution/keeper/allocation_test.go index f683225213d4..7ad05a0ffd6e 100644 --- a/tests/integration/distribution/keeper/allocation_test.go +++ b/tests/integration/distribution/keeper/allocation_test.go @@ -201,7 +201,7 @@ func TestAllocateTokensTruncation(t *testing.T) { Address: valConsPk1.Address(), Power: 10, } - abciValС := abci.Validator{ + abciValC := abci.Validator{ Address: valConsPk2.Address(), Power: 10, } @@ -236,7 +236,7 @@ func TestAllocateTokensTruncation(t *testing.T) { SignedLastBlock: true, }, { - Validator: abciValС, + Validator: abciValC, SignedLastBlock: true, }, } diff --git a/x/auth/client/cli/encode_test.go b/x/auth/client/cli/encode_test.go index 219491b2fce6..9eed60caaaa3 100644 --- a/x/auth/client/cli/encode_test.go +++ b/x/auth/client/cli/encode_test.go @@ -7,39 +7,28 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "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/auth" "github.com/cosmos/cosmos-sdk/x/auth/client/cli" - authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil" ) func TestGetCommandEncode(t *testing.T) { - var ( - txCfg client.TxConfig - legacyAmino *codec.LegacyAmino - codec codec.Codec - ) - - err := depinject.Inject( - authtestutil.AppConfig, - &txCfg, - &legacyAmino, - &codec, - ) - require.NoError(t, err) + encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) + txConfig := encodingConfig.TxConfig + cdc := encodingConfig.Codec cmd := cli.GetEncodeCommand() _ = testutil.ApplyMockIODiscardOutErr(cmd) // Build a test transaction - builder := txCfg.NewTxBuilder() + builder := txConfig.NewTxBuilder() builder.SetGasLimit(50000) builder.SetFeeAmount(sdk.Coins{sdk.NewInt64Coin("atom", 150)}) builder.SetMemo("foomemo") - jsonEncoded, err := txCfg.TxJSONEncoder()(builder.GetTx()) + jsonEncoded, err := txConfig.TxJSONEncoder()(builder.GetTx()) require.NoError(t, err) txFile := testutil.WriteToNewTempFile(t, string(jsonEncoded)) @@ -47,8 +36,8 @@ func TestGetCommandEncode(t *testing.T) { ctx := context.Background() clientCtx := client.Context{}. - WithTxConfig(txCfg). - WithCodec(codec) + WithTxConfig(txConfig). + WithCodec(cdc) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd.SetArgs([]string{txFileName}) @@ -57,31 +46,21 @@ func TestGetCommandEncode(t *testing.T) { } func TestGetCommandDecode(t *testing.T) { - var ( - txCfg client.TxConfig - legacyAmino *codec.LegacyAmino - codec codec.Codec - ) - - err := depinject.Inject( - authtestutil.AppConfig, - &txCfg, - &legacyAmino, - &codec, - ) - require.NoError(t, err) + encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) + txConfig := encodingConfig.TxConfig + cdc := encodingConfig.Codec clientCtx := client.Context{}. - WithTxConfig(txCfg). - WithCodec(codec) + WithTxConfig(txConfig). + WithCodec(cdc) cmd := cli.GetDecodeCommand() _ = testutil.ApplyMockIODiscardOutErr(cmd) - clientCtx = clientCtx.WithTxConfig(txCfg) + clientCtx = clientCtx.WithTxConfig(txConfig) // Build a test transaction - builder := txCfg.NewTxBuilder() + builder := txConfig.NewTxBuilder() builder.SetGasLimit(50000) builder.SetFeeAmount(sdk.Coins{sdk.NewInt64Coin("atom", 150)}) builder.SetMemo("foomemo") diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 1690635ae6df..ae88666db473 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -7,15 +7,13 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "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/auth" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil" ) func TestParseQueryResponse(t *testing.T) { @@ -38,39 +36,33 @@ func TestParseQueryResponse(t *testing.T) { func TestReadTxFromFile(t *testing.T) { t.Parallel() - var ( - txCfg client.TxConfig - interfaceRegistry codectypes.InterfaceRegistry - ) - err := depinject.Inject( - authtestutil.AppConfig, - &interfaceRegistry, - &txCfg, - ) - require.NoError(t, err) + + encodingConfig := moduletestutil.MakeTestEncodingConfig() + interfaceRegistry := encodingConfig.InterfaceRegistry + txConfig := encodingConfig.TxConfig clientCtx := client.Context{} clientCtx = clientCtx.WithInterfaceRegistry(interfaceRegistry) - clientCtx = clientCtx.WithTxConfig(txCfg) + clientCtx = clientCtx.WithTxConfig(txConfig) feeAmount := sdk.Coins{sdk.NewInt64Coin("atom", 150)} gasLimit := uint64(50000) memo := "foomemo" - txBuilder := txCfg.NewTxBuilder() + txBuilder := txConfig.NewTxBuilder() txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) txBuilder.SetMemo(memo) // Write it to the file - encodedTx, err := txCfg.TxJSONEncoder()(txBuilder.GetTx()) + encodedTx, err := txConfig.TxJSONEncoder()(txBuilder.GetTx()) require.NoError(t, err) jsonTxFile := testutil.WriteToNewTempFile(t, string(encodedTx)) // Read it back decodedTx, err := authclient.ReadTxFromFile(clientCtx, jsonTxFile.Name()) require.NoError(t, err) - txBldr, err := txCfg.WrapTxBuilder(decodedTx) + txBldr, err := txConfig.WrapTxBuilder(decodedTx) require.NoError(t, err) t.Log(txBuilder.GetTx()) t.Log(txBldr.GetTx()) @@ -80,22 +72,19 @@ func TestReadTxFromFile(t *testing.T) { func TestBatchScanner_Scan(t *testing.T) { t.Parallel() - var txGen client.TxConfig - err := depinject.Inject( - authtestutil.AppConfig, - &txGen, - ) - require.NoError(t, err) + + encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) + txConfig := encodingConfig.TxConfig clientCtx := client.Context{} - clientCtx = clientCtx.WithTxConfig(txGen) + clientCtx = clientCtx.WithTxConfig(txConfig) // generate some tx JSON - bldr := txGen.NewTxBuilder() + bldr := txConfig.NewTxBuilder() bldr.SetGasLimit(50000) bldr.SetFeeAmount(sdk.NewCoins(sdk.NewInt64Coin("atom", 150))) bldr.SetMemo("foomemo") - txJSON, err := txGen.TxJSONEncoder()(bldr.GetTx()) + txJSON, err := txConfig.TxJSONEncoder()(bldr.GetTx()) require.NoError(t, err) // use the tx JSON to generate some tx batches (it doesn't matter that we use the same JSON because we don't care about the actual context) diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 0f813917f1ea..97416a9df891 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -5,16 +5,14 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/client" clienttx "github.com/cosmos/cosmos-sdk/client/tx" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" txtypes "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/cosmos/cosmos-sdk/x/auth/testutil" ) var ( @@ -38,16 +36,9 @@ var ( // Then it tests integrating the 2 AuxSignerData into a // client.TxBuilder created by the fee payer. func TestBuilderWithAux(t *testing.T) { - var ( - interfaceRegistry codectypes.InterfaceRegistry - txConfig client.TxConfig - ) - - err := depinject.Inject(testutil.AppConfig, - &interfaceRegistry, - &txConfig, - ) - require.NoError(t, err) + encodingConfig := moduletestutil.MakeTestEncodingConfig() + interfaceRegistry := encodingConfig.InterfaceRegistry + txConfig := encodingConfig.TxConfig testdata.RegisterInterfaces(interfaceRegistry) diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index da21c8e62c2c..e6d3c5c468cf 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -67,9 +67,9 @@ func TestBaseSequence(t *testing.T) { func TestBaseAccountMarshal(t *testing.T) { var accountKeeper authkeeper.AccountKeeper - err := depinject.Inject(testutil.AppConfig, &accountKeeper) require.NoError(t, err) + _, pub, addr := testdata.KeyTestPubAddr() acc := types.NewBaseAccountWithAddress(addr) seq := uint64(7) diff --git a/x/feegrant/migrations/v2/store_test.go b/x/feegrant/migrations/v2/store_test.go index d73616db7735..c762a45750b4 100644 --- a/x/feegrant/migrations/v2/store_test.go +++ b/x/feegrant/migrations/v2/store_test.go @@ -4,23 +4,21 @@ import ( "testing" "time" - "cosmossdk.io/depinject" + "github.com/stretchr/testify/require" + storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/feegrant" v2 "cosmossdk.io/x/feegrant/migrations/v2" - feegranttestutil "cosmossdk.io/x/feegrant/testutil" - - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/x/feegrant/module" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/stretchr/testify/require" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestMigration(t *testing.T) { - var cdc codec.Codec - depinject.Inject(feegranttestutil.AppConfig, &cdc) + encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + cdc := encodingConfig.Codec feegrantKey := storetypes.NewKVStoreKey(v2.ModuleName) ctx := testutil.DefaultContext(feegrantKey, storetypes.NewTransientStoreKey("transient_test")) diff --git a/x/feegrant/simulation/decoder_test.go b/x/feegrant/simulation/decoder_test.go index cef4549079b1..621f85939f24 100644 --- a/x/feegrant/simulation/decoder_test.go +++ b/x/feegrant/simulation/decoder_test.go @@ -6,14 +6,13 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/depinject" "cosmossdk.io/x/feegrant" + "cosmossdk.io/x/feegrant/module" "cosmossdk.io/x/feegrant/simulation" - feegranttestutil "cosmossdk.io/x/feegrant/testutil" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) var ( @@ -23,8 +22,8 @@ var ( ) func TestDecodeStore(t *testing.T) { - var cdc codec.Codec - depinject.Inject(feegranttestutil.AppConfig, &cdc) + encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) grant, err := feegrant.NewGrant(granterAddr, granteeAddr, &feegrant.BasicAllowance{ diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 354b1bd80a0d..0954d171f61d 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -5,15 +5,25 @@ import ( "testing" "time" + _ "cosmossdk.io/x/feegrant/module" + _ "github.com/cosmos/cosmos-sdk/x/auth" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" + _ "github.com/cosmos/cosmos-sdk/x/bank" + _ "github.com/cosmos/cosmos-sdk/x/consensus" + _ "github.com/cosmos/cosmos-sdk/x/genutil" + _ "github.com/cosmos/cosmos-sdk/x/mint" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/keeper" "cosmossdk.io/x/feegrant/simulation" - "cosmossdk.io/x/feegrant/testutil" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/configurator" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -38,7 +48,16 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { var err error - suite.app, err = simtestutil.Setup(testutil.AppConfig, + suite.app, err = simtestutil.Setup(configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.ParamsModule(), + configurator.GenutilModule(), + configurator.FeegrantModule(), + ), &suite.feegrantKeeper, &suite.bankKeeper, &suite.accountKeeper, diff --git a/x/feegrant/testutil/app_config.go b/x/feegrant/testutil/app_config.go deleted file mode 100644 index 8896a0f71516..000000000000 --- a/x/feegrant/testutil/app_config.go +++ /dev/null @@ -1,28 +0,0 @@ -package testutil - -import ( - "github.com/cosmos/cosmos-sdk/testutil/configurator" - - _ "cosmossdk.io/x/feegrant/module" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/mint" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring -) - -var AppConfig = configurator.NewAppConfig( - configurator.AuthModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.ParamsModule(), - configurator.GenutilModule(), - configurator.FeegrantModule(), - configurator.VestingModule(), -) From 6c9ea087cdb8c19b9a96bf1ecc90770ad0ca5567 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 23 Mar 2023 15:43:15 +0100 Subject: [PATCH 3/4] fix --- x/distribution/simulation/operations_test.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 2fc4d738d318..d416a27b817d 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil/configurator" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -21,6 +20,7 @@ import ( banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/distribution/keeper" "github.com/cosmos/cosmos-sdk/x/distribution/simulation" + distrtestutil "github.com/cosmos/cosmos-sdk/x/distribution/testutil" "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -234,15 +234,7 @@ func (suite *SimTestSuite) SetupTest() { appBuilder *runtime.AppBuilder err error ) - suite.app, err = simtestutil.Setup(configurator.NewAppConfig( - configurator.AuthModule(), - configurator.ParamsModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.DistributionModule(), - ), &suite.accountKeeper, + suite.app, err = simtestutil.Setup(distrtestutil.AppConfig, &suite.accountKeeper, &suite.bankKeeper, &suite.cdc, &appBuilder, From c14e43d5f8d4a74aa176bc72bfe0b81a9fba36e1 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 23 Mar 2023 16:40:16 +0100 Subject: [PATCH 4/4] updates --- tests/e2e/params/app_config.go | 23 +++++++++++++++++++++++ tests/e2e/params/suite.go | 3 +-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/params/app_config.go diff --git a/tests/e2e/params/app_config.go b/tests/e2e/params/app_config.go new file mode 100644 index 000000000000..415c01e0553f --- /dev/null +++ b/tests/e2e/params/app_config.go @@ -0,0 +1,23 @@ +package testutil + +import ( + "github.com/cosmos/cosmos-sdk/testutil/configurator" + + _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring +) + +var AppConfig = configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.ParamsModule(), + configurator.GenutilModule(), +) diff --git a/tests/e2e/params/suite.go b/tests/e2e/params/suite.go index 0d4c05df0fb4..0d4e852ebd14 100644 --- a/tests/e2e/params/suite.go +++ b/tests/e2e/params/suite.go @@ -20,7 +20,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/client/cli" "github.com/cosmos/cosmos-sdk/x/params/keeper" - "github.com/cosmos/cosmos-sdk/x/params/testutil" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -58,7 +57,7 @@ func (s *E2ETestSuite) SetupSuite() { appBuilder *runtime.AppBuilder paramsKeeper keeper.Keeper ) - if err := depinject.Inject(testutil.AppConfig, &appBuilder, ¶msKeeper); err != nil { + if err := depinject.Inject(AppConfig, &appBuilder, ¶msKeeper); err != nil { panic(err) }