From ce005bc725a4b539e950c47fe70cbf1bbe3891f8 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 7 Mar 2024 18:51:18 +0530 Subject: [PATCH 1/5] Use variable block timeout in E2E test network --- tests/e2e/auction/suite.go | 5 +++-- tests/e2e/auction/tx.go | 3 ++- tests/e2e/bond/suite.go | 7 ++++--- tests/e2e/common.go | 5 +++++ tests/e2e/registry/suite.go | 17 +++++++++-------- testutil/network/network.go | 16 ++++++++-------- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/tests/e2e/auction/suite.go b/tests/e2e/auction/suite.go index 37d2ff10..1cfa7d51 100644 --- a/tests/e2e/auction/suite.go +++ b/tests/e2e/auction/suite.go @@ -15,6 +15,7 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + "git.vdb.to/cerc-io/laconic2d/tests/e2e" "git.vdb.to/cerc-io/laconic2d/testutil/network" types "git.vdb.to/cerc-io/laconic2d/x/auction" "git.vdb.to/cerc-io/laconic2d/x/auction/client/cli" @@ -49,7 +50,7 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg) sr.NoError(err) - _, err = ets.network.WaitForHeight(1) + _, err = ets.network.WaitForHeight(1, e2e.TenSeconds) sr.NoError(err) // setting up random owner and bidder accounts @@ -90,7 +91,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd *accountAddress = newAddr.String() // wait for tx to take effect - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) } diff --git a/tests/e2e/auction/tx.go b/tests/e2e/auction/tx.go index 1675d25e..7305fe3c 100644 --- a/tests/e2e/auction/tx.go +++ b/tests/e2e/auction/tx.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" + "git.vdb.to/cerc-io/laconic2d/tests/e2e" auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction" "git.vdb.to/cerc-io/laconic2d/x/auction/client/cli" ) @@ -96,7 +97,7 @@ func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller str return sdk.TxResponse{}, err } - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) if err != nil { return sdk.TxResponse{}, err } diff --git a/tests/e2e/bond/suite.go b/tests/e2e/bond/suite.go index 6da8cbbb..58214b2c 100644 --- a/tests/e2e/bond/suite.go +++ b/tests/e2e/bond/suite.go @@ -13,6 +13,7 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + "git.vdb.to/cerc-io/laconic2d/tests/e2e" "git.vdb.to/cerc-io/laconic2d/testutil/network" bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond" "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli" @@ -41,7 +42,7 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg) sr.NoError(err) - _, err = ets.network.WaitForHeight(1) + _, err = ets.network.WaitForHeight(1, e2e.TenSeconds) sr.NoError(err) // setting up random account @@ -78,7 +79,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd *accountAddress = newAddr.String() // wait for tx to take effect - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) } @@ -102,7 +103,7 @@ func (ets *E2ETestSuite) createBond() string { sr.Zero(d.Code) // wait for tx to take effect - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) // getting the bonds list and returning the bond-id diff --git a/tests/e2e/common.go b/tests/e2e/common.go index 0a59e1ed..e7ccb682 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -3,6 +3,7 @@ package e2e import ( "fmt" "os" + "time" "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" @@ -25,6 +26,10 @@ import ( "git.vdb.to/cerc-io/laconic2d/testutil/network" ) +const ( + TenSeconds = 10 * time.Second +) + // NewTestNetworkFixture returns a new LaconicApp AppConstructor for network simulation tests func NewTestNetworkFixture() network.TestFixture { dir, err := os.MkdirTemp("", "laconic") diff --git a/tests/e2e/registry/suite.go b/tests/e2e/registry/suite.go index 3ac4f37c..82460144 100644 --- a/tests/e2e/registry/suite.go +++ b/tests/e2e/registry/suite.go @@ -15,6 +15,7 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + "git.vdb.to/cerc-io/laconic2d/tests/e2e" "git.vdb.to/cerc-io/laconic2d/testutil/network" bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond" bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli" @@ -58,7 +59,7 @@ func (ets *E2ETestSuite) SetupSuite() { ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg) sr.NoError(err) - _, err = ets.network.WaitForHeight(2) + _, err = ets.network.WaitForHeight(2, 2*e2e.TenSeconds) sr.NoError(err) // setting up random account @@ -97,7 +98,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd *accountAddress = newAddr.String() // wait for tx to take effect - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) } @@ -121,7 +122,7 @@ func (ets *E2ETestSuite) createBond() string { sr.Zero(d.Code) // wait for tx to take effect - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) // getting the bonds list and returning the bond-id @@ -164,7 +165,7 @@ func (ets *E2ETestSuite) reserveName(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) } @@ -191,7 +192,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) // Get the bond-id @@ -214,7 +215,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) args = []string{ @@ -235,7 +236,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) } @@ -265,7 +266,7 @@ func (ets *E2ETestSuite) createRecord(bondId string) { sr.NoError(err) sr.Zero(d.Code, d.RawLog) - err = ets.network.WaitForNextBlock() + err = ets.network.WaitForNextBlock(e2e.TenSeconds) sr.NoError(err) } diff --git a/testutil/network/network.go b/testutil/network/network.go index a401a9b3..771b75b1 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -659,7 +659,7 @@ func trapSignal(cleanupFunc func()) { // LatestHeight returns the latest height of the network or an error if the // query fails or no validators exist. -func (n *Network) LatestHeight() (int64, error) { +func (n *Network) LatestHeight(t time.Duration) (int64, error) { if len(n.Validators) == 0 { return 0, errors.New("no validators available") } @@ -667,7 +667,7 @@ func (n *Network) LatestHeight() (int64, error) { ticker := time.NewTicker(time.Second) defer ticker.Stop() - timeout := time.NewTimer(time.Second * 5) + timeout := time.NewTimer(t) defer timeout.Stop() var latestHeight int64 @@ -702,8 +702,8 @@ func (n *Network) LatestHeight() (int64, error) { // 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, // an error is returned. Regardless, the latest height queried is returned. -func (n *Network) WaitForHeight(h int64) (int64, error) { - return n.WaitForHeightWithTimeout(h, 10*time.Second) +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 @@ -745,7 +745,7 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err // blocks has been reached. func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error { for i := 0; i < blocks; i++ { - _ = n.WaitForNextBlock() + _ = n.WaitForNextBlock(10 * time.Second) err := retryFunc() if err == nil { return nil @@ -760,13 +760,13 @@ func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error { // WaitForNextBlock waits for the next block to be committed, returning an error // upon failure. -func (n *Network) WaitForNextBlock() error { - lastBlock, err := n.LatestHeight() +func (n *Network) WaitForNextBlock(t time.Duration) error { + lastBlock, err := n.LatestHeight(t) if err != nil { return err } - _, err = n.WaitForHeight(lastBlock + 1) + _, err = n.WaitForHeight(lastBlock+1, t) if err != nil { return err } -- 2.45.2 From f2345ea0897dbe6495add0fa21baaf54993fea38 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 11 Mar 2024 12:15:50 +0530 Subject: [PATCH 2/5] Disable timeouts in E2E test network --- testutil/network/network.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index 771b75b1..f55ca8a5 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -676,8 +676,8 @@ func (n *Network) LatestHeight(t time.Duration) (int64, error) { for { select { - case <-timeout.C: - return latestHeight, errors.New("timeout exceeded waiting for block") + // case <-timeout.C: + // return latestHeight, errors.New("timeout exceeded waiting for block") case <-ticker.C: done := make(chan struct{}) go func() { @@ -695,6 +695,7 @@ func (n *Network) LatestHeight(t time.Duration) (int64, error) { return latestHeight, nil } } + default: //nolint: all } } } @@ -725,8 +726,8 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err for { select { - case <-timeout.C: - return latestHeight, errors.New("timeout exceeded waiting for block") + // case <-timeout.C: + // return latestHeight, errors.New("timeout exceeded waiting for block") case <-ticker.C: res, err := queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{}) @@ -736,6 +737,7 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err return latestHeight, nil } } + default: //nolint: all } } } -- 2.45.2 From 8fbf6455927c31a329944544480d2ad1bc1e5a7d Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 11 Mar 2024 13:53:31 +0530 Subject: [PATCH 3/5] Update reserve authority command usage in tests --- tests/e2e/registry/suite.go | 4 ++-- x/registry/client/cli/tx.go | 21 +++++---------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/tests/e2e/registry/suite.go b/tests/e2e/registry/suite.go index 82460144..117198c8 100644 --- a/tests/e2e/registry/suite.go +++ b/tests/e2e/registry/suite.go @@ -150,7 +150,7 @@ func (ets *E2ETestSuite) reserveName(authorityName string) { cmd := cli.GetCmdReserveAuthority() args := []string{ authorityName, - fmt.Sprintf("--owner=%s", ets.accountAddress), + ets.accountAddress, fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=json", flags.FlagOutput), @@ -178,7 +178,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) { cmd := cli.GetCmdReserveAuthority() args := []string{ authorityName, - fmt.Sprintf("--owner=%s", ets.accountAddress), + ets.accountAddress, fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=json", flags.FlagOutput), diff --git a/x/registry/client/cli/tx.go b/x/registry/client/cli/tx.go index f0c63f72..c2d400d9 100644 --- a/x/registry/client/cli/tx.go +++ b/x/registry/client/cli/tx.go @@ -88,27 +88,16 @@ func GetPayloadFromFile(filePath string) (*registrytypes.ReadablePayload, error) // GetCmdReserveAuthority is the CLI command for reserving a name. func GetCmdReserveAuthority() *cobra.Command { cmd := &cobra.Command{ - Use: "reserve-name [name]", - Short: "Reserve name.", - Long: strings.TrimSpace( - fmt.Sprintf(`Reserver name with owner address . -Example: -$ %s tx %s reserve-name [name] --owner [ownerAddress] -`, - version.AppName, registrytypes.ModuleName, - ), - ), - Args: cobra.ExactArgs(1), + Use: "reserve-authority [name]", + Short: "Reserve authority name", + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - owner, err := cmd.Flags().GetString("owner") - if err != nil { - return err - } - ownerAddress, err := sdk.AccAddressFromBech32(owner) + + ownerAddress, err := sdk.AccAddressFromBech32(args[1]) if err != nil { return err } -- 2.45.2 From c9b33ca00a4782cb9227c9f3b45184c28c1f51cf Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 11 Mar 2024 14:24:48 +0530 Subject: [PATCH 4/5] Wait for next block after creating an auction and clean up --- tests/e2e/auction/suite.go | 8 +++++--- tests/e2e/auction/tx.go | 3 +-- tests/e2e/bond/suite.go | 7 +++---- tests/e2e/registry/suite.go | 17 ++++++++--------- testutil/network/network.go | 30 ++++++++---------------------- 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/tests/e2e/auction/suite.go b/tests/e2e/auction/suite.go index 1cfa7d51..13a3f19c 100644 --- a/tests/e2e/auction/suite.go +++ b/tests/e2e/auction/suite.go @@ -15,7 +15,6 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" - "git.vdb.to/cerc-io/laconic2d/tests/e2e" "git.vdb.to/cerc-io/laconic2d/testutil/network" types "git.vdb.to/cerc-io/laconic2d/x/auction" "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) sr.NoError(err) - _, err = ets.network.WaitForHeight(1, e2e.TenSeconds) + _, err = ets.network.WaitForHeight(1) sr.NoError(err) // setting up random owner and bidder accounts @@ -91,7 +90,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd *accountAddress = newAddr.String() // wait for tx to take effect - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) } @@ -111,6 +110,9 @@ func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) stri resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount) sr.NoError(err) sr.Zero(resp.Code) + err = ets.network.WaitForNextBlock() + sr.NoError(err) + out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.GetCmdList(), queryJSONFlag) sr.NoError(err) var queryResponse types.QueryAuctionsResponse diff --git a/tests/e2e/auction/tx.go b/tests/e2e/auction/tx.go index 7305fe3c..1675d25e 100644 --- a/tests/e2e/auction/tx.go +++ b/tests/e2e/auction/tx.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" - "git.vdb.to/cerc-io/laconic2d/tests/e2e" auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction" "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 } - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() if err != nil { return sdk.TxResponse{}, err } diff --git a/tests/e2e/bond/suite.go b/tests/e2e/bond/suite.go index 58214b2c..6da8cbbb 100644 --- a/tests/e2e/bond/suite.go +++ b/tests/e2e/bond/suite.go @@ -13,7 +13,6 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" - "git.vdb.to/cerc-io/laconic2d/tests/e2e" "git.vdb.to/cerc-io/laconic2d/testutil/network" bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond" "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) sr.NoError(err) - _, err = ets.network.WaitForHeight(1, e2e.TenSeconds) + _, err = ets.network.WaitForHeight(1) sr.NoError(err) // setting up random account @@ -79,7 +78,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd *accountAddress = newAddr.String() // wait for tx to take effect - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) } @@ -103,7 +102,7 @@ func (ets *E2ETestSuite) createBond() string { sr.Zero(d.Code) // wait for tx to take effect - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) // getting the bonds list and returning the bond-id diff --git a/tests/e2e/registry/suite.go b/tests/e2e/registry/suite.go index 117198c8..4d605715 100644 --- a/tests/e2e/registry/suite.go +++ b/tests/e2e/registry/suite.go @@ -15,7 +15,6 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" - "git.vdb.to/cerc-io/laconic2d/tests/e2e" "git.vdb.to/cerc-io/laconic2d/testutil/network" bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond" 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) sr.NoError(err) - _, err = ets.network.WaitForHeight(2, 2*e2e.TenSeconds) + _, err = ets.network.WaitForHeight(2) sr.NoError(err) // setting up random account @@ -98,7 +97,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd *accountAddress = newAddr.String() // wait for tx to take effect - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) } @@ -122,7 +121,7 @@ func (ets *E2ETestSuite) createBond() string { sr.Zero(d.Code) // wait for tx to take effect - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) // getting the bonds list and returning the bond-id @@ -165,7 +164,7 @@ func (ets *E2ETestSuite) reserveName(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) } @@ -192,7 +191,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) // Get the bond-id @@ -215,7 +214,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) args = []string{ @@ -236,7 +235,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) { sr.NoError(err) sr.Zero(d.Code) - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) } @@ -266,7 +265,7 @@ func (ets *E2ETestSuite) createRecord(bondId string) { sr.NoError(err) sr.Zero(d.Code, d.RawLog) - err = ets.network.WaitForNextBlock(e2e.TenSeconds) + err = ets.network.WaitForNextBlock() sr.NoError(err) } diff --git a/testutil/network/network.go b/testutil/network/network.go index f55ca8a5..ceed27e1 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -659,7 +659,7 @@ func trapSignal(cleanupFunc func()) { // LatestHeight returns the latest height of the network or an error if the // 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 { 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) defer ticker.Stop() - timeout := time.NewTimer(t) + timeout := time.NewTimer(time.Second * 5) defer timeout.Stop() var latestHeight int64 @@ -676,8 +676,6 @@ func (n *Network) LatestHeight(t time.Duration) (int64, error) { for { select { - // case <-timeout.C: - // return latestHeight, errors.New("timeout exceeded waiting for block") case <-ticker.C: done := make(chan struct{}) 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 -// committed after a given block. If that height is not reached within a timeout, -// an error is returned. Regardless, the latest height queried is returned. -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) { +// committed after a given block. +func (n *Network) WaitForHeight(h int64) (int64, error) { ticker := time.NewTicker(time.Second) defer ticker.Stop() - timeout := time.NewTimer(t) - defer timeout.Stop() - if len(n.Validators) == 0 { return 0, errors.New("no validators available") } @@ -726,8 +714,6 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err for { select { - // case <-timeout.C: - // return latestHeight, errors.New("timeout exceeded waiting for block") case <-ticker.C: 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. func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error { for i := 0; i < blocks; i++ { - _ = n.WaitForNextBlock(10 * time.Second) + _ = n.WaitForNextBlock() err := retryFunc() if err == 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 // upon failure. -func (n *Network) WaitForNextBlock(t time.Duration) error { - lastBlock, err := n.LatestHeight(t) +func (n *Network) WaitForNextBlock() error { + lastBlock, err := n.LatestHeight() if err != nil { return err } - _, err = n.WaitForHeight(lastBlock+1, t) + _, err = n.WaitForHeight(lastBlock + 1) if err != nil { return err } -- 2.45.2 From a69390754814843288cb8dfed0f3607e287b9411 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 11 Mar 2024 15:07:21 +0530 Subject: [PATCH 5/5] Remove unused constant --- tests/e2e/common.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/e2e/common.go b/tests/e2e/common.go index e7ccb682..0a59e1ed 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -3,7 +3,6 @@ package e2e import ( "fmt" "os" - "time" "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" @@ -26,10 +25,6 @@ import ( "git.vdb.to/cerc-io/laconic2d/testutil/network" ) -const ( - TenSeconds = 10 * time.Second -) - // NewTestNetworkFixture returns a new LaconicApp AppConstructor for network simulation tests func NewTestNetworkFixture() network.TestFixture { dir, err := os.MkdirTemp("", "laconic") -- 2.45.2