From 87e3751f5cad74387e68c498766052b0d25133f6 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 8 Oct 2020 12:44:11 +0200 Subject: [PATCH] Update TM to latest (+add test) (#7442) * Add test for /block_results * Fix test * Use http RPC client * Fix temporarily block_results * Use init * Add flag back * Remove init * Update TM master * Address comments * Fix build * require refactor * Add build flag back * More timeout on test * fix timeout-minutes Co-authored-by: Aaron Craelius Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .github/workflows/test.yml | 18 ++++---- go.mod | 2 +- go.sum | 2 + testutil/network/network.go | 20 +++++---- x/staking/client/cli/cli_test.go | 76 ++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0439c41311..58716fb982 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -255,7 +255,7 @@ jobs: test-race-1: runs-on: ubuntu-latest needs: split-test-files - timeout-minutes: 15 + timeout-minutes: 30 steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 @@ -275,7 +275,7 @@ jobs: name: "${{ github.sha }}-aa" if: "env.GIT_DIFF != ''" - name: Run tests with race detector - run: cat xaa.txt | xargs go test -mod=readonly -json -timeout 15m -race -tags='cgo ledger test_ledger_mock' > xaa-race-output.txt + run: cat xaa.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xaa-race-output.txt if: "env.GIT_DIFF != ''" - uses: actions/upload-artifact@v2 with: @@ -285,7 +285,7 @@ jobs: test-race-2: runs-on: ubuntu-latest needs: split-test-files - timeout-minutes: 15 + timeout-minutes: 30 steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 @@ -305,7 +305,7 @@ jobs: name: "${{ github.sha }}-ab" if: "env.GIT_DIFF != ''" - name: Run tests with race detector - run: cat xab.txt | xargs go test -mod=readonly -json -timeout 15m -race -tags='cgo ledger test_ledger_mock' > xab-race-output.txt + run: cat xab.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xab-race-output.txt if: "env.GIT_DIFF != ''" - uses: actions/upload-artifact@v2 with: @@ -315,7 +315,7 @@ jobs: test-race-3: runs-on: ubuntu-latest needs: split-test-files - timeout-minutes: 15 + timeout-minutes: 30 steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 @@ -335,7 +335,7 @@ jobs: name: "${{ github.sha }}-ac" if: "env.GIT_DIFF != ''" - name: Run tests with race detector - run: cat xac.txt | xargs go test -mod=readonly -json -timeout 15m -race -tags='cgo ledger test_ledger_mock' > xac-race-output.txt + run: cat xac.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xac-race-output.txt if: "env.GIT_DIFF != ''" - uses: actions/upload-artifact@v2 with: @@ -345,7 +345,7 @@ jobs: test-race-4: runs-on: ubuntu-latest needs: split-test-files - timeout-minutes: 15 + timeout-minutes: 30 steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 @@ -365,7 +365,7 @@ jobs: name: "${{ github.sha }}-ad" if: "env.GIT_DIFF != ''" - name: Run tests with race detector - run: cat xad.txt | xargs go test -mod=readonly -json -timeout 15m -race -tags='cgo ledger test_ledger_mock' > xad-race-output.txt + run: cat xad.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xad-race-output.txt if: "env.GIT_DIFF != ''" - uses: actions/upload-artifact@v2 with: @@ -430,7 +430,7 @@ jobs: run: | ./contrib/localnet_liveness.sh 100 5 50 localhost if: "env.GIT_DIFF != ''" - + docker-build: runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/go.mod b/go.mod index 7272880066..7504e763d1 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/tendermint/btcd v0.1.1 github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 github.com/tendermint/go-amino v0.16.0 - github.com/tendermint/tendermint v0.34.0-rc4 + github.com/tendermint/tendermint v0.34.0-rc4.0.20201005135527-d7d0ffea13c6 github.com/tendermint/tm-db v0.6.2 golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 diff --git a/go.sum b/go.sum index fa49f96b6a..608591dc03 100644 --- a/go.sum +++ b/go.sum @@ -583,6 +583,8 @@ github.com/tendermint/tendermint v0.34.0-rc3 h1:d7Fsd5rdbxq4GmJ0kRfx7l7LesQM7e70 github.com/tendermint/tendermint v0.34.0-rc3/go.mod h1:BoHcEpjfpBHc1Be7RQz3AHaXFNObcDG7SNHCev6Or4g= github.com/tendermint/tendermint v0.34.0-rc4 h1:fnPyDFz9QGAU6tjExoQ8ZY63eHkzdBg5StQgDoeuK0s= github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= +github.com/tendermint/tendermint v0.34.0-rc4.0.20201005135527-d7d0ffea13c6 h1:gqZ0WDpDYgMm/iaiMEXvI1nt/GoWCuwtBomVpUMiAIs= +github.com/tendermint/tendermint v0.34.0-rc4.0.20201005135527-d7d0ffea13c6/go.mod h1:BSXqR6vWbOecet726v66qVwSkFDLfEeBrq+EhkKbij4= github.com/tendermint/tm-db v0.6.1 h1:w3X87itMPXopcRPlFiqspEKhw4FXihPk2rnFFkP0zGk= github.com/tendermint/tm-db v0.6.1/go.mod h1:m3x9kRP4UFd7JODJL0yBAZqE7wTw+S37uAE90cTx7OA= github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM= diff --git a/testutil/network/network.go b/testutil/network/network.go index 582a0cb1a0..914ed792dc 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -37,6 +37,7 @@ import ( srvconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/params" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -52,13 +53,16 @@ var lock = new(sync.Mutex) // creates an ABCI Application to provide to Tendermint. type AppConstructor = func(val Validator) servertypes.Application -func NewSimApp(val Validator) servertypes.Application { - return simapp.NewSimApp( - val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, - simapp.MakeEncodingConfig(), - baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), - baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), - ) +// NewAppConstructor returns a new simapp AppConstructor +func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { + return func(val Validator) servertypes.Application { + return simapp.NewSimApp( + val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, + encodingCfg, + baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), + baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), + ) + } } // Config defines the necessary configuration used to bootstrap and start an @@ -98,7 +102,7 @@ func DefaultConfig() Config { LegacyAmino: encCfg.Amino, InterfaceRegistry: encCfg.InterfaceRegistry, AccountRetriever: authtypes.AccountRetriever{}, - AppConstructor: NewSimApp, + AppConstructor: NewAppConstructor(encCfg), GenesisState: simapp.ModuleBasics.DefaultGenesis(encCfg.Marshaler), TimeoutCommit: 2 * time.Second, ChainID: "chain-" + tmrand.NewRand().Str(6), diff --git a/x/staking/client/cli/cli_test.go b/x/staking/client/cli/cli_test.go index ba0f7119fc..3ec0546665 100644 --- a/x/staking/client/cli/cli_test.go +++ b/x/staking/client/cli/cli_test.go @@ -3,6 +3,7 @@ package cli_test import ( + "context" json "encoding/json" "fmt" "strings" @@ -11,6 +12,8 @@ import ( "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/proto/tendermint/crypto" + "github.com/tendermint/tendermint/rpc/client/http" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" @@ -36,6 +39,10 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") + if testing.Short() { + s.T().Skip("skipping test in unit-tests mode.") + } + cfg := network.DefaultConfig() cfg.NumValidators = 2 @@ -1260,6 +1267,75 @@ func (s *IntegrationTestSuite) TestNewCmdUnbond() { } } +// TestBlockResults tests that the validator updates correctly show when +// calling the /block_results RPC endpoint. +// ref: https://github.com/cosmos/cosmos-sdk/issues/7401. +func (s *IntegrationTestSuite) TestBlockResults() { + require := s.Require() + val := s.network.Validators[0] + + // Create new account in the keyring. + info, _, err := val.ClientCtx.Keyring.NewMnemonic("NewDelegator", keyring.English, sdk.FullFundraiserPath, hd.Secp256k1) + require.NoError(err) + newAddr := sdk.AccAddress(info.GetPubKey().Address()) + + // Send some funds to the new account. + _, err = banktestutil.MsgSendExec( + val.ClientCtx, + val.Address, + newAddr, + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + ) + require.NoError(err) + + // Use CLI to create a delegation from the new account to validator `val`. + delHeight, err := s.network.LatestHeight() + require.NoError(err) + cmd := cli.NewDelegateCmd() + _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, []string{ + val.ValAddress.String(), + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(150)).String(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + }) + require.NoError(err) + + // Create a HTTP rpc client. + rpcClient, err := http.New(val.RPCAddress, "/websocket") + + // Loop until we find a block result with the correct validator updates. + // By experience, it happens around 2 blocks after `delHeight`. + for { + latestHeight, err := s.network.LatestHeight() + require.NoError(err) + + // Wait maximum 10 blocks, or else fail test. + if latestHeight > delHeight+10 { + s.Fail("timeout reached") + } + + res, err := rpcClient.BlockResults(context.Background(), &latestHeight) + require.NoError(err) + + if len(res.ValidatorUpdates) > 0 { + valUpdate := res.ValidatorUpdates[0] + require.Equal( + valUpdate.GetPubKey().Sum.(*crypto.PublicKey_Ed25519).Ed25519, + val.PubKey.Bytes(), + ) + + // We got our validator update, test passed. + break + } + + s.network.WaitForNextBlock() + } +} + func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) }