test: fix more flaky tests (#14699)

This commit is contained in:
Facundo Medica 2023-01-19 20:06:01 -03:00 committed by GitHub
parent d5d39c0538
commit d74d0e4e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 11 deletions

View File

@ -1164,11 +1164,12 @@ func (s *E2ETestSuite) TestCLIMultisign() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr)
s.Require().NoError(err)
var balRes banktypes.QueryAllBalancesResponse
err = s.network.RetryForBlocks(func() error {
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr)
if err != nil {
return err
}
return val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
}, 3)
s.Require().NoError(err)

View File

@ -1024,7 +1024,10 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
s.Require().NoError(s.network.WaitForNextBlock())
// query tx and check result
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
err = s.network.RetryForBlocks(func() error {
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
return err
}, 3)
s.Require().NoError(err)
s.Contains(out.String(), fmt.Sprintf("cannot send to %s address", notAllowedAddr))
}
@ -1241,7 +1244,10 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
// query tx and check result
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
err = s.network.RetryForBlocks(func() error {
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
return err
}, 3)
s.Require().NoError(err)
s.Contains(out.String(), fmt.Sprintf("cannot delegate/undelegate to %s validator", val.ValAddress.String()))
}

View File

@ -26,8 +26,8 @@ func TestDepositTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
genesisState := v1.DefaultGenesisState()
maxDepPeriod := time.Duration(15) * time.Second
votingPeriod := time.Duration(5) * time.Second
maxDepPeriod := time.Duration(20) * time.Second
votingPeriod := time.Duration(8) * time.Second
genesisState.Params.MaxDepositPeriod = &maxDepPeriod
genesisState.Params.VotingPeriod = &votingPeriod
bz, err := cfg.Codec.MarshalJSON(genesisState)

View File

@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/client/flags"
"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"
@ -111,7 +112,6 @@ func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() {
deposit := s.queryDeposit(val, proposalID, false, "")
s.Require().NotNil(deposit)
s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount.String())
s.Require().NoError(s.network.WaitForNextBlock())
// query deposits
deposits := s.queryDeposits(val, proposalID, false, "")
@ -157,7 +157,20 @@ func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID stri
args := []string{proposalID, fmt.Sprintf("--%s=json", flags.FlagOutput)}
var depositsRes *v1.QueryDepositsResponse
cmd := cli.GetCmdQueryDeposits()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
var (
out testutil.BufferWriter
err error
)
err = s.network.RetryForBlocks(func() error {
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
if err == nil {
err = val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositsRes)
return err
}
return err
}, 3)
if exceptErr {
s.Require().Error(err)
@ -166,7 +179,6 @@ func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID stri
}
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositsRes))
return depositsRes
}
@ -174,7 +186,16 @@ func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID strin
args := []string{proposalID, val.Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)}
var depositRes *v1.Deposit
cmd := cli.GetCmdQueryDeposit()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
var (
out testutil.BufferWriter
err error
)
err = s.network.RetryForBlocks(func() error {
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
return err
}, 3)
if exceptErr {
s.Require().Error(err)
s.Require().Contains(err.Error(), message)