From 95361579e766015db1a5632dca6e987875e5938d Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Fri, 12 Jul 2024 21:28:27 +0530 Subject: [PATCH 01/13] feat(codec): introducing test codec Signed-off-by: Deepanshu Tripathi --- helpers/base/codec.go | 6 ++++++ .../auxiliaries/conform/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/define/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/member/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/authenticate/auxiliary_keeper_test.go | 11 +++++------ .../auxiliaries/authorize/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/deputize/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/maintain/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/revoke/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/super/auxiliary_keeper_test.go | 6 ++---- x/metas/auxiliaries/scrub/auxiliary_keeper_test.go | 6 ++---- x/orders/block/block_test.go | 6 ++---- x/splits/auxiliaries/purge/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/renumerate/auxiliary_keeper_test.go | 6 ++---- .../auxiliaries/transfer/auxiliary_keeper_test.go | 9 ++++----- 15 files changed, 39 insertions(+), 59 deletions(-) diff --git a/helpers/base/codec.go b/helpers/base/codec.go index 0067d1847..5c9feed42 100644 --- a/helpers/base/codec.go +++ b/helpers/base/codec.go @@ -50,3 +50,9 @@ func CodecPrototype() helpers.Codec { codec.legacyAmino = sdkCodec.NewLegacyAmino() return codec } + +// TestCodec +// Deprecated: Only for testing. Use CodecPrototype instead. +func TestCodec() helpers.Codec { + return CodecPrototype().Initialize(NewModuleManager(auth.AppModule{})) +} diff --git a/x/classifications/auxiliaries/conform/auxiliary_keeper_test.go b/x/classifications/auxiliaries/conform/auxiliary_keeper_test.go index e1b8164a1..1816c16bb 100644 --- a/x/classifications/auxiliaries/conform/auxiliary_keeper_test.go +++ b/x/classifications/auxiliaries/conform/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -43,10 +42,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/classifications/auxiliaries/define/auxiliary_keeper_test.go b/x/classifications/auxiliaries/define/auxiliary_keeper_test.go index 86cd1d7d5..dc5001d0f 100644 --- a/x/classifications/auxiliaries/define/auxiliary_keeper_test.go +++ b/x/classifications/auxiliaries/define/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -42,10 +41,9 @@ func createTestInput(t *testing.T) (context.Context, TestKeepers, helpers.Mapper paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/classifications/auxiliaries/member/auxiliary_keeper_test.go b/x/classifications/auxiliaries/member/auxiliary_keeper_test.go index 33d8712a8..ca1808288 100644 --- a/x/classifications/auxiliaries/member/auxiliary_keeper_test.go +++ b/x/classifications/auxiliaries/member/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -43,10 +42,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go b/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go index 33a4a701e..d1c194584 100644 --- a/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go +++ b/x/identities/auxiliaries/authenticate/auxiliary_keeper_test.go @@ -5,10 +5,8 @@ package authenticate import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/AssetMantle/modules/helpers" + baseHelpers "github.com/AssetMantle/modules/helpers/base" errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/identities/constants" @@ -24,6 +22,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -80,11 +79,11 @@ var ( testIdentity = base.PrototypeNameIdentity().ProvisionAddress(provisionedAddress) testIdentityID = testIdentity.(documents.NameIdentity).GetNameIdentityID() + codec = baseHelpers.TestCodec() + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) - ParamsKeeper = paramsKeeper.NewKeeper(encodingConfig.Codec, encodingConfig.Amino, paramsStoreKey, paramsTransientStoreKeys) - - encodingConfig = testutil.MakeTestEncodingConfig() + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())) diff --git a/x/maintainers/auxiliaries/authorize/auxiliary_keeper_test.go b/x/maintainers/auxiliaries/authorize/auxiliary_keeper_test.go index 1751c65c4..7ed8f3132 100644 --- a/x/maintainers/auxiliaries/authorize/auxiliary_keeper_test.go +++ b/x/maintainers/auxiliaries/authorize/auxiliary_keeper_test.go @@ -6,7 +6,6 @@ package authorize import ( "context" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -101,10 +100,9 @@ func Test_auxiliaryKeeper_Initialize(t *testing.T) { paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/maintainers/auxiliaries/deputize/auxiliary_keeper_test.go b/x/maintainers/auxiliaries/deputize/auxiliary_keeper_test.go index cf185d727..be591425e 100644 --- a/x/maintainers/auxiliaries/deputize/auxiliary_keeper_test.go +++ b/x/maintainers/auxiliaries/deputize/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -56,10 +55,9 @@ func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/maintainers/auxiliaries/maintain/auxiliary_keeper_test.go b/x/maintainers/auxiliaries/maintain/auxiliary_keeper_test.go index 0e0feb551..eca4c5524 100644 --- a/x/maintainers/auxiliaries/maintain/auxiliary_keeper_test.go +++ b/x/maintainers/auxiliaries/maintain/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -53,10 +52,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/maintainers/auxiliaries/revoke/auxiliary_keeper_test.go b/x/maintainers/auxiliaries/revoke/auxiliary_keeper_test.go index 8e7a007e4..70e97ec5d 100644 --- a/x/maintainers/auxiliaries/revoke/auxiliary_keeper_test.go +++ b/x/maintainers/auxiliaries/revoke/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -54,10 +53,9 @@ func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/maintainers/auxiliaries/super/auxiliary_keeper_test.go b/x/maintainers/auxiliaries/super/auxiliary_keeper_test.go index a92740a13..7f6b5de81 100644 --- a/x/maintainers/auxiliaries/super/auxiliary_keeper_test.go +++ b/x/maintainers/auxiliaries/super/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -48,10 +47,9 @@ func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/metas/auxiliaries/scrub/auxiliary_keeper_test.go b/x/metas/auxiliaries/scrub/auxiliary_keeper_test.go index a33fb04cb..257ca0771 100644 --- a/x/metas/auxiliaries/scrub/auxiliary_keeper_test.go +++ b/x/metas/auxiliaries/scrub/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "github.com/cosmos/cosmos-sdk/store" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -35,10 +34,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers) { paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/block/block_test.go b/x/orders/block/block_test.go index 7ff86a993..622cbcb3a 100644 --- a/x/orders/block/block_test.go +++ b/x/orders/block/block_test.go @@ -5,7 +5,6 @@ package block import ( storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "testing" tendermintDB "github.com/cometbft/cometbft-db" @@ -42,10 +41,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, helpers.Mapper, helpers.Au require.Nil(t, err) Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/splits/auxiliaries/purge/auxiliary_keeper_test.go b/x/splits/auxiliaries/purge/auxiliary_keeper_test.go index 3efcb70d9..1d0bebb66 100644 --- a/x/splits/auxiliaries/purge/auxiliary_keeper_test.go +++ b/x/splits/auxiliaries/purge/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -44,10 +43,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/splits/auxiliaries/renumerate/auxiliary_keeper_test.go b/x/splits/auxiliaries/renumerate/auxiliary_keeper_test.go index 2f44fb606..fd41bc69e 100644 --- a/x/splits/auxiliaries/renumerate/auxiliary_keeper_test.go +++ b/x/splits/auxiliaries/renumerate/auxiliary_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -44,10 +43,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go b/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go index b62faa823..7d28409be 100644 --- a/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go +++ b/x/splits/auxiliaries/transfer/auxiliary_keeper_test.go @@ -5,10 +5,8 @@ package transfer import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/AssetMantle/modules/helpers" + baseHelpers "github.com/AssetMantle/modules/helpers/base" errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/splits/constants" @@ -31,6 +29,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -101,11 +100,11 @@ var ( uninitializedCoinAsset = base.NewCoinAsset("uninitialized") uninitializedCoinAssetID = uninitializedCoinAsset.GetCoinAssetID() - encodingConfig = testutil.MakeTestEncodingConfig() + codec = baseHelpers.TestCodec() paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) - ParamsKeeper = paramsKeeper.NewKeeper(encodingConfig.Codec, encodingConfig.Amino, paramsStoreKey, paramsTransientStoreKeys) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) AuxiliaryKeeper = auxiliaryKeeper{mapper.Prototype().Initialize(moduleStoreKey), parameterManager} From d947af293a052670b11bfbc3e5dd5593ec4d4729 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:16:48 +0530 Subject: [PATCH 02/13] feat(helpers): defining basic module interface Signed-off-by: Deepanshu Tripathi --- helpers/basic_module.go | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 helpers/basic_module.go diff --git a/helpers/basic_module.go b/helpers/basic_module.go new file mode 100644 index 000000000..238a8d605 --- /dev/null +++ b/helpers/basic_module.go @@ -0,0 +1,9 @@ +package helpers + +import ( + "github.com/cosmos/cosmos-sdk/types/module" +) + +type BasicModule interface { + module.AppModule +} From b6e14c16175823f8d993a1ac14770dcba97e0ad9 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:21:28 +0530 Subject: [PATCH 03/13] feat(helpers): defining module manager interface Signed-off-by: Deepanshu Tripathi --- helpers/module_manager.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 helpers/module_manager.go diff --git a/helpers/module_manager.go b/helpers/module_manager.go new file mode 100644 index 000000000..b1a74e51b --- /dev/null +++ b/helpers/module_manager.go @@ -0,0 +1,39 @@ +package helpers + +import ( + "encoding/json" + abciTypes "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + sdkCodecTypes "github.com/cosmos/cosmos-sdk/codec/types" + sdkTypes "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" +) + +type ModuleManager interface { + GetVersionMap() module.VersionMap + GetBasicManager() module.BasicManager + + AddTxCommands(*cobra.Command) + AddQueryCommands(*cobra.Command) + + InitGenesis(sdkTypes.Context, codec.JSONCodec, map[string]json.RawMessage) abciTypes.ResponseInitChain + ExportGenesisForModules(sdkTypes.Context, codec.JSONCodec, []string) map[string]json.RawMessage + + RegisterServices(module.Configurator) + RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) + RegisterInvariants(sdkTypes.InvariantRegistry) + RegisterInterfaces(sdkCodecTypes.InterfaceRegistry) + RegisterLegacyAminoCodec(*codec.LegacyAmino) + + SetOrderBeginBlockers(...string) + SetOrderEndBlockers(...string) + SetOrderInitGenesis(...string) + + BeginBlock(sdkTypes.Context, abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock + EndBlock(sdkTypes.Context, abciTypes.RequestEndBlock) abciTypes.ResponseEndBlock + + RunMigrations(sdkTypes.Context, module.Configurator, module.VersionMap) (module.VersionMap, error) +} From 8ea186fcb228128763c0e8cd9035143e15da5d53 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:22:34 +0530 Subject: [PATCH 04/13] refactor: import sdkCodec import alias Signed-off-by: Deepanshu Tripathi --- x/assets/transactions/send/transaction_request_test.go | 6 +++--- x/assets/transactions/unwrap/transaction_request_test.go | 6 +++--- x/assets/transactions/wrap/transaction_request_test.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/assets/transactions/send/transaction_request_test.go b/x/assets/transactions/send/transaction_request_test.go index 0a0f3d460..a13ed9b9f 100644 --- a/x/assets/transactions/send/transaction_request_test.go +++ b/x/assets/transactions/send/transaction_request_test.go @@ -12,7 +12,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -238,14 +238,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { Value string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), assetID.AsString(), testRate.String()}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), assetID.AsString(), testRate.String()}, args{codec.GetLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/unwrap/transaction_request_test.go b/x/assets/transactions/unwrap/transaction_request_test.go index 3efb096d6..968d221fb 100644 --- a/x/assets/transactions/unwrap/transaction_request_test.go +++ b/x/assets/transactions/unwrap/transaction_request_test.go @@ -17,7 +17,7 @@ import ( baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -228,14 +228,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { Coins string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), coins.String()}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), coins.String()}, args{codec.GetLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/wrap/transaction_request_test.go b/x/assets/transactions/wrap/transaction_request_test.go index d7142d685..40fdedbf9 100644 --- a/x/assets/transactions/wrap/transaction_request_test.go +++ b/x/assets/transactions/wrap/transaction_request_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "github.com/AssetMantle/modules/utilities/rest" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "reflect" "testing" @@ -16,7 +17,6 @@ import ( baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -224,14 +224,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { Coins string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), coins.String()}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), coins.String()}, args{codec.GetLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 027c041210e01e272b2998b5738b383bb356ae83 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:23:17 +0530 Subject: [PATCH 05/13] refactor: import sdkCodec import alias Signed-off-by: Deepanshu Tripathi --- x/assets/transactions/wrap/transaction_request.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/assets/transactions/wrap/transaction_request.go b/x/assets/transactions/wrap/transaction_request.go index ecc69cd9b..921444d11 100644 --- a/x/assets/transactions/wrap/transaction_request.go +++ b/x/assets/transactions/wrap/transaction_request.go @@ -11,7 +11,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -84,7 +84,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { coins, ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { From 9d8bf840b0ce3b7b1fa748b46c88b4070e410c8a Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:25:24 +0530 Subject: [PATCH 06/13] refactor: introducing test codec Signed-off-by: Deepanshu Tripathi --- .../transactions/burn/transaction_keeper_test.go | 6 ++---- .../define/transaction_keeper_test.go | 6 ++---- .../deputize/transaction_keeper_test.go | 6 ++---- .../transactions/mint/transaction_keeper_test.go | 9 +++------ .../renumerate/transaction_keeper_test.go | 6 ++---- .../revoke/transaction_keeper_test.go | 9 +++------ .../transactions/send/transaction_keeper_test.go | 9 ++++----- .../unwrap/transaction_keeper_test.go | 10 +++++----- .../transactions/wrap/transaction_keeper_test.go | 15 +++++++-------- .../define/transaction_keeper_test.go | 9 +++------ .../deputize/transaction_keeper_test.go | 9 +++------ .../transactions/issue/transaction_keeper_test.go | 6 ++---- .../transactions/name/transaction_keeper_test.go | 9 +++------ .../provision/transaction_keeper_test.go | 6 ++---- .../transactions/quash/transaction_keeper_test.go | 6 ++---- .../revoke/transaction_keeper_test.go | 6 ++---- .../unprovision/transaction_keeper_test.go | 6 ++---- .../update/transaction_keeper_test.go | 6 ++---- .../reveal/transaction_keeper_test.go | 9 +++------ .../cancel/transaction_keeper_test.go | 6 ++---- .../define/transaction_keeper_test.go | 6 ++---- .../deputize/transaction_keeper_test.go | 6 ++---- .../transactions/get/transaction_keeper_test.go | 6 ++---- .../immediate/transaction_keeper_test.go | 6 ++---- .../transactions/make/transaction_keeper_test.go | 6 ++---- .../modify/transaction_keeper_test.go | 6 ++---- .../transactions/put/transaction_keeper_test.go | 6 ++---- .../revoke/transaction_keeper_test.go | 6 ++---- .../transactions/take/transaction_keeper_test.go | 6 ++---- 29 files changed, 74 insertions(+), 134 deletions(-) diff --git a/x/assets/transactions/burn/transaction_keeper_test.go b/x/assets/transactions/burn/transaction_keeper_test.go index 21554fa1f..9c6adaf8e 100644 --- a/x/assets/transactions/burn/transaction_keeper_test.go +++ b/x/assets/transactions/burn/transaction_keeper_test.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/AssetMantle/modules/x/assets/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -52,10 +51,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/assets/transactions/define/transaction_keeper_test.go b/x/assets/transactions/define/transaction_keeper_test.go index 4a7ee45f8..3630a4d4c 100644 --- a/x/assets/transactions/define/transaction_keeper_test.go +++ b/x/assets/transactions/define/transaction_keeper_test.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/AssetMantle/modules/x/assets/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -52,10 +51,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() PramsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/assets/transactions/deputize/transaction_keeper_test.go b/x/assets/transactions/deputize/transaction_keeper_test.go index 63f8eee44..202c608e7 100644 --- a/x/assets/transactions/deputize/transaction_keeper_test.go +++ b/x/assets/transactions/deputize/transaction_keeper_test.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/AssetMantle/modules/x/assets/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -50,10 +49,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/assets/transactions/mint/transaction_keeper_test.go b/x/assets/transactions/mint/transaction_keeper_test.go index fdac95592..54991a4ff 100644 --- a/x/assets/transactions/mint/transaction_keeper_test.go +++ b/x/assets/transactions/mint/transaction_keeper_test.go @@ -5,9 +5,6 @@ package mint import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" "github.com/AssetMantle/modules/x/assets/mapper" @@ -28,6 +25,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -54,10 +52,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/assets/transactions/renumerate/transaction_keeper_test.go b/x/assets/transactions/renumerate/transaction_keeper_test.go index e43343cd1..397f59d6c 100644 --- a/x/assets/transactions/renumerate/transaction_keeper_test.go +++ b/x/assets/transactions/renumerate/transaction_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -55,10 +54,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/assets/transactions/revoke/transaction_keeper_test.go b/x/assets/transactions/revoke/transaction_keeper_test.go index de7252cea..041b5ddcb 100644 --- a/x/assets/transactions/revoke/transaction_keeper_test.go +++ b/x/assets/transactions/revoke/transaction_keeper_test.go @@ -5,9 +5,6 @@ package revoke import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -26,6 +23,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -49,10 +47,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 7a3889625..718661e1c 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -5,10 +5,8 @@ package send import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/AssetMantle/modules/helpers" + baseHelpers "github.com/AssetMantle/modules/helpers/base" errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/assets/constants" @@ -35,6 +33,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -141,11 +140,11 @@ var ( transferAuxiliaryAuxiliary = new(MockAuxiliary) _ = transferAuxiliaryAuxiliary.On("GetKeeper").Return(transferAuxiliaryKeeper) - encodingConfig = testutil.MakeTestEncodingConfig() + codec = baseHelpers.TestCodec() paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) - ParamsKeeper = paramsKeeper.NewKeeper(encodingConfig.Codec, encodingConfig.Amino, paramsStoreKey, paramsTransientStoreKeys) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) setContext = func() sdkTypes.Context { memDB := tendermintDB.NewMemDB() diff --git a/x/assets/transactions/unwrap/transaction_keeper_test.go b/x/assets/transactions/unwrap/transaction_keeper_test.go index b4f77f6f2..fb4dce300 100644 --- a/x/assets/transactions/unwrap/transaction_keeper_test.go +++ b/x/assets/transactions/unwrap/transaction_keeper_test.go @@ -5,8 +5,8 @@ package unwrap import ( "context" + baseHelpers "github.com/AssetMantle/modules/helpers/base" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/AssetMantle/modules/helpers" @@ -102,19 +102,19 @@ var ( burnAuxiliary = new(MockAuxiliary) _ = burnAuxiliary.On("GetKeeper").Return(burnAuxiliaryKeeper) - encodingConfig = testutil.MakeTestEncodingConfig() + codec = baseHelpers.TestCodec() paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) - ParamsKeeper = paramsKeeper.NewKeeper(encodingConfig.Codec, encodingConfig.Amino, paramsStoreKey, paramsTransientStoreKeys) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} - AuthKeeper = authKeeper.NewAccountKeeper(encodingConfig.Codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} - BankKeeper = bankKeeper.NewBaseKeeper(encodingConfig.Codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) Context = setContext() diff --git a/x/assets/transactions/wrap/transaction_keeper_test.go b/x/assets/transactions/wrap/transaction_keeper_test.go index bdc95f6b6..7299ff76f 100644 --- a/x/assets/transactions/wrap/transaction_keeper_test.go +++ b/x/assets/transactions/wrap/transaction_keeper_test.go @@ -5,11 +5,8 @@ package wrap import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/AssetMantle/modules/helpers" + baseHelpers "github.com/AssetMantle/modules/helpers/base" errorConstants "github.com/AssetMantle/modules/helpers/constants" "github.com/AssetMantle/modules/utilities/random" "github.com/AssetMantle/modules/x/assets/constants" @@ -30,12 +27,14 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/mock" @@ -101,19 +100,19 @@ var ( mintAuxiliary = new(MockAuxiliary) _ = mintAuxiliary.On("GetKeeper").Return(mintAuxiliaryKeeper) - encodingConfig = testutil.MakeTestEncodingConfig() + codec = baseHelpers.TestCodec() paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) - ParamsKeeper = paramsKeeper.NewKeeper(encodingConfig.Codec, encodingConfig.Amino, paramsStoreKey, paramsTransientStoreKeys) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} - AuthKeeper = authKeeper.NewAccountKeeper(encodingConfig.Codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} - BankKeeper = bankKeeper.NewBaseKeeper(encodingConfig.Codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) Context = setContext() diff --git a/x/identities/transactions/define/transaction_keeper_test.go b/x/identities/transactions/define/transaction_keeper_test.go index dfec1b77e..03f6d1e78 100644 --- a/x/identities/transactions/define/transaction_keeper_test.go +++ b/x/identities/transactions/define/transaction_keeper_test.go @@ -5,9 +5,6 @@ package define import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -28,6 +25,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -54,10 +52,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/deputize/transaction_keeper_test.go b/x/identities/transactions/deputize/transaction_keeper_test.go index 1e0bf30ba..15126be09 100644 --- a/x/identities/transactions/deputize/transaction_keeper_test.go +++ b/x/identities/transactions/deputize/transaction_keeper_test.go @@ -5,9 +5,6 @@ package deputize import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -26,6 +23,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -50,10 +48,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/issue/transaction_keeper_test.go b/x/identities/transactions/issue/transaction_keeper_test.go index 851c14dbc..ff095e7b4 100644 --- a/x/identities/transactions/issue/transaction_keeper_test.go +++ b/x/identities/transactions/issue/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/identities/mapper" "github.com/AssetMantle/modules/x/identities/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -53,10 +52,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/name/transaction_keeper_test.go b/x/identities/transactions/name/transaction_keeper_test.go index e3090f107..e6e21935c 100644 --- a/x/identities/transactions/name/transaction_keeper_test.go +++ b/x/identities/transactions/name/transaction_keeper_test.go @@ -5,9 +5,6 @@ package name import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" "github.com/AssetMantle/modules/x/identities/mapper" @@ -16,6 +13,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -30,10 +28,9 @@ func CreateTestInput(t *testing.T) (context.Context, helpers.Mapper, helpers.Par paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/provision/transaction_keeper_test.go b/x/identities/transactions/provision/transaction_keeper_test.go index b9301e3c7..13a186e53 100644 --- a/x/identities/transactions/provision/transaction_keeper_test.go +++ b/x/identities/transactions/provision/transaction_keeper_test.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/modules/x/identities/mapper" "github.com/AssetMantle/modules/x/identities/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -49,10 +48,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/quash/transaction_keeper_test.go b/x/identities/transactions/quash/transaction_keeper_test.go index 4ecaef4d7..5197b8f18 100644 --- a/x/identities/transactions/quash/transaction_keeper_test.go +++ b/x/identities/transactions/quash/transaction_keeper_test.go @@ -11,7 +11,6 @@ import ( "github.com/AssetMantle/modules/x/identities/record" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/authorize" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -52,10 +51,9 @@ func CreateTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/revoke/transaction_keeper_test.go b/x/identities/transactions/revoke/transaction_keeper_test.go index 3e514fd72..9c469e8ed 100644 --- a/x/identities/transactions/revoke/transaction_keeper_test.go +++ b/x/identities/transactions/revoke/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/identities/mapper" "github.com/AssetMantle/modules/x/identities/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -50,10 +49,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/unprovision/transaction_keeper_test.go b/x/identities/transactions/unprovision/transaction_keeper_test.go index e40b9d77b..0d3e89fcf 100644 --- a/x/identities/transactions/unprovision/transaction_keeper_test.go +++ b/x/identities/transactions/unprovision/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/identities/mapper" "github.com/AssetMantle/modules/x/identities/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -49,10 +48,9 @@ func CreateTestInput(t *testing.T) (context.Context, TestKeepers, helpers.Mapper paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/transactions/update/transaction_keeper_test.go b/x/identities/transactions/update/transaction_keeper_test.go index a46b24d5c..8922083b4 100644 --- a/x/identities/transactions/update/transaction_keeper_test.go +++ b/x/identities/transactions/update/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/identities/mapper" "github.com/AssetMantle/modules/x/identities/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -52,10 +51,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/metas/transactions/reveal/transaction_keeper_test.go b/x/metas/transactions/reveal/transaction_keeper_test.go index 3d84d3f38..c12e08dc7 100644 --- a/x/metas/transactions/reveal/transaction_keeper_test.go +++ b/x/metas/transactions/reveal/transaction_keeper_test.go @@ -5,9 +5,6 @@ package reveal import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" "github.com/AssetMantle/modules/x/metas/mapper" @@ -18,6 +15,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -36,10 +34,9 @@ func CreateTestInput(t *testing.T) (context.Context, TestKeepers) { paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/cancel/transaction_keeper_test.go b/x/orders/transactions/cancel/transaction_keeper_test.go index 36d4b98c7..da7306fb0 100644 --- a/x/orders/transactions/cancel/transaction_keeper_test.go +++ b/x/orders/transactions/cancel/transaction_keeper_test.go @@ -11,7 +11,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -57,10 +56,9 @@ func CreateTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/define/transaction_keeper_test.go b/x/orders/transactions/define/transaction_keeper_test.go index 7b2f4e7e1..8728ad9a3 100644 --- a/x/orders/transactions/define/transaction_keeper_test.go +++ b/x/orders/transactions/define/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -52,10 +51,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/deputize/transaction_keeper_test.go b/x/orders/transactions/deputize/transaction_keeper_test.go index f27a904ee..34e2b1add 100644 --- a/x/orders/transactions/deputize/transaction_keeper_test.go +++ b/x/orders/transactions/deputize/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -50,10 +49,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/get/transaction_keeper_test.go b/x/orders/transactions/get/transaction_keeper_test.go index b18ffd14f..be11f23d6 100644 --- a/x/orders/transactions/get/transaction_keeper_test.go +++ b/x/orders/transactions/get/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -53,10 +52,9 @@ func CreateTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/immediate/transaction_keeper_test.go b/x/orders/transactions/immediate/transaction_keeper_test.go index bb187b45a..f53a699a8 100644 --- a/x/orders/transactions/immediate/transaction_keeper_test.go +++ b/x/orders/transactions/immediate/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -55,10 +54,9 @@ func CreateTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/make/transaction_keeper_test.go b/x/orders/transactions/make/transaction_keeper_test.go index 4866aa098..01fc299f4 100644 --- a/x/orders/transactions/make/transaction_keeper_test.go +++ b/x/orders/transactions/make/transaction_keeper_test.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -59,10 +58,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/modify/transaction_keeper_test.go b/x/orders/transactions/modify/transaction_keeper_test.go index 4927ed1fa..204399e09 100644 --- a/x/orders/transactions/modify/transaction_keeper_test.go +++ b/x/orders/transactions/modify/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -55,10 +54,9 @@ func CreateTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/put/transaction_keeper_test.go b/x/orders/transactions/put/transaction_keeper_test.go index 970e82846..1d2699a05 100644 --- a/x/orders/transactions/put/transaction_keeper_test.go +++ b/x/orders/transactions/put/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -53,10 +52,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/revoke/transaction_keeper_test.go b/x/orders/transactions/revoke/transaction_keeper_test.go index a4eb8e55e..8e9ab0185 100644 --- a/x/orders/transactions/revoke/transaction_keeper_test.go +++ b/x/orders/transactions/revoke/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -50,10 +49,9 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/transactions/take/transaction_keeper_test.go b/x/orders/transactions/take/transaction_keeper_test.go index f6b6d245f..012ab770b 100644 --- a/x/orders/transactions/take/transaction_keeper_test.go +++ b/x/orders/transactions/take/transaction_keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/AssetMantle/modules/x/orders/mapper" "github.com/AssetMantle/modules/x/orders/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -53,10 +52,9 @@ func CreateTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, From 904fab6e277e52bf07c20e4e8cc6944b59426b9b Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:26:06 +0530 Subject: [PATCH 07/13] refactor: introducing test codec Signed-off-by: Deepanshu Tripathi --- x/assets/queries/asset/query_keeper_test.go | 9 +++------ .../queries/classification/query_keeper_test.go | 6 ++---- x/identities/queries/identity/query_keeper_test.go | 9 +++------ x/maintainers/queries/maintainer/query_keeper_test.go | 9 +++------ x/metas/queries/meta/query_keeper_test.go | 9 +++------ x/orders/queries/order/query_keeper_test.go | 9 +++------ x/splits/queries/balances/query_keeper_test.go | 6 ++---- x/splits/queries/split/query_keeper_test.go | 9 +++------ x/splits/queries/supply/query_keeper_test.go | 6 ++---- 9 files changed, 24 insertions(+), 48 deletions(-) diff --git a/x/assets/queries/asset/query_keeper_test.go b/x/assets/queries/asset/query_keeper_test.go index 5fb378cf6..05ad7d016 100644 --- a/x/assets/queries/asset/query_keeper_test.go +++ b/x/assets/queries/asset/query_keeper_test.go @@ -5,9 +5,6 @@ package asset import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -25,6 +22,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -43,10 +41,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/classifications/queries/classification/query_keeper_test.go b/x/classifications/queries/classification/query_keeper_test.go index 249f1df4a..677d1c5ab 100644 --- a/x/classifications/queries/classification/query_keeper_test.go +++ b/x/classifications/queries/classification/query_keeper_test.go @@ -6,7 +6,6 @@ package classification import ( "github.com/AssetMantle/modules/x/classifications/record" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "testing" baseDocuments "github.com/AssetMantle/schema/documents/base" @@ -48,10 +47,9 @@ func CreateTestInput2(t *testing.T) (sdkTypes.Context, helpers.Keeper) { }, false, log.NewNopLogger()) Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/identities/queries/identity/query_keeper_test.go b/x/identities/queries/identity/query_keeper_test.go index cbf95728e..9232cc629 100644 --- a/x/identities/queries/identity/query_keeper_test.go +++ b/x/identities/queries/identity/query_keeper_test.go @@ -5,9 +5,6 @@ package identity import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -25,6 +22,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -43,10 +41,9 @@ func CreateTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, paramsStoreKey := types.NewKVStoreKey("testParams") paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/maintainers/queries/maintainer/query_keeper_test.go b/x/maintainers/queries/maintainer/query_keeper_test.go index 94ea9163a..6db475a65 100644 --- a/x/maintainers/queries/maintainer/query_keeper_test.go +++ b/x/maintainers/queries/maintainer/query_keeper_test.go @@ -5,9 +5,6 @@ package maintainer import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -26,6 +23,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -55,10 +53,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/metas/queries/meta/query_keeper_test.go b/x/metas/queries/meta/query_keeper_test.go index 7b128a09b..d89459fd3 100644 --- a/x/metas/queries/meta/query_keeper_test.go +++ b/x/metas/queries/meta/query_keeper_test.go @@ -5,9 +5,6 @@ package meta import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -20,6 +17,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -38,10 +36,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/orders/queries/order/query_keeper_test.go b/x/orders/queries/order/query_keeper_test.go index c25d66f0f..f4b55fe6c 100644 --- a/x/orders/queries/order/query_keeper_test.go +++ b/x/orders/queries/order/query_keeper_test.go @@ -5,9 +5,6 @@ package order import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -20,6 +17,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -38,10 +36,9 @@ func CreateTestInputForQueries(t *testing.T) (sdkTypes.Context, TestKeepers, hel paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/splits/queries/balances/query_keeper_test.go b/x/splits/queries/balances/query_keeper_test.go index 121a4e54b..403c47a07 100644 --- a/x/splits/queries/balances/query_keeper_test.go +++ b/x/splits/queries/balances/query_keeper_test.go @@ -10,7 +10,6 @@ import ( "github.com/AssetMantle/modules/x/splits/record" baseDocuments "github.com/AssetMantle/schema/documents/base" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -44,10 +43,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/splits/queries/split/query_keeper_test.go b/x/splits/queries/split/query_keeper_test.go index 4bba25726..8c2121dbd 100644 --- a/x/splits/queries/split/query_keeper_test.go +++ b/x/splits/queries/split/query_keeper_test.go @@ -5,9 +5,6 @@ package split import ( "context" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - "fmt" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" @@ -25,6 +22,7 @@ import ( "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" @@ -43,10 +41,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := mapper.Prototype().Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, diff --git a/x/splits/queries/supply/query_keeper_test.go b/x/splits/queries/supply/query_keeper_test.go index 12726aafd..f7c355eea 100644 --- a/x/splits/queries/supply/query_keeper_test.go +++ b/x/splits/queries/supply/query_keeper_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" "reflect" "testing" @@ -43,10 +42,9 @@ func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mappe paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") Mapper := baseHelpers.NewMapper(record.Prototype).Initialize(storeKey) - encodingConfig := testutil.MakeTestEncodingConfig() - appCodec := encodingConfig.Codec + codec := baseHelpers.TestCodec() ParamsKeeper := paramsKeeper.NewKeeper( - appCodec, + codec, legacyAmino, paramsStoreKey, paramsTransientStoreKeys, From 3efe862c7ceabbd86cb9869f0a9fa51ed0c99f41 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:26:38 +0530 Subject: [PATCH 08/13] refactor: introducing test codec Signed-off-by: Deepanshu Tripathi --- x/assets/transactions/send/message_test.go | 6 +++--- x/assets/transactions/unwrap/message_test.go | 6 +++--- x/assets/transactions/wrap/message_test.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/assets/transactions/send/message_test.go b/x/assets/transactions/send/message_test.go index fcb3e12da..f65db4d0e 100644 --- a/x/assets/transactions/send/message_test.go +++ b/x/assets/transactions/send/message_test.go @@ -12,7 +12,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -195,14 +195,14 @@ func Test_message_RegisterCodec(t *testing.T) { Value types.Int } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress.String(), fromID, fromID, assetID, testRate}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, fromID, assetID, testRate}, args{codec.GetLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/unwrap/message_test.go b/x/assets/transactions/unwrap/message_test.go index d29932880..6d96f10d4 100644 --- a/x/assets/transactions/unwrap/message_test.go +++ b/x/assets/transactions/unwrap/message_test.go @@ -9,7 +9,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "reflect" "testing" @@ -213,14 +213,14 @@ func Test_message_RegisterCodec(t *testing.T) { Coins types.Coins } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress.String(), fromID, coins}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, coins}, args{codec.GetLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/wrap/message_test.go b/x/assets/transactions/wrap/message_test.go index 86d8a647a..f6938098e 100644 --- a/x/assets/transactions/wrap/message_test.go +++ b/x/assets/transactions/wrap/message_test.go @@ -11,7 +11,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -216,14 +216,14 @@ func Test_message_RegisterCodec(t *testing.T) { Coins types.Coins } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress.String(), fromID, coins}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, coins}, args{codec.GetLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 23a0be205583dabfa0e469461aa4baa689dcb539 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:33:58 +0530 Subject: [PATCH 09/13] refactor(codec): introducing helpers.ModuleManager Signed-off-by: Deepanshu Tripathi --- helpers/base/codec.go | 13 ++++++------- helpers/codec.go | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/helpers/base/codec.go b/helpers/base/codec.go index 5c9feed42..1bf24e46c 100644 --- a/helpers/base/codec.go +++ b/helpers/base/codec.go @@ -1,16 +1,15 @@ package base import ( + "github.com/AssetMantle/modules/helpers" + "github.com/AssetMantle/modules/utilities/rest/id_getters/docs" schemaCodec "github.com/AssetMantle/schema/codec" sdkClient "github.com/cosmos/cosmos-sdk/client" sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkCodecTypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" - sdkModuleTypes "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/tx" - - "github.com/AssetMantle/modules/helpers" - "github.com/AssetMantle/modules/utilities/rest/id_getters/docs" ) type codec struct { @@ -31,14 +30,14 @@ func (codec codec) GetLegacyAmino() *sdkCodec.LegacyAmino { func (codec codec) InterfaceRegistry() sdkCodecTypes.InterfaceRegistry { return codec.interfaceRegistry } -func (codec codec) Initialize(moduleBasicManager sdkModuleTypes.BasicManager) helpers.Codec { +func (codec codec) Initialize(moduleManager helpers.ModuleManager) helpers.Codec { std.RegisterLegacyAminoCodec(codec.legacyAmino) std.RegisterInterfaces(codec.interfaceRegistry) helpers.RegisterLegacyAminoCodec(codec.legacyAmino) schemaCodec.RegisterLegacyAminoCodec(codec.legacyAmino) docs.RegisterLegacyAminoCodec(codec.legacyAmino) - moduleBasicManager.RegisterLegacyAminoCodec(codec.legacyAmino) - moduleBasicManager.RegisterInterfaces(codec.interfaceRegistry) + moduleManager.RegisterLegacyAminoCodec(codec.legacyAmino) + moduleManager.RegisterInterfaces(codec.interfaceRegistry) return codec } diff --git a/helpers/codec.go b/helpers/codec.go index d8158f930..68c0d484e 100644 --- a/helpers/codec.go +++ b/helpers/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/types/module" ) type Codec interface { @@ -14,5 +13,5 @@ type Codec interface { GetProtoCodec() *codec.ProtoCodec GetLegacyAmino() *codec.LegacyAmino InterfaceRegistry() types.InterfaceRegistry - Initialize(module.BasicManager) Codec + Initialize(ModuleManager) Codec } From 5d7af203ff4ef23d0fb37e1dd4bbf55741fd03f9 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:34:07 +0530 Subject: [PATCH 10/13] refactor(codec): introducing helpers.ModuleManager Signed-off-by: Deepanshu Tripathi --- helpers/base/codec_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/helpers/base/codec_test.go b/helpers/base/codec_test.go index 850288ddb..9372d68af 100644 --- a/helpers/base/codec_test.go +++ b/helpers/base/codec_test.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - sdkModuleTypes "github.com/cosmos/cosmos-sdk/types/module" "github.com/stretchr/testify/assert" "testing" ) @@ -22,7 +21,7 @@ func Test_codec_Initialize(t *testing.T) { ProtoCodec *sdkCodec.ProtoCodec } type args struct { - moduleBasicManager sdkModuleTypes.BasicManager + moduleManager helpers.ModuleManager } tests := []struct { name string @@ -39,7 +38,7 @@ func Test_codec_Initialize(t *testing.T) { ProtoCodec: sdkCodec.NewProtoCodec(types.NewInterfaceRegistry()), }, args: args{ - moduleBasicManager: sdkModuleTypes.BasicManager{}, + moduleManager: NewModuleManager(), }, want: codec{ interfaceRegistry: types.NewInterfaceRegistry(), @@ -58,8 +57,8 @@ func Test_codec_Initialize(t *testing.T) { legacyAmino: tt.fields.legacyAmino, ProtoCodec: tt.fields.ProtoCodec, } - Codec := codec.Initialize(tt.args.moduleBasicManager) - assert.Equalf(t, tt.want.GetProtoCodec(), Codec.GetProtoCodec(), "Initialize(%v)", tt.args.moduleBasicManager) + Codec := codec.Initialize(tt.args.moduleManager) + assert.Equalf(t, tt.want.GetProtoCodec(), Codec.GetProtoCodec(), "Initialize(%v)", tt.args.moduleManager) }) } } From 017a856efaab28beaceb093ece202d4306a75a93 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:34:42 +0530 Subject: [PATCH 11/13] refactor: import sdkCodec import alias Signed-off-by: Deepanshu Tripathi --- x/assets/transactions/wrap/message.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/assets/transactions/wrap/message.go b/x/assets/transactions/wrap/message.go index 3d3883e34..f89e645b5 100644 --- a/x/assets/transactions/wrap/message.go +++ b/x/assets/transactions/wrap/message.go @@ -9,7 +9,7 @@ import ( codecUtilities "github.com/AssetMantle/schema/codec/utilities" "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -48,7 +48,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { From bf61ea873ec5a7be585d53e2a8a45fcaefcdbdd4 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:47:38 +0530 Subject: [PATCH 12/13] feat(moduleManager): early implementation, testing required Signed-off-by: Deepanshu Tripathi --- helpers/base/module_manager.go | 117 +++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 helpers/base/module_manager.go diff --git a/helpers/base/module_manager.go b/helpers/base/module_manager.go new file mode 100644 index 000000000..b632c4cd5 --- /dev/null +++ b/helpers/base/module_manager.go @@ -0,0 +1,117 @@ +package base + +import ( + "encoding/json" + "github.com/AssetMantle/modules/helpers" + abciTypes "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdkTypes "github.com/cosmos/cosmos-sdk/types" + sdkModuleTypes "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" +) + +type moduleManager struct { + basicModules []helpers.BasicModule + orderInitGenesis []string + orderExportGenesis []string + orderBeginBlockers []string + orderEndBlockers []string + orderMigrations []string +} + +var _ helpers.ModuleManager = (*moduleManager)(nil) + +func (moduleManager moduleManager) AddTxCommands(command *cobra.Command) { + for _, basicModule := range moduleManager.basicModules { + if cmd := basicModule.GetTxCmd(); cmd != nil { + command.AddCommand(cmd) + } + } +} +func (moduleManager moduleManager) AddQueryCommands(rootQueryCmd *cobra.Command) { + for _, basicModule := range moduleManager.basicModules { + if cmd := basicModule.GetQueryCmd(); cmd != nil { + rootQueryCmd.AddCommand(cmd) + } + } +} +func (moduleManager moduleManager) InitGenesis(context sdkTypes.Context, jsonCodec sdkCodec.JSONCodec, genesisData map[string]json.RawMessage) abciTypes.ResponseInitChain { + return moduleManager.getModuleManager().InitGenesis(context, jsonCodec, genesisData) +} +func (moduleManager moduleManager) GetVersionMap() sdkModuleTypes.VersionMap { + return moduleManager.getModuleManager().GetVersionMap() +} +func (moduleManager moduleManager) RegisterServices(configurator sdkModuleTypes.Configurator) { + moduleManager.getModuleManager().RegisterServices(configurator) +} +func (moduleManager moduleManager) SetOrderBeginBlockers(moduleName ...string) { + sdkModuleManager := moduleManager.getModuleManager() + sdkModuleManager.SetOrderBeginBlockers(moduleName...) + moduleManager.orderBeginBlockers = sdkModuleManager.OrderBeginBlockers +} +func (moduleManager moduleManager) SetOrderEndBlockers(moduleName ...string) { + sdkModuleManager := moduleManager.getModuleManager() + sdkModuleManager.SetOrderEndBlockers(moduleName...) + moduleManager.orderEndBlockers = sdkModuleManager.OrderEndBlockers +} +func (moduleManager moduleManager) SetOrderInitGenesis(moduleName ...string) { + sdkModuleManager := moduleManager.getModuleManager() + sdkModuleManager.SetOrderInitGenesis(moduleName...) + moduleManager.orderInitGenesis = sdkModuleManager.OrderInitGenesis +} +func (moduleManager moduleManager) BeginBlock(context sdkTypes.Context, requestBeginBlock abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock { + return moduleManager.getModuleManager().BeginBlock(context, requestBeginBlock) +} +func (moduleManager moduleManager) EndBlock(context sdkTypes.Context, requestEndBlock abciTypes.RequestEndBlock) abciTypes.ResponseEndBlock { + return moduleManager.getModuleManager().EndBlock(context, requestEndBlock) +} +func (moduleManager moduleManager) RunMigrations(context sdkTypes.Context, configurator sdkModuleTypes.Configurator, versionMap sdkModuleTypes.VersionMap) (sdkModuleTypes.VersionMap, error) { + return moduleManager.getModuleManager().RunMigrations(context, configurator, versionMap) +} +func (moduleManager moduleManager) RegisterInvariants(invariantRegistry sdkTypes.InvariantRegistry) { + moduleManager.getModuleManager().RegisterInvariants(invariantRegistry) +} +func (moduleManager moduleManager) GetBasicManager() sdkModuleTypes.BasicManager { + return sdkModuleTypes.NewBasicManager(moduleManager.getAppModulesBasic()...) +} +func (moduleManager moduleManager) ExportGenesisForModules(context sdkTypes.Context, jsonCodec sdkCodec.JSONCodec, moduleNames []string) map[string]json.RawMessage { + return moduleManager.getModuleManager().ExportGenesisForModules(context, jsonCodec, moduleNames) +} +func (moduleManager moduleManager) RegisterGRPCGatewayRoutes(context client.Context, serverMux *runtime.ServeMux) { + for _, basicModule := range moduleManager.basicModules { + basicModule.RegisterGRPCGatewayRoutes(context, serverMux) + } +} +func (moduleManager moduleManager) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { + for _, basicModule := range moduleManager.basicModules { + basicModule.RegisterLegacyAminoCodec(legacyAmino) + } +} +func (moduleManager moduleManager) RegisterInterfaces(interfaceRegistry types.InterfaceRegistry) { + for _, basicModule := range moduleManager.basicModules { + basicModule.RegisterInterfaces(interfaceRegistry) + } +} +func (moduleManager moduleManager) getModuleManager() *sdkModuleTypes.Manager { + appModules := make([]sdkModuleTypes.AppModule, len(moduleManager.basicModules)) + for i, basicModule := range moduleManager.basicModules { + appModules[i] = basicModule + } + return sdkModuleTypes.NewManager(appModules...) +} +func (moduleManager moduleManager) getAppModulesBasic() []sdkModuleTypes.AppModuleBasic { + appModules := make([]sdkModuleTypes.AppModuleBasic, len(moduleManager.basicModules)) + for i, basicModule := range moduleManager.basicModules { + appModules[i] = basicModule + } + return appModules +} + +func NewModuleManager(basicModules ...helpers.BasicModule) helpers.ModuleManager { + return moduleManager{ + basicModules: basicModules, + } +} From aec1e1b13636c7642b61fe268cbded6adfa40ff1 Mon Sep 17 00:00:00 2001 From: Deepanshu Tripathi Date: Mon, 15 Jul 2024 17:49:20 +0530 Subject: [PATCH 13/13] refactor(module): early implementation, testing required Signed-off-by: Deepanshu Tripathi --- helpers/base/module.go | 82 +++++++++++++++++++++++++----------------- helpers/module.go | 9 +++++ 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/helpers/base/module.go b/helpers/base/module.go index c06676dd4..fb3e3a839 100644 --- a/helpers/base/module.go +++ b/helpers/base/module.go @@ -6,8 +6,10 @@ package base import ( "encoding/json" "fmt" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" "math/rand" + abciTypes "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/client" sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -18,7 +20,6 @@ import ( "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" - abciTypes "github.com/tendermint/tendermint/abci/types" "github.com/AssetMantle/modules/helpers" ) @@ -48,6 +49,15 @@ type module struct { var _ helpers.Module = (*module)(nil) +func (module module) IsOnePerModuleType() { + //TODO implement me + panic("implement me") +} + +func (module module) IsAppModule() { + //TODO implement me + panic("implement me") +} func (module module) Name() string { return module.name } @@ -134,10 +144,14 @@ func (module module) GetQueryCmd() *cobra.Command { func (module module) GenerateGenesisState(simulationState *sdkModuleTypes.SimulationState) { module.simulatorPrototype().RandomizedGenesisState(simulationState) } +func (module module) ProposalMsgs(simulationState sdkModuleTypes.SimulationState) []simulationTypes.WeightedProposalMsg { + //TODO implement me + panic("implement me") +} func (module module) ProposalContents(simulationState sdkModuleTypes.SimulationState) []simulationTypes.WeightedProposalContent { return module.simulatorPrototype().WeightedProposalContentList(simulationState) } -func (module module) RandomizedParams(r *rand.Rand) []simulationTypes.ParamChange { +func (module module) RandomizedParams(r *rand.Rand) []simulationTypes.LegacyParamChange { return module.simulatorPrototype().ParamChangeList(r) } func (module module) RegisterStoreDecoder(storeDecoderRegistry sdkTypes.StoreDecoderRegistry) { @@ -149,40 +163,44 @@ func (module module) WeightedOperations(simulationState sdkModuleTypes.Simulatio func (module module) RegisterInvariants(invariantRegistry sdkTypes.InvariantRegistry) { module.invariantsPrototype().Register(invariantRegistry) } -func (module module) Route() sdkTypes.Route { - return sdkTypes.NewRoute(module.Name(), func(context sdkTypes.Context, msg sdkTypes.Msg) (*sdkTypes.Result, error) { - if module.transactions == nil { - panic(fmt.Errorf("transactions for module %s not initialized", module.Name())) - } - if message, ok := msg.(helpers.Message); ok { - if transaction := module.transactions.GetTransaction(message.Type()); transaction != nil { - return transaction.HandleMessage(sdkTypes.WrapSDKContext(context.WithEventManager(sdkTypes.NewEventManager())), message) - } - } - return nil, fmt.Errorf("message type %T is not supported by module %s", msg, module.Name()) - }) -} +// TODO remove if unnecessary +// +// func (module module) Route() sdkTypes.Route { +// return sdkTypes.NewRoute(module.Name(), func(context sdkTypes.Context, msg sdkTypes.Msg) (*sdkTypes.Result, error) { +// if module.transactions == nil { +// panic(fmt.Errorf("transactions for module %s not initialized", module.Name())) +// } +// +// if message, ok := msg.(helpers.Message); ok { +// if transaction := module.transactions.GetTransaction(message.Type()); transaction != nil { +// return transaction.HandleMessage(sdkTypes.WrapSDKContext(context.WithEventManager(sdkTypes.NewEventManager())), message) +// } +// } +// return nil, fmt.Errorf("message type %T is not supported by module %s", msg, module.Name()) +// }) +// } func (module module) QuerierRoute() string { return module.name } -func (module module) LegacyQuerierHandler(_ *sdkCodec.LegacyAmino) sdkTypes.Querier { - return func(context sdkTypes.Context, path []string, requestQuery abciTypes.RequestQuery) ([]byte, error) { - if module.queries == nil { - panic(fmt.Errorf("queries for module %s not initialized", module.Name())) - } - - if query := module.queries.GetQuery(path[0]); query != nil { - return query.HandleQuery(sdkTypes.WrapSDKContext(context), requestQuery) - } - if path[0] == "parameters" { - return CodecPrototype().MarshalJSON(module.parameterManager.Fetch(sdkTypes.WrapSDKContext(context)).Get()) - } - - return nil, fmt.Errorf("unknown query path, %v for module %v", path[0], module.Name()) - } -} +// func (module module) LegacyQuerierHandler(_ *sdkCodec.LegacyAmino) sdkTypes.Querier { +// return func(context sdkTypes.Context, path []string, requestQuery abciTypes.RequestQuery) ([]byte, error) { +// if module.queries == nil { +// panic(fmt.Errorf("queries for module %s not initialized", module.Name())) +// } +// +// if query := module.queries.GetQuery(path[0]); query != nil { +// return query.HandleQuery(sdkTypes.WrapSDKContext(context), requestQuery) +// } +// +// if path[0] == "parameters" { +// return CodecPrototype().MarshalJSON(module.parameterManager.Fetch(sdkTypes.WrapSDKContext(context)).Get()) +// } +// +// return nil, fmt.Errorf("unknown query path, %v for module %v", path[0], module.Name()) +// } +// } func (module module) RegisterServices(configurator sdkModuleTypes.Configurator) { for _, query := range module.queries.Get() { query.RegisterService(configurator) @@ -236,7 +254,7 @@ func (module module) DecodeModuleTransactionRequest(transactionName string, rawM return nil, fmt.Errorf("transaction %s is not supported by module %s", transactionName, module.Name()) } -func (module module) Initialize(kvStoreKey *sdkTypes.KVStoreKey, paramsSubspace paramsTypes.Subspace, auxiliaryKeepers ...interface{}) helpers.Module { +func (module module) Initialize(kvStoreKey *storeTypes.KVStoreKey, paramsSubspace paramsTypes.Subspace, auxiliaryKeepers ...interface{}) helpers.Module { module.mapper = module.mapperPrototype().Initialize(kvStoreKey) module.genesis = module.genesisPrototype() diff --git a/helpers/module.go b/helpers/module.go index 0558e49cd..2e5fbd6b2 100644 --- a/helpers/module.go +++ b/helpers/module.go @@ -13,9 +13,18 @@ import ( ) type Module interface { + BasicModule + sdkModuleTypes.AppModuleGenesis sdkModuleTypes.EndBlockAppModule sdkModuleTypes.BeginBlockAppModule + + sdkModuleTypes.HasConsensusVersion + sdkModuleTypes.HasInvariants + sdkModuleTypes.HasServices + sdkModuleTypes.AppModuleSimulation + sdkModuleTypes.HasProposalContents + sdkModuleTypes.HasProposalMsgs GetAuxiliary(string) Auxiliary