From 39b190a39498d8410fcd734d4d8b8579e72524f1 Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Wed, 22 Jan 2025 10:32:47 +0100 Subject: [PATCH] fix: sanitize gov v1 proposal in e2e tests for compatibility with 0.52 (#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 --- e2e/go.mod | 2 +- e2e/testsuite/sanitize/messages.go | 54 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/e2e/go.mod b/e2e/go.mod index 9dce48335f4..a68ab517a5b 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -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 @@ -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 diff --git a/e2e/testsuite/sanitize/messages.go b/e2e/testsuite/sanitize/messages.go index b52c2b3a8bd..f245b3846c6 100644 --- a/e2e/testsuite/sanitize/messages.go +++ b/e2e/testsuite/sanitize/messages.go @@ -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 ( @@ -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. @@ -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 { @@ -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 = "" +}