Add tests for remaining auction module gRPC requests
All checks were successful
Integration Tests / test-integration (pull_request) Successful in 1m23s

This commit is contained in:
Prathamesh Musale 2024-03-02 09:27:59 +05:30
parent fd755d1c27
commit f11ae48e6f
2 changed files with 230 additions and 0 deletions

View File

@ -70,3 +70,188 @@ func (ets *E2ETestSuite) TestGetAllAuctionsGrpc() {
})
}
}
func (ets *E2ETestSuite) TestGetAuctionGrpc() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/auction/v1/auctions/", val.APIAddress)
testCases := []struct {
msg string
url string
errorMsg string
isErrorExpected bool
preRun func() string
}{
{
"invalid request to get an auction",
reqURL + randomAuctionID,
"",
true,
func() string { return "" },
},
{
"valid request to get an auction",
reqURL,
"",
false,
func() string { return ets.defaultAuctionId },
},
}
for _, tc := range testCases {
ets.Run(tc.msg, func() {
auctionID := tc.preRun()
resp, err := testutil.GetRequest(tc.url + auctionID)
if tc.isErrorExpected {
sr.Contains(string(resp), tc.errorMsg)
} else {
sr.NoError(err)
var auction auctiontypes.QueryAuctionResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &auction)
sr.NoError(err)
sr.Equal(auctionID, auction.Auction.Id)
}
})
}
}
func (ets *E2ETestSuite) TestGetBidsGrpc() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/auction/v1/bids/", val.APIAddress)
testCases := []struct {
msg string
url string
errorMsg string
isErrorExpected bool
preRun func() string
}{
{
"invalid request to get all bids",
reqURL,
"",
true,
func() string { return "" },
},
{
"valid request to get all bids",
reqURL,
"",
false,
func() string { return ets.createAuctionAndBid(false, true) },
},
}
for _, tc := range testCases {
ets.Run(tc.msg, func() {
auctionID := tc.preRun()
tc.url += auctionID
resp, err := testutil.GetRequest(tc.url)
if tc.isErrorExpected {
sr.Contains(string(resp), tc.errorMsg)
} else {
sr.NoError(err)
var bids auctiontypes.QueryBidsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bids)
sr.NoError(err)
sr.Equal(auctionID, bids.Bids[0].AuctionId)
}
})
}
}
func (ets *E2ETestSuite) TestGetBidGrpc() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/auction/v1/bids/", val.APIAddress)
testCases := []struct {
msg string
url string
errorMsg string
isErrorExpected bool
}{
{
"invalid request to get bid",
fmt.Sprintf("%s/%s/", reqURL, randomAuctionID),
"",
true,
},
{
"valid request to get bid",
fmt.Sprintf("%s/%s/%s", reqURL, randomAuctionID, randomBidderAddress),
"",
false,
},
}
for _, tc := range testCases {
ets.Run(tc.msg, func() {
resp, err := testutil.GetRequest(tc.url)
if tc.isErrorExpected {
sr.Contains(string(resp), tc.errorMsg)
} else {
sr.NoError(err)
var bid auctiontypes.QueryBidResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bid)
sr.NoError(err)
}
})
}
}
func (ets *E2ETestSuite) TestGetAuctionsByOwnerGrpc() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/auction/v1/by-owner/", val.APIAddress)
testCases := []struct {
msg string
url string
errorMsg string
isErrorExpected bool
}{
{
"invalid request to get auctions by owner",
reqURL,
"",
true,
},
{
"valid request to get auctions by owner",
fmt.Sprintf("%s/%s", reqURL, randomOwnerAddress), // TODO: use ownerAddress?
"",
false,
},
}
for _, tc := range testCases {
ets.Run(tc.msg, func() {
resp, err := testutil.GetRequest(tc.url)
if tc.isErrorExpected {
sr.Contains(string(resp), tc.errorMsg)
} else {
sr.NoError(err)
var auctions auctiontypes.QueryAuctionsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &auctions)
sr.NoError(err)
}
})
}
}
func (ets *E2ETestSuite) TestQueryBalanceGrpc() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/auction/v1/balance", val.APIAddress)
msg := "valid request to get the auction module balance"
ets.createAuctionAndBid(false, true)
ets.Run(msg, func() {
resp, err := testutil.GetRequest(reqURL)
sr.NoError(err)
var response auctiontypes.QueryGetAuctionModuleBalanceResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
sr.NotZero(len(response.GetBalance()))
})
}

45
tests/e2e/auction/tx.go Normal file
View File

@ -0,0 +1,45 @@
package auction
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
)
const (
sampleCommitTime = "90s"
sampleRevealTime = "5s"
placeholderAuctionId = "placeholder_auction_id"
)
func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller string) (sdk.TxResponse, error) {
val := ets.network.Validators[0]
additionalArgs := []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, caller),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
}
args = append(args, additionalArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
if err != nil {
return sdk.TxResponse{}, err
}
var resp sdk.TxResponse
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp)
if err != nil {
return sdk.TxResponse{}, err
}
err = ets.network.WaitForNextBlock()
if err != nil {
return sdk.TxResponse{}, err
}
return resp, nil
}