Wait for next block after creating an auction and clean up
All checks were successful
Integration Tests / test-integration (pull_request) Successful in 2m52s
Build / build (pull_request) Successful in 3m4s
Lint / Run golangci-lint (pull_request) Successful in 4m57s
Unit Tests / test-unit (pull_request) Successful in 2m4s
E2E Tests / test-e2e (pull_request) Successful in 2m49s

This commit is contained in:
Prathamesh Musale 2024-03-11 14:24:48 +05:30
parent 8fbf645592
commit c9b33ca00a
5 changed files with 25 additions and 40 deletions

View File

@ -15,7 +15,6 @@ 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"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
"git.vdb.to/cerc-io/laconic2d/testutil/network" "git.vdb.to/cerc-io/laconic2d/testutil/network"
types "git.vdb.to/cerc-io/laconic2d/x/auction" types "git.vdb.to/cerc-io/laconic2d/x/auction"
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli" "git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
@ -50,7 +49,7 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg) ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
sr.NoError(err) sr.NoError(err)
_, err = ets.network.WaitForHeight(1, e2e.TenSeconds) _, err = ets.network.WaitForHeight(1)
sr.NoError(err) sr.NoError(err)
// setting up random owner and bidder accounts // setting up random owner and bidder accounts
@ -91,7 +90,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
*accountAddress = newAddr.String() *accountAddress = newAddr.String()
// wait for tx to take effect // wait for tx to take effect
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
} }
@ -111,6 +110,9 @@ func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) stri
resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount) resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
sr.NoError(err) sr.NoError(err)
sr.Zero(resp.Code) sr.Zero(resp.Code)
err = ets.network.WaitForNextBlock()
sr.NoError(err)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.GetCmdList(), queryJSONFlag) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.GetCmdList(), queryJSONFlag)
sr.NoError(err) sr.NoError(err)
var queryResponse types.QueryAuctionsResponse var queryResponse types.QueryAuctionsResponse

View File

@ -8,7 +8,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction" auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli" "git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
) )
@ -97,7 +96,7 @@ func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller str
return sdk.TxResponse{}, err return sdk.TxResponse{}, err
} }
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
if err != nil { if err != nil {
return sdk.TxResponse{}, err return sdk.TxResponse{}, err
} }

View File

@ -13,7 +13,6 @@ 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"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
"git.vdb.to/cerc-io/laconic2d/testutil/network" "git.vdb.to/cerc-io/laconic2d/testutil/network"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond" bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli" "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
@ -42,7 +41,7 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg) ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
sr.NoError(err) sr.NoError(err)
_, err = ets.network.WaitForHeight(1, e2e.TenSeconds) _, err = ets.network.WaitForHeight(1)
sr.NoError(err) sr.NoError(err)
// setting up random account // setting up random account
@ -79,7 +78,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
*accountAddress = newAddr.String() *accountAddress = newAddr.String()
// wait for tx to take effect // wait for tx to take effect
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
} }
@ -103,7 +102,7 @@ func (ets *E2ETestSuite) createBond() string {
sr.Zero(d.Code) sr.Zero(d.Code)
// wait for tx to take effect // wait for tx to take effect
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
// getting the bonds list and returning the bond-id // getting the bonds list and returning the bond-id

View File

@ -15,7 +15,6 @@ 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"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
"git.vdb.to/cerc-io/laconic2d/testutil/network" "git.vdb.to/cerc-io/laconic2d/testutil/network"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond" bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli" bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
@ -59,7 +58,7 @@ func (ets *E2ETestSuite) SetupSuite() {
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg) ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
sr.NoError(err) sr.NoError(err)
_, err = ets.network.WaitForHeight(2, 2*e2e.TenSeconds) _, err = ets.network.WaitForHeight(2)
sr.NoError(err) sr.NoError(err)
// setting up random account // setting up random account
@ -98,7 +97,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
*accountAddress = newAddr.String() *accountAddress = newAddr.String()
// wait for tx to take effect // wait for tx to take effect
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
} }
@ -122,7 +121,7 @@ func (ets *E2ETestSuite) createBond() string {
sr.Zero(d.Code) sr.Zero(d.Code)
// wait for tx to take effect // wait for tx to take effect
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
// getting the bonds list and returning the bond-id // getting the bonds list and returning the bond-id
@ -165,7 +164,7 @@ func (ets *E2ETestSuite) reserveName(authorityName string) {
sr.NoError(err) sr.NoError(err)
sr.Zero(d.Code) sr.Zero(d.Code)
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
} }
@ -192,7 +191,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
sr.NoError(err) sr.NoError(err)
sr.Zero(d.Code) sr.Zero(d.Code)
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
// Get the bond-id // Get the bond-id
@ -215,7 +214,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
sr.NoError(err) sr.NoError(err)
sr.Zero(d.Code) sr.Zero(d.Code)
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
args = []string{ args = []string{
@ -236,7 +235,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
sr.NoError(err) sr.NoError(err)
sr.Zero(d.Code) sr.Zero(d.Code)
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
} }
@ -266,7 +265,7 @@ func (ets *E2ETestSuite) createRecord(bondId string) {
sr.NoError(err) sr.NoError(err)
sr.Zero(d.Code, d.RawLog) sr.Zero(d.Code, d.RawLog)
err = ets.network.WaitForNextBlock(e2e.TenSeconds) err = ets.network.WaitForNextBlock()
sr.NoError(err) sr.NoError(err)
} }

