Skip to content

Commit 66463cc

Browse files
authored
Merge pull request #26382 from cosmos/mergify/bp/release/v0.54.x/pr-26353
fix(x/gov): remove leading comma in proposal_messages event attribute (backport #26353)
2 parents 8810f3b + e69da8d commit 66463cc

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
4848

4949
### Bug Fixes
5050

51+
* (x/gov) [#26353](https://github.com/cosmos/cosmos-sdk/pull/26353) Fix leading comma in `proposal_messages` event attribute emitted by `SubmitProposal`.
52+
5153
### Deprecated
5254

5355
## [v0.54.2](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.54.2) - 2026-04-15

x/gov/keeper/proposal.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"strings"
89
"time"
910

1011
"cosmossdk.io/collections"
@@ -35,13 +36,12 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata
3536
return v1.Proposal{}, err
3637
}
3738

38-
// Will hold a comma-separated string of all Msg type URLs.
39-
msgsStr := ""
39+
msgTypeURLs := make([]string, 0, len(messages))
4040

4141
// Loop through all messages and confirm that each has a handler and the gov module account
4242
// as the only signer
4343
for _, msg := range messages {
44-
msgsStr += fmt.Sprintf(",%s", sdk.MsgTypeURL(msg))
44+
msgTypeURLs = append(msgTypeURLs, sdk.MsgTypeURL(msg))
4545

4646
// perform a basic validation of the message
4747
if m, ok := msg.(sdk.HasValidateBasic); ok {
@@ -124,7 +124,7 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata
124124
types.EventTypeSubmitProposal,
125125
sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposalID)),
126126
sdk.NewAttribute(types.AttributeKeyProposalProposer, proposer.String()),
127-
sdk.NewAttribute(types.AttributeKeyProposalMessages, msgsStr),
127+
sdk.NewAttribute(types.AttributeKeyProposalMessages, strings.Join(msgTypeURLs, ",")),
128128
),
129129
)
130130

x/gov/keeper/proposal_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,33 @@ func (suite *KeeperTestSuite) TestSubmitProposal() {
173173
}
174174
}
175175

176+
// TestSubmitProposal_EmitsMessagesWithoutLeadingComma is a regression test for
177+
// https://github.com/cosmos/cosmos-sdk/issues/26045 — the proposal_messages
178+
// event attribute previously contained a leading comma because each type URL
179+
// was prepended with one inside the loop.
180+
func (suite *KeeperTestSuite) TestSubmitProposal_EmitsMessagesWithoutLeadingComma() {
181+
suite.reset()
182+
183+
govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress().String()
184+
tp := v1beta1.TextProposal{Title: "title", Description: "description"}
185+
prop, err := v1.NewLegacyContent(&tp, govAcct)
186+
suite.Require().NoError(err)
187+
188+
msgs := []sdk.Msg{prop, prop}
189+
_, err = suite.govKeeper.SubmitProposal(suite.ctx, msgs, "", "title", "summary", suite.addrs[0], false)
190+
suite.Require().NoError(err)
191+
192+
attrs, ok := suite.ctx.EventManager().Events().GetAttributes(types.AttributeKeyProposalMessages)
193+
suite.Require().True(ok, "proposal_messages attribute should be emitted")
194+
suite.Require().NotEmpty(attrs)
195+
196+
value := attrs[0].Value
197+
suite.Require().False(strings.HasPrefix(value, ","), "proposal_messages must not start with a leading comma, got %q", value)
198+
199+
expected := strings.Join([]string{sdk.MsgTypeURL(prop), sdk.MsgTypeURL(prop)}, ",")
200+
suite.Require().Equal(expected, value)
201+
}
202+
176203
func (suite *KeeperTestSuite) TestCancelProposal() {
177204
govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress().String()
178205
tp := v1beta1.TextProposal{Title: "title", Description: "description"}

0 commit comments

Comments
 (0)