Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: check tx result on x/foundation e2e test #1237

Merged
merged 7 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/go-lint-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
fi
2 changes: 1 addition & 1 deletion tests/e2e/foundation/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package foundation
import (
"fmt"

"github.com/gogo/protobuf/proto"
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/math"

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/foundation/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
39 changes: 23 additions & 16 deletions tests/e2e/foundation/suite.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)}
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
38 changes: 30 additions & 8 deletions tests/e2e/foundation/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
})
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down
5 changes: 2 additions & 3 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion x/foundation/authz.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion x/foundation/events.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion x/foundation/foundation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion x/foundation/genesis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package foundation

import (
"github.com/gogo/protobuf/proto"
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/core/address"
"cosmossdk.io/math"
Expand Down
2 changes: 1 addition & 1 deletion x/foundation/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/foundation/keeper/internal/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion x/foundation/msgs.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading