From 35e6c7243f6523419986f31ab82aedd5570070f6 Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Fri, 16 Feb 2024 01:48:18 +0000 Subject: [PATCH] test: check tx result on x/foundation e2e test (#1237) * Query tx in blocks * Update CHANGELOG.md * Fix lint * Lint * Use cosmos gogoproto * Update CHANGELOG.md * Skip sonar where token is not provided --- .github/workflows/test.yml | 2 +- .golangci.yml | 3 +- CHANGELOG.md | 1 + scripts/go-lint-all.bash | 4 +-- tests/e2e/foundation/grpc.go | 2 +- tests/e2e/foundation/query.go | 2 +- tests/e2e/foundation/suite.go | 39 +++++++++++++--------- tests/e2e/foundation/tx.go | 38 ++++++++++++++++----- tests/go.mod | 5 ++- tests/go.sum | 2 -- x/foundation/authz.go | 2 +- x/foundation/events.go | 2 +- x/foundation/foundation.go | 2 +- x/foundation/genesis.go | 2 +- x/foundation/go.mod | 2 +- x/foundation/keeper/internal/grpc_query.go | 2 +- x/foundation/msgs.go | 2 +- 17 files changed, 69 insertions(+), 43 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa638b80f5..54ff0dc876 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -185,7 +185,7 @@ jobs: name: "${{ github.sha }}-e2e-coverage" continue-on-error: true - name: sonarcloud - if: ${{ env.GIT_DIFF && !github.event.pull_request.draft }} + if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null}} uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml index 37d5c4b41d..8ea09b0436 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -52,8 +52,7 @@ issues: - text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out linters: - staticcheck - - path: "client/cli" # TODO(@0Tech): remove after foundation exec proposal removed - text: "SA1019: govcli.FlagDescription is deprecated" + - text: "SA1019: govcli.FlagDescription is deprecated" # TODO(@0Tech): remove after foundation exec proposal removed linters: - staticcheck - text: "leading space" diff --git a/CHANGELOG.md b/CHANGELOG.md index c8d2b6cdc3..ee2b6b5a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/crisis) [#1167](https://github.com/Finschia/finschia-sdk/pull/1167) Use `CacheContext()` in `AssertInvariants()` * (chore) [\#1168](https://github.com/Finschia/finschia-sdk/pull/1168) Replace `ExactArgs(0)` with `NoArgs()` in `x/upgrade` module * (server) [\#1175](https://github.com/Finschia/finschia-sdk/pull/1175) Use go embed for swagger +* (e2e) [\#1237](https://github.com/Finschia/finschia-sdk/pull/1237) Check tx result on x/foundation e2e test ### Bug Fixes * chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue diff --git a/scripts/go-lint-all.bash b/scripts/go-lint-all.bash index 8850c65cd1..decaaa8287 100755 --- a/scripts/go-lint-all.bash +++ b/scripts/go-lint-all.bash @@ -31,7 +31,7 @@ else for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do echo "linting $f [$(date -Iseconds -u)]" && cd $f && - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" && + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" cd $REPO_ROOT done -fi \ No newline at end of file +fi diff --git a/tests/e2e/foundation/grpc.go b/tests/e2e/foundation/grpc.go index 95aa701f65..73c0ece707 100644 --- a/tests/e2e/foundation/grpc.go +++ b/tests/e2e/foundation/grpc.go @@ -3,7 +3,7 @@ package foundation import ( "fmt" - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "cosmossdk.io/math" diff --git a/tests/e2e/foundation/query.go b/tests/e2e/foundation/query.go index a31f9ffe8c..713bc945c9 100644 --- a/tests/e2e/foundation/query.go +++ b/tests/e2e/foundation/query.go @@ -4,7 +4,7 @@ import ( "fmt" cmtcli "github.com/cometbft/cometbft/libs/cli" - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "cosmossdk.io/math" diff --git a/tests/e2e/foundation/suite.go b/tests/e2e/foundation/suite.go index 9d65a7d9bb..c1a1ffca98 100644 --- a/tests/e2e/foundation/suite.go +++ b/tests/e2e/foundation/suite.go @@ -1,10 +1,12 @@ package foundation import ( + "encoding/hex" "encoding/json" "fmt" "time" + "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" "cosmossdk.io/core/address" @@ -135,23 +137,13 @@ func (s *E2ETestSuite) SetupSuite() { s.createAccount("leavingmember", leavingMemberMnemonic) s.createAccount("permanentmember", permanentMemberMnemonic) - s.submitProposal(&foundation.MsgWithdrawFromTreasury{ + s.proposalID = s.submitProposal(&foundation.MsgWithdrawFromTreasury{ Authority: s.bytesToString(s.authority), To: s.bytesToString(s.stranger), Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))), }, false) - s.proposalID = 1 s.vote(s.proposalID, []sdk.AccAddress{s.leavingMember, s.permanentMember}) - // submit another two proposals without votes - for range make([]struct{}, 2) { - s.submitProposal(&foundation.MsgWithdrawFromTreasury{ - Authority: s.bytesToString(s.authority), - To: s.bytesToString(s.stranger), - Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))), - }, false) - } - s.setupHeight, err = s.network.LatestHeight() s.Require().NoError(err) } @@ -168,7 +160,7 @@ func (s *E2ETestSuite) bytesToString(addr sdk.AccAddress) string { } // submit a proposal -func (s *E2ETestSuite) submitProposal(msg sdk.Msg, try bool) { +func (s *E2ETestSuite) submitProposal(msg sdk.Msg, try bool) uint64 { val := s.network.Validators[0] proposers := []string{s.bytesToString(s.permanentMember)} @@ -190,7 +182,18 @@ func (s *E2ETestSuite) submitProposal(msg sdk.Msg, try bool) { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) s.Require().Zero(res.Code, out.String()) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) + + dataBytes, err := hex.DecodeString(res.Data) + s.Require().NoError(err) + var data sdk.TxMsgData + s.Require().NoError(proto.Unmarshal(dataBytes, &data)) + var msgResp foundation.MsgSubmitProposalResponse + s.Require().NoError(proto.Unmarshal(data.MsgResponses[0].Value, &msgResp), data.MsgResponses[0]) + + return msgResp.ProposalId } func (s *E2ETestSuite) vote(proposalID uint64, voters []sdk.AccAddress) { @@ -209,9 +212,11 @@ func (s *E2ETestSuite) vote(proposalID uint64, voters []sdk.AccAddress) { var res sdk.TxResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) s.Require().Zero(res.Code, out.String()) - } - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) + } } func (s *E2ETestSuite) msgToString(msg sdk.Msg) string { @@ -260,5 +265,7 @@ func (s *E2ETestSuite) createAccount(uid, mnemonic string) { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) s.Require().Zero(res.Code, out.String()) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) } diff --git a/tests/e2e/foundation/tx.go b/tests/e2e/foundation/tx.go index 4a90845de8..616f7b39be 100644 --- a/tests/e2e/foundation/tx.go +++ b/tests/e2e/foundation/tx.go @@ -61,7 +61,9 @@ func (s *E2ETestSuite) TestNewTxCmdFundTreasury() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) s.Require().Zero(res.Code, out) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) }) } } @@ -276,7 +278,9 @@ func (s *E2ETestSuite) TestNewTxCmdSubmitProposal() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) s.Require().Zero(res.Code, out) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) }) } } @@ -290,7 +294,12 @@ func (s *E2ETestSuite) TestNewTxCmdWithdrawProposal() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)))), } - proposalID := 2 + proposalID := s.submitProposal(&foundation.MsgWithdrawFromTreasury{ + Authority: s.bytesToString(s.authority), + To: s.bytesToString(s.stranger), + Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))), + }, false) + testCases := map[string]struct { args []string valid bool @@ -328,7 +337,9 @@ func (s *E2ETestSuite) TestNewTxCmdWithdrawProposal() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) s.Require().Zero(res.Code, out) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) }) } } @@ -342,7 +353,12 @@ func (s *E2ETestSuite) TestNewTxCmdVote() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)))), } - proposalID := 3 + proposalID := s.submitProposal(&foundation.MsgWithdrawFromTreasury{ + Authority: s.bytesToString(s.authority), + To: s.bytesToString(s.stranger), + Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(123))), + }, false) + testCases := map[string]struct { args []string valid bool @@ -384,7 +400,9 @@ func (s *E2ETestSuite) TestNewTxCmdVote() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) s.Require().Zero(res.Code, out) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) }) } } @@ -435,7 +453,9 @@ func (s *E2ETestSuite) TestNewTxCmdExec() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) s.Require().Zero(res.Code, out) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) }) } } @@ -547,7 +567,9 @@ func (s *E2ETestSuite) TestNewTxCmdLeaveFoundation() { s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) s.Require().Zero(res.Code, out) - s.Require().NoError(s.network.WaitForNextBlock()) + res, err = clitestutil.GetTxResponse(s.network, val.ClientCtx, res.TxHash) + s.Require().NoError(err) + s.Require().Zero(res.Code, res.RawLog) }) } } diff --git a/tests/go.mod b/tests/go.mod index 419d76cd06..309d5d13f5 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -20,7 +20,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect // this version is not used as it is always replaced by the latest Cosmos SDK version github.com/cosmos/cosmos-sdk v0.51.0 - github.com/cosmos/gogoproto v1.4.11 // indirect + github.com/cosmos/gogoproto v1.4.11 github.com/golang/mock v1.6.0 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/stretchr/testify v1.8.4 @@ -33,7 +33,6 @@ require ( require ( github.com/Finschia/finschia-sdk/simapp v0.0.0-00010101000000-000000000000 github.com/Finschia/finschia-sdk/x/foundation v0.0.0-00010101000000-000000000000 - github.com/gogo/protobuf v1.3.2 ) require ( @@ -42,7 +41,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.3 // indirect cloud.google.com/go/storage v1.30.1 // indirect - cosmossdk.io/client/v2 v2.0.0-beta.1 // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/x/circuit v0.1.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect @@ -93,6 +91,7 @@ require ( github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/googleapis v1.4.1 // indirect + github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.2.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect diff --git a/tests/go.sum b/tests/go.sum index fc07295a21..484c1485a9 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -189,8 +189,6 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/api v0.7.2 h1:BO3i5fvKMKvfaUiMkCznxViuBEfyWA/k6w2eAF6q1C4= cosmossdk.io/api v0.7.2/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/client/v2 v2.0.0-beta.1 h1:XkHh1lhrLYIT9zKl7cIOXUXg2hdhtjTPBUfqERNA1/Q= -cosmossdk.io/client/v2 v2.0.0-beta.1/go.mod h1:JEUSu9moNZQ4kU3ir1DKD5eU4bllmAexrGWjmb9k8qU= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/x/foundation/authz.go b/x/foundation/authz.go index cf29bbabdb..bb0e1bd619 100644 --- a/x/foundation/authz.go +++ b/x/foundation/authz.go @@ -1,7 +1,7 @@ package foundation import ( - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/foundation/events.go b/x/foundation/events.go index 42032f1af0..5cd21d8b3e 100644 --- a/x/foundation/events.go +++ b/x/foundation/events.go @@ -1,7 +1,7 @@ package foundation import ( - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/foundation/foundation.go b/x/foundation/foundation.go index 5fe3e68945..1a9c30e609 100644 --- a/x/foundation/foundation.go +++ b/x/foundation/foundation.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "cosmossdk.io/core/address" errorsmod "cosmossdk.io/errors" diff --git a/x/foundation/genesis.go b/x/foundation/genesis.go index 8cfb5e46b1..195d2f8525 100644 --- a/x/foundation/genesis.go +++ b/x/foundation/genesis.go @@ -1,7 +1,7 @@ package foundation import ( - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "cosmossdk.io/core/address" "cosmossdk.io/math" diff --git a/x/foundation/go.mod b/x/foundation/go.mod index 94d6ef675a..5917c1c5bc 100644 --- a/x/foundation/go.mod +++ b/x/foundation/go.mod @@ -14,7 +14,6 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.50.2 github.com/cosmos/gogoproto v1.4.11 - github.com/gogo/protobuf v1.3.2 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -73,6 +72,7 @@ require ( github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/googleapis v1.4.1 // indirect + github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.2.0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect diff --git a/x/foundation/keeper/internal/grpc_query.go b/x/foundation/keeper/internal/grpc_query.go index deef12f9b9..74d84e2955 100644 --- a/x/foundation/keeper/internal/grpc_query.go +++ b/x/foundation/keeper/internal/grpc_query.go @@ -3,7 +3,7 @@ package internal import ( "context" - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/x/foundation/msgs.go b/x/foundation/msgs.go index 74ff7259d6..44ce8bc7ed 100644 --- a/x/foundation/msgs.go +++ b/x/foundation/msgs.go @@ -1,7 +1,7 @@ package foundation import ( - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types"