From 2ada9f5601b627224e5c075f638a1f0f2be9bcb5 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Mon, 21 Mar 2022 12:14:10 -0700 Subject: [PATCH 1/4] feat: SellOrders query and sub-queries --- .../server/marketplace/query_sell_orders.go | 116 +++++++++++++++ .../marketplace/query_sell_orders_test.go | 137 ++++++++++++++++++ x/ecocredit/server/marketplace/sell_test.go | 6 +- 3 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 x/ecocredit/server/marketplace/query_sell_orders.go create mode 100644 x/ecocredit/server/marketplace/query_sell_orders_test.go diff --git a/x/ecocredit/server/marketplace/query_sell_orders.go b/x/ecocredit/server/marketplace/query_sell_orders.go new file mode 100644 index 0000000000..742e0c1585 --- /dev/null +++ b/x/ecocredit/server/marketplace/query_sell_orders.go @@ -0,0 +1,116 @@ +package marketplace + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/orm/model/ormlist" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + marketplacev1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" + "github.com/regen-network/regen-ledger/types/ormutil" + v1 "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" +) + +// SellOrders queries all sell orders in state with optional pagination +func (k Keeper) SellOrders(ctx context.Context, req *v1.QuerySellOrdersRequest) (*v1.QuerySellOrdersResponse, error) { + pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) + if err != nil { + return nil, err + } + + it, err := k.stateStore.SellOrderTable().List(ctx, marketplacev1.SellOrderSellerIndexKey{}, ormlist.Paginate(pg)) + if err != nil { + return nil, err + } + defer it.Close() + + orders := make([]*v1.SellOrder, 0, 10) + for it.Next() { + v, err := it.Value() + if err != nil { + return nil, err + } + var order v1.SellOrder + err = ormutil.PulsarToGogoSlow(v, &order) + if err != nil { + return nil, err + } + orders = append(orders, &order) + } + return &v1.QuerySellOrdersResponse{SellOrders: orders}, nil +} + +// SellOrdersByBatchDenom queries all sell orders under a specific batch denom with optional pagination +func (k Keeper) SellOrdersByBatchDenom(ctx context.Context, req *v1.QuerySellOrdersByBatchDenomRequest) (*v1.QuerySellOrdersByBatchDenomResponse, error) { + pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) + if err != nil { + return nil, err + } + + batch, err := k.coreStore.BatchInfoTable().GetByBatchDenom(ctx, req.BatchDenom) + if err != nil { + return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) + } + + it, err := k.stateStore.SellOrderTable().List(ctx, marketplacev1.SellOrderBatchIdIndexKey{}.WithBatchId(batch.Id), ormlist.Paginate(pg)) + if err != nil { + return nil, err + } + defer it.Close() + + orders := make([]*v1.SellOrder, 0, 10) + for it.Next() { + v, err := it.Value() + if err != nil { + return nil, err + } + + var order v1.SellOrder + err = ormutil.PulsarToGogoSlow(v, &order) + if err != nil { + return nil, err + } + + orders = append(orders, &order) + } + + return &v1.QuerySellOrdersByBatchDenomResponse{SellOrders: orders}, nil +} + +// SellOrdersByAddress queries all sell orders created by the given address with optional pagination +func (k Keeper) SellOrdersByAddress(ctx context.Context, req *v1.QuerySellOrdersByAddressRequest) (*v1.QuerySellOrdersByAddressResponse, error) { + pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) + if err != nil { + return nil, err + } + + seller, err := sdk.AccAddressFromBech32(req.Address) + if err != nil { + return nil, err + } + + it, err := k.stateStore.SellOrderTable().List(ctx, marketplacev1.SellOrderSellerIndexKey{}.WithSeller(seller), ormlist.Paginate(pg)) + if err != nil { + return nil, err + } + defer it.Close() + + orders := make([]*v1.SellOrder, 0, 10) + for it.Next() { + v, err := it.Value() + if err != nil { + return nil, err + } + + var order v1.SellOrder + err = ormutil.PulsarToGogoSlow(v, &order) + if err != nil { + return nil, err + } + + orders = append(orders, &order) + } + + return &v1.QuerySellOrdersByAddressResponse{SellOrders: orders}, nil +} diff --git a/x/ecocredit/server/marketplace/query_sell_orders_test.go b/x/ecocredit/server/marketplace/query_sell_orders_test.go new file mode 100644 index 0000000000..31b89b14d3 --- /dev/null +++ b/x/ecocredit/server/marketplace/query_sell_orders_test.go @@ -0,0 +1,137 @@ +package marketplace + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/protobuf/types/known/timestamppb" + "gotest.tools/v3/assert" + + api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" + ecocreditv1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + "github.com/regen-network/regen-ledger/x/ecocredit" + "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" +) + +var ( + classId = "C01" + batchDenom = "C01-20200101-20200201-001" + start, end = timestamppb.Now(), timestamppb.Now() + ask = sdk.NewInt64Coin("ufoo", 10) + creditType = ecocredit.CreditType{Name: "carbon", Abbreviation: "C", Unit: "tonnes", Precision: 6} +) + +func TestSellOrders(t *testing.T) { + t.Parallel() + s := setupBase(t) + testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) + _, _, addr2 := testdata.KeyTestPubAddr() + + insertSellOrder(t, s, s.addr, 1) + insertSellOrder(t, s, addr2, 1) + + res, err := s.k.SellOrders(s.ctx, &marketplace.QuerySellOrdersRequest{ + Pagination: nil, + }) + assert.NilError(t, err) + assert.Equal(t, 2, len(res.SellOrders)) +} + +func TestSellOrdersByDenom(t *testing.T) { + t.Parallel() + s := setupBase(t) + testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) + + // make another batch + otherDenom := "C01-19990101-20290101-001" + assert.NilError(t, s.coreStore.BatchInfoTable().Insert(s.ctx, &ecocreditv1.BatchInfo{ + ProjectId: 1, + BatchDenom: otherDenom, + Metadata: "", + StartDate: nil, + EndDate: nil, + })) + + insertSellOrder(t, s, s.addr, 1) + insertSellOrder(t, s, s.addr, 2) + + // query the first denom + res, err := s.k.SellOrdersByBatchDenom(s.ctx, &marketplace.QuerySellOrdersByBatchDenomRequest{ + BatchDenom: batchDenom, + Pagination: nil, + }) + assert.NilError(t, err) + assert.Equal(t, 1, len(res.SellOrders)) + + // query the second denom + res, err = s.k.SellOrdersByBatchDenom(s.ctx, &marketplace.QuerySellOrdersByBatchDenomRequest{ + BatchDenom: otherDenom, + Pagination: nil, + }) + assert.NilError(t, err) + assert.Equal(t, 1, len(res.SellOrders)) + + // bad denom should error + res, err = s.k.SellOrdersByBatchDenom(s.ctx, &marketplace.QuerySellOrdersByBatchDenomRequest{ + BatchDenom: "yikes!", + Pagination: nil, + }) + assert.ErrorContains(t, err, ormerrors.NotFound.Error()) +} + +func TestSellOrdersByAddress(t *testing.T) { + t.Parallel() + s := setupBase(t) + testSellSetup(t, s, batchDenom, ask.Denom, ask.Denom[1:], classId, start, end, creditType) + + _, _, otherAddr := testdata.KeyTestPubAddr() + _, _, noOrdersAddr := testdata.KeyTestPubAddr() + + insertSellOrder(t, s, s.addr, 1) + insertSellOrder(t, s, otherAddr, 1) + + res, err := s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{ + Address: s.addr.String(), + Pagination: nil, + }) + assert.NilError(t, err) + assert.Equal(t, 1, len(res.SellOrders)) + + res, err = s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{ + Address: otherAddr.String(), + Pagination: nil, + }) + assert.NilError(t, err) + assert.Equal(t, 1, len(res.SellOrders)) + + // addr with no sell orders should just return empty slice + res, err = s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{ + Address: noOrdersAddr.String(), + Pagination: nil, + }) + assert.NilError(t, err) + assert.Equal(t, 0, len(res.SellOrders)) + + // bad address should fail + res, err = s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{ + Address: "foobar1vlk23jrkl", + Pagination: nil, + }) + assert.ErrorContains(t, err, "decoding bech32 failed") +} + +func insertSellOrder(t *testing.T, s *baseSuite, addr sdk.AccAddress, batchId uint64) { + sellOrder := &api.SellOrder{ + Seller: addr, + BatchId: batchId, + Quantity: "10", + MarketId: 1, + AskPrice: "10", + DisableAutoRetire: false, + Expiration: timestamppb.Now(), + Maker: false, + } + assert.NilError(t, s.marketStore.SellOrderTable().Insert(s.ctx, sellOrder)) +} diff --git a/x/ecocredit/server/marketplace/sell_test.go b/x/ecocredit/server/marketplace/sell_test.go index e8a0bc75bd..e1d8c0ac42 100644 --- a/x/ecocredit/server/marketplace/sell_test.go +++ b/x/ecocredit/server/marketplace/sell_test.go @@ -1,11 +1,12 @@ package marketplace import ( - "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit/server" "testing" "time" + "github.com/regen-network/regen-ledger/types/math" + "github.com/regen-network/regen-ledger/x/ecocredit/server" + "github.com/golang/mock/gomock" "google.golang.org/protobuf/types/known/timestamppb" "gotest.tools/v3/assert" @@ -193,6 +194,7 @@ func assertCoinsEscrowed(t *testing.T, balanceBefore, balanceAfter *ecocreditv1. assert.Check(t, calculatedESupply.Equal(supAfterEscrowed)) } +// testSellSetup sets up a batch, class, market, and issues a balance of 100 retired and tradable to the base suite's addr. func testSellSetup(t *testing.T, s *baseSuite, batchDenom, bankDenom, displayDenom, classId string, start, end *timestamppb.Timestamp, creditType ecocredit.CreditType) { assert.NilError(t, s.coreStore.BatchInfoTable().Insert(s.ctx, &ecocreditv1.BatchInfo{ ProjectId: 1, From 968acc8b7e057345f5620d47c4658b02ff9dd86c Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Mon, 21 Mar 2022 12:19:57 -0700 Subject: [PATCH 2/4] chore: fmt --- x/ecocredit/server/marketplace/sell_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x/ecocredit/server/marketplace/sell_test.go b/x/ecocredit/server/marketplace/sell_test.go index e1d8c0ac42..40214e41f0 100644 --- a/x/ecocredit/server/marketplace/sell_test.go +++ b/x/ecocredit/server/marketplace/sell_test.go @@ -4,9 +4,6 @@ import ( "testing" "time" - "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit/server" - "github.com/golang/mock/gomock" "google.golang.org/protobuf/types/known/timestamppb" "gotest.tools/v3/assert" @@ -15,8 +12,10 @@ import ( marketApi "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" ecocreditv1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + "github.com/regen-network/regen-ledger/types/math" "github.com/regen-network/regen-ledger/x/ecocredit" v1 "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" + "github.com/regen-network/regen-ledger/x/ecocredit/server" ) func TestSell_Valid(t *testing.T) { From f142cc931fe0e9172da944cf609a20100cbc6f95 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Mon, 21 Mar 2022 12:38:24 -0700 Subject: [PATCH 3/4] chore: reorder --- x/ecocredit/server/marketplace/query_sell_orders_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/ecocredit/server/marketplace/query_sell_orders_test.go b/x/ecocredit/server/marketplace/query_sell_orders_test.go index 31b89b14d3..b480ad84ab 100644 --- a/x/ecocredit/server/marketplace/query_sell_orders_test.go +++ b/x/ecocredit/server/marketplace/query_sell_orders_test.go @@ -3,11 +3,12 @@ package marketplace import ( "testing" + "google.golang.org/protobuf/types/known/timestamppb" + "gotest.tools/v3/assert" + "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" - "google.golang.org/protobuf/types/known/timestamppb" - "gotest.tools/v3/assert" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" ecocreditv1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" From 58e3f55667b5fb8c1d931f65d53ccaf190895689 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Mon, 21 Mar 2022 17:31:39 -0700 Subject: [PATCH 4/4] chore: add pagination tests --- .../server/marketplace/query_sell_orders.go | 50 ++++++++++++------- .../marketplace/query_sell_orders_test.go | 23 ++++++--- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/x/ecocredit/server/marketplace/query_sell_orders.go b/x/ecocredit/server/marketplace/query_sell_orders.go index 742e0c1585..a6ad484bb4 100644 --- a/x/ecocredit/server/marketplace/query_sell_orders.go +++ b/x/ecocredit/server/marketplace/query_sell_orders.go @@ -7,42 +7,48 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - marketplacev1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" + api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" "github.com/regen-network/regen-ledger/types/ormutil" - v1 "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" + "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" ) // SellOrders queries all sell orders in state with optional pagination -func (k Keeper) SellOrders(ctx context.Context, req *v1.QuerySellOrdersRequest) (*v1.QuerySellOrdersResponse, error) { +func (k Keeper) SellOrders(ctx context.Context, req *marketplace.QuerySellOrdersRequest) (*marketplace.QuerySellOrdersResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { return nil, err } - it, err := k.stateStore.SellOrderTable().List(ctx, marketplacev1.SellOrderSellerIndexKey{}, ormlist.Paginate(pg)) + it, err := k.stateStore.SellOrderTable().List(ctx, api.SellOrderSellerIndexKey{}, ormlist.Paginate(pg)) if err != nil { return nil, err } defer it.Close() - orders := make([]*v1.SellOrder, 0, 10) + orders := make([]*marketplace.SellOrder, 0, 10) for it.Next() { v, err := it.Value() if err != nil { return nil, err } - var order v1.SellOrder + var order marketplace.SellOrder err = ormutil.PulsarToGogoSlow(v, &order) if err != nil { return nil, err } orders = append(orders, &order) } - return &v1.QuerySellOrdersResponse{SellOrders: orders}, nil + + pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) + if err != nil { + return nil, err + } + + return &marketplace.QuerySellOrdersResponse{SellOrders: orders, Pagination: pr}, nil } // SellOrdersByBatchDenom queries all sell orders under a specific batch denom with optional pagination -func (k Keeper) SellOrdersByBatchDenom(ctx context.Context, req *v1.QuerySellOrdersByBatchDenomRequest) (*v1.QuerySellOrdersByBatchDenomResponse, error) { +func (k Keeper) SellOrdersByBatchDenom(ctx context.Context, req *marketplace.QuerySellOrdersByBatchDenomRequest) (*marketplace.QuerySellOrdersByBatchDenomResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { return nil, err @@ -53,20 +59,20 @@ func (k Keeper) SellOrdersByBatchDenom(ctx context.Context, req *v1.QuerySellOrd return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) } - it, err := k.stateStore.SellOrderTable().List(ctx, marketplacev1.SellOrderBatchIdIndexKey{}.WithBatchId(batch.Id), ormlist.Paginate(pg)) + it, err := k.stateStore.SellOrderTable().List(ctx, api.SellOrderBatchIdIndexKey{}.WithBatchId(batch.Id), ormlist.Paginate(pg)) if err != nil { return nil, err } defer it.Close() - orders := make([]*v1.SellOrder, 0, 10) + orders := make([]*marketplace.SellOrder, 0, 10) for it.Next() { v, err := it.Value() if err != nil { return nil, err } - var order v1.SellOrder + var order marketplace.SellOrder err = ormutil.PulsarToGogoSlow(v, &order) if err != nil { return nil, err @@ -75,11 +81,16 @@ func (k Keeper) SellOrdersByBatchDenom(ctx context.Context, req *v1.QuerySellOrd orders = append(orders, &order) } - return &v1.QuerySellOrdersByBatchDenomResponse{SellOrders: orders}, nil + pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) + if err != nil { + return nil, err + } + + return &marketplace.QuerySellOrdersByBatchDenomResponse{SellOrders: orders, Pagination: pr}, nil } // SellOrdersByAddress queries all sell orders created by the given address with optional pagination -func (k Keeper) SellOrdersByAddress(ctx context.Context, req *v1.QuerySellOrdersByAddressRequest) (*v1.QuerySellOrdersByAddressResponse, error) { +func (k Keeper) SellOrdersByAddress(ctx context.Context, req *marketplace.QuerySellOrdersByAddressRequest) (*marketplace.QuerySellOrdersByAddressResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { return nil, err @@ -90,20 +101,20 @@ func (k Keeper) SellOrdersByAddress(ctx context.Context, req *v1.QuerySellOrders return nil, err } - it, err := k.stateStore.SellOrderTable().List(ctx, marketplacev1.SellOrderSellerIndexKey{}.WithSeller(seller), ormlist.Paginate(pg)) + it, err := k.stateStore.SellOrderTable().List(ctx, api.SellOrderSellerIndexKey{}.WithSeller(seller), ormlist.Paginate(pg)) if err != nil { return nil, err } defer it.Close() - orders := make([]*v1.SellOrder, 0, 10) + orders := make([]*marketplace.SellOrder, 0, 10) for it.Next() { v, err := it.Value() if err != nil { return nil, err } - var order v1.SellOrder + var order marketplace.SellOrder err = ormutil.PulsarToGogoSlow(v, &order) if err != nil { return nil, err @@ -112,5 +123,10 @@ func (k Keeper) SellOrdersByAddress(ctx context.Context, req *v1.QuerySellOrders orders = append(orders, &order) } - return &v1.QuerySellOrdersByAddressResponse{SellOrders: orders}, nil + pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) + if err != nil { + return nil, err + } + + return &marketplace.QuerySellOrdersByAddressResponse{SellOrders: orders, Pagination: pr}, nil } diff --git a/x/ecocredit/server/marketplace/query_sell_orders_test.go b/x/ecocredit/server/marketplace/query_sell_orders_test.go index b480ad84ab..296cd15902 100644 --- a/x/ecocredit/server/marketplace/query_sell_orders_test.go +++ b/x/ecocredit/server/marketplace/query_sell_orders_test.go @@ -9,9 +9,10 @@ import ( "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" - ecocreditv1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + ecocreditApi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/marketplace" ) @@ -34,10 +35,11 @@ func TestSellOrders(t *testing.T) { insertSellOrder(t, s, addr2, 1) res, err := s.k.SellOrders(s.ctx, &marketplace.QuerySellOrdersRequest{ - Pagination: nil, + Pagination: &query.PageRequest{CountTotal: true}, }) assert.NilError(t, err) assert.Equal(t, 2, len(res.SellOrders)) + assert.Equal(t, uint64(2), res.Pagination.Total) } func TestSellOrdersByDenom(t *testing.T) { @@ -47,7 +49,7 @@ func TestSellOrdersByDenom(t *testing.T) { // make another batch otherDenom := "C01-19990101-20290101-001" - assert.NilError(t, s.coreStore.BatchInfoTable().Insert(s.ctx, &ecocreditv1.BatchInfo{ + assert.NilError(t, s.coreStore.BatchInfoTable().Insert(s.ctx, &ecocreditApi.BatchInfo{ ProjectId: 1, BatchDenom: otherDenom, Metadata: "", @@ -61,18 +63,20 @@ func TestSellOrdersByDenom(t *testing.T) { // query the first denom res, err := s.k.SellOrdersByBatchDenom(s.ctx, &marketplace.QuerySellOrdersByBatchDenomRequest{ BatchDenom: batchDenom, - Pagination: nil, + Pagination: &query.PageRequest{CountTotal: true}, }) assert.NilError(t, err) assert.Equal(t, 1, len(res.SellOrders)) + assert.Equal(t, uint64(1), res.Pagination.Total) // query the second denom res, err = s.k.SellOrdersByBatchDenom(s.ctx, &marketplace.QuerySellOrdersByBatchDenomRequest{ BatchDenom: otherDenom, - Pagination: nil, + Pagination: &query.PageRequest{CountTotal: true}, }) assert.NilError(t, err) assert.Equal(t, 1, len(res.SellOrders)) + assert.Equal(t, uint64(1), res.Pagination.Total) // bad denom should error res, err = s.k.SellOrdersByBatchDenom(s.ctx, &marketplace.QuerySellOrdersByBatchDenomRequest{ @@ -95,25 +99,28 @@ func TestSellOrdersByAddress(t *testing.T) { res, err := s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{ Address: s.addr.String(), - Pagination: nil, + Pagination: &query.PageRequest{CountTotal: true}, }) assert.NilError(t, err) assert.Equal(t, 1, len(res.SellOrders)) + assert.Equal(t, uint64(1), res.Pagination.Total) res, err = s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{ Address: otherAddr.String(), - Pagination: nil, + Pagination: &query.PageRequest{CountTotal: true}, }) assert.NilError(t, err) assert.Equal(t, 1, len(res.SellOrders)) + assert.Equal(t, uint64(1), res.Pagination.Total) // addr with no sell orders should just return empty slice res, err = s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{ Address: noOrdersAddr.String(), - Pagination: nil, + Pagination: &query.PageRequest{CountTotal: true}, }) assert.NilError(t, err) assert.Equal(t, 0, len(res.SellOrders)) + assert.Equal(t, uint64(0), res.Pagination.Total) // bad address should fail res, err = s.k.SellOrdersByAddress(s.ctx, &marketplace.QuerySellOrdersByAddressRequest{