Add remaining auction module keeper tests
This commit is contained in:
parent
6c2f3c288f
commit
c3d0cca716
@ -1,7 +1,6 @@
|
|||||||
package keeper_test
|
package keeper_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"cosmossdk.io/core/appmodule"
|
"cosmossdk.io/core/appmodule"
|
||||||
@ -121,9 +120,3 @@ func (kts *KeeperTestSuite) SetupTest() {
|
|||||||
func TestKeeperTestSuite(t *testing.T) {
|
func TestKeeperTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(KeeperTestSuite))
|
suite.Run(t, new(KeeperTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
type bondDenomProvider struct{}
|
|
||||||
|
|
||||||
func (bdp bondDenomProvider) BondDenom(ctx context.Context) (string, error) {
|
|
||||||
return sdk.DefaultBondDenom, nil
|
|
||||||
}
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"cosmossdk.io/math"
|
"cosmossdk.io/math"
|
||||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||||
)
|
)
|
||||||
@ -57,17 +58,19 @@ func (kts *KeeperTestSuite) TestGrpcGetAuction() {
|
|||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||||
|
var expectedAuction types.Auction
|
||||||
if test.createAuction {
|
if test.createAuction {
|
||||||
auction, _, err := kts.createAuctionAndCommitBid(false)
|
auction, _, err := kts.createAuctionAndCommitBid(false)
|
||||||
kts.Require().Nil(err)
|
kts.Require().Nil(err)
|
||||||
test.req.Id = auction.Id
|
test.req.Id = auction.Id
|
||||||
|
expectedAuction = *auction
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := queryClient.GetAuction(context.Background(), test.req)
|
resp, err := queryClient.GetAuction(context.Background(), test.req)
|
||||||
if test.createAuction {
|
if test.createAuction {
|
||||||
kts.Require().Nil(err)
|
kts.Require().Nil(err)
|
||||||
kts.Require().NotNil(resp.GetAuction())
|
kts.Require().NotNil(resp.GetAuction())
|
||||||
kts.Require().Equal(test.req.Id, resp.GetAuction().Id)
|
kts.Require().EqualExportedValues(expectedAuction, *resp.GetAuction())
|
||||||
} else {
|
} else {
|
||||||
kts.Require().NotNil(err)
|
kts.Require().NotNil(err)
|
||||||
kts.Require().Error(err)
|
kts.Require().Error(err)
|
||||||
@ -76,6 +79,267 @@ func (kts *KeeperTestSuite) TestGrpcGetAuction() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (kts *KeeperTestSuite) TestGrpcGetAllAuctions() {
|
||||||
|
qr := kts.app.QueryHelper()
|
||||||
|
queryClient := types.NewQueryClient(qr)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
msg string
|
||||||
|
req *types.QueryAuctionsRequest
|
||||||
|
createAuctions bool
|
||||||
|
auctionCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"fetch auctions when no auctions exist",
|
||||||
|
&types.QueryAuctionsRequest{},
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"fetch auctions with one auction created",
|
||||||
|
&types.QueryAuctionsRequest{},
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||||
|
if test.createAuctions {
|
||||||
|
_, _, err := kts.createAuctionAndCommitBid(false)
|
||||||
|
kts.Require().Nil(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, _ := queryClient.Auctions(context.Background(), test.req)
|
||||||
|
kts.Require().Equal(test.auctionCount, len(resp.GetAuctions().Auctions))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kts *KeeperTestSuite) TestGrpcGetBids() {
|
||||||
|
qr := kts.app.QueryHelper()
|
||||||
|
queryClient := types.NewQueryClient(qr)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
msg string
|
||||||
|
req *types.QueryBidsRequest
|
||||||
|
createAuction bool
|
||||||
|
commitBid bool
|
||||||
|
bidCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"fetch all bids when no auction exists",
|
||||||
|
&types.QueryBidsRequest{},
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch all bids for valid auction but no added bids",
|
||||||
|
&types.QueryBidsRequest{},
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch all bids for valid auction and valid bid",
|
||||||
|
&types.QueryBidsRequest{},
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||||
|
if test.createAuction {
|
||||||
|
auction, _, err := kts.createAuctionAndCommitBid(test.commitBid)
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
test.req.AuctionId = auction.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := queryClient.GetBids(context.Background(), test.req)
|
||||||
|
if test.createAuction {
|
||||||
|
kts.Require().Nil(err)
|
||||||
|
kts.Require().Equal(test.bidCount, len(resp.GetBids()))
|
||||||
|
} else {
|
||||||
|
kts.Require().NotNil(err)
|
||||||
|
kts.Require().Error(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kts *KeeperTestSuite) TestGrpcGetBid() {
|
||||||
|
qr := kts.app.QueryHelper()
|
||||||
|
queryClient := types.NewQueryClient(qr)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
msg string
|
||||||
|
req *types.QueryBidRequest
|
||||||
|
createAuctionAndBid bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"fetch bid when bid does not exist",
|
||||||
|
&types.QueryBidRequest{},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch bid when valid bid exists",
|
||||||
|
&types.QueryBidRequest{},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||||
|
if test.createAuctionAndBid {
|
||||||
|
auction, bid, err := kts.createAuctionAndCommitBid(test.createAuctionAndBid)
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
test.req.AuctionId = auction.Id
|
||||||
|
test.req.Bidder = bid.BidderAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := queryClient.GetBid(context.Background(), test.req)
|
||||||
|
if test.createAuctionAndBid {
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
kts.Require().NotNil(resp.Bid)
|
||||||
|
kts.Require().Equal(test.req.Bidder, resp.Bid.BidderAddress)
|
||||||
|
} else {
|
||||||
|
kts.Require().NotNil(err)
|
||||||
|
kts.Require().Error(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kts *KeeperTestSuite) TestGrpcGetAuctionsByBidder() {
|
||||||
|
qr := kts.app.QueryHelper()
|
||||||
|
queryClient := types.NewQueryClient(qr)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
msg string
|
||||||
|
req *types.QueryAuctionsByBidderRequest
|
||||||
|
createAuctionAndCommitBid bool
|
||||||
|
auctionCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"get auctions by bidder with invalid bidder address",
|
||||||
|
&types.QueryAuctionsByBidderRequest{},
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get auctions by bidder with valid auction and bid",
|
||||||
|
&types.QueryAuctionsByBidderRequest{},
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||||
|
if test.createAuctionAndCommitBid {
|
||||||
|
_, bid, err := kts.createAuctionAndCommitBid(test.createAuctionAndCommitBid)
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
test.req.BidderAddress = bid.BidderAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := queryClient.AuctionsByBidder(context.Background(), test.req)
|
||||||
|
if test.createAuctionAndCommitBid {
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
kts.Require().NotNil(resp.Auctions)
|
||||||
|
kts.Require().Equal(test.auctionCount, len(resp.Auctions.Auctions))
|
||||||
|
} else {
|
||||||
|
kts.Require().NotNil(err)
|
||||||
|
kts.Require().Error(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kts *KeeperTestSuite) TestGrpcGetAuctionsByOwner() {
|
||||||
|
qr := kts.app.QueryHelper()
|
||||||
|
queryClient := types.NewQueryClient(qr)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
msg string
|
||||||
|
req *types.QueryAuctionsByOwnerRequest
|
||||||
|
createAuction bool
|
||||||
|
auctionCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"get auctions by owner with invalid owner address",
|
||||||
|
&types.QueryAuctionsByOwnerRequest{},
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get auctions by owner with valid auction",
|
||||||
|
&types.QueryAuctionsByOwnerRequest{},
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||||
|
if test.createAuction {
|
||||||
|
auction, _, err := kts.createAuctionAndCommitBid(false)
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
test.req.OwnerAddress = auction.OwnerAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := queryClient.AuctionsByOwner(context.Background(), test.req)
|
||||||
|
if test.createAuction {
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
kts.Require().NotNil(resp.Auctions)
|
||||||
|
kts.Require().Equal(test.auctionCount, len(resp.Auctions.Auctions))
|
||||||
|
} else {
|
||||||
|
kts.Require().NotNil(err)
|
||||||
|
kts.Require().Error(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kts *KeeperTestSuite) TestGrpcQueryBalance() {
|
||||||
|
qr := kts.app.QueryHelper()
|
||||||
|
queryClient := types.NewQueryClient(qr)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
msg string
|
||||||
|
req *types.QueryGetAuctionModuleBalanceRequest
|
||||||
|
createAuction bool
|
||||||
|
auctionCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"get balance with no auctions created",
|
||||||
|
&types.QueryGetAuctionModuleBalanceRequest{},
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get balance with single auction created",
|
||||||
|
&types.QueryGetAuctionModuleBalanceRequest{},
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
if test.createAuction {
|
||||||
|
_, _, err := kts.createAuctionAndCommitBid(true)
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := queryClient.GetAuctionModuleBalance(context.Background(), test.req)
|
||||||
|
kts.Require().NoError(err)
|
||||||
|
kts.Require().Equal(test.auctionCount, len(resp.GetBalance()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Auction, *types.Bid, error) {
|
func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Auction, *types.Bid, error) {
|
||||||
ctx, k := kts.sdkCtx, kts.auctionKeeper
|
ctx, k := kts.sdkCtx, kts.auctionKeeper
|
||||||
accCount := 1
|
accCount := 1
|
||||||
@ -106,3 +370,9 @@ func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Au
|
|||||||
|
|
||||||
return auction, nil, nil
|
return auction, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bondDenomProvider struct{}
|
||||||
|
|
||||||
|
func (bdp bondDenomProvider) BondDenom(ctx context.Context) (string, error) {
|
||||||
|
return sdk.DefaultBondDenom, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user