Skip to content

Commit

Permalink
fix: remove duplicated message events
Browse files Browse the repository at this point in the history
  • Loading branch information
dadamu committed Dec 28, 2023
1 parent cfefad2 commit 6fb9439
Show file tree
Hide file tree
Showing 29 changed files with 7 additions and 923 deletions.
75 changes: 0 additions & 75 deletions x/posts/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ func (k msgServer) CreatePost(goCtx context.Context, msg *types.MsgCreatePost) (
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Author),
),
sdk.NewEvent(
types.EventTypeCreatePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -162,12 +156,6 @@ func (k msgServer) EditPost(goCtx context.Context, msg *types.MsgEditPost) (*typ
k.SavePost(ctx, updatedPost)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Editor),
),
sdk.NewEvent(
types.EventTypeEditPost,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -207,12 +195,6 @@ func (k msgServer) DeletePost(goCtx context.Context, msg *types.MsgDeletePost) (
k.Keeper.DeletePost(ctx, msg.SubspaceID, msg.PostID)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Signer),
),
sdk.NewEvent(
types.EventTypeDeletePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -313,12 +295,6 @@ func (k msgServer) AddPostAttachment(goCtx context.Context, msg *types.MsgAddPos
k.SavePost(ctx, post)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Editor),
),
sdk.NewEvent(
types.EventTypeAddPostAttachment,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -376,12 +352,6 @@ func (k msgServer) RemovePostAttachment(goCtx context.Context, msg *types.MsgRem
k.SavePost(ctx, post)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Editor),
),
sdk.NewEvent(
types.EventTypeRemovePostAttachment,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -461,12 +431,6 @@ func (k msgServer) AnswerPoll(goCtx context.Context, msg *types.MsgAnswerPoll) (
k.SaveUserAnswer(ctx, answer)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Signer),
),
sdk.NewEvent(
types.EventTypeAnswerPoll,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand All @@ -488,15 +452,6 @@ func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParam
ctx := sdk.UnwrapSDKContext(goCtx)
m.SetParams(ctx, msg.Params)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Authority),
),
})

return &types.MsgUpdateParamsResponse{}, nil
}

