Add e2e tests for gRPC requests and CLI commands #13
@ -169,23 +169,29 @@ func (ets *E2ETestSuite) TestGetBidGrpc() {
|
|||||||
url string
|
url string
|
||||||
errorMsg string
|
errorMsg string
|
||||||
isErrorExpected bool
|
isErrorExpected bool
|
||||||
|
preRun func() string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"invalid request to get bid",
|
"invalid request to get bid",
|
||||||
fmt.Sprintf("%s/%s/", reqURL, randomAuctionID),
|
reqURL,
|
||||||
"",
|
"",
|
||||||
true,
|
true,
|
||||||
|
func() string { return randomAuctionID },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid request to get bid",
|
"valid request to get bid",
|
||||||
fmt.Sprintf("%s/%s/%s", reqURL, randomAuctionID, randomBidderAddress),
|
reqURL,
|
||||||
"",
|
"",
|
||||||
false,
|
false,
|
||||||
|
func() string { return ets.createAuctionAndBid(false, true) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
ets.Run(tc.msg, func() {
|
ets.Run(tc.msg, func() {
|
||||||
|
auctionID := tc.preRun()
|
||||||
|
tc.url += auctionID + "/" + bidderAddress
|
||||||
resp, err := testutil.GetRequest(tc.url)
|
resp, err := testutil.GetRequest(tc.url)
|
||||||
|
|
||||||
if tc.isErrorExpected {
|
if tc.isErrorExpected {
|
||||||
sr.Contains(string(resp), tc.errorMsg)
|
sr.Contains(string(resp), tc.errorMsg)
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,15 +39,16 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ets *E2ETestSuite) SetupSuite() { //nolint: all
|
func (ets *E2ETestSuite) SetupSuite() { //nolint: all
|
||||||
|
sr := ets.Require()
|
||||||
ets.T().Log("setting up e2e test suite")
|
ets.T().Log("setting up e2e test suite")
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
||||||
ets.Require().NoError(err)
|
sr.NoError(err)
|
||||||
|
|
||||||
_, err = ets.network.WaitForHeight(1)
|
_, err = ets.network.WaitForHeight(1)
|
||||||
ets.Require().NoError(err)
|
sr.NoError(err)
|
||||||
|
|
||||||
// setting up random owner and bidder accounts
|
// setting up random owner and bidder accounts
|
||||||
ets.createAccountWithBalance(ownerAccount, &ownerAddress)
|
ets.createAccountWithBalance(ownerAccount, &ownerAddress)
|
||||||
@ -78,11 +79,15 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
|
|||||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), // TODO
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))).String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))).String()),
|
||||||
)
|
)
|
||||||
sr.NoError(err)
|
sr.NoError(err)
|
||||||
*accountAddress = newAddr.String()
|
*accountAddress = newAddr.String()
|
||||||
|
|
||||||
|
// wait for tx to take effect
|
||||||
|
err = ets.network.WaitForNextBlock()
|
||||||
|
sr.NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) string {
|
func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) string {
|
||||||
@ -90,9 +95,6 @@ func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) stri
|
|||||||
sr := ets.Require()
|
sr := ets.Require()
|
||||||
auctionId := ""
|
auctionId := ""
|
||||||
|
|
||||||
err := ets.network.WaitForNextBlock()
|
|
||||||
sr.NoError(err)
|
|
||||||
|
|
||||||
if createAuction {
|
if createAuction {
|
||||||
auctionArgs := []string{
|
auctionArgs := []string{
|
||||||
sampleCommitTime, sampleRevealTime,
|
sampleCommitTime, sampleRevealTime,
|
||||||
|
@ -7,6 +7,9 @@ import (
|
|||||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||||
|
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -15,6 +18,63 @@ const (
|
|||||||
placeholderAuctionId = "placeholder_auction_id"
|
placeholderAuctionId = "placeholder_auction_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (ets *E2ETestSuite) TestTxCommitBid() {
|
||||||
|
val := ets.network.Validators[0]
|
||||||
|
sr := ets.Require()
|
||||||
|
testCases := []struct {
|
||||||
|
msg string
|
||||||
|
args []string
|
||||||
|
createAuction bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"commit bid with missing args",
|
||||||
|
[]string{fmt.Sprintf("200%s", ets.cfg.BondDenom)},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit bid with valid args",
|
||||||
|
[]string{
|
||||||
|
placeholderAuctionId,
|
||||||
|
fmt.Sprintf("200%s", ets.cfg.BondDenom),
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
ets.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||||
|
if test.createAuction {
|
||||||
|
auctionArgs := []string{
|
||||||
|
sampleCommitTime, sampleRevealTime,
|
||||||
|
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||||
|
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||||
|
fmt.Sprintf("100%s", ets.cfg.BondDenom),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
|
||||||
|
sr.NoError(err)
|
||||||
|
|
||||||
|
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.GetCmdList(),
|
||||||
|
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)})
|
||||||
|
sr.NoError(err)
|
||||||
|
var queryResponse auctiontypes.QueryAuctionsResponse
|
||||||
|
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
||||||
|
sr.NoError(err)
|
||||||
|
sr.NotNil(queryResponse.GetAuctions())
|
||||||
|
test.args[0] = queryResponse.GetAuctions().Auctions[0].Id
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := ets.executeTx(cli.GetCmdCommitBid(), test.args, bidderAccount)
|
||||||
|
if test.createAuction {
|
||||||
|
sr.NoError(err)
|
||||||
|
sr.Zero(resp.Code)
|
||||||
|
} else {
|
||||||
|
sr.Error(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller string) (sdk.TxResponse, error) {
|
func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller string) (sdk.TxResponse, error) {
|
||||||
val := ets.network.Validators[0]
|
val := ets.network.Validators[0]
|
||||||
additionalArgs := []string{
|
additionalArgs := []string{
|
||||||
|
@ -18,10 +18,11 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
|
|
||||||
laconicApp "git.vdb.to/cerc-io/laconic2d/app"
|
laconicApp "git.vdb.to/cerc-io/laconic2d/app"
|
||||||
"git.vdb.to/cerc-io/laconic2d/app/params"
|
|
||||||
auctionmodule "git.vdb.to/cerc-io/laconic2d/x/auction/module"
|
auctionmodule "git.vdb.to/cerc-io/laconic2d/x/auction/module"
|
||||||
bondmodule "git.vdb.to/cerc-io/laconic2d/x/bond/module"
|
bondmodule "git.vdb.to/cerc-io/laconic2d/x/bond/module"
|
||||||
registrymodule "git.vdb.to/cerc-io/laconic2d/x/registry/module"
|
registrymodule "git.vdb.to/cerc-io/laconic2d/x/registry/module"
|
||||||
|
|
||||||
|
_ "git.vdb.to/cerc-io/laconic2d/app/params" // import for side-effects (see init)
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTestNetworkFixture returns a new LaconicApp AppConstructor for network simulation tests
|
// NewTestNetworkFixture returns a new LaconicApp AppConstructor for network simulation tests
|
||||||
@ -52,9 +53,6 @@ func NewTestNetworkFixture() network.TestFixture {
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update prefixes
|
|
||||||
params.SetAddressPrefixes()
|
|
||||||
|
|
||||||
return network.TestFixture{
|
return network.TestFixture{
|
||||||
AppConstructor: appCtr,
|
AppConstructor: appCtr,
|
||||||
GenesisState: app.DefaultGenesis(),
|
GenesisState: app.DefaultGenesis(),
|
||||||
|
Loading…
Reference in New Issue
Block a user