Skip to content

Commit

Permalink
extract checkTxCode
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Sep 22, 2022
1 parent a79138f commit 31c9df9
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 183 deletions.
17 changes: 1 addition & 16 deletions tests/e2e/crisis/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package crisis
import (
"fmt"

"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"
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"
)

type IntegrationTestSuite struct {
Expand Down Expand Up @@ -102,20 +99,8 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, 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())
}
21 changes: 4 additions & 17 deletions tests/e2e/feegrant/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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"
Expand Down Expand Up @@ -600,7 +599,7 @@ func (s *IntegrationTestSuite) TestNewCmdFeeGrant() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -707,7 +706,7 @@ func (s *IntegrationTestSuite) TestNewCmdRevokeFeegrant() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -892,7 +891,7 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -983,23 +982,11 @@ 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.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
})
}
}

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())
}
64 changes: 25 additions & 39 deletions tests/e2e/group/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ 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"
"github.com/cosmos/cosmos-sdk/testutil"
"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"
Expand Down Expand Up @@ -111,7 +109,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.Require().NoError(err, out.String())
txResp := sdk.TxResponse{}
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.checkTxCode(val.ClientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))

s.group = &group.GroupInfo{Id: 1, Admin: val.Address.String(), Metadata: validMetadata, TotalWeight: "3", Version: 1}

Expand Down Expand Up @@ -142,7 +140,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
)
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.checkTxCode(val.ClientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, 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())
Expand All @@ -166,7 +164,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
)
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.checkTxCode(val.ClientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))

// vote
out, err = cli.ExecTestCLICmd(val.ClientCtx, client.MsgVoteCmd(),
Expand All @@ -182,7 +180,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
)
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.checkTxCode(val.ClientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, 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())
Expand Down Expand Up @@ -355,7 +353,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroup() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -387,7 +385,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.checkTxCode(val.ClientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))
groupIDs[i] = s.getGroupIDFromTxResponse(txResp)
}

Expand Down Expand Up @@ -556,7 +554,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupMetadata() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -678,7 +676,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupMembers() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -884,7 +882,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupWithPolicy() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1052,7 +1050,7 @@ func (s *IntegrationTestSuite) TestTxCreateGroupPolicy() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1152,7 +1150,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyAdmin() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1297,7 +1295,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyDecisionPolicy() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1412,7 +1410,7 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupPolicyMetadata() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1600,7 +1598,7 @@ func (s *IntegrationTestSuite) TestTxSubmitProposal() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1634,7 +1632,7 @@ func (s *IntegrationTestSuite) TestTxVote() {

var txResp sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.checkTxCode(clientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, 0))
ids[i] = s.getProposalIDFromTxResponse(txResp)
}

Expand Down Expand Up @@ -1793,7 +1791,7 @@ func (s *IntegrationTestSuite) TestTxVote() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1821,7 +1819,7 @@ func (s *IntegrationTestSuite) TestTxWithdrawProposal() {

var txResp sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.checkTxCode(clientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, 0))
ids[i] = s.getProposalIDFromTxResponse(txResp)
}

Expand Down Expand Up @@ -1919,7 +1917,7 @@ func (s *IntegrationTestSuite) TestTxWithdrawProposal() {
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -1964,7 +1962,7 @@ func (s *IntegrationTestSuite) TestTxExec() {

var txResp sdk.TxResponse
require.NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.checkTxCode(clientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, 0))
proposalID := s.getProposalIDFromTxResponse(txResp)
proposalIDs = append(proposalIDs, proposalID)

Expand Down Expand Up @@ -2252,7 +2250,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.checkTxCode(clientCtx, resp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))

return err
},
Expand All @@ -2279,7 +2277,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.checkTxCode(clientCtx, resp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))

return err
},
Expand All @@ -2306,7 +2304,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.checkTxCode(clientCtx, resp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))

return err
},
Expand Down Expand Up @@ -2338,7 +2336,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.checkTxCode(clientCtx, resp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))

return err
},
Expand Down Expand Up @@ -2392,7 +2390,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.checkTxCode(clientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, 0))

}

Expand Down Expand Up @@ -2544,7 +2542,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.checkTxCode(val.ClientCtx, txResp.TxHash, 0)
s.Require().NoError(clitestutil.CheckTxCode(s.network, 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())
Expand Down Expand Up @@ -2575,15 +2573,3 @@ 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())
}
17 changes: 1 addition & 16 deletions tests/e2e/nft/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ 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"
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"
)

Expand Down Expand Up @@ -135,7 +132,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.checkTxCode(clientCtx, txResp.TxHash, tc.expectedCode)
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
}
})
}
Expand Down Expand Up @@ -163,15 +160,3 @@ func (s *IntegrationTestSuite) initAccount() {
_, 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())
}
Loading

0 comments on commit 31c9df9

Please sign in to comment.