From 24e7e5a7d7c8c34d9a0521c14956296633462d2e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 30 Jun 2022 14:20:28 -0300 Subject: [PATCH 01/11] progress --- x/nft/keeper/keeper_test.go | 55 +++++----- x/nft/module/module.go | 2 +- x/nft/simulation/operations_test.go | 132 ++++++++++++++--------- x/nft/testutil/expected_keepers_mocks.go | 101 +++++++++++++++++ 4 files changed, 213 insertions(+), 77 deletions(-) create mode 100644 x/nft/testutil/expected_keepers_mocks.go diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 61e6b74f4901..b55d17efbbfe 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -3,19 +3,23 @@ package keeper_test import ( "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + "github.com/tendermint/tendermint/libs/log" tmtime "github.com/tendermint/tendermint/libs/time" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/nft" "github.com/cosmos/cosmos-sdk/x/nft/keeper" - "github.com/cosmos/cosmos-sdk/x/nft/testutil" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/cosmos/cosmos-sdk/x/nft/module" + nftTestutil "github.com/cosmos/cosmos-sdk/x/nft/testutil" ) const ( @@ -37,34 +41,37 @@ type TestSuite struct { addrs []sdk.AccAddress queryClient nft.QueryClient nftKeeper keeper.Keeper + + encCfg testutil.TestEncodingConfig } func (s *TestSuite) SetupTest() { - var ( - interfaceRegistry codectypes.InterfaceRegistry - bankKeeper bankkeeper.Keeper - stakingKeeper *stakingkeeper.Keeper - nftKeeper keeper.Keeper - ) - - app, err := simtestutil.Setup( - testutil.AppConfig, - &interfaceRegistry, - &nftKeeper, - &bankKeeper, - &stakingKeeper, - ) + // suite setup + s.addrs = simtestutil.CreateIncrementalAccounts(3) + s.encCfg = testutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + + mkey := sdk.NewKVStoreKey(nft.StoreKey) + db := dbm.NewMemDB() + cms := store.NewCommitMultiStore(db) + cms.MountStoreWithDB(mkey, storetypes.StoreTypeIAVL, nil) + err := cms.LoadLatestVersion() s.Require().NoError(err) - - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) ctx = ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) - queryHelper := baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry) + + // gomock initializations + ctrl := gomock.NewController(s.T()) + accountKeeper := nftTestutil.NewMockAccountKeeper(ctrl) + bankKeeper := nftTestutil.NewMockBankKeeper(ctrl) + accountKeeper.EXPECT().GetModuleAddress("nft").Return(s.addrs[0]).AnyTimes() + + nftKeeper := keeper.NewKeeper(mkey, s.encCfg.Codec, accountKeeper, bankKeeper) + queryHelper := baseapp.NewQueryServerTestHelper(ctx, s.encCfg.InterfaceRegistry) nft.RegisterQueryServer(queryHelper, nftKeeper) - s.ctx = ctx - s.queryClient = nft.NewQueryClient(queryHelper) - s.addrs = simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(30000000)) s.nftKeeper = nftKeeper + s.queryClient = nft.NewQueryClient(queryHelper) + s.ctx = ctx } func TestTestSuite(t *testing.T) { diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 966e23c1d764..2532b8fab793 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -1,4 +1,4 @@ -package nft +package module import ( "context" diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index e5feef0c896d..5a2002f4850e 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -5,72 +5,107 @@ import ( "testing" "time" - "github.com/stretchr/testify/suite" - - abci "github.com/tendermint/tendermint/abci/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + moduletypes "github.com/cosmos/cosmos-sdk/types/module" + moduleTestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/nft" + "github.com/cosmos/cosmos-sdk/x/nft/keeper" nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper" + "github.com/cosmos/cosmos-sdk/x/nft/module" "github.com/cosmos/cosmos-sdk/x/nft/simulation" - "github.com/cosmos/cosmos-sdk/x/nft/testutil" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + nftTestutil "github.com/cosmos/cosmos-sdk/x/nft/testutil" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tmtime "github.com/tendermint/tendermint/libs/time" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) type SimTestSuite struct { suite.Suite - ctx sdk.Context - - app *runtime.App - codec codec.Codec - interfaceRegistry codectypes.InterfaceRegistry - accountKeeper authkeeper.AccountKeeper - bankKeeper bankkeeper.Keeper - stakingKeeper *stakingkeeper.Keeper - nftKeeper nftkeeper.Keeper + ctx sdk.Context + baseApp *baseapp.BaseApp + accountKeeper *nftTestutil.MockAccountKeeper + bankKeeper *nftTestutil.MockBankKeeper + nftKeeper nftkeeper.Keeper + encCfg moduleTestutil.TestEncodingConfig } func (suite *SimTestSuite) SetupTest() { - app, err := simtestutil.Setup( - testutil.AppConfig, - &suite.codec, - &suite.interfaceRegistry, - &suite.accountKeeper, - &suite.bankKeeper, - &suite.stakingKeeper, - &suite.nftKeeper, + key := sdk.NewKVStoreKey(nft.StoreKey) + // suite setup + addrs := simtestutil.CreateIncrementalAccounts(3) + suite.encCfg = moduleTestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + + // gomock initializations + ctrl := gomock.NewController(suite.T()) + suite.accountKeeper = nftTestutil.NewMockAccountKeeper(ctrl) + suite.bankKeeper = nftTestutil.NewMockBankKeeper(ctrl) + + suite.accountKeeper.EXPECT().GetModuleAddress(nft.ModuleName).Return(addrs[0]).AnyTimes() + + // keys := sdk.NewK(nft.StoreKey) + ctx, db, cms := testutil.DefaultContextWithDB(key, sdk.NewTransientStoreKey("transient_test")) + // ads := ctx.KVStore(keys[nft.StoreKey]) + // panic(ads) + suite.baseApp = baseapp.NewBaseApp( + "nft", + log.NewNopLogger(), + db, + suite.encCfg.TxConfig.TxDecoder(), ) - suite.Require().NoError(err) - suite.app = app - suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) + suite.baseApp.SetCMS(cms) + + suite.baseApp.SetInterfaceRegistry(suite.encCfg.InterfaceRegistry) + suite.ctx = ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) + + suite.nftKeeper = keeper.NewKeeper(key, suite.encCfg.Codec, suite.accountKeeper, suite.bankKeeper) + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) + nft.RegisterQueryServer(queryHelper, suite.nftKeeper) + + cfg := moduletypes.NewConfigurator(suite.encCfg.Codec, suite.baseApp.MsgServiceRouter(), suite.baseApp.GRPCQueryRouter()) + + appModule := module.NewAppModule(suite.encCfg.Codec, suite.nftKeeper, suite.accountKeeper, suite.bankKeeper, suite.encCfg.InterfaceRegistry) + appModule.RegisterServices(cfg) + appModule.RegisterInterfaces(suite.encCfg.InterfaceRegistry) + } func (suite *SimTestSuite) TestWeightedOperations() { weightedOps := simulation.WeightedOperations( - suite.interfaceRegistry, + suite.encCfg.InterfaceRegistry, make(simtypes.AppParams), - suite.codec, + suite.encCfg.Codec, suite.accountKeeper, suite.bankKeeper, suite.nftKeeper, ) + // begin new block + suite.baseApp.BeginBlock(abci.RequestBeginBlock{ + Header: tmproto.Header{ + Height: suite.baseApp.LastBlockHeight() + 1, + AppHash: suite.baseApp.LastCommitID().Hash, + }, + }) + // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) accs := suite.getTestingAccounts(r, 3) + suite.accountKeeper.EXPECT().GetAccount(suite.ctx, accs[2].Address).Return(authtypes.NewBaseAccount(accs[2].Address, accs[2].PubKey, 0, 0)).Times(1) + suite.bankKeeper.EXPECT().SpendableCoins(suite.ctx, accs[2].Address).Return(sdk.Coins{sdk.NewInt64Coin("stake", 10)}).Times(1) + expected := []struct { weight int opMsgRoute string @@ -80,7 +115,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { } for i, w := range weightedOps { - operationMsg, _, err := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + operationMsg, _, err := w.Op()(r, suite.baseApp, suite.ctx, accs, "") suite.Require().NoError(err) // the following checks are very much dependent from the ordering of the output given @@ -94,17 +129,6 @@ func (suite *SimTestSuite) TestWeightedOperations() { func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { accounts := simtypes.RandomAccounts(r, n) - - initAmt := suite.stakingKeeper.TokensFromConsensusPower(suite.ctx, 200000) - initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt)) - - // add coins to the accounts - for _, account := range accounts { - acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address) - suite.accountKeeper.SetAccount(suite.ctx, acc) - suite.Require().NoError(banktestutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins)) - } - return accounts } @@ -115,22 +139,26 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { blockTime := time.Now().UTC() ctx := suite.ctx.WithBlockTime(blockTime) + acc := authtypes.NewBaseAccount(accounts[0].Address, accounts[0].PubKey, 0, 0) + suite.accountKeeper.EXPECT().GetAccount(ctx, accounts[0].Address).Return(acc).Times(1) + suite.bankKeeper.EXPECT().SpendableCoins(ctx, accounts[0].Address).Return(sdk.Coins{sdk.NewInt64Coin("stake", 10)}).Times(1) + // begin new block - suite.app.BeginBlock(abci.RequestBeginBlock{ + suite.baseApp.BeginBlock(abci.RequestBeginBlock{ Header: tmproto.Header{ - Height: suite.app.LastBlockHeight() + 1, - AppHash: suite.app.LastCommitID().Hash, + Height: suite.baseApp.LastBlockHeight() + 1, + AppHash: suite.baseApp.LastCommitID().Hash, }, }) // execute operation - registry := suite.interfaceRegistry + registry := suite.encCfg.InterfaceRegistry op := simulation.SimulateMsgSend(codec.NewProtoCodec(registry), suite.accountKeeper, suite.bankKeeper, suite.nftKeeper) - operationMsg, futureOperations, err := op(r, suite.app.BaseApp, ctx, accounts, "") + operationMsg, futureOperations, err := op(r, suite.baseApp, ctx, accounts, "") suite.Require().NoError(err) var msg nft.MsgSend - suite.codec.UnmarshalJSON(operationMsg.Msg, &msg) + suite.encCfg.Codec.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Len(futureOperations, 0) } diff --git a/x/nft/testutil/expected_keepers_mocks.go b/x/nft/testutil/expected_keepers_mocks.go new file mode 100644 index 000000000000..49d193397ee2 --- /dev/null +++ b/x/nft/testutil/expected_keepers_mocks.go @@ -0,0 +1,101 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/nft/expected_keepers.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + types0 "github.com/cosmos/cosmos-sdk/x/auth/types" + gomock "github.com/golang/mock/gomock" +) + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx types.Context, addr types.AccAddress) types0.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types0.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// GetModuleAddress mocks base method. +func (m *MockAccountKeeper) GetModuleAddress(name string) types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAddress", name) + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// GetModuleAddress indicates an expected call of GetModuleAddress. +func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name) +} From c14380bb0c6e546813ab13840da57afcc63a176e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 1 Jul 2022 04:49:42 -0300 Subject: [PATCH 02/11] progress --- Makefile | 1 + testutil/context.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Makefile b/Makefile index 057fcca9038f..870454ea42f0 100644 --- a/Makefile +++ b/Makefile @@ -150,6 +150,7 @@ mocks: $(MOCKS_DIR) $(mockgen_cmd) -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server $(mockgen_cmd) -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger $(mockgen_cmd) -source=orm/model/ormtable/hooks.go -package ormmocks -destination orm/testing/ormmocks/hooks.go + $(mockgen_cmd) -source=x/nft/expected_keepers.go -package testutil -destination x/nft/testutil/expected_keepers_mocks.go .PHONY: mocks $(MOCKS_DIR): diff --git a/testutil/context.go b/testutil/context.go index 1addf17c287a..c20029fa1925 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -24,3 +24,18 @@ func DefaultContext(key storetypes.StoreKey, tkey storetypes.StoreKey) sdk.Conte return ctx } + +func DefaultContextWithDB(key storetypes.StoreKey, tkey storetypes.StoreKey) (sdk.Context, *dbm.MemDB, store.CommitMultiStore) { + db := dbm.NewMemDB() + cms := store.NewCommitMultiStore(db) + cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) + cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) + err := cms.LoadLatestVersion() + if err != nil { + panic(err) + } + + ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) + + return ctx, db, cms +} From 848ca6295c522b00ba925f6f989e0846ff85bee4 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 1 Jul 2022 04:49:49 -0300 Subject: [PATCH 03/11] progress --- types/module/testutil/codec.go | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 types/module/testutil/codec.go diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go new file mode 100644 index 000000000000..e3912d81172e --- /dev/null +++ b/types/module/testutil/codec.go @@ -0,0 +1,40 @@ +package testutil + +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/std" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth/tx" +) + +type TestEncodingConfig struct { + InterfaceRegistry types.InterfaceRegistry + Codec codec.Codec + TxConfig client.TxConfig + Amino *codec.LegacyAmino + bm module.BasicManager +} + +func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig { + cdc := codec.NewLegacyAmino() + interfaceRegistry := types.NewInterfaceRegistry() + codec := codec.NewProtoCodec(interfaceRegistry) + + encCfg := TestEncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Codec: codec, + TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes), + Amino: cdc, + } + + mb := module.NewBasicManager(modules...) + + std.RegisterLegacyAminoCodec(encCfg.Amino) + std.RegisterInterfaces(encCfg.InterfaceRegistry) + mb.RegisterLegacyAminoCodec(encCfg.Amino) + mb.RegisterInterfaces(encCfg.InterfaceRegistry) + + return encCfg +} From 3880260ffc26be95ce82f7a9f55bb9774f8aa07e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 1 Jul 2022 06:00:36 -0300 Subject: [PATCH 04/11] cleanup --- x/nft/simulation/operations_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index 5a2002f4850e..d091babbb98a 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -52,10 +52,7 @@ func (suite *SimTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetModuleAddress(nft.ModuleName).Return(addrs[0]).AnyTimes() - // keys := sdk.NewK(nft.StoreKey) ctx, db, cms := testutil.DefaultContextWithDB(key, sdk.NewTransientStoreKey("transient_test")) - // ads := ctx.KVStore(keys[nft.StoreKey]) - // panic(ads) suite.baseApp = baseapp.NewBaseApp( "nft", log.NewNopLogger(), From 07caf739ccae8022cf65ddd86d51d6f235993aa5 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 4 Jul 2022 11:35:04 -0300 Subject: [PATCH 05/11] suggestions --- testutil/context.go | 10 ++++++++-- x/nft/keeper/keeper_test.go | 30 +++++++++++------------------ x/nft/simulation/operations_test.go | 24 +++++++++++------------ 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/testutil/context.go b/testutil/context.go index c20029fa1925..0aa4e4b81b48 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -25,7 +25,13 @@ func DefaultContext(key storetypes.StoreKey, tkey storetypes.StoreKey) sdk.Conte return ctx } -func DefaultContextWithDB(key storetypes.StoreKey, tkey storetypes.StoreKey) (sdk.Context, *dbm.MemDB, store.CommitMultiStore) { +type TestContext struct { + Ctx sdk.Context + DB *dbm.MemDB + CMS store.CommitMultiStore +} + +func DefaultContextWithDB(key storetypes.StoreKey, tkey storetypes.StoreKey) TestContext { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) @@ -37,5 +43,5 @@ func DefaultContextWithDB(key storetypes.StoreKey, tkey storetypes.StoreKey) (sd ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) - return ctx, db, cms + return TestContext{ctx, db, cms} } diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index b55d17efbbfe..76bf09f76220 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -5,21 +5,18 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/libs/log" tmtime "github.com/tendermint/tendermint/libs/time" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/store" - storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/nft" "github.com/cosmos/cosmos-sdk/x/nft/keeper" "github.com/cosmos/cosmos-sdk/x/nft/module" - nftTestutil "github.com/cosmos/cosmos-sdk/x/nft/testutil" + nfttestutil "github.com/cosmos/cosmos-sdk/x/nft/testutil" ) const ( @@ -42,30 +39,25 @@ type TestSuite struct { queryClient nft.QueryClient nftKeeper keeper.Keeper - encCfg testutil.TestEncodingConfig + encCfg moduletestutil.TestEncodingConfig } func (s *TestSuite) SetupTest() { // suite setup s.addrs = simtestutil.CreateIncrementalAccounts(3) - s.encCfg = testutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) - mkey := sdk.NewKVStoreKey(nft.StoreKey) - db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(mkey, storetypes.StoreTypeIAVL, nil) - err := cms.LoadLatestVersion() - s.Require().NoError(err) - ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) - ctx = ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) + key := sdk.NewKVStoreKey(nft.StoreKey) + testCtx := testutil.DefaultContextWithDB(key, sdk.NewTransientStoreKey("transient_test")) + ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) // gomock initializations ctrl := gomock.NewController(s.T()) - accountKeeper := nftTestutil.NewMockAccountKeeper(ctrl) - bankKeeper := nftTestutil.NewMockBankKeeper(ctrl) + accountKeeper := nfttestutil.NewMockAccountKeeper(ctrl) + bankKeeper := nfttestutil.NewMockBankKeeper(ctrl) accountKeeper.EXPECT().GetModuleAddress("nft").Return(s.addrs[0]).AnyTimes() - nftKeeper := keeper.NewKeeper(mkey, s.encCfg.Codec, accountKeeper, bankKeeper) + nftKeeper := keeper.NewKeeper(key, s.encCfg.Codec, accountKeeper, bankKeeper) queryHelper := baseapp.NewQueryServerTestHelper(ctx, s.encCfg.InterfaceRegistry) nft.RegisterQueryServer(queryHelper, nftKeeper) diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index d091babbb98a..b167d3f4676c 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -11,7 +11,7 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" moduletypes "github.com/cosmos/cosmos-sdk/types/module" - moduleTestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/nft" @@ -19,7 +19,7 @@ import ( nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper" "github.com/cosmos/cosmos-sdk/x/nft/module" "github.com/cosmos/cosmos-sdk/x/nft/simulation" - nftTestutil "github.com/cosmos/cosmos-sdk/x/nft/testutil" + nfttestutil "github.com/cosmos/cosmos-sdk/x/nft/testutil" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" @@ -33,37 +33,37 @@ type SimTestSuite struct { ctx sdk.Context baseApp *baseapp.BaseApp - accountKeeper *nftTestutil.MockAccountKeeper - bankKeeper *nftTestutil.MockBankKeeper + accountKeeper *nfttestutil.MockAccountKeeper + bankKeeper *nfttestutil.MockBankKeeper nftKeeper nftkeeper.Keeper - encCfg moduleTestutil.TestEncodingConfig + encCfg moduletestutil.TestEncodingConfig } func (suite *SimTestSuite) SetupTest() { key := sdk.NewKVStoreKey(nft.StoreKey) // suite setup addrs := simtestutil.CreateIncrementalAccounts(3) - suite.encCfg = moduleTestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) // gomock initializations ctrl := gomock.NewController(suite.T()) - suite.accountKeeper = nftTestutil.NewMockAccountKeeper(ctrl) - suite.bankKeeper = nftTestutil.NewMockBankKeeper(ctrl) + suite.accountKeeper = nfttestutil.NewMockAccountKeeper(ctrl) + suite.bankKeeper = nfttestutil.NewMockBankKeeper(ctrl) suite.accountKeeper.EXPECT().GetModuleAddress(nft.ModuleName).Return(addrs[0]).AnyTimes() - ctx, db, cms := testutil.DefaultContextWithDB(key, sdk.NewTransientStoreKey("transient_test")) + testCtx := testutil.DefaultContextWithDB(key, sdk.NewTransientStoreKey("transient_test")) suite.baseApp = baseapp.NewBaseApp( "nft", log.NewNopLogger(), - db, + testCtx.DB, suite.encCfg.TxConfig.TxDecoder(), ) - suite.baseApp.SetCMS(cms) + suite.baseApp.SetCMS(testCtx.CMS) suite.baseApp.SetInterfaceRegistry(suite.encCfg.InterfaceRegistry) - suite.ctx = ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) + suite.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) suite.nftKeeper = keeper.NewKeeper(key, suite.encCfg.Codec, suite.accountKeeper, suite.bankKeeper) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) From 18ff00e2d610e17ab501ec5fd2ebf5facd57d4ea Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 4 Jul 2022 12:20:57 -0300 Subject: [PATCH 06/11] move mockgen to a separate script --- Makefile | 12 +----------- scripts/mockgen.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100755 scripts/mockgen.sh diff --git a/Makefile b/Makefile index 870454ea42f0..8ac5ec4e148d 100644 --- a/Makefile +++ b/Makefile @@ -138,19 +138,9 @@ cosmovisor: .PHONY: build build-linux cosmovisor -mockgen_cmd=go run github.com/golang/mock/mockgen mocks: $(MOCKS_DIR) - $(mockgen_cmd) -source=client/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go - $(mockgen_cmd) -package mocks -destination tests/mocks/tendermint_tm_db_DB.go github.com/tendermint/tm-db DB - $(mockgen_cmd) -source db/types.go -package mocks -destination tests/mocks/db/types.go - $(mockgen_cmd) -source=types/module/module.go -package mocks -destination tests/mocks/types_module_module.go - $(mockgen_cmd) -source=types/invariant.go -package mocks -destination tests/mocks/types_invariant.go - $(mockgen_cmd) -source=types/router.go -package mocks -destination tests/mocks/types_router.go - $(mockgen_cmd) -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server - $(mockgen_cmd) -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger - $(mockgen_cmd) -source=orm/model/ormtable/hooks.go -package ormmocks -destination orm/testing/ormmocks/hooks.go - $(mockgen_cmd) -source=x/nft/expected_keepers.go -package testutil -destination x/nft/testutil/expected_keepers_mocks.go + sh ./scripts/mockgen.sh .PHONY: mocks $(MOCKS_DIR): diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh new file mode 100755 index 000000000000..15ff219d0b38 --- /dev/null +++ b/scripts/mockgen.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +mockgen_cmd="go run github.com/golang/mock/mockgen" +$mockgen_cmd -source=client/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go +$mockgen_cmd -package mocks -destination tests/mocks/tendermint_tm_db_DB.go github.com/tendermint/tm-db DB +$mockgen_cmd -source db/types.go -package mocks -destination tests/mocks/db/types.go +$mockgen_cmd -source=types/module/module.go -package mocks -destination tests/mocks/types_module_module.go +$mockgen_cmd -source=types/invariant.go -package mocks -destination tests/mocks/types_invariant.go +$mockgen_cmd -source=types/router.go -package mocks -destination tests/mocks/types_router.go +$mockgen_cmd -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server +$mockgen_cmd -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger +$mockgen_cmd -source=orm/model/ormtable/hooks.go -package ormmocks -destination orm/testing/ormmocks/hooks.go +$mockgen_cmd -source=x/nft/expected_keepers.go -package testutil -destination x/nft/testutil/expected_keepers_mocks.go \ No newline at end of file From 003dc69ad3fdf399a6ad54675b0a1a9cfdb67dc0 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 4 Jul 2022 16:52:41 -0300 Subject: [PATCH 07/11] suggestion from bez --- testutil/context.go | 9 +++++---- x/nft/keeper/keeper_test.go | 2 +- x/nft/simulation/operations_test.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/testutil/context.go b/testutil/context.go index 0aa4e4b81b48..d422dd33b642 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -1,6 +1,9 @@ package testutil import ( + "testing" + + "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -31,15 +34,13 @@ type TestContext struct { CMS store.CommitMultiStore } -func DefaultContextWithDB(key storetypes.StoreKey, tkey storetypes.StoreKey) TestContext { +func DefaultContextWithDB(t *testing.T, key storetypes.StoreKey, tkey storetypes.StoreKey) TestContext { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) err := cms.LoadLatestVersion() - if err != nil { - panic(err) - } + assert.NoError(t, err) ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 76bf09f76220..b3eb892fc826 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -48,7 +48,7 @@ func (s *TestSuite) SetupTest() { s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) key := sdk.NewKVStoreKey(nft.StoreKey) - testCtx := testutil.DefaultContextWithDB(key, sdk.NewTransientStoreKey("transient_test")) + testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) // gomock initializations diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index b167d3f4676c..61beb83eb888 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -52,7 +52,7 @@ func (suite *SimTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetModuleAddress(nft.ModuleName).Return(addrs[0]).AnyTimes() - testCtx := testutil.DefaultContextWithDB(key, sdk.NewTransientStoreKey("transient_test")) + testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) suite.baseApp = baseapp.NewBaseApp( "nft", log.NewNopLogger(), From c1e4799bb7aa437adc6a39dea66e109727b06c7e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 4 Jul 2022 17:13:41 -0300 Subject: [PATCH 08/11] remove app.yaml --- x/nft/testutil/app.yaml | 52 ------------------------------------ x/nft/testutil/app_config.go | 20 -------------- 2 files changed, 72 deletions(-) delete mode 100644 x/nft/testutil/app.yaml delete mode 100644 x/nft/testutil/app_config.go diff --git a/x/nft/testutil/app.yaml b/x/nft/testutil/app.yaml deleted file mode 100644 index 674372666a50..000000000000 --- a/x/nft/testutil/app.yaml +++ /dev/null @@ -1,52 +0,0 @@ -modules: - - name: runtime - config: - "@type": cosmos.app.runtime.v1alpha1.Module - - app_name: NFTApp - - begin_blockers: [staking, auth, bank, mint, genutil, nft, params] - end_blockers: [staking, auth, bank, mint, genutil, nft, params] - init_genesis: [auth, bank, staking, mint, genutil, nft, params] - - - name: auth - config: - "@type": cosmos.auth.module.v1.Module - bech32_prefix: cosmos - module_account_permissions: - - account: fee_collector - - account: mint - permissions: [minter] - - account: bonded_tokens_pool - permissions: [burner, staking] - - account: not_bonded_tokens_pool - permissions: [burner, staking] - - account: nft - - - name: bank - config: - "@type": cosmos.bank.module.v1.Module - - - name: params - config: - "@type": cosmos.params.module.v1.Module - - - name: tx - config: - "@type": cosmos.tx.module.v1.Module - - - name: staking - config: - "@type": cosmos.staking.module.v1.Module - - - name: genutil - config: - "@type": cosmos.genutil.module.v1.Module - - - name: mint - config: - "@type": cosmos.mint.module.v1.Module - - - name: nft - config: - "@type": cosmos.nft.module.v1.Module diff --git a/x/nft/testutil/app_config.go b/x/nft/testutil/app_config.go deleted file mode 100644 index 69487c5fac35..000000000000 --- a/x/nft/testutil/app_config.go +++ /dev/null @@ -1,20 +0,0 @@ -package testutil - -import ( - _ "embed" - - "cosmossdk.io/core/appconfig" - _ "github.com/cosmos/cosmos-sdk/x/auth" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" - _ "github.com/cosmos/cosmos-sdk/x/bank" - _ "github.com/cosmos/cosmos-sdk/x/genutil" - _ "github.com/cosmos/cosmos-sdk/x/mint" - _ "github.com/cosmos/cosmos-sdk/x/nft/module" - _ "github.com/cosmos/cosmos-sdk/x/params" - _ "github.com/cosmos/cosmos-sdk/x/staking" -) - -//go:embed app.yaml -var appConfig []byte - -var AppConfig = appconfig.LoadYAML(appConfig) From f5f3df758f1269876c8bc279a319c10fa980491d Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 4 Jul 2022 17:18:17 -0300 Subject: [PATCH 09/11] fix tests --- x/nft/simulation/decoder_test.go | 14 ++++++-------- x/nft/simulation/genesis_test.go | 10 ++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/x/nft/simulation/decoder_test.go b/x/nft/simulation/decoder_test.go index ea8c8921625f..c195eec3114c 100644 --- a/x/nft/simulation/decoder_test.go +++ b/x/nft/simulation/decoder_test.go @@ -6,15 +6,14 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/depinject" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/nft" "github.com/cosmos/cosmos-sdk/x/nft/keeper" + "github.com/cosmos/cosmos-sdk/x/nft/module" "github.com/cosmos/cosmos-sdk/x/nft/simulation" - "github.com/cosmos/cosmos-sdk/x/nft/testutil" ) var ( @@ -23,9 +22,8 @@ var ( ) func TestDecodeStore(t *testing.T) { - var cdc codec.Codec - depinject.Inject(testutil.AppConfig, &cdc) - dec := simulation.NewDecodeStore(cdc) + encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + dec := simulation.NewDecodeStore(encCfg.Codec) class := nft.Class{ Id: "ClassID", @@ -34,7 +32,7 @@ func TestDecodeStore(t *testing.T) { Description: "ClassDescription", Uri: "ClassURI", } - classBz, err := cdc.Marshal(&class) + classBz, err := encCfg.Codec.Marshal(&class) require.NoError(t, err) nft := nft.NFT{ @@ -42,7 +40,7 @@ func TestDecodeStore(t *testing.T) { Id: "NFTID", Uri: "NFTURI", } - nftBz, err := cdc.Marshal(&nft) + nftBz, err := encCfg.Codec.Marshal(&nft) require.NoError(t, err) nftOfClassByOwnerValue := []byte{0x01} diff --git a/x/nft/simulation/genesis_test.go b/x/nft/simulation/genesis_test.go index 01a5c00de067..ae47c9a9602d 100644 --- a/x/nft/simulation/genesis_test.go +++ b/x/nft/simulation/genesis_test.go @@ -8,25 +8,23 @@ import ( "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/types/module" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/nft" + nftmodule "github.com/cosmos/cosmos-sdk/x/nft/module" "github.com/cosmos/cosmos-sdk/x/nft/simulation" - "github.com/cosmos/cosmos-sdk/x/nft/testutil" ) func TestRandomizedGenState(t *testing.T) { - var cdc codec.Codec - depinject.Inject(testutil.AppConfig, &cdc) + encCfg := moduletestutil.MakeTestEncodingConfig(nftmodule.AppModuleBasic{}) s := rand.NewSource(1) r := rand.New(s) simState := module.SimulationState{ AppParams: make(simtypes.AppParams), - Cdc: cdc, + Cdc: encCfg.Codec, Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), From 6fc114ceac9d7e06870772236765a6e4746ab4f1 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 5 Jul 2022 10:14:46 -0300 Subject: [PATCH 10/11] replace appconfig yaml with go --- x/nft/testutil/app_config.go | 113 +++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 x/nft/testutil/app_config.go diff --git a/x/nft/testutil/app_config.go b/x/nft/testutil/app_config.go new file mode 100644 index 000000000000..539ed518c22f --- /dev/null +++ b/x/nft/testutil/app_config.go @@ -0,0 +1,113 @@ +package testutil + +import ( + "cosmossdk.io/core/appconfig" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/nft" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" + appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" + mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" + nftmodulev1 "cosmossdk.io/api/cosmos/nft/module/v1" + paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" + stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" + txmodulev1 "cosmossdk.io/api/cosmos/tx/module/v1" +) + +var AppConfig = appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "NFTApp", + // During begin block slashing happens after distr.BeginBlocker so that + // there is nothing left over in the validator fee pool, so as to keep the + // CanWithdrawInvariant invariant. + // NOTE: staking module is required if HistoricalEntries param > 0 + // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) + BeginBlockers: []string{ + minttypes.ModuleName, + stakingtypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + genutiltypes.ModuleName, + nft.ModuleName, + paramstypes.ModuleName, + }, + EndBlockers: []string{ + stakingtypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + nft.ModuleName, + paramstypes.ModuleName, + }, + OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ + { + ModuleName: authtypes.ModuleName, + KvStoreKey: "acc", + }, + }, + InitGenesis: []string{ + authtypes.ModuleName, + banktypes.ModuleName, + stakingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + nft.ModuleName, + paramstypes.ModuleName, + }, + }), + }, + { + Name: authtypes.ModuleName, + Config: appconfig.WrapAny(&authmodulev1.Module{ + Bech32Prefix: "cosmos", + ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ + {Account: authtypes.FeeCollectorName}, + {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, + {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + {Account: nft.ModuleName}, + }, + }), + }, + { + Name: banktypes.ModuleName, + Config: appconfig.WrapAny(&bankmodulev1.Module{}), + }, + { + Name: stakingtypes.ModuleName, + Config: appconfig.WrapAny(&stakingmodulev1.Module{}), + }, + { + Name: paramstypes.ModuleName, + Config: appconfig.WrapAny(¶msmodulev1.Module{}), + }, + { + Name: "tx", + Config: appconfig.WrapAny(&txmodulev1.Module{}), + }, + { + Name: genutiltypes.ModuleName, + Config: appconfig.WrapAny(&genutilmodulev1.Module{}), + }, + { + Name: minttypes.ModuleName, + Config: appconfig.WrapAny(&mintmodulev1.Module{}), + }, + { + Name: nft.ModuleName, + Config: appconfig.WrapAny(&nftmodulev1.Module{}), + }, + }, +}) From 241aa6e99164c694be150e3a961a5422eab301a1 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Tue, 5 Jul 2022 10:16:47 -0300 Subject: [PATCH 11/11] remove comment --- x/nft/testutil/app_config.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/nft/testutil/app_config.go b/x/nft/testutil/app_config.go index 539ed518c22f..49354c549d31 100644 --- a/x/nft/testutil/app_config.go +++ b/x/nft/testutil/app_config.go @@ -28,11 +28,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{ Name: "runtime", Config: appconfig.WrapAny(&runtimev1alpha1.Module{ AppName: "NFTApp", - // During begin block slashing happens after distr.BeginBlocker so that - // there is nothing left over in the validator fee pool, so as to keep the - // CanWithdrawInvariant invariant. - // NOTE: staking module is required if HistoricalEntries param > 0 - // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) BeginBlockers: []string{ minttypes.ModuleName, stakingtypes.ModuleName,