Skip to content

Commit

Permalink
Introduce two following changes to the commitBlock method in testing:
Browse files Browse the repository at this point in the history
* increment the proposer priority of validators
* update the proposer address in the current header
  • Loading branch information
sainoe committed Oct 9, 2024
1 parent 7df9ebd commit 49f3026
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion 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,7 @@ func (chain *TestChain) commitBlock(res *abci.ResponseFinalizeBlock) {
Time: chain.CurrentHeader.Time,
ValidatorsHash: chain.Vals.Hash(),
NextValidatorsHash: chain.NextVals.Hash(),
ProposerAddress: chain.CurrentHeader.ProposerAddress,
ProposerAddress: chain.Vals.Proposer.Address,
}
}

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

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

Check failure on line 9 in testing/chain_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

Check failure on line 9 in testing/chain_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

Check failure on line 10 in testing/chain_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

Check failure on line 10 in testing/chain_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
"github.com/cosmos/cosmos-sdk/x/staking/types"

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 49f3026

Please sign in to comment.