diff --git a/tests/e2e/auction/grpc.go b/tests/e2e/auction/grpc.go index f4503d49..ad3cabc2 100644 --- a/tests/e2e/auction/grpc.go +++ b/tests/e2e/auction/grpc.go @@ -169,23 +169,29 @@ func (ets *E2ETestSuite) TestGetBidGrpc() { url string errorMsg string isErrorExpected bool + preRun func() string }{ { "invalid request to get bid", - fmt.Sprintf("%s/%s/", reqURL, randomAuctionID), + reqURL, "", true, + func() string { return randomAuctionID }, }, { "valid request to get bid", - fmt.Sprintf("%s/%s/%s", reqURL, randomAuctionID, randomBidderAddress), + reqURL, "", false, + func() string { return ets.createAuctionAndBid(false, true) }, }, } for _, tc := range testCases { ets.Run(tc.msg, func() { + auctionID := tc.preRun() + tc.url += auctionID + "/" + bidderAddress resp, err := testutil.GetRequest(tc.url) + if tc.isErrorExpected { sr.Contains(string(resp), tc.errorMsg) } else { diff --git a/tests/e2e/auction/suite.go b/tests/e2e/auction/suite.go index 844c323d..5cd1f3dc 100644 --- a/tests/e2e/auction/suite.go +++ b/tests/e2e/auction/suite.go @@ -39,15 +39,16 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { } func (ets *E2ETestSuite) SetupSuite() { //nolint: all + sr := ets.Require() ets.T().Log("setting up e2e test suite") var err error ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg) - ets.Require().NoError(err) + sr.NoError(err) _, err = ets.network.WaitForHeight(1) - ets.Require().NoError(err) + sr.NoError(err) // setting up random owner and bidder accounts 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=true", flags.FlagSkipConfirmation), 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()), ) sr.NoError(err) *accountAddress = newAddr.String() + + // wait for tx to take effect + err = ets.network.WaitForNextBlock() + sr.NoError(err) } func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) string { @@ -90,9 +95,6 @@ func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) stri sr := ets.Require() auctionId := "" - err := ets.network.WaitForNextBlock() - sr.NoError(err) - if createAuction { auctionArgs := []string{ sampleCommitTime, sampleRevealTime, diff --git a/tests/e2e/auction/tx.go b/tests/e2e/auction/tx.go index 419dcbd3..1675d25e 100644 --- a/tests/e2e/auction/tx.go +++ b/tests/e2e/auction/tx.go @@ -7,6 +7,9 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" + + auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction" + "git.vdb.to/cerc-io/laconic2d/x/auction/client/cli" ) const ( @@ -15,6 +18,63 @@ const ( 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) { val := ets.network.Validators[0] additionalArgs := []string{ diff --git a/tests/e2e/common.go b/tests/e2e/common.go index 12adbffc..7a746eb1 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -18,10 +18,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" 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" bondmodule "git.vdb.to/cerc-io/laconic2d/x/bond/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 @@ -52,9 +53,6 @@ func NewTestNetworkFixture() network.TestFixture { return app } - // Update prefixes - params.SetAddressPrefixes() - return network.TestFixture{ AppConstructor: appCtr, GenesisState: app.DefaultGenesis(),