From 73bc64f433684e61370fe75ffcea67491473c5d4 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 12 Jan 2023 21:47:24 -0300 Subject: [PATCH 1/9] test: fix flaky tests + new method RetryForBlocks --- tests/e2e/auth/suite.go | 11 +++-- tests/e2e/feegrant/suite.go | 1 - tests/e2e/gov/deposits.go | 93 ++++++++++++++++++------------------ tests/e2e/staking/suite.go | 2 +- tests/e2e/tx/service_test.go | 10 ++-- testutil/network/network.go | 56 ++++++++++++++++++---- 6 files changed, 107 insertions(+), 66 deletions(-) diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index ac5eca9a1c5f..0efabd5257fb 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -310,7 +310,6 @@ func (s *E2ETestSuite) TestCLISignBatch() { ) s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) - s.Require().NoError(s.network.WaitForNextBlock()) // fetch the sequence after a tx, should be incremented. _, seq1, err := val.ClientCtx.AccountRetriever.GetAccountNumberSequence(val.ClientCtx, val.Address) @@ -568,7 +567,10 @@ func (s *E2ETestSuite) TestCLIQueryTxCmdByEvents() { s.Require().NoError(s.network.WaitForNextBlock()) // Query the tx by hash to get the inner tx. - out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{txRes.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)}) + err = s.network.RetryForBlocks(func() error { + out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{txRes.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)}) + return err + }, 3) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) protoTx := txRes.GetTx().(*tx.Tx) @@ -1154,7 +1156,9 @@ func (s *E2ETestSuite) TestCLIMultisign() { s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse - err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = s.network.RetryForBlocks(func() error { + return val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + }, 3) s.Require().NoError(err) s.Require().True(sendTokens.Amount.Equal(balRes.Balances.AmountOf(s.cfg.BondDenom))) @@ -1683,7 +1687,6 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() { ) require.NoError(err) require.NoError(s.network.WaitForNextBlock()) - require.NoError(s.network.WaitForNextBlock()) var txRes sdk.TxResponse require.NoError(val0.ClientCtx.Codec.UnmarshalJSON(res.Bytes(), &txRes)) diff --git a/tests/e2e/feegrant/suite.go b/tests/e2e/feegrant/suite.go index a81758ecb2c6..f5ac365212b6 100644 --- a/tests/e2e/feegrant/suite.go +++ b/tests/e2e/feegrant/suite.go @@ -102,7 +102,6 @@ func (s *E2ETestSuite) createGrant(granter, grantee sdk.Address) { _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) - s.Require().NoError(s.network.WaitForNextBlock()) } func (s *E2ETestSuite) TearDownSuite() { diff --git a/tests/e2e/gov/deposits.go b/tests/e2e/gov/deposits.go index 13f4fcdf3805..7640c4abfaaf 100644 --- a/tests/e2e/gov/deposits.go +++ b/tests/e2e/gov/deposits.go @@ -2,6 +2,7 @@ package gov import ( "fmt" + "strconv" "time" "github.com/stretchr/testify/suite" @@ -19,10 +20,10 @@ import ( type DepositTestSuite struct { suite.Suite - cfg network.Config - network *network.Network - deposits sdk.Coins - proposalIDs []string + cfg network.Config + network *network.Network + // deposits sdk.Coins + // proposalIDs []string } func NewDepositTestSuite(cfg network.Config) *DepositTestSuite { @@ -35,38 +36,9 @@ func (s *DepositTestSuite) SetupSuite() { var err error s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - - s.Require().NoError(s.network.WaitForNextBlock()) - - val := s.network.Validators[0] - - deposits := sdk.Coins{ - sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(0)), - sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens), - sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Sub(sdk.NewInt(50))), - } - s.deposits = deposits - - // create 2 proposals for testing - for i := 0; i < len(deposits); i++ { - id := i + 1 - deposit := deposits[i] - - s.submitProposal(val, deposit, id) - s.proposalIDs = append(s.proposalIDs, fmt.Sprintf("%d", id)) - } } -func (s *DepositTestSuite) SetupNewSuite() { - s.T().Log("setting up new test suite") - - var err error - s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) - s.Require().NoError(err) - s.Require().NoError(s.network.WaitForNextBlock()) -} - -func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit sdk.Coin, id int) { +func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit sdk.Coin, name string) uint64 { var exactArgs []string if !initialDeposit.IsZero() { @@ -76,13 +48,25 @@ func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit _, err := govclitestutil.MsgSubmitLegacyProposal( val.ClientCtx, val.Address.String(), - fmt.Sprintf("Text Proposal %d", id), + fmt.Sprintf("Text Proposal %s", name), "Where is the title!?", v1beta1.ProposalTypeText, exactArgs..., ) s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) + + // query proposals, return the last's id + cmd := cli.GetCmdQueryProposals() + args := []string{fmt.Sprintf("--%s=json", flags.FlagOutput)} + res, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) + s.Require().NoError(err) + + var proposals v1.QueryProposalsResponse + err = s.cfg.Codec.UnmarshalJSON(res.Bytes(), &proposals) + s.Require().NoError(err) + + return proposals.Proposals[len(proposals.Proposals)-1].Id } func (s *DepositTestSuite) TearDownSuite() { @@ -93,7 +77,10 @@ func (s *DepositTestSuite) TearDownSuite() { func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() { val := s.network.Validators[0] clientCtx := val.ClientCtx - proposalID := s.proposalIDs[0] + + // submit proposal without initial deposit + id := s.submitProposal(val, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(0)), "TestQueryDepositsWithoutInitialDeposit") + proposalID := strconv.FormatUint(id, 10) // deposit amount depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String() @@ -105,7 +92,6 @@ func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() { deposit := s.queryDeposit(val, proposalID, false, "") s.Require().NotNil(deposit) s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount) - s.Require().NoError(s.network.WaitForNextBlock()) // query deposits deposits := s.queryDeposits(val, proposalID, false, "") @@ -117,12 +103,16 @@ func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() { func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() { val := s.network.Validators[0] - proposalID := s.proposalIDs[1] + depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens) + + // submit proposal with an initial deposit + id := s.submitProposal(val, depositAmount, "TestQueryDepositsWithInitialDeposit") + proposalID := strconv.FormatUint(id, 10) // query deposit deposit := s.queryDeposit(val, proposalID, false, "") s.Require().NotNil(deposit) - s.Require().Equal(sdk.Coins(deposit.Amount).String(), s.deposits[1].String()) + s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount.String()) s.Require().NoError(s.network.WaitForNextBlock()) // query deposits @@ -130,25 +120,34 @@ func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() { s.Require().NotNil(deposits) s.Require().Len(deposits.Deposits, 1) // verify initial deposit - s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), s.deposits[1].String()) + s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), depositAmount.String()) } func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() { val := s.network.Validators[0] - clientCtx := val.ClientCtx - proposalID := s.proposalIDs[2] + depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Sub(sdk.NewInt(50))) + + // submit proposal with an initial deposit + id := s.submitProposal(val, depositAmount, "TestQueryProposalAfterVotingPeriod") + proposalID := strconv.FormatUint(id, 10) + + args := []string{fmt.Sprintf("--%s=json", flags.FlagOutput)} + cmd := cli.GetCmdQueryProposals() + res, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) + fmt.Println(res.String()) + s.Require().NoError(err) // query proposal - args := []string{proposalID, fmt.Sprintf("--%s=json", flags.FlagOutput)} - cmd := cli.GetCmdQueryProposal() - _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + args = []string{proposalID, fmt.Sprintf("--%s=json", flags.FlagOutput)} + cmd = cli.GetCmdQueryProposal() + _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) s.Require().NoError(err) // waiting for deposit and voting period to end - time.Sleep(20 * time.Second) + time.Sleep(25 * time.Second) // query proposal - _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) s.Require().Error(err) s.Require().Contains(err.Error(), fmt.Sprintf("proposal %s doesn't exist", proposalID)) diff --git a/tests/e2e/staking/suite.go b/tests/e2e/staking/suite.go index bef1512bbbf9..d41036e87fb8 100644 --- a/tests/e2e/staking/suite.go +++ b/tests/e2e/staking/suite.go @@ -76,7 +76,7 @@ func (s *E2ETestSuite) SetupSuite() { out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbondingAmount) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) - s.Require().Equal(uint32(0), txRes.Code) + s.Require().Equalf(uint32(0), txRes.Code, "out: %s", txRes.RawLog) s.Require().NoError(s.network.WaitForNextBlock()) // unbonding the amount diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index 38450dc40725..3abd715149f5 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -101,10 +101,13 @@ func (s *E2ETestSuite) SetupSuite() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &tr)) s.Require().Equal(uint32(0), tr.Code) - s.Require().NoError(s.network.WaitForNextBlock()) - height, err := s.network.LatestHeight() + // s.Require().NoError(s.network.WaitForNextBlock()) + // height, err := s.network.LatestHeight() + + resp, err := cli.GetTxResponse(s.network, val.ClientCtx, tr.TxHash) s.Require().NoError(err) - s.txHeight = height + // val.RPCClient.Tx(val.ClientCtx., []byte(tr.TxHash), false) + s.txHeight = resp.Height } func (s *E2ETestSuite) TearDownSuite() { @@ -121,7 +124,6 @@ func (s *E2ETestSuite) TestQueryBySig() { s.Require().NoError(err) s.Require().NotEmpty(resp.TxResponse.TxHash) - s.Require().NoError(s.network.WaitForNextBlock()) s.Require().NoError(s.network.WaitForNextBlock()) // get the signature out of the builder diff --git a/testutil/network/network.go b/testutil/network/network.go index 1d6120940ff6..ddc07e93b4cb 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -23,13 +23,16 @@ import ( "google.golang.org/grpc" "cosmossdk.io/math" + tmlog "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/testutil/configurator" "github.com/cosmos/cosmos-sdk/testutil/testdata" - tmlog "github.com/tendermint/tendermint/libs/log" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -603,12 +606,27 @@ func (n *Network) LatestHeight() (int64, error) { return 0, errors.New("no validators available") } - status, err := n.Validators[0].RPCClient.Status(context.Background()) - if err != nil { - return 0, err - } + ticker := time.NewTicker(time.Second) + defer ticker.Stop() + + timeout := time.NewTimer(time.Second * 5) + defer timeout.Stop() - return status.SyncInfo.LatestBlockHeight, nil + var latestHeight int64 + val := n.Validators[0] + queryClient := tmservice.NewServiceClient(val.ClientCtx) + + for { + select { + case <-timeout.C: + return latestHeight, errors.New("timeout exceeded waiting for block") + case <-ticker.C: + res, err := queryClient.GetLatestBlock(context.Background(), &tmservice.GetLatestBlockRequest{}) + if err == nil && res != nil { + return res.SdkBlock.Header.Height, nil + } + } + } } // WaitForHeight performs a blocking check where it waits for a block to be @@ -633,15 +651,17 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err var latestHeight int64 val := n.Validators[0] + queryClient := tmservice.NewServiceClient(val.ClientCtx) for { select { case <-timeout.C: return latestHeight, errors.New("timeout exceeded waiting for block") case <-ticker.C: - status, err := val.RPCClient.Status(context.Background()) - if err == nil && status != nil { - latestHeight = status.SyncInfo.LatestBlockHeight + + res, err := queryClient.GetLatestBlock(context.Background(), &tmservice.GetLatestBlockRequest{}) + if err == nil && res != nil { + latestHeight = res.GetSdkBlock().Header.Height if latestHeight >= h { return latestHeight, nil } @@ -650,6 +670,24 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err } } +// RetryForBlocks will wait for the next block and execute the function provided. +// It will do this until the function returns a nil error or until the number of +// blocks has been reached. +func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error { + for i := 0; i < blocks; i++ { + n.WaitForNextBlock() + err := retryFunc() + if err == nil { + return nil + } + // we've reached the last block to wait, return the error + if i == blocks-1 { + return err + } + } + return nil +} + // WaitForNextBlock waits for the next block to be committed, returning an error // upon failure. func (n *Network) WaitForNextBlock() error { From 7e84fecbbab0d8c703757f8de144ca29812fcc23 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 13 Jan 2023 10:52:25 -0300 Subject: [PATCH 2/9] fix test --- client/rpc/rpc_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/rpc/rpc_test.go b/client/rpc/rpc_test.go index 21dbd2b8cd3a..27cda1f2a4a5 100644 --- a/client/rpc/rpc_test.go +++ b/client/rpc/rpc_test.go @@ -3,6 +3,7 @@ package rpc_test import ( "context" "fmt" + "strconv" "testing" "github.com/stretchr/testify/suite" @@ -61,7 +62,9 @@ func (s *IntegrationTestSuite) TestCLIQueryConn() { s.NoError(err) blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader) - s.Require().Equal([]string{"1"}, blockHeight) + height, err := strconv.Atoi(blockHeight[0]) + s.Require().NoError(err) + s.Require().GreaterOrEqual(height, 1) // at least the 1st block s.Equal("hello", res.Message) } From 9cb3036aecbdd0bdb0b7d8d2090c9a10d651961a Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 13 Jan 2023 12:06:27 -0300 Subject: [PATCH 3/9] fix test --- tests/e2e/auth/suite.go | 20 ++++++++++++++++---- tests/e2e/gov/deposits.go | 2 -- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 0efabd5257fb..c3f926403c91 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -529,9 +529,15 @@ func (s *E2ETestSuite) TestCLIQueryTxCmdByHash() { s.Run(tc.name, func() { cmd := authcli.QueryTxCmd() clientCtx := val.ClientCtx + var ( + out testutil.BufferWriter + err error + ) - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - + err = s.network.RetryForBlocks(func() error { + out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) + return err + }, 2) if tc.expectErr { s.Require().Error(err) s.Require().NotEqual("internal", err.Error()) @@ -687,7 +693,10 @@ func (s *E2ETestSuite) TestCLIQueryTxsCmdByEvents() { s.Require().NoError(s.network.WaitForNextBlock()) // Query the tx by hash to get the inner tx. - out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{txRes.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)}) + err = s.network.RetryForBlocks(func() error { + out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{txRes.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)}) + return err + }, 3) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) @@ -867,7 +876,10 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().NoError(s.network.WaitForNextBlock()) // Ensure destiny account state - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr) + err = s.network.RetryForBlocks(func() error { + resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr) + return err + }, 3) s.Require().NoError(err) err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) diff --git a/tests/e2e/gov/deposits.go b/tests/e2e/gov/deposits.go index 7640c4abfaaf..59907d3282ac 100644 --- a/tests/e2e/gov/deposits.go +++ b/tests/e2e/gov/deposits.go @@ -22,8 +22,6 @@ type DepositTestSuite struct { cfg network.Config network *network.Network - // deposits sdk.Coins - // proposalIDs []string } func NewDepositTestSuite(cfg network.Config) *DepositTestSuite { From dec240e17e216d9a8bf8d9c5396ec6a8495a72f0 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 13 Jan 2023 12:44:54 -0300 Subject: [PATCH 4/9] fix test --- tests/e2e/staking/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/staking/suite.go b/tests/e2e/staking/suite.go index d41036e87fb8..bef1512bbbf9 100644 --- a/tests/e2e/staking/suite.go +++ b/tests/e2e/staking/suite.go @@ -76,7 +76,7 @@ func (s *E2ETestSuite) SetupSuite() { out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbondingAmount) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) - s.Require().Equalf(uint32(0), txRes.Code, "out: %s", txRes.RawLog) + s.Require().Equal(uint32(0), txRes.Code) s.Require().NoError(s.network.WaitForNextBlock()) // unbonding the amount From b5d8839350e03a8e5a511c5236d1ea24adcc236f Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 13 Jan 2023 15:16:33 -0300 Subject: [PATCH 5/9] fix test --- tests/e2e/staking/suite.go | 62 ++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/tests/e2e/staking/suite.go b/tests/e2e/staking/suite.go index bef1512bbbf9..07a7f41ae305 100644 --- a/tests/e2e/staking/suite.go +++ b/tests/e2e/staking/suite.go @@ -2,6 +2,7 @@ package testutil import ( "context" + "errors" "fmt" "strings" "testing" @@ -47,7 +48,7 @@ func (s *E2ETestSuite) SetupSuite() { var err error s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - s.Require().NoError(s.network.WaitForNextBlock()) + // s.Require().NoError(s.network.WaitForNextBlock()) unbond, err := sdk.ParseCoinNormalized("10stake") s.Require().NoError(err) @@ -1460,8 +1461,8 @@ func (s *E2ETestSuite) TestBlockResults() { require.NoError(s.network.WaitForNextBlock()) // Use CLI to create a delegation from the new account to validator `val`. - delHeight, err := s.network.LatestHeight() - require.NoError(err) + // delHeight, err := s.network.LatestHeight() + // require.NoError(err) cmd := cli.NewDelegateCmd() _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, []string{ val.ValAddress.String(), @@ -1480,31 +1481,52 @@ func (s *E2ETestSuite) TestBlockResults() { // Loop until we find a block result with the correct validator updates. // By experience, it happens around 2 blocks after `delHeight`. - for { + s.network.RetryForBlocks(func() error { latestHeight, err := s.network.LatestHeight() require.NoError(err) + res, err := rpcClient.BlockResults(context.Background(), &latestHeight) + if err != nil { + return err + } - // Wait maximum 10 blocks, or else fail test. - if latestHeight > delHeight+10 { - s.Fail("timeout reached") + if len(res.ValidatorUpdates) == 0 { + return errors.New("validator update not found yet") } - res, err := rpcClient.BlockResults(context.Background(), &latestHeight) - require.NoError(err) + valUpdate := res.ValidatorUpdates[0] + require.Equal( + valUpdate.GetPubKey().Sum.(*crypto.PublicKey_Ed25519).Ed25519, + val.PubKey.Bytes(), + ) - if len(res.ValidatorUpdates) > 0 { - valUpdate := res.ValidatorUpdates[0] - require.Equal( - valUpdate.GetPubKey().Sum.(*crypto.PublicKey_Ed25519).Ed25519, - val.PubKey.Bytes(), - ) + return nil - // We got our validator update, test passed. - break - } + }, 10) + // for { + // latestHeight, err := s.network.LatestHeight() + // require.NoError(err) - s.network.WaitForNextBlock() - } + // // Wait maximum 10 blocks, or else fail test. + // if latestHeight > delHeight+10 { + // s.Fail("timeout reached") + // } + + // res, err := rpcClient.BlockResults(context.Background(), &latestHeight) + // require.NoError(err) + + // if len(res.ValidatorUpdates) > 0 { + // valUpdate := res.ValidatorUpdates[0] + // require.Equal( + // valUpdate.GetPubKey().Sum.(*crypto.PublicKey_Ed25519).Ed25519, + // val.PubKey.Bytes(), + // ) + + // // We got our validator update, test passed. + // break + // } + + // require.NoError(s.network.WaitForNextBlock()) + // } } // https://github.com/cosmos/cosmos-sdk/issues/10660 From 8ffd97fef6652777569fe466da40b13b227eadce Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 13 Jan 2023 20:01:19 -0300 Subject: [PATCH 6/9] remove commetns --- tests/e2e/staking/suite.go | 28 ---------------------------- tests/e2e/tx/service_test.go | 4 ---- 2 files changed, 32 deletions(-) diff --git a/tests/e2e/staking/suite.go b/tests/e2e/staking/suite.go index 07a7f41ae305..6bcc5c6a7c6a 100644 --- a/tests/e2e/staking/suite.go +++ b/tests/e2e/staking/suite.go @@ -48,7 +48,6 @@ func (s *E2ETestSuite) SetupSuite() { var err error s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - // s.Require().NoError(s.network.WaitForNextBlock()) unbond, err := sdk.ParseCoinNormalized("10stake") s.Require().NoError(err) @@ -1461,8 +1460,6 @@ func (s *E2ETestSuite) TestBlockResults() { require.NoError(s.network.WaitForNextBlock()) // Use CLI to create a delegation from the new account to validator `val`. - // delHeight, err := s.network.LatestHeight() - // require.NoError(err) cmd := cli.NewDelegateCmd() _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, []string{ val.ValAddress.String(), @@ -1502,31 +1499,6 @@ func (s *E2ETestSuite) TestBlockResults() { return nil }, 10) - // for { - // latestHeight, err := s.network.LatestHeight() - // require.NoError(err) - - // // Wait maximum 10 blocks, or else fail test. - // if latestHeight > delHeight+10 { - // s.Fail("timeout reached") - // } - - // res, err := rpcClient.BlockResults(context.Background(), &latestHeight) - // require.NoError(err) - - // if len(res.ValidatorUpdates) > 0 { - // valUpdate := res.ValidatorUpdates[0] - // require.Equal( - // valUpdate.GetPubKey().Sum.(*crypto.PublicKey_Ed25519).Ed25519, - // val.PubKey.Bytes(), - // ) - - // // We got our validator update, test passed. - // break - // } - - // require.NoError(s.network.WaitForNextBlock()) - // } } // https://github.com/cosmos/cosmos-sdk/issues/10660 diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index 3abd715149f5..c30129073be6 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -101,12 +101,8 @@ func (s *E2ETestSuite) SetupSuite() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &tr)) s.Require().Equal(uint32(0), tr.Code) - // s.Require().NoError(s.network.WaitForNextBlock()) - // height, err := s.network.LatestHeight() - resp, err := cli.GetTxResponse(s.network, val.ClientCtx, tr.TxHash) s.Require().NoError(err) - // val.RPCClient.Tx(val.ClientCtx., []byte(tr.TxHash), false) s.txHeight = resp.Height } From fdcc9e7cedc9a039a0f52120773f42db5ae8d60f Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 13 Jan 2023 20:29:32 -0300 Subject: [PATCH 7/9] fix test --- tests/e2e/distribution/withdraw_all_suite.go | 37 +++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/e2e/distribution/withdraw_all_suite.go b/tests/e2e/distribution/withdraw_all_suite.go index f1dc83a97a79..25a431d54c1f 100644 --- a/tests/e2e/distribution/withdraw_all_suite.go +++ b/tests/e2e/distribution/withdraw_all_suite.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -94,21 +95,31 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { } _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) require.NoError(err) - require.NoError(s.network.WaitForNextBlock()) - args = []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), - fmt.Sprintf("--%s=1", cli.FlagMaxMessagesPerTx), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), - } - cmd = cli.NewWithdrawAllRewardsCmd() - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + var out testutil.BufferWriter + err = s.network.RetryForBlocks(func() error { + args = []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + fmt.Sprintf("--%s=1", cli.FlagMaxMessagesPerTx), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + } + cmd = cli.NewWithdrawAllRewardsCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + if err != nil { + return err + } + + // expect 2 transactions in the generated file when --max-msgs in a tx set 1. + txLen := len(strings.Split(strings.Trim(out.String(), "\n"), "\n")) + if txLen != 2 { + return fmt.Errorf("expected 2 transactions in the generated file, got %d", txLen) + } + return nil + }, 3) require.NoError(err) - // expect 2 transactions in the generated file when --max-msgs in a tx set 1. - s.Require().Equal(2, len(strings.Split(strings.Trim(out.String(), "\n"), "\n"))) args = []string{ fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), From 459f3558f059d12039001871e299a6c198ce7b41 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Sat, 14 Jan 2023 20:45:19 -0300 Subject: [PATCH 8/9] cl++ --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b3e59a732a..c815ad4cedb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#14609](https://github.com/cosmos/cosmos-sdk/pull/14609) Add RetryForBlocks method to use in tests that require waiting for a transaction to be included in a block. * [#14529](https://github.com/cosmos/cosmos-sdk/pull/14529) Add new property `BondDenom` to `SimulationState` struct. * (x/group, x/gov) [#14483](https://github.com/cosmos/cosmos-sdk/pull/14483) Add support for `[]string` and `[]int` in `draft-proposal` prompt. * (protobuf) [#14476](https://github.com/cosmos/cosmos-sdk/pull/14476) Clean up protobuf annotations `{accepts,implements}_interface`. From 3e3d7a42af7a9a7c66443c7e54e65f2e8bdac0eb Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 16 Jan 2023 13:39:00 -0300 Subject: [PATCH 9/9] remove print --- tests/e2e/gov/deposits.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/e2e/gov/deposits.go b/tests/e2e/gov/deposits.go index 59907d3282ac..0e8f5e6ed0b4 100644 --- a/tests/e2e/gov/deposits.go +++ b/tests/e2e/gov/deposits.go @@ -131,8 +131,7 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() { args := []string{fmt.Sprintf("--%s=json", flags.FlagOutput)} cmd := cli.GetCmdQueryProposals() - res, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - fmt.Println(res.String()) + _, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) s.Require().NoError(err) // query proposal