From 23d928184de45aa943d3aff7710285406d178e0c Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 9 Oct 2024 16:49:54 +0200 Subject: [PATCH 1/2] Introduce two following changes to the `commitBlock` method in testing: * increment the proposer priority of validators * update the proposer address in the current header --- CHANGELOG.md | 4 ++++ testing/chain.go | 5 ++++- testing/chain_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2225e03952..e68c1a222da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 * [\#7247](https://github.com/cosmos/ibc-go/pull/7247) Bump CometBFT to v0.38.12. diff --git a/testing/chain.go b/testing/chain.go index e7b254db2ee..a898b64fd3d 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -323,6 +323,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.ProposedHeader = cmtproto.Header{ ChainID: chain.ChainID, @@ -333,7 +336,7 @@ func (chain *TestChain) commitBlock(res *abci.ResponseFinalizeBlock) { Time: chain.ProposedHeader.Time, ValidatorsHash: chain.Vals.Hash(), NextValidatorsHash: chain.NextVals.Hash(), - ProposerAddress: chain.ProposedHeader.ProposerAddress, + ProposerAddress: chain.Vals.Proposer.Address, } } diff --git a/testing/chain_test.go b/testing/chain_test.go index 512e426eaca..5cab5dd5dd4 100644 --- a/testing/chain_test.go +++ b/testing/chain_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -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))) +} From 796396886d128c5b454ff8a8923cdc3fea4fdd46 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Mon, 14 Oct 2024 14:31:12 +0200 Subject: [PATCH 2/2] fix linter --- testing/chain_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/chain_test.go b/testing/chain_test.go index 5cab5dd5dd4..e72057765b3 100644 --- a/testing/chain_test.go +++ b/testing/chain_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ibctesting "github.com/cosmos/ibc-go/v9/testing"