diff --git a/x/opchild/keeper/msg_server.go b/x/opchild/keeper/msg_server.go index 20d9f2d..4d44d37 100644 --- a/x/opchild/keeper/msg_server.go +++ b/x/opchild/keeper/msg_server.go @@ -441,10 +441,14 @@ func (ms MsgServer) FinalizeTokenDeposit(ctx context.Context, req *types.MsgFina if depositSuccess && len(req.Data) > 0 { hookSuccess, reason = ms.handleBridgeHook(sdkCtx, req.Data) event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeySuccess, strconv.FormatBool(hookSuccess))) - event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeyReason, "hook failed; "+reason)) + if !hookSuccess { + event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeyReason, "hook failed; "+reason)) + } } else { event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeySuccess, strconv.FormatBool(depositSuccess))) - event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeyReason, reason)) + if !depositSuccess { + event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeyReason, "deposit failed; "+reason)) + } } // emit deposit event diff --git a/x/opchild/keeper/msg_server_test.go b/x/opchild/keeper/msg_server_test.go index 79968b9..f3e88f6 100644 --- a/x/opchild/keeper/msg_server_test.go +++ b/x/opchild/keeper/msg_server_test.go @@ -413,13 +413,22 @@ func Test_MsgServer_Deposit_ToModuleAccount(t *testing.T) { _, err := ms.FinalizeTokenDeposit(ctx, msg) require.NoError(t, err) + for _, event := range sdk.UnwrapSDKContext(ctx).EventManager().Events() { + if event.Type == types.EventTypeFinalizeTokenDeposit { + attrIdx := slices.Index(event.Attributes, sdk.NewAttribute(types.AttributeKeySuccess, "false").ToKVPair()) + require.Positive(t, attrIdx) + require.Equal(t, event.Attributes[attrIdx+1].Key, types.AttributeKeyReason) + require.Contains(t, event.Attributes[attrIdx+1].Value, "deposit failed;") + } + } + afterToBalance := input.BankKeeper.GetBalance(ctx, addrs[1], denom) require.Equal(t, math.ZeroInt(), afterToBalance.Amount) afterModuleBalance := input.BankKeeper.GetBalance(ctx, opchildModuleAddress, denom) require.True(t, afterModuleBalance.Amount.IsZero()) - // token withdrawal inititated + // token withdrawal initiated events := sdk.UnwrapSDKContext(ctx).EventManager().Events() lastEvent := events[len(events)-1] require.Equal(t, sdk.NewEvent(