From 6c2f3c288f4778e8855434ced47f4e4fe0c5ddba Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 28 Feb 2024 16:21:18 +0530 Subject: [PATCH] Add a test for getting auction by id --- go.mod | 2 +- .../integration/auction/keeper/common_test.go | 9 +++ .../auction/keeper/query_server_test.go | 77 +++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 21ec8029..c3677768 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( google.golang.org/grpc v1.60.1 google.golang.org/protobuf v1.32.0 gopkg.in/yaml.v3 v3.0.1 - gotest.tools/v3 v3.5.1 ) require ( @@ -180,6 +179,7 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gotest.tools/v3 v3.5.1 // indirect lukechampine.com/blake3 v1.1.6 // indirect nhooyr.io/websocket v1.8.6 // indirect pgregory.net/rapid v1.1.0 // indirect diff --git a/tests/integration/auction/keeper/common_test.go b/tests/integration/auction/keeper/common_test.go index 0014a844..4335fcf6 100644 --- a/tests/integration/auction/keeper/common_test.go +++ b/tests/integration/auction/keeper/common_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "testing" "cosmossdk.io/core/appmodule" @@ -23,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" auctionTypes "git.vdb.to/cerc-io/laconic2d/x/auction" auctionkeeper "git.vdb.to/cerc-io/laconic2d/x/auction/keeper" @@ -59,6 +61,7 @@ func (kts *KeeperTestSuite) SetupTest() { authority := authtypes.NewModuleAddress("gov") maccPerms := map[string][]string{ + minttypes.ModuleName: {authtypes.Minter}, auctionTypes.ModuleName: {}, auctionTypes.AuctionBurnModuleAccountName: {}, bondTypes.ModuleName: {}, @@ -118,3 +121,9 @@ func (kts *KeeperTestSuite) SetupTest() { func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } + +type bondDenomProvider struct{} + +func (bdp bondDenomProvider) BondDenom(ctx context.Context) (string, error) { + return sdk.DefaultBondDenom, nil +} diff --git a/tests/integration/auction/keeper/query_server_test.go b/tests/integration/auction/keeper/query_server_test.go index 2bd9f2d5..1eb63062 100644 --- a/tests/integration/auction/keeper/query_server_test.go +++ b/tests/integration/auction/keeper/query_server_test.go @@ -4,9 +4,14 @@ import ( "context" "fmt" + "cosmossdk.io/math" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + types "git.vdb.to/cerc-io/laconic2d/x/auction" ) +const testCommitHash = "71D8CF34026E32A3A34C2C2D4ADF25ABC8D7943A4619761BE27F196603D91B9D" + func (kts *KeeperTestSuite) TestGrpcQueryParams() { qr := kts.app.QueryHelper() queryClient := types.NewQueryClient(qr) @@ -29,3 +34,75 @@ func (kts *KeeperTestSuite) TestGrpcQueryParams() { } } +func (kts *KeeperTestSuite) TestGrpcGetAuction() { + qr := kts.app.QueryHelper() + queryClient := types.NewQueryClient(qr) + + testCases := []struct { + msg string + req *types.QueryAuctionRequest + createAuction bool + }{ + { + "fetch auction with empty auction ID", + &types.QueryAuctionRequest{}, + false, + }, + { + "fetch auction with valid auction ID", + &types.QueryAuctionRequest{}, + true, + }, + } + + for _, test := range testCases { + kts.Run(fmt.Sprintf("Case %s", test.msg), func() { + if test.createAuction { + auction, _, err := kts.createAuctionAndCommitBid(false) + kts.Require().Nil(err) + test.req.Id = auction.Id + } + + resp, err := queryClient.GetAuction(context.Background(), test.req) + if test.createAuction { + kts.Require().Nil(err) + kts.Require().NotNil(resp.GetAuction()) + kts.Require().Equal(test.req.Id, resp.GetAuction().Id) + } else { + kts.Require().NotNil(err) + kts.Require().Error(err) + } + }) + } +} + +func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Auction, *types.Bid, error) { + ctx, k := kts.sdkCtx, kts.auctionKeeper + accCount := 1 + if commitBid { + accCount++ + } + + accounts := simtestutil.AddTestAddrs(kts.bankKeeper, bondDenomProvider{}, ctx, 2, math.NewInt(100)) + + params, err := k.GetParams(ctx) + if err != nil { + return nil, nil, err + } + + auction, err := k.CreateAuction(ctx, types.NewMsgCreateAuction(*params, accounts[0])) + if err != nil { + return nil, nil, err + } + + if commitBid { + bid, err := k.CommitBid(ctx, types.NewMsgCommitBid(auction.Id, testCommitHash, accounts[1])) + if err != nil { + return nil, nil, err + } + + return auction, bid, nil + } + + return auction, nil, nil +}