Skip to content

Commit

Permalink
test: update block proposer in testing (#7430)
Browse files Browse the repository at this point in the history
* Introduce two following changes to the `commitBlock` method in testing:
* increment the proposer priority of validators
* update the proposer address in the current header

* fix linter

(cherry picked from commit 64f33e0)

# Conflicts:
#	testing/chain.go
  • Loading branch information
sainoe authored and mergify[bot] committed Oct 14, 2024
1 parent 7df9ebd commit 0259fcf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [[Unreleased]]

### Testing

* [\#7430](https://github.com/cosmos/ibc-go/pull/7430) Update the block proposer in test chains for each block.

### Dependencies

### API Breaking
Expand Down
7 changes: 7 additions & 0 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ func (chain *TestChain) commitBlock(res *abci.ResponseFinalizeBlock) {
chain.Vals = chain.NextVals
chain.NextVals = ApplyValSetChanges(chain, chain.Vals, res.ValidatorUpdates)

// increment the proposer priority of validators
chain.Vals.IncrementProposerPriority(1)

// increment the current header
chain.CurrentHeader = cmtproto.Header{
ChainID: chain.ChainID,
Expand All @@ -327,7 +330,11 @@ func (chain *TestChain) commitBlock(res *abci.ResponseFinalizeBlock) {
Time: chain.CurrentHeader.Time,
ValidatorsHash: chain.Vals.Hash(),
NextValidatorsHash: chain.NextVals.Hash(),
<<<<<<< HEAD

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

expected operand, found '<<' (typecheck)

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected <<, expected expression

Check failure on line 333 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

expected operand, found '<<' (typecheck)
ProposerAddress: chain.CurrentHeader.ProposerAddress,
=======
ProposerAddress: chain.Vals.Proposer.Address,
>>>>>>> 64f33e09 (test: update block proposer in testing (#7430))

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

illegal character U+0023 '#' (typecheck)

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

invalid character U+0023 '#'

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 337 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

illegal character U+0023 '#' (typecheck)
}
}

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: non-declaration statement outside function body (typecheck)

Check failure on line 339 in testing/chain.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: non-declaration statement outside function body (typecheck)

Expand Down
34 changes: 34 additions & 0 deletions testing/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"

ibctesting "github.com/cosmos/ibc-go/v8/testing"
Expand Down Expand Up @@ -41,3 +42,36 @@ func TestChangeValSet(t *testing.T) {
err = path.EndpointB.UpdateClient()
require.NoError(t, err)
}

func TestJailProposerValidator(t *testing.T) {
coord := ibctesting.NewCoordinator(t, 2)
chainA := coord.GetChain(ibctesting.GetChainID(1))
chainB := coord.GetChain(ibctesting.GetChainID(2))

path := ibctesting.NewPath(chainA, chainB)
coord.Setup(path)

// save valset length before jailing
valsetLen := len(chainA.Vals.Validators)

// jail the proposer validator in chain A
propAddr := sdk.ConsAddress(chainA.Vals.Proposer.Address)

err := chainA.GetSimApp().StakingKeeper.Jail(
chainA.GetContext(), propAddr)
require.NoError(t, err)

coord.CommitBlock(chainA)

// verify that update clients works even after validator update goes into effect
err = path.EndpointB.UpdateClient()
require.NoError(t, err)
err = path.EndpointB.UpdateClient()
require.NoError(t, err)

// check that the jailing has taken effect in chain A
require.Equal(t, valsetLen-1, len(chainA.Vals.Validators))

// check that the valset in chain A has a new proposer
require.False(t, propAddr.Equals(sdk.ConsAddress(chainA.Vals.Proposer.Address)))
}

0 comments on commit 0259fcf

Please sign in to comment.