View File

@ -659,7 +659,7 @@ func trapSignal(cleanupFunc func()) {
// LatestHeight returns the latest height of the network or an error if the // LatestHeight returns the latest height of the network or an error if the
// query fails or no validators exist. // query fails or no validators exist.
func (n *Network) LatestHeight(t time.Duration) (int64, error) { func (n *Network) LatestHeight() (int64, error) {
if len(n.Validators) == 0 { if len(n.Validators) == 0 {
return 0, errors.New("no validators available") return 0, errors.New("no validators available")
} }
@ -667,7 +667,7 @@ func (n *Network) LatestHeight(t time.Duration) (int64, error) {
ticker := time.NewTicker(time.Second) ticker := time.NewTicker(time.Second)
defer ticker.Stop() defer ticker.Stop()
timeout := time.NewTimer(t) timeout := time.NewTimer(time.Second * 5)
defer timeout.Stop() defer timeout.Stop()
var latestHeight int64 var latestHeight int64
@ -676,8 +676,6 @@ func (n *Network) LatestHeight(t time.Duration) (int64, error) {
for { for {
select { select {
// case <-timeout.C:
// return latestHeight, errors.New("timeout exceeded waiting for block")
case <-ticker.C: case <-ticker.C:
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
@ -701,21 +699,11 @@ func (n *Network) LatestHeight(t time.Duration) (int64, error) {
} }
// WaitForHeight performs a blocking check where it waits for a block to be // WaitForHeight performs a blocking check where it waits for a block to be
// committed after a given block. If that height is not reached within a timeout, // committed after a given block.
// an error is returned. Regardless, the latest height queried is returned. func (n *Network) WaitForHeight(h int64) (int64, error) {
func (n *Network) WaitForHeight(h int64, t time.Duration) (int64, error) {
return n.WaitForHeightWithTimeout(h, t)
}
// WaitForHeightWithTimeout is the same as WaitForHeight except the caller can
// provide a custom timeout.
func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) {
ticker := time.NewTicker(time.Second) ticker := time.NewTicker(time.Second)
defer ticker.Stop() defer ticker.Stop()
timeout := time.NewTimer(t)
defer timeout.Stop()
if len(n.Validators) == 0 { if len(n.Validators) == 0 {
return 0, errors.New("no validators available") return 0, errors.New("no validators available")
} }
@ -726,8 +714,6 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err
for { for {
select { select {
// case <-timeout.C:
// return latestHeight, errors.New("timeout exceeded waiting for block")
case <-ticker.C: case <-ticker.C:
res, err := queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{}) res, err := queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{})
@ -747,7 +733,7 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err
// blocks has been reached. // blocks has been reached.
func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error { func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error {
for i := 0; i < blocks; i++ { for i := 0; i < blocks; i++ {
_ = n.WaitForNextBlock(10 * time.Second) _ = n.WaitForNextBlock()
err := retryFunc() err := retryFunc()
if err == nil { if err == nil {
return nil return nil
@ -762,13 +748,13 @@ func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error {
// WaitForNextBlock waits for the next block to be committed, returning an error // WaitForNextBlock waits for the next block to be committed, returning an error
// upon failure. // upon failure.
func (n *Network) WaitForNextBlock(t time.Duration) error { func (n *Network) WaitForNextBlock() error {
lastBlock, err := n.LatestHeight(t) lastBlock, err := n.LatestHeight()
if err != nil { if err != nil {
return err return err
} }
_, err = n.WaitForHeight(lastBlock+1, t) _, err = n.WaitForHeight(lastBlock + 1)
if err != nil { if err != nil {
return err return err
} }