From a6023966e43cd12bd49c4fdc1cf42c636d7a587e Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 4 Mar 2024 19:10:33 +0530 Subject: [PATCH] Add msg validation for auction module --- tests/e2e/bond/suite.go | 6 ++++-- x/auction/keeper/keeper.go | 9 ++++----- x/auction/keeper/msg_server.go | 10 ++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/e2e/bond/suite.go b/tests/e2e/bond/suite.go index 67f435d9..484aad86 100644 --- a/tests/e2e/bond/suite.go +++ b/tests/e2e/bond/suite.go @@ -118,6 +118,8 @@ func (ets *E2ETestSuite) createBond() string { sr.NoError(err) // extract bond id from bonds list - bond := queryResponse.GetBonds()[0] - return bond.GetId() + bonds := queryResponse.GetBonds() + sr.NotEmpty(bonds) + + return queryResponse.GetBonds()[0].GetId() } diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index edcb72ba..1ca091b3 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -285,12 +285,11 @@ func (k Keeper) QueryAuctionsByBidder(ctx sdk.Context, bidderAddress string) ([] // CreateAuction creates a new auction. func (k Keeper) CreateAuction(ctx sdk.Context, msg auctiontypes.MsgCreateAuction) (*auctiontypes.Auction, error) { - // TODO: Setup checks // Might be called from another module directly, always validate. - // err := msg.ValidateBasic() - // if err != nil { - // return nil, err - // } + err := msg.ValidateBasic() + if err != nil { + return nil, err + } signerAddress, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { diff --git a/x/auction/keeper/msg_server.go b/x/auction/keeper/msg_server.go index b2035a9e..382b1691 100644 --- a/x/auction/keeper/msg_server.go +++ b/x/auction/keeper/msg_server.go @@ -52,6 +52,11 @@ func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreate // CommitBid is the command for committing a bid // nolint: all func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) { + err := msg.ValidateBasic() + if err != nil { + return nil, err + } + ctx := sdk.UnwrapSDKContext(c) signerAddress, err := sdk.AccAddressFromBech32(msg.Signer) @@ -83,6 +88,11 @@ func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) // RevealBid is the command for revealing a bid // nolint: all func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) { + err := msg.ValidateBasic() + if err != nil { + return nil, err + } + ctx := sdk.UnwrapSDKContext(c) signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)