Skip to content

Commit

Permalink
fix: sanitize gov v1 proposal in e2e tests for compatibility with 0.52 (
Browse files Browse the repository at this point in the history
#7861)

* fix: sanitize gov v1 proposal in e2e tests for compatibility with 0.52

* sanitize validator for cometbft v1

* tidy

* rename replace to convert to show mutation-in-place
  • Loading branch information
gjermundgaraba authored Jan 22, 2025
1 parent e795b54 commit 39b190a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ replace (
)

require (
cosmossdk.io/api v0.8.2 // indirect
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.5.0
cosmossdk.io/x/upgrade v0.1.4
Expand All @@ -30,7 +31,6 @@ require (
require (
buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.36.2-20241120201313-68e42a58b301.1 // indirect
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.36.2-20240130113600-88ef6483f90f.1 // indirect
cosmossdk.io/api v0.8.2 // indirect
cosmossdk.io/collections v1.0.0 // indirect
cosmossdk.io/core v1.0.0 // indirect
cosmossdk.io/depinject v1.1.0 // indirect
Expand Down
54 changes: 54 additions & 0 deletions e2e/testsuite/sanitize/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import (

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

cmtcrypto "github.com/cometbft/cometbft/api/cometbft/crypto/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"

"github.com/cosmos/ibc-go/e2e/semverutil"
icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint"
)

var (
Expand All @@ -28,6 +33,14 @@ var (
"v8.1",
},
}
// groupsv1ProposalProposalType represents the releases that support the new proposal type field.
govv1ProposalProposalType = semverutil.FeatureReleases{
MajorVersion: "v10",
}
// cometBFTv1Validator represents the releases that support the new validator fields.
cometBFTv1Validator = semverutil.FeatureReleases{
MajorVersion: "v10",
}
)

// Messages removes any fields that are not supported by the chain version.
Expand All @@ -49,6 +62,9 @@ func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
msg.Title = ""
msg.Summary = ""
}
if !govv1ProposalProposalType.IsSupported(tag) {
msg.ProposalType = govtypesv1.ProposalType_PROPOSAL_TYPE_UNSPECIFIED
}
// sanitize messages contained in the x/gov proposal
msgs, err := msg.GetMsgs()
if err != nil {
Expand Down Expand Up @@ -78,6 +94,44 @@ func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
if !icaUnorderedChannelFeatureReleases.IsSupported(tag) {
msg.Ordering = channeltypes.NONE
}
case *clienttypes.MsgUpdateClient:
if !cometBFTv1Validator.IsSupported(tag) {
clientMessage, err := clienttypes.UnpackClientMessage(msg.ClientMessage)
if err != nil {
panic(err)
}
header, ok := clientMessage.(*ibctm.Header)
if !ok {
return msg
}

convertCometBFTValidatorV1(header.ValidatorSet.Proposer)
for _, validator := range header.ValidatorSet.Validators {
convertCometBFTValidatorV1(validator)
}

convertCometBFTValidatorV1(header.TrustedValidators.Proposer)
for _, validator := range header.TrustedValidators.Validators {
convertCometBFTValidatorV1(validator)
}

// repack the client message
clientMessageAny, err := clienttypes.PackClientMessage(header)
if err != nil {
panic(err)
}
msg.ClientMessage = clientMessageAny
}
}
return msg
}

func convertCometBFTValidatorV1(validator *cmtproto.Validator) {
validator.PubKey = &cmtcrypto.PublicKey{
Sum: &cmtcrypto.PublicKey_Ed25519{
Ed25519: validator.PubKeyBytes,
},
}
validator.PubKeyBytes = nil
validator.PubKeyType = ""
}

0 comments on commit 39b190a

Please sign in to comment.