diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd31e4a6971..c464a6442291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,7 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module. * [#12693](https://github.com/cosmos/cosmos-sdk/pull/12693) Make sure the order of each node is consistent when emitting proto events. * [#12455](https://github.com/cosmos/cosmos-sdk/pull/12455) Show attempts count in error for signing. -* [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store +* [#12885](https://github.com/cosmos/cosmos-sdk/pull/12885) Amortize cost of processing cache KV store * [#12953](https://github.com/cosmos/cosmos-sdk/pull/12953) Change the default priority mechanism to be based on gas price. ### State Machine Breaking diff --git a/tests/e2e/crisis/suite.go b/tests/e2e/crisis/suite.go index aad74ace303a..8ae71b4ea32f 100644 --- a/tests/e2e/crisis/suite.go +++ b/tests/e2e/crisis/suite.go @@ -3,13 +3,17 @@ package crisis import ( "fmt" + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/crisis/client/cli" ) @@ -73,7 +77,7 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() { true, 0, nil, }, { - "valid transaction", + "valid traclientCtx.Codec.UnmarshalJSON(out.Bytes(), nsaction", []string{ "bank", "total-supply", fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), @@ -100,8 +104,20 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } } + +func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +} diff --git a/tests/e2e/slashing/client/testutil/suite.go b/tests/e2e/slashing/client/testutil/suite.go index 2623eb03dba8..94340f6996b5 100644 --- a/tests/e2e/slashing/client/testutil/suite.go +++ b/tests/e2e/slashing/client/testutil/suite.go @@ -8,11 +8,14 @@ import ( "github.com/stretchr/testify/suite" tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) type EndToEndTestSuite struct { @@ -35,8 +38,7 @@ func (s *EndToEndTestSuite) SetupSuite() { s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) } // TearDownSuite performs cleanup logic after all the tests, i.e. once after the @@ -159,7 +161,7 @@ func (s *EndToEndTestSuite) TestNewUnjailTxCmd() { fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), // sync mode as there are no funds yet fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), }, - false, 0, &sdk.TxResponse{}, + false, slashingtypes.ErrValidatorNotJailed.ABCICode(), &sdk.TxResponse{}, }, } @@ -178,8 +180,20 @@ func (s *EndToEndTestSuite) TestNewUnjailTxCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } } + +func (s *EndToEndTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +} diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index 27ecbed53bde..d53ba4958cd0 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -124,9 +124,6 @@ func (s *IntegrationTestSuite) TestQueryBySig() { s.Require().NoError(s.network.WaitForNextBlock()) - // wait for tx to be included - s.network.WaitForNextBlock() - // get the signature out of the builder sigs, err := txb.GetTx().GetSignaturesV2() s.Require().NoError(err) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 71b3097ad397..58bbef1df9cb 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -1551,8 +1551,9 @@ func (s *IntegrationTestSuite) TestSignWithMultiSignersAminoJSON() { signedTxFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), ) - require.NoError(err) + require.NoError(s.network.WaitForNextBlock()) + var txRes sdk.TxResponse require.NoError(val0.ClientCtx.Codec.UnmarshalJSON(res.Bytes(), &txRes)) require.Equal(uint32(0), txRes.Code, txRes.RawLog) @@ -1566,10 +1567,7 @@ func (s *IntegrationTestSuite) TestSignWithMultiSignersAminoJSON() { require.Equal(sdk.NewCoins(val0Coin, val1Coin), queryRes.Balances) } -// TODO to re-enable in #12274 func (s *IntegrationTestSuite) TestAuxSigner() { - s.T().Skip() - require := s.Require() val := s.network.Validators[0] val0Coin := sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(10)) diff --git a/x/authz/client/testutil/grpc.go b/x/authz/client/testutil/grpc.go index d5e3269c58fc..f22ea3fbb910 100644 --- a/x/authz/client/testutil/grpc.go +++ b/x/authz/client/testutil/grpc.go @@ -119,6 +119,7 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { fmt.Sprintf("--%s=%d", cli.FlagExpiration, time.Now().Add(time.Minute*time.Duration(120)).Unix()), }) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) }, func(g *authz.QueryGrantsResponse) { s.Require().Len(g.Grants, 2) diff --git a/x/authz/client/testutil/query.go b/x/authz/client/testutil/query.go index d62ab8beec90..42584a5999c7 100644 --- a/x/authz/client/testutil/query.go +++ b/x/authz/client/testutil/query.go @@ -34,6 +34,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) testCases := []struct { name string @@ -112,6 +113,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorization() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) testCases := []struct { name string diff --git a/x/authz/client/testutil/tx.go b/x/authz/client/testutil/tx.go index 50069aa5ae09..11bfa4ef58eb 100644 --- a/x/authz/client/testutil/tx.go +++ b/x/authz/client/testutil/tx.go @@ -6,7 +6,9 @@ import ( "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -14,6 +16,7 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/client/cli" bank "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -50,14 +53,13 @@ func (s *IntegrationTestSuite) SetupSuite() { // Create new account in the keyring. s.grantee[0] = s.createAccount("grantee1") s.msgSendExec(s.grantee[0]) - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) // create a proposal with deposit _, err = govtestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(), "Text Proposal 1", "Where is the title!?", govv1beta1.ProposalTypeText, fmt.Sprintf("--%s=%s", govcli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, govv1.DefaultMinDepositTokens).String())) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) // Create new account in the keyring. s.grantee[1] = s.createAccount("grantee2") @@ -76,10 +78,10 @@ func (s *IntegrationTestSuite) SetupSuite() { fmt.Sprintf("--%s=%d", cli.FlagExpiration, time.Now().Add(time.Minute*time.Duration(120)).Unix()), }) s.Require().NoError(err) - s.Require().Contains(out.String(), `"code":0`) - - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + var response sdk.TxResponse + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.checkTxCode(val.ClientCtx, response.TxHash, 0) // Create new account in the keyring. s.grantee[2] = s.createAccount("grantee3") @@ -96,6 +98,7 @@ func (s *IntegrationTestSuite) SetupSuite() { fmt.Sprintf("--%s=%d", cli.FlagExpiration, time.Now().Add(time.Minute*time.Duration(120)).Unix()), }) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) // Create new accounts in the keyring. s.grantee[3] = s.createAccount("grantee4") @@ -120,14 +123,10 @@ func (s *IntegrationTestSuite) SetupSuite() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) - err = s.network.WaitForNextBlock() - s.Require().NoError(err) - - var response sdk.TxResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(int(response.Code), 0) - s.Require().NotEqual(int(response.Height), 0) + s.checkTxCode(val.ClientCtx, response.TxHash, 0) } func (s *IntegrationTestSuite) createAccount(uid string) sdk.AccAddress { @@ -155,6 +154,7 @@ func (s *IntegrationTestSuite) msgSendExec(grantee sdk.AccAddress) { ) s.Require().NoError(err) s.Require().Contains(out.String(), `"code":0`) + s.Require().NoError(s.network.WaitForNextBlock()) } func (s *IntegrationTestSuite) TearDownSuite() { @@ -514,7 +514,6 @@ func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() { for _, tc := range testCases { s.Run(tc.name, func() { - clientCtx := val.ClientCtx out, err := CreateGrant( val, tc.args, @@ -525,8 +524,8 @@ func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() { } else { var txResp sdk.TxResponse s.Require().NoError(err) - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -559,6 +558,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) // generic-authorization _, err = CreateGrant( @@ -575,6 +575,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) // generic-authorization used for amino testing _, err = CreateGrant( @@ -592,6 +593,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) testCases := []struct { name string @@ -679,7 +681,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -714,7 +716,7 @@ func (s *IntegrationTestSuite) TestExecAuthorizationWithExpiration() { cmd := cli.NewCmdExecAuthorization() clientCtx := val.ClientCtx - res, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{ + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{ execMsg.Name(), fmt.Sprintf("--%s=%s", flags.FlagFrom, grantee.String()), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), @@ -722,7 +724,9 @@ func (s *IntegrationTestSuite) TestExecAuthorizationWithExpiration() { fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), }) s.Require().NoError(err) - s.Require().Contains(res.String(), authz.ErrNoAuthorizationFound.Error()) + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.checkTxCode(clientCtx, response.TxHash, authz.ErrNoAuthorizationFound.ABCICode()) } func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() { @@ -744,6 +748,7 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) // msg vote voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String()) @@ -820,7 +825,7 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -846,6 +851,8 @@ func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + tokens := sdk.NewCoins( sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(12)), ) @@ -928,7 +935,7 @@ func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() { default: s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(tc.expectedCode, response.Code, out.String()) + s.checkTxCode(val.ClientCtx, response.TxHash, tc.expectedCode) } }) } @@ -956,6 +963,7 @@ func (s *IntegrationTestSuite) TestExecSendAuthzWithAllowList() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) tokens := sdk.NewCoins( sdk.NewCoin("stake", sdk.NewInt(12)), @@ -1000,6 +1008,7 @@ func (s *IntegrationTestSuite) TestExecSendAuthzWithAllowList() { out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().NoError(s.network.WaitForNextBlock()) // test sending to not allowed address args = []string{ @@ -1011,6 +1020,13 @@ func (s *IntegrationTestSuite) TestExecSendAuthzWithAllowList() { } out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().NoError(s.network.WaitForNextBlock()) + + // query tx and check result + cmd = authcli.QueryTxCmd() + out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, []string{response.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) s.Contains(out.String(), fmt.Sprintf("cannot send to %s address", notAllowedAddr)) } @@ -1034,6 +1050,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) tokens := sdk.NewCoins( sdk.NewCoin("stake", sdk.NewInt(50)), @@ -1105,7 +1122,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { var response sdk.TxResponse s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(tc.expectedCode, response.Code, out.String()) + s.checkTxCode(val.ClientCtx, response.TxHash, tc.expectedCode) } }) } @@ -1125,6 +1142,8 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + tokens = sdk.NewCoins( sdk.NewCoin("stake", sdk.NewInt(50)), ) @@ -1182,7 +1201,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { var response sdk.TxResponse s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(tc.expectedCode, response.Code, out.String()) + s.checkTxCode(val.ClientCtx, response.TxHash, tc.expectedCode) } }) } @@ -1203,6 +1222,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) args := []string{ execMsg.Name(), @@ -1214,6 +1234,15 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { cmd := cli.NewCmdExecAuthorization() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + var response sdk.TxResponse + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + + // query tx and check result + cmd = authcli.QueryTxCmd() + out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, []string{response.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) s.Contains(out.String(), fmt.Sprintf("cannot delegate/undelegate to %s validator", val.ValAddress.String())) } @@ -1238,6 +1267,7 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) // delegating stakes to validator _, err = execDelegate( @@ -1326,7 +1356,7 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { var response sdk.TxResponse s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(tc.expectedCode, response.Code, out.String()) + s.checkTxCode(val.ClientCtx, response.TxHash, tc.expectedCode) } }) } @@ -1346,6 +1376,8 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { }, ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + tokens = sdk.NewCoins( sdk.NewCoin("stake", sdk.NewInt(50)), ) @@ -1405,8 +1437,20 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { var response sdk.TxResponse s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(tc.expectedCode, response.Code, out.String()) + s.checkTxCode(val.ClientCtx, response.TxHash, tc.expectedCode) } }) } } + +func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +} diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 9b56b6c663b0..e1f0312daf1c 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -168,10 +168,6 @@ $ %[1]s tx distribution withdraw-all-rewards --from mykey } chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx) - if !clientCtx.GenerateOnly && clientCtx.BroadcastMode != flags.BroadcastSync && chunkSize > 0 { - return fmt.Errorf("cannot use broadcast mode %[1]s with %[2]s != 0", - clientCtx.BroadcastMode, FlagMaxMessagesPerTx) - } return newSplitAndApply(tx.GenerateOrBroadcastTxCLI, clientCtx, cmd.Flags(), msgs, chunkSize) }, diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 09d3a1494158..4265f3e68c5d 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -11,10 +11,12 @@ import ( "github.com/stretchr/testify/suite" tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/distribution/client/cli" "github.com/cosmos/cosmos-sdk/x/distribution/testutil" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -522,9 +524,15 @@ func (s *IntegrationTestSuite) TestNewWithdrawRewardsCmd() { } else { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(bz, tc.respType), string(bz)) + s.Require().NoError(s.network.WaitForNextBlock()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code) + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txResp.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), txResp), out.String()) + s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) data, err := hex.DecodeString(txResp.Data) s.Require().NoError(err) @@ -608,9 +616,15 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsCmd() { } else { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) + s.Require().NoError(s.network.WaitForNextBlock()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code) + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txResp.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), txResp), out.String()) + s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) data, err := hex.DecodeString(txResp.Data) s.Require().NoError(err) @@ -691,7 +705,7 @@ func (s *IntegrationTestSuite) TestNewSetWithdrawAddrCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code) + s.checkTx(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -746,8 +760,20 @@ func (s *IntegrationTestSuite) TestNewFundCommunityPoolCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code) + s.checkTx(clientCtx, txResp.TxHash, tc.expectedCode) } }) } } + +func (s *IntegrationTestSuite) checkTx(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +} diff --git a/x/distribution/client/testutil/withdraw_all_suite.go b/x/distribution/client/testutil/withdraw_all_suite.go index 85df247a1874..a7067b0a81a5 100644 --- a/x/distribution/client/testutil/withdraw_all_suite.go +++ b/x/distribution/client/testutil/withdraw_all_suite.go @@ -69,6 +69,7 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) require.NoError(err) + require.NoError(s.network.WaitForNextBlock()) // delegate 500 tokens to validator1 args := []string{ @@ -82,6 +83,7 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { cmd := stakingcli.NewDelegateCmd() _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) require.NoError(err) + require.NoError(s.network.WaitForNextBlock()) // delegate 500 tokens to validator2 args = []string{ @@ -94,6 +96,7 @@ 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()), diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index b077693da88b..0d0a9c34828b 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -18,6 +18,7 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/client/cli" govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil" @@ -100,11 +101,9 @@ func (s *IntegrationTestSuite) createGrant(granter, grantee sdk.Address) { ) cmd := cli.NewCmdFeeGrant() - _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) } func (s *IntegrationTestSuite) TearDownSuite() { @@ -599,7 +598,7 @@ func (s *IntegrationTestSuite) TestNewCmdFeeGrant() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -706,15 +705,13 @@ func (s *IntegrationTestSuite) TestNewCmdRevokeFeegrant() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } } func (s *IntegrationTestSuite) TestTxWithFeeGrant() { - s.T().Skip() // TODO to re-enable in #12274 - val := s.network.Validators[0] clientCtx := val.ClientCtx granter := val.Address @@ -749,8 +746,7 @@ func (s *IntegrationTestSuite) TestTxWithFeeGrant() { _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) testcases := []struct { name string @@ -804,8 +800,6 @@ func (s *IntegrationTestSuite) TestTxWithFeeGrant() { } func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { - s.T().Skip() // TODO to re-enable in #12274 - val := s.network.Validators[0] granter := val.Address @@ -891,7 +885,7 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -982,7 +976,7 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) }) } } @@ -990,3 +984,15 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { func getFormattedExpiration(duration int64) string { return time.Now().Add(time.Duration(duration) * time.Second).Format(time.RFC3339) } + +func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +} diff --git a/x/gov/client/testutil/deposits.go b/x/gov/client/testutil/deposits.go index ee609ac9f451..40965a13d251 100644 --- a/x/gov/client/testutil/deposits.go +++ b/x/gov/client/testutil/deposits.go @@ -108,6 +108,7 @@ 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, "") @@ -125,6 +126,7 @@ func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() { deposit := s.queryDeposit(val, proposalID, false, "") s.Require().NotNil(deposit) s.Require().Equal(sdk.Coins(deposit.Amount).String(), s.deposits[1].String()) + s.Require().NoError(s.network.WaitForNextBlock()) // query deposits deposits := s.queryDeposits(val, proposalID, false, "") diff --git a/x/gov/client/testutil/tx.go b/x/gov/client/testutil/tx.go index d3c9e5d72ef3..b52515b5a057 100644 --- a/x/gov/client/testutil/tx.go +++ b/x/gov/client/testutil/tx.go @@ -4,7 +4,9 @@ import ( "encoding/base64" "fmt" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/testutil" + tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" @@ -13,6 +15,7 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -156,7 +159,7 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -249,7 +252,7 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitLegacyProposal() { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -327,7 +330,7 @@ func (s *IntegrationTestSuite) TestNewCmdDeposit() { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String()) - s.Require().Equal(tc.expectedCode, resp.Code, out.String()) + s.checkTxCode(clientCtx, resp.TxHash, tc.expectedCode) } }) } @@ -401,7 +404,7 @@ func (s *IntegrationTestSuite) TestNewCmdVote() { } else { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -498,8 +501,20 @@ func (s *IntegrationTestSuite) TestNewCmdWeightedVote() { } else { s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } } + +func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +} diff --git a/x/group/client/testutil/tx.go b/x/group/client/testutil/tx.go index c733c6ba96fd..7e1fa366d388 100644 --- a/x/group/client/testutil/tx.go +++ b/x/group/client/testutil/tx.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/suite" tmcli "github.com/tendermint/tendermint/libs/cli" + sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -19,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/group" client "github.com/cosmos/cosmos-sdk/x/group/client/cli" @@ -81,6 +83,7 @@ func (s *IntegrationTestSuite) SetupSuite() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) memberWeight := "3" // create a group @@ -105,11 +108,10 @@ func (s *IntegrationTestSuite) SetupSuite() { s.commonFlags..., ), ) - s.Require().NoError(err, out.String()) txResp := sdk.TxResponse{} s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, 0) s.group = &group.GroupInfo{Id: 1, Admin: val.Address.String(), Metadata: validMetadata, TotalWeight: "3", Version: 1} @@ -140,7 +142,7 @@ func (s *IntegrationTestSuite) SetupSuite() { ) s.Require().NoError(err, out.String()) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, 0) out, err = cli.ExecTestCLICmd(val.ClientCtx, client.QueryGroupPoliciesByGroupCmd(), []string{"1", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) s.Require().NoError(err, out.String()) @@ -164,7 +166,7 @@ func (s *IntegrationTestSuite) SetupSuite() { ) s.Require().NoError(err, out.String()) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, 0) // vote out, err = cli.ExecTestCLICmd(val.ClientCtx, client.MsgVoteCmd(), @@ -180,7 +182,7 @@ func (s *IntegrationTestSuite) SetupSuite() { ) s.Require().NoError(err, out.String()) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, 0) out, err = cli.ExecTestCLICmd(val.ClientCtx, client.QueryProposalCmd(), []string{"1", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) s.Require().NoError(err, out.String()) @@ -353,7 +355,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroup() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -385,7 +387,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupAdmin() { require.NoError(err, out.String()) var txResp sdk.TxResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, 0) groupIDs[i] = s.getGroupIDFromTxResponse(txResp) } @@ -554,7 +556,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupMetadata() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -676,7 +678,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupMembers() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -882,7 +884,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1050,7 +1052,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1150,7 +1152,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyAdmin() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1295,7 +1297,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1410,7 +1412,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyMetadata() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1598,7 +1600,7 @@ func (s *IntegrationTestSuite) TestTxSubmitProposal() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1632,7 +1634,7 @@ func (s *IntegrationTestSuite) TestTxVote() { var txResp sdk.TxResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, 0) ids[i] = s.getProposalIDFromTxResponse(txResp) } @@ -1791,7 +1793,7 @@ func (s *IntegrationTestSuite) TestTxVote() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1819,7 +1821,7 @@ func (s *IntegrationTestSuite) TestTxWithdrawProposal() { var txResp sdk.TxResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, 0) ids[i] = s.getProposalIDFromTxResponse(txResp) } @@ -1917,7 +1919,7 @@ func (s *IntegrationTestSuite) TestTxWithdrawProposal() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1962,7 +1964,7 @@ func (s *IntegrationTestSuite) TestTxExec() { var txResp sdk.TxResponse require.NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - require.Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, 0) proposalID := s.getProposalIDFromTxResponse(txResp) proposalIDs = append(proposalIDs, proposalID) @@ -2250,7 +2252,7 @@ func (s *IntegrationTestSuite) TestExecProposalsWhenMemberLeavesOrIsUpdated() { s.Require().NoError(err, out.String()) var resp sdk.TxResponse s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String()) - s.Require().Equal(uint32(0), resp.Code, out.String()) + s.checkTxCode(clientCtx, resp.TxHash, 0) return err }, @@ -2277,7 +2279,7 @@ func (s *IntegrationTestSuite) TestExecProposalsWhenMemberLeavesOrIsUpdated() { s.Require().NoError(err, out.String()) var resp sdk.TxResponse s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String()) - s.Require().Equal(uint32(0), resp.Code, out.String()) + s.checkTxCode(clientCtx, resp.TxHash, 0) return err }, @@ -2304,7 +2306,7 @@ func (s *IntegrationTestSuite) TestExecProposalsWhenMemberLeavesOrIsUpdated() { s.Require().NoError(err, out.String()) var resp sdk.TxResponse s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String()) - s.Require().Equal(uint32(0), resp.Code, out.String()) + s.checkTxCode(clientCtx, resp.TxHash, 0) return err }, @@ -2336,7 +2338,7 @@ func (s *IntegrationTestSuite) TestExecProposalsWhenMemberLeavesOrIsUpdated() { s.Require().NoError(err, out.String()) var resp sdk.TxResponse s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String()) - s.Require().Equal(uint32(0), resp.Code, out.String()) + s.checkTxCode(clientCtx, resp.TxHash, 0) return err }, @@ -2390,7 +2392,7 @@ func (s *IntegrationTestSuite) TestExecProposalsWhenMemberLeavesOrIsUpdated() { var txResp sdk.TxResponse s.Require().NoError(err, out.String()) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, 0) } @@ -2489,8 +2491,10 @@ func (s *IntegrationTestSuite) createAccounts(quantity int) []string { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) s.Require().NoError(err) - s.Require().NoError(err) } + + s.Require().NoError(s.network.WaitForNextBlock()) + return accounts } @@ -2540,7 +2544,7 @@ func (s *IntegrationTestSuite) createGroupThresholdPolicyWithBalance(adminAddres txResp := sdk.TxResponse{} s.Require().NoError(err, out.String()) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(uint32(0), txResp.Code, out.String()) + s.checkTxCode(val.ClientCtx, txResp.TxHash, 0) out, err = cli.ExecTestCLICmd(val.ClientCtx, client.QueryGroupPoliciesByGroupCmd(), []string{groupID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) s.Require().NoError(err, out.String()) @@ -2571,3 +2575,15 @@ func (s *IntegrationTestSuite) newValidMembers(weights, membersAddress []string) } return membersValid } + +func (s *IntegrationTestSuite) checkTxCode(clientCtx sdkclient.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := cli.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +} diff --git a/x/nft/client/testutil/tx.go b/x/nft/client/testutil/tx.go index a68ebc526cc6..233790293ec1 100644 --- a/x/nft/client/testutil/tx.go +++ b/x/nft/client/testutil/tx.go @@ -4,11 +4,14 @@ import ( "fmt" "github.com/stretchr/testify/suite" + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/testutil/cli" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/nft" ) @@ -80,13 +83,10 @@ func (s *IntegrationTestSuite) SetupSuite() { s.cfg.GenesisState = genesisState s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) s.initAccount() - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) } func (s *IntegrationTestSuite) TearDownSuite() { @@ -135,7 +135,7 @@ func (s *IntegrationTestSuite) TestCLITxSend() { var txResp sdk.TxResponse s.Require().NoError(err) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -160,6 +160,18 @@ func (s *IntegrationTestSuite) initAccount() { s.Require().NoError(err) amount := sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))) - _, err = cli.MsgSendExec(ctx, val.Address, s.owner, amount, args...) + _, err = clitestutil.MsgSendExec(ctx, val.Address, s.owner, amount, args...) + s.Require().NoError(err) +} + +func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) } diff --git a/x/staking/client/testutil/suite.go b/x/staking/client/testutil/suite.go index 288b99f06b31..8fad4776fb0a 100644 --- a/x/staking/client/testutil/suite.go +++ b/x/staking/client/testutil/suite.go @@ -13,6 +13,7 @@ import ( "github.com/tendermint/tendermint/proto/tendermint/crypto" "github.com/tendermint/tendermint/rpc/client/http" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -23,6 +24,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" + authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/staking/client/cli" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -48,9 +50,7 @@ func (s *IntegrationTestSuite) SetupSuite() { var err error s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) - - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) unbond, err := sdk.ParseCoinNormalized("10stake") s.Require().NoError(err) @@ -71,24 +71,24 @@ func (s *IntegrationTestSuite) SetupSuite() { var txRes sdk.TxResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) s.Require().Equal(uint32(0), txRes.Code) - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) unbondingAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5)) + // unbonding the amount 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().NoError(s.network.WaitForNextBlock()) + // unbonding the amount out, err = MsgUnbondExec(val.ClientCtx, val.Address, val.ValAddress, unbondingAmount) s.Require().NoError(err) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) s.Require().Equal(uint32(0), txRes.Code) - - err = s.network.WaitForNextBlock() - s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) } func (s *IntegrationTestSuite) TearDownSuite() { @@ -121,6 +121,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) require.NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) testCases := []struct { name string @@ -223,19 +224,27 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() { require.NoError(err, "test: %s\noutput: %s", tc.name, out.String()) err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType) require.NoError(err, out.String(), "test: %s, output\n:", tc.name, out.String()) + s.Require().NoError(s.network.WaitForNextBlock()) txResp := tc.respType.(*sdk.TxResponse) - require.Equal(tc.expectedCode, txResp.Code, - "test: %s, output\n:", tc.name, out.String()) + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txResp.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), txResp), out.String()) + s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + var hadEvent bool events := txResp.Logs[0].GetEvents() for i := 0; i < len(events); i++ { if events[i].GetType() == "create_validator" { attributes := events[i].GetAttributes() require.Equal(attributes[1].Value, "100stake") + hadEvent = true break } } + + s.Require().True(hadEvent) } }) } @@ -1065,7 +1074,7 @@ func (s *IntegrationTestSuite) TestNewEditValidatorCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1091,6 +1100,7 @@ func (s *IntegrationTestSuite) TestNewDelegateCmd() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) testCases := []struct { name string @@ -1150,7 +1160,7 @@ func (s *IntegrationTestSuite) TestNewDelegateCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1236,7 +1246,7 @@ func (s *IntegrationTestSuite) TestNewRedelegateCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1303,7 +1313,7 @@ func (s *IntegrationTestSuite) TestNewUnbondCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1422,7 +1432,7 @@ func (s *IntegrationTestSuite) TestNewCancelUnbondingDelegationCmd() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode) } }) } @@ -1452,6 +1462,7 @@ func (s *IntegrationTestSuite) TestBlockResults() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) require.NoError(err) + require.NoError(s.network.WaitForNextBlock()) // Use CLI to create a delegation from the new account to validator `val`. delHeight, err := s.network.LatestHeight() @@ -1466,6 +1477,7 @@ func (s *IntegrationTestSuite) TestBlockResults() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), }) require.NoError(err) + require.NoError(s.network.WaitForNextBlock()) // Create a HTTP rpc client. rpcClient, err := http.New(val.RPCAddress, "/websocket") @@ -1517,6 +1529,7 @@ func (s *IntegrationTestSuite) TestEditValidatorMoniker() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), }) require.NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) queryCmd := cli.GetCmdQueryValidator() res, err := clitestutil.ExecTestCLICmd( @@ -1537,13 +1550,25 @@ func (s *IntegrationTestSuite) TestEditValidatorMoniker() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), }) require.NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) res, err = clitestutil.ExecTestCLICmd( val.ClientCtx, queryCmd, []string{val.ValAddress.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}, ) require.NoError(err) - require.NoError(val.ClientCtx.Codec.UnmarshalJSON(res.Bytes(), &result)) require.Equal(result.GetMoniker(), moniker) } + +func (s *IntegrationTestSuite) checkTxCode(clientCtx client.Context, txHash string, expectedCode uint32) { + s.Require().NoError(s.network.WaitForNextBlock()) + + cmd := authcli.QueryTxCmd() + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}) + s.Require().NoError(err) + + var response sdk.TxResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + s.Require().Equal(expectedCode, response.Code, out.String()) +}