-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix groups test / sanitize messages (#3516)
* sanitizate messages in broadcast messages function * Update e2e/testsuite/sanitize/messages.go --------- Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
- Loading branch information
1 parent
48341b4
commit 6894016
Showing
2 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sanitize | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
grouptypes "github.com/cosmos/cosmos-sdk/x/group" | ||
|
||
"github.com/cosmos/ibc-go/e2e/semverutil" | ||
) | ||
|
||
var ( | ||
// groupsv1ProposalTitleAndSummary represents the releases that support the new title and summary fields. | ||
groupsv1ProposalTitleAndSummary = semverutil.FeatureReleases{ | ||
MajorVersion: "v7", | ||
} | ||
// govv1ProposalTitleAndSummary represents the releases that support the new title and summary fields. | ||
govv1ProposalTitleAndSummary = semverutil.FeatureReleases{ | ||
MajorVersion: "v7", | ||
} | ||
) | ||
|
||
// Messages removes any fields that are not supported by the chain version. | ||
// For example, any fields that have been added in later sdk releases. | ||
func Messages(tag string, msgs ...sdk.Msg) []sdk.Msg { | ||
sanitizedMsgs := make([]sdk.Msg, len(msgs)) | ||
for i := range msgs { | ||
sanitizedMsgs[i] = removeUnknownFields(tag, msgs[i]) | ||
} | ||
return sanitizedMsgs | ||
} | ||
|
||
// removeUnknownFields removes any fields that are not supported by the chain version. | ||
// The input message is returned if no changes are made. | ||
func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg { | ||
switch msg := msg.(type) { | ||
case *govtypesv1.MsgSubmitProposal: | ||
if !govv1ProposalTitleAndSummary.IsSupported(tag) { | ||
msg.Title = "" | ||
msg.Summary = "" | ||
} | ||
return msg | ||
case *grouptypes.MsgSubmitProposal: | ||
if !groupsv1ProposalTitleAndSummary.IsSupported(tag) { | ||
msg.Title = "" | ||
msg.Summary = "" | ||
} | ||
return msg | ||
} | ||
return msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters