Add a test for getting auction by id
This commit is contained in:
parent
3f25325e0f
commit
6c2f3c288f
2
go.mod
2
go.mod
@ -43,7 +43,6 @@ require (
|
|||||||
google.golang.org/grpc v1.60.1
|
google.golang.org/grpc v1.60.1
|
||||||
google.golang.org/protobuf v1.32.0
|
google.golang.org/protobuf v1.32.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
gotest.tools/v3 v3.5.1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -180,6 +179,7 @@ require (
|
|||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gotest.tools/v3 v3.5.1 // indirect
|
||||||
lukechampine.com/blake3 v1.1.6 // indirect
|
lukechampine.com/blake3 v1.1.6 // indirect
|
||||||
nhooyr.io/websocket v1.8.6 // indirect
|
nhooyr.io/websocket v1.8.6 // indirect
|
||||||
pgregory.net/rapid v1.1.0 // indirect
|
pgregory.net/rapid v1.1.0 // indirect
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package keeper_test
|
package keeper_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"cosmossdk.io/core/appmodule"
|
"cosmossdk.io/core/appmodule"
|
||||||
@ -23,6 +24,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
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"
|
auctionTypes "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||||
auctionkeeper "git.vdb.to/cerc-io/laconic2d/x/auction/keeper"
|
auctionkeeper "git.vdb.to/cerc-io/laconic2d/x/auction/keeper"
|
||||||
@ -59,6 +61,7 @@ func (kts *KeeperTestSuite) SetupTest() {
|
|||||||
authority := authtypes.NewModuleAddress("gov")
|
authority := authtypes.NewModuleAddress("gov")
|
||||||
|
|
||||||
maccPerms := map[string][]string{
|
maccPerms := map[string][]string{
|
||||||
|
minttypes.ModuleName: {authtypes.Minter},
|
||||||
auctionTypes.ModuleName: {},
|
auctionTypes.ModuleName: {},
|
||||||
auctionTypes.AuctionBurnModuleAccountName: {},
|
auctionTypes.AuctionBurnModuleAccountName: {},
|
||||||
bondTypes.ModuleName: {},
|
bondTypes.ModuleName: {},
|
||||||
@ -118,3 +121,9 @@ 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
|
||||||
|
}
|
||||||
|
@ -4,9 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"cosmossdk.io/math"
|
||||||
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
|
|
||||||
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const testCommitHash = "71D8CF34026E32A3A34C2C2D4ADF25ABC8D7943A4619761BE27F196603D91B9D"
|
||||||
|
|
||||||
func (kts *KeeperTestSuite) TestGrpcQueryParams() {
|
func (kts *KeeperTestSuite) TestGrpcQueryParams() {
|
||||||
qr := kts.app.QueryHelper()
|
qr := kts.app.QueryHelper()
|
||||||
queryClient := types.NewQueryClient(qr)
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user