From 9c90f980d21df3a4861afe537f2a48752f468378 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 15 Jul 2022 08:19:51 -0500 Subject: [PATCH] refactor(types): remove dependency on simapp in integration test (#12587) ## Description Closes: #12584 - refactored tests to use a test suite initialized by `depinject` - dependency on `simapp` replaced by 3 dependencies on modules used in the integration test: bank, auth, and params. - introduces a prototype composable AppConfig configurator which I plan to reuse and refine in the future test refactors --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- testutil/configurator/configurator.go | 109 ++++++++++++++++++++++++ types/query/filtered_pagination_test.go | 73 +++++++--------- types/query/pagination_test.go | 88 +++++++++++-------- 3 files changed, 195 insertions(+), 75 deletions(-) create mode 100644 testutil/configurator/configurator.go diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go new file mode 100644 index 0000000000..a69d138e42 --- /dev/null +++ b/testutil/configurator/configurator.go @@ -0,0 +1,109 @@ +package configurator + +import ( + 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" + paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" + "cosmossdk.io/core/appconfig" + "cosmossdk.io/depinject" +) + +var beginBlockOrder = []string{ + "mint", + "staking", + "auth", + "bank", + "params", +} + +var endBlockersOrder = []string{ + "staking", + "auth", + "bank", + "mint", + "params", +} + +type ModuleOption func(options map[string]*appv1alpha1.ModuleConfig) + +func BankModule() ModuleOption { + return func(options map[string]*appv1alpha1.ModuleConfig) { + options["bank"] = &appv1alpha1.ModuleConfig{ + Name: "bank", + Config: appconfig.WrapAny(&bankmodulev1.Module{}), + } + } +} + +func AuthModule() ModuleOption { + return func(options map[string]*appv1alpha1.ModuleConfig) { + options["auth"] = &appv1alpha1.ModuleConfig{ + Name: "auth", + Config: appconfig.WrapAny(&authmodulev1.Module{ + Bech32Prefix: "cosmos", + ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ + {Account: "fee_collector"}, + {Account: "mint", Permissions: []string{"minter"}}, + {Account: "bonded_tokens_pool", Permissions: []string{"burner", "staking"}}, + {Account: "not_bonded_tokens_pool", Permissions: []string{"burner", "staking"}}, + }, + }), + } + } +} + +func ParamsModule() ModuleOption { + return func(options map[string]*appv1alpha1.ModuleConfig) { + options["params"] = &appv1alpha1.ModuleConfig{ + Name: "params", + Config: appconfig.WrapAny(¶msmodulev1.Module{}), + } + } +} + +func NewAppConfig(opts ...ModuleOption) depinject.Config { + options := make(map[string]*appv1alpha1.ModuleConfig) + for _, opt := range opts { + opt(options) + } + + beginBlockers := make([]string, 0) + endBlockers := make([]string, 0) + overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0) + + for _, s := range beginBlockOrder { + if _, ok := options[s]; ok { + beginBlockers = append(beginBlockers, s) + } + } + + for _, s := range endBlockersOrder { + if _, ok := options[s]; ok { + endBlockers = append(endBlockers, s) + } + } + + if _, ok := options["auth"]; ok { + overrides = append(overrides, &runtimev1alpha1.StoreKeyConfig{ModuleName: "auth", KvStoreKey: "acc"}) + } + + modules := []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "TestApp", + BeginBlockers: beginBlockers, + EndBlockers: endBlockers, + OverrideStoreKeys: overrides, + }), + }, + } + + for _, m := range options { + modules = append(modules, m) + } + + return appconfig.Compose(&appv1alpha1.Config{Modules: modules}) +} diff --git a/types/query/filtered_pagination_test.go b/types/query/filtered_pagination_test.go index 2da46f8312..ee118f9c7a 100644 --- a/types/query/filtered_pagination_test.go +++ b/types/query/filtered_pagination_test.go @@ -2,7 +2,6 @@ package query_test import ( "fmt" - "testing" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" @@ -17,7 +16,6 @@ import ( var addr1 = sdk.AccAddress([]byte("addr1")) func (s *paginationTestSuite) TestFilteredPaginations() { - app, ctx, appCodec := setupTest(s.T()) var balances sdk.Coins for i := 0; i < numBalances; i++ { @@ -32,20 +30,20 @@ func (s *paginationTestSuite) TestFilteredPaginations() { balances = balances.Sort() addr1 := sdk.AccAddress([]byte("addr1")) - acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) - app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, addr1, balances)) - store := ctx.KVStore(app.GetKey(types.StoreKey)) + acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1) + s.accountKeeper.SetAccount(s.ctx, acc1) + s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)) + store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey)) // verify pagination with limit > total values pageReq := &query.PageRequest{Key: nil, Limit: 5, CountTotal: true} - balances, res, err := execFilterPaginate(store, pageReq, appCodec) + balances, res, err := execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(4, len(balances)) s.T().Log("verify empty request") - balances, res, err = execFilterPaginate(store, nil, appCodec) + balances, res, err = execFilterPaginate(store, nil, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(4, len(balances)) @@ -54,7 +52,7 @@ func (s *paginationTestSuite) TestFilteredPaginations() { s.T().Log("verify nextKey is returned if there are more results") pageReq = &query.PageRequest{Key: nil, Limit: 2, CountTotal: true} - balances, res, err = execFilterPaginate(store, pageReq, appCodec) + balances, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(2, len(balances)) @@ -64,12 +62,12 @@ func (s *paginationTestSuite) TestFilteredPaginations() { s.T().Log("verify both key and offset can't be given") pageReq = &query.PageRequest{Key: res.NextKey, Limit: 1, Offset: 2, CountTotal: true} - _, _, err = execFilterPaginate(store, pageReq, appCodec) + _, _, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().Error(err) s.T().Log("use nextKey for query") pageReq = &query.PageRequest{Key: res.NextKey, Limit: 2, CountTotal: true} - balances, res, err = execFilterPaginate(store, pageReq, appCodec) + balances, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(2, len(balances)) @@ -77,7 +75,7 @@ func (s *paginationTestSuite) TestFilteredPaginations() { s.T().Log("verify default limit") pageReq = &query.PageRequest{Key: nil, Limit: 0} - balances, res, err = execFilterPaginate(store, pageReq, appCodec) + balances, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(4, len(balances)) @@ -85,15 +83,13 @@ func (s *paginationTestSuite) TestFilteredPaginations() { s.T().Log("verify with offset") pageReq = &query.PageRequest{Offset: 2, Limit: 2} - balances, res, err = execFilterPaginate(store, pageReq, appCodec) + balances, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().LessOrEqual(len(balances), 2) } func (s *paginationTestSuite) TestReverseFilteredPaginations() { - app, ctx, appCodec := setupTest(s.T()) - var balances sdk.Coins for i := 0; i < numBalances; i++ { denom := fmt.Sprintf("foo%ddenom", i) @@ -107,20 +103,20 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() { balances = balances.Sort() addr1 := sdk.AccAddress([]byte("addr1")) - acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) - app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, addr1, balances)) - store := ctx.KVStore(app.GetKey(types.StoreKey)) + acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1) + s.accountKeeper.SetAccount(s.ctx, acc1) + s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)) + store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey)) // verify pagination with limit > total values pageReq := &query.PageRequest{Key: nil, Limit: 5, CountTotal: true, Reverse: true} - balns, res, err := execFilterPaginate(store, pageReq, appCodec) + balns, res, err := execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(5, len(balns)) s.T().Log("verify empty request") - balns, res, err = execFilterPaginate(store, nil, appCodec) + balns, res, err = execFilterPaginate(store, nil, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(10, len(balns)) @@ -129,7 +125,7 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() { s.T().Log("verify default limit") pageReq = &query.PageRequest{Reverse: true} - balns, res, err = execFilterPaginate(store, pageReq, appCodec) + balns, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(10, len(balns)) @@ -137,7 +133,7 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() { s.T().Log("verify nextKey is returned if there are more results") pageReq = &query.PageRequest{Limit: 2, CountTotal: true, Reverse: true} - balns, res, err = execFilterPaginate(store, pageReq, appCodec) + balns, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(2, len(balns)) @@ -147,12 +143,12 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() { s.T().Log("verify both key and offset can't be given") pageReq = &query.PageRequest{Key: res.NextKey, Limit: 1, Offset: 2, Reverse: true} - _, _, err = execFilterPaginate(store, pageReq, appCodec) + _, _, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().Error(err) s.T().Log("use nextKey for query and reverse true") pageReq = &query.PageRequest{Key: res.NextKey, Limit: 2, Reverse: true} - balns, res, err = execFilterPaginate(store, pageReq, appCodec) + balns, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(2, len(balns)) @@ -161,7 +157,7 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() { s.T().Log("verify last page records, nextKey for query and reverse true") pageReq = &query.PageRequest{Key: res.NextKey, Reverse: true} - balns, res, err = execFilterPaginate(store, pageReq, appCodec) + balns, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(6, len(balns)) @@ -171,9 +167,7 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() { s.Require().Equal(balances[235:241].String(), balns.Sort().String()) } -func ExampleFilteredPaginate(t *testing.T) { - app, ctx, _ := setupTest(t) - +func (s *paginationTestSuite) TestFilteredPaginate() { var balances sdk.Coins for i := 0; i < numBalances; i++ { denom := fmt.Sprintf("foo%ddenom", i) @@ -187,15 +181,15 @@ func ExampleFilteredPaginate(t *testing.T) { balances = balances.Sort() addr1 := sdk.AccAddress([]byte("addr1")) - acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) - app.AccountKeeper.SetAccount(ctx, acc1) - err := testutil.FundAccount(app.BankKeeper, ctx, addr1, balances) + acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1) + s.accountKeeper.SetAccount(s.ctx, acc1) + err := testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances) if err != nil { // should return no error fmt.Println(err) } pageReq := &query.PageRequest{Key: nil, Limit: 1, CountTotal: true} - store := ctx.KVStore(app.GetKey(types.StoreKey)) + store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey)) balancesStore := prefix.NewStore(store, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, address.MustLengthPrefix(addr1)) @@ -254,7 +248,6 @@ func execFilterPaginate(store sdk.KVStore, pageReq *query.PageRequest, appCodec } func (s *paginationTestSuite) TestFilteredPaginationsNextKey() { - app, ctx, appCodec := setupTest(s.T()) var balances sdk.Coins @@ -265,10 +258,10 @@ func (s *paginationTestSuite) TestFilteredPaginationsNextKey() { balances = balances.Sort() addr1 := sdk.AccAddress([]byte("addr1")) - acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) - app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, addr1, balances)) - store := ctx.KVStore(app.GetKey(types.StoreKey)) + acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1) + s.accountKeeper.SetAccount(s.ctx, acc1) + s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)) + store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey)) execFilterPaginate := func(store sdk.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { balancesStore := prefix.NewStore(store, types.BalancesPrefix) @@ -299,7 +292,7 @@ func (s *paginationTestSuite) TestFilteredPaginationsNextKey() { s.T().Log("verify next key of offset query") pageReq := &query.PageRequest{Key: nil, Limit: 1, CountTotal: true} - balances, res, err := execFilterPaginate(store, pageReq, appCodec) + balances, res, err := execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(1, len(balances)) @@ -308,7 +301,7 @@ func (s *paginationTestSuite) TestFilteredPaginationsNextKey() { s.Require().NotNil(res.NextKey) pageReq = &query.PageRequest{Key: res.NextKey, Limit: 1} - balances, res, err = execFilterPaginate(store, pageReq, appCodec) + balances, res, err = execFilterPaginate(store, pageReq, s.cdc) s.Require().NoError(err) s.Require().NotNil(res) s.Require().Equal(1, len(balances)) diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 784ebd5a5c..fe79af04c4 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -7,19 +7,25 @@ import ( "github.com/stretchr/testify/suite" 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/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/store/prefix" + "github.com/cosmos/cosmos-sdk/testutil/configurator" + testutilsims "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/x/auth" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + _ "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/bank/types" + _ "github.com/cosmos/cosmos-sdk/x/params" ) const ( @@ -35,12 +41,41 @@ const ( type paginationTestSuite struct { suite.Suite + ctx sdk.Context + bankKeeper bankkeeper.Keeper + accountKeeper authkeeper.AccountKeeper + cdc codec.Codec + interfaceReg codectypes.InterfaceRegistry + app *runtime.App } func TestPaginationTestSuite(t *testing.T) { suite.Run(t, new(paginationTestSuite)) } +func (s *paginationTestSuite) SetupTest() { + var ( + bankKeeper bankkeeper.Keeper + accountKeeper authkeeper.AccountKeeper + reg codectypes.InterfaceRegistry + cdc codec.Codec + ) + + app, err := testutilsims.Setup( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.ParamsModule()), + &bankKeeper, &accountKeeper, ®, &cdc) + + s.NoError(err) + + ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1}) + + s.ctx, s.bankKeeper, s.accountKeeper, s.cdc, s.app, s.interfaceReg = + ctx, bankKeeper, accountKeeper, cdc, app, reg +} + func (s *paginationTestSuite) TestParsePagination() { s.T().Log("verify default values for empty page request") pageReq := &query.PageRequest{} @@ -61,9 +96,8 @@ func (s *paginationTestSuite) TestParsePagination() { } func (s *paginationTestSuite) TestPagination() { - app, ctx, _ := setupTest(s.T()) - queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, app.BankKeeper) + queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.interfaceReg) + types.RegisterQueryServer(queryHelper, s.bankKeeper) queryClient := types.NewQueryClient(queryHelper) var balances sdk.Coins @@ -75,9 +109,9 @@ func (s *paginationTestSuite) TestPagination() { balances = balances.Sort() addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) - app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, addr1, balances)) + acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1) + s.accountKeeper.SetAccount(s.ctx, acc1) + s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)) s.T().Log("verify empty page request results a max of defaultLimit records and counts total records") pageReq := &query.PageRequest{} @@ -170,9 +204,8 @@ func (s *paginationTestSuite) TestPagination() { } func (s *paginationTestSuite) TestReversePagination() { - app, ctx, _ := setupTest(s.T()) - queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, app.BankKeeper) + queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.interfaceReg) + types.RegisterQueryServer(queryHelper, s.bankKeeper) queryClient := types.NewQueryClient(queryHelper) var balances sdk.Coins @@ -184,9 +217,9 @@ func (s *paginationTestSuite) TestReversePagination() { balances = balances.Sort() addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) - app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, addr1, balances)) + acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1) + s.accountKeeper.SetAccount(s.ctx, acc1) + s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)) s.T().Log("verify paginate with custom limit and countTotal, Reverse false") pageReq := &query.PageRequest{Limit: 2, CountTotal: true, Reverse: true, Key: nil} @@ -293,9 +326,7 @@ func (s *paginationTestSuite) TestReversePagination() { s.Require().Nil(res.Pagination.NextKey) } -func ExamplePaginate(t *testing.T) { - app, ctx, _ := setupTest(t) - +func (s *paginationTestSuite) TestPaginate() { var balances sdk.Coins for i := 0; i < 2; i++ { @@ -305,9 +336,9 @@ func ExamplePaginate(t *testing.T) { balances = balances.Sort() addr1 := sdk.AccAddress([]byte("addr1")) - acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) - app.AccountKeeper.SetAccount(ctx, acc1) - err := testutil.FundAccount(app.BankKeeper, ctx, addr1, balances) + acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1) + s.accountKeeper.SetAccount(s.ctx, acc1) + err := testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances) if err != nil { // should return no error fmt.Println(err) } @@ -315,7 +346,7 @@ func ExamplePaginate(t *testing.T) { pageReq := &query.PageRequest{Key: nil, Limit: 1, CountTotal: true} request := types.NewQueryAllBalancesRequest(addr1, pageReq) balResult := sdk.NewCoins() - authStore := ctx.KVStore(app.GetKey(types.StoreKey)) + authStore := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey)) balancesStore := prefix.NewStore(authStore, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, address.MustLengthPrefix(addr1)) pageRes, err := query.Paginate(accountStore, request.Pagination, func(key []byte, value []byte) error { @@ -334,16 +365,3 @@ func ExamplePaginate(t *testing.T) { // Output: // balances: pagination: } - -func setupTest(t *testing.T) (*simapp.SimApp, sdk.Context, codec.Codec) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1}) - appCodec := app.AppCodec() - - db := dbm.NewMemDB() - ms := store.NewCommitMultiStore(db) - - ms.LoadLatestVersion() - - return app, ctx, appCodec -}