From da0ca88641c48caf75990bd53aacba43aa56a765 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 10 Feb 2021 02:26:32 +0530 Subject: [PATCH 1/2] fix tests --- types/query/filtered_pagination_test.go | 8 +++++--- types/query/pagination_test.go | 26 +++++++++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/types/query/filtered_pagination_test.go b/types/query/filtered_pagination_test.go index 898db58a1ab6..2e99c252a4aa 100644 --- a/types/query/filtered_pagination_test.go +++ b/types/query/filtered_pagination_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -101,6 +100,8 @@ func ExampleFilteredPaginate() { denom := fmt.Sprintf("test%ddenom", i) balances = append(balances, sdk.NewInt64Coin(denom, 250)) } + + balances = balances.Sort() addr1 := sdk.AccAddress([]byte("addr1")) acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) app.AccountKeeper.SetAccount(ctx, acc1) @@ -110,7 +111,7 @@ func ExampleFilteredPaginate() { } pageReq := &query.PageRequest{Key: nil, Limit: 1, CountTotal: true} - store := ctx.KVStore(app.GetKey(authtypes.StoreKey)) + store := ctx.KVStore(app.GetKey(types.StoreKey)) balancesStore := prefix.NewStore(store, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, addr1.Bytes()) @@ -144,9 +145,10 @@ func ExampleFilteredPaginate() { func execFilterPaginate(store sdk.KVStore, pageReq *query.PageRequest, appCodec codec.Marshaler) (balances sdk.Coins, res *query.PageResponse, err error) { balancesStore := prefix.NewStore(store, types.BalancesPrefix) + accountStore := prefix.NewStore(balancesStore, addr1.Bytes()) var balResult sdk.Coins - res, err = query.FilteredPaginate(balancesStore, pageReq, func(key []byte, value []byte, accumulate bool) (bool, error) { + res, err = query.FilteredPaginate(accountStore, pageReq, func(key []byte, value []byte, accumulate bool) (bool, error) { var bal sdk.Coin err := appCodec.UnmarshalBinaryBare(value, &bal) if err != nil { diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 7f37aab0f528..bfd42d5287b6 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -3,6 +3,9 @@ package query_test import ( gocontext "context" "fmt" + 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" "testing" "github.com/stretchr/testify/suite" @@ -18,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -73,13 +75,11 @@ func (s *paginationTestSuite) TestPagination() { balances = append(balances, sdk.NewInt64Coin(denom, 100)) } - balances = balances.Sort() - addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) app.AccountKeeper.SetAccount(ctx, acc1) - // s.Require().NoError(app.BankKeeper.SetBalances(ctx, addr1, balances)) - s.Require().NoError(simapp.FundAccount(app, ctx, addr1, balances)) + s.Require().NoError(app.BankKeeper.SetBalances(ctx, addr1, balances)) + s.T().Log("verify empty page request results a max of defaultLimit records and counts total records") pageReq := &query.PageRequest{} request := types.NewQueryAllBalancesRequest(addr1, pageReq) @@ -180,18 +180,19 @@ func ExamplePaginate() { balances = append(balances, sdk.NewInt64Coin(denom, 100)) } + balances = balances.Sort() addr1 := sdk.AccAddress([]byte("addr1")) acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) app.AccountKeeper.SetAccount(ctx, acc1) - err := app.BankKeeper.SetBalances(ctx, addr1, balances) - if err != nil { + err := simapp.FundAccount(app, ctx, addr1, balances) + if err != nil { // should return no error fmt.Println(err) } // Paginate example pageReq := &query.PageRequest{Key: nil, Limit: 1, CountTotal: true} request := types.NewQueryAllBalancesRequest(addr1, pageReq) balResult := sdk.NewCoins() - authStore := ctx.KVStore(app.GetKey(authtypes.StoreKey)) + authStore := ctx.KVStore(app.GetKey(types.StoreKey)) balancesStore := prefix.NewStore(authStore, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, addr1.Bytes()) pageRes, err := query.Paginate(accountStore, request.Pagination, func(key []byte, value []byte) error { @@ -228,5 +229,14 @@ func setupTest() (*simapp.SimApp, sdk.Context, codec.Marshaler) { maccPerms[multiPerm] = []string{authtypes.Burner, authtypes.Minter, authtypes.Staking} maccPerms[randomPerm] = []string{"random"} + app.AccountKeeper = authkeeper.NewAccountKeeper( + appCodec, app.GetKey(authtypes.StoreKey), app.GetSubspace(authtypes.ModuleName), + authtypes.ProtoBaseAccount, maccPerms, + ) + app.BankKeeper = bankkeeper.NewBaseKeeper( + appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, + app.GetSubspace(types.ModuleName), make(map[string]bool), + ) + return app, ctx, appCodec } From e844198d36751bda825e19bbc8834b426fc0e391 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 10 Feb 2021 02:34:55 +0530 Subject: [PATCH 2/2] lint --- types/query/pagination_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index bfd42d5287b6..0a99ed95d156 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -3,9 +3,6 @@ package query_test import ( gocontext "context" "fmt" - 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" "testing" "github.com/stretchr/testify/suite" @@ -21,6 +18,9 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + 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" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -75,10 +75,11 @@ func (s *paginationTestSuite) TestPagination() { balances = append(balances, sdk.NewInt64Coin(denom, 100)) } + balances = balances.Sort() addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1) app.AccountKeeper.SetAccount(ctx, acc1) - s.Require().NoError(app.BankKeeper.SetBalances(ctx, addr1, balances)) + s.Require().NoError(simapp.FundAccount(app, ctx, addr1, balances)) s.T().Log("verify empty page request results a max of defaultLimit records and counts total records") pageReq := &query.PageRequest{}