Expand Down Expand Up @@ -574,12 +529,6 @@ func (k msgServer) MovePost(goCtx context.Context, msg *types.MsgMovePost) (*typ
k.Keeper.DeletePost(ctx, msg.SubspaceID, msg.PostID)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Owner),
),
sdk.NewEvent(
types.EventTypeMovePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -636,12 +585,6 @@ func (k msgServer) RequestPostOwnerTransfer(goCtx context.Context, msg *types.Ms
))

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
),
sdk.NewEvent(
types.EventTypeRequestPostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -673,12 +616,6 @@ func (k msgServer) CancelPostOwnerTransferRequest(goCtx context.Context, msg *ty
k.DeletePostOwnerTransferRequest(ctx, msg.SubspaceID, msg.PostID)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
),
sdk.NewEvent(
types.EventTypeCancelPostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -735,12 +672,6 @@ func (k msgServer) AcceptPostOwnerTransferRequest(goCtx context.Context, msg *ty
k.DeletePostOwnerTransferRequest(ctx, msg.SubspaceID, msg.PostID)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Receiver),
),
sdk.NewEvent(
types.EventTypeAcceptPostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down Expand Up @@ -771,12 +702,6 @@ func (k msgServer) RefusePostOwnerTransferRequest(goCtx context.Context, msg *ty
k.DeletePostOwnerTransferRequest(ctx, msg.SubspaceID, msg.PostID)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(msg)),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Receiver),
),
sdk.NewEvent(
types.EventTypeRefusePostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, fmt.Sprintf("%d", msg.SubspaceID)),
Expand Down
99 changes: 1 addition & 98 deletions x/posts/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,6 @@ func (suite *KeeperTestSuite) TestMsgServer_CreatePost() {
CreationDate: time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC),
},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgCreatePost{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeCreatePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -485,12 +479,6 @@ func (suite *KeeperTestSuite) TestMsgServer_CreatePost() {
CreationDate: time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC),
},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgCreatePost{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeCreatePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -778,12 +766,6 @@ func (suite *KeeperTestSuite) TestMsgServer_EditPost() {
EditDate: time.Date(2021, 1, 1, 12, 00, 00, 000, time.UTC),
},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgEditPost{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeEditPost,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -985,12 +967,6 @@ func (suite *KeeperTestSuite) TestMsgServer_DeletePost() {
msg: types.NewMsgDeletePost(1, 1, "cosmos1r9jamre0x0qqy562rhhckt6sryztwhnvhafyz4"),
shouldErr: false,
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgDeletePost{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos1r9jamre0x0qqy562rhhckt6sryztwhnvhafyz4"),
),
sdk.NewEvent(
types.EventTypeDeletePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -1042,12 +1018,6 @@ func (suite *KeeperTestSuite) TestMsgServer_DeletePost() {
},
msg: types.NewMsgDeletePost(1, 1, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgDeletePost{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeDeletePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -1289,12 +1259,6 @@ func (suite *KeeperTestSuite) TestMsgServer_AddPostAttachment() {
EditDate: time.Date(2021, 1, 1, 12, 00, 00, 000, time.UTC),
},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgAddPostAttachment{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeAddPostAttachment,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -1619,12 +1583,6 @@ func (suite *KeeperTestSuite) TestMsgServer_RemovePostAttachment() {
EditDate: time.Date(2021, 1, 1, 12, 00, 00, 000, time.UTC),
},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgRemovePostAttachment{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos1r9jamre0x0qqy562rhhckt6sryztwhnvhafyz4"),
),
sdk.NewEvent(
types.EventTypeRemovePostAttachment,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -1707,12 +1665,6 @@ func (suite *KeeperTestSuite) TestMsgServer_RemovePostAttachment() {
EditDate: time.Date(2021, 1, 1, 12, 00, 00, 000, time.UTC),
},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgRemovePostAttachment{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeRemovePostAttachment,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -2235,12 +2187,6 @@ func (suite *KeeperTestSuite) TestMsgServer_AnswerPoll() {
),
shouldErr: false,
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgAnswerPoll{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeAnswerPoll,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -2322,12 +2268,6 @@ func (suite *KeeperTestSuite) TestMsgServer_AnswerPoll() {
),
shouldErr: false,
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgAnswerPoll{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeAnswerPoll,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -2403,14 +2343,7 @@ func (suite *KeeperTestSuite) TestMsgServer_UpdateParams() {
authtypes.NewModuleAddress("gov").String(),
),
shouldErr: false,
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgUpdateParams{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"),
),
},
expEvents: sdk.Events{},
check: func(ctx sdk.Context) {
params := suite.k.GetParams(ctx)
suite.Require().Equal(types.DefaultParams(), params)
Expand Down Expand Up @@ -2832,12 +2765,6 @@ func (suite *KeeperTestSuite) TestMsgServer_MovePost() {
),
shouldErr: false,
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgMovePost{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeMovePost,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -3227,12 +3154,6 @@ func (suite *KeeperTestSuite) TestMsgServer_RequestPostOwnerTransfer() {
),
expResponse: &types.MsgRequestPostOwnerTransferResponse{},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgRequestPostOwnerTransfer{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg"),
),
sdk.NewEvent(
types.EventTypeRequestPostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -3342,12 +3263,6 @@ func (suite *KeeperTestSuite) TestMsgServer_CancelPostOwnerTransfer() {
),
expResponse: &types.MsgCancelPostOwnerTransferRequestResponse{},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgCancelPostOwnerTransferRequest{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg"),
),
sdk.NewEvent(
types.EventTypeCancelPostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -3588,12 +3503,6 @@ func (suite *KeeperTestSuite) TestMsgServer_AcceptPostOwnerTransfer() {
),
expResponse: &types.MsgAcceptPostOwnerTransferRequestResponse{},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgAcceptPostOwnerTransferRequest{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeAcceptPostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down Expand Up @@ -3689,12 +3598,6 @@ func (suite *KeeperTestSuite) TestMsgServer_RefusePostOwnerTransfer() {
),
expResponse: &types.MsgRefusePostOwnerTransferRequestResponse{},
expEvents: sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgRefusePostOwnerTransferRequest{})),
sdk.NewAttribute(sdk.AttributeKeySender, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"),
),
sdk.NewEvent(
types.EventTypeRefusePostOwnerTransfer,
sdk.NewAttribute(types.AttributeKeySubspaceID, "1"),
Expand Down
2 changes: 1 addition & 1 deletion x/posts/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const (
EventTypeCancelPostOwnerTransfer = "cancel_post_owner_transfer"
EventTypeAcceptPostOwnerTransfer = "accept_post_owner_transfer"
EventTypeRefusePostOwnerTransfer = "refuse_post_owner_transfer"
EventTypeUpdateParams = "update_params"

AttributeValueCategory = ModuleName
AttributeKeySubspaceID = "subspace_id"
AttributeKeySectionID = "section_id"
AttributeKeyPostID = "post_id"
Expand Down
Loading

0 comments on commit 6fb9439

Please sign in to comment.