diff --git a/x/wasm/keeper/msg_server.go b/x/wasm/keeper/msg_server.go index fe410c79d2..5c5f47e19e 100644 --- a/x/wasm/keeper/msg_server.go +++ b/x/wasm/keeper/msg_server.go @@ -29,12 +29,6 @@ func (m msgServer) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*t return nil, sdkerrors.Wrap(err, "sender") } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) - codeID, checksum, err := m.keeper.Create(ctx, senderAddr, msg.WASMByteCode, msg.InstantiatePermission) if err != nil { return nil, err @@ -64,12 +58,6 @@ func (m msgServer) InstantiateContract(goCtx context.Context, msg *types.MsgInst } } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) - contractAddr, data, err := m.keeper.Instantiate(ctx, msg.CodeID, senderAddr, adminAddr, msg.Msg, msg.Label, msg.Funds) if err != nil { return nil, err @@ -99,11 +87,6 @@ func (m msgServer) InstantiateContract2(goCtx context.Context, msg *types.MsgIns } } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) contractAddr, data, err := m.keeper.Instantiate2(ctx, msg.CodeID, senderAddr, adminAddr, msg.Msg, msg.Label, msg.Funds, msg.Salt, msg.FixMsg) if err != nil { return nil, err @@ -130,12 +113,6 @@ func (m msgServer) ExecuteContract(goCtx context.Context, msg *types.MsgExecuteC return nil, sdkerrors.Wrap(err, "contract") } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) - data, err := m.keeper.Execute(ctx, contractAddr, senderAddr, msg.Msg, msg.Funds) if err != nil { return nil, err @@ -161,12 +138,6 @@ func (m msgServer) MigrateContract(goCtx context.Context, msg *types.MsgMigrateC return nil, sdkerrors.Wrap(err, "contract") } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) - data, err := m.keeper.Migrate(ctx, contractAddr, senderAddr, msg.CodeID, msg.Msg) if err != nil { return nil, err @@ -196,12 +167,6 @@ func (m msgServer) UpdateAdmin(goCtx context.Context, msg *types.MsgUpdateAdmin) return nil, sdkerrors.Wrap(err, "new admin") } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) - if err := m.keeper.UpdateContractAdmin(ctx, contractAddr, senderAddr, newAdminAddr); err != nil { return nil, err } @@ -224,12 +189,6 @@ func (m msgServer) ClearAdmin(goCtx context.Context, msg *types.MsgClearAdmin) ( return nil, sdkerrors.Wrap(err, "contract") } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) - if err := m.keeper.ClearContractAdmin(ctx, contractAddr, senderAddr); err != nil { return nil, err } diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index 72b2cc6bf0..9d5087c507 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -189,12 +189,10 @@ func TestHandleInstantiate(t *testing.T) { require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", contractBech32Addr) // this should be standard x/wasm init event, nothing from contract - require.Equal(t, 3, len(res.Events), prettyEvents(res.Events)) - require.Equal(t, "message", res.Events[0].Type) - assertAttribute(t, "module", "wasm", res.Events[0].Attributes[0]) - require.Equal(t, "instantiate", res.Events[1].Type) - require.Equal(t, "wasm", res.Events[2].Type) - assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[2].Attributes[0]) + require.Equal(t, 2, len(res.Events), prettyEvents(res.Events)) + require.Equal(t, "instantiate", res.Events[0].Type) + require.Equal(t, "wasm", res.Events[1].Type) + assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[1].Attributes[0]) assertCodeList(t, q, data.ctx, 1) assertCodeBytes(t, q, data.ctx, 1, testContract) @@ -249,15 +247,13 @@ func TestHandleExecute(t *testing.T) { require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", contractBech32Addr) // this should be standard x/wasm message event, init event, plus a bank send event (2), with no custom contract events - require.Equal(t, 6, len(res.Events), prettyEvents(res.Events)) - require.Equal(t, "message", res.Events[0].Type) - assertAttribute(t, "module", "wasm", res.Events[0].Attributes[0]) - require.Equal(t, "coin_spent", res.Events[1].Type) - require.Equal(t, "coin_received", res.Events[2].Type) - require.Equal(t, "transfer", res.Events[3].Type) - require.Equal(t, "instantiate", res.Events[4].Type) - require.Equal(t, "wasm", res.Events[5].Type) - assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[5].Attributes[0]) + require.Equal(t, 5, len(res.Events), prettyEvents(res.Events)) + require.Equal(t, "coin_spent", res.Events[0].Type) + require.Equal(t, "coin_received", res.Events[1].Type) + require.Equal(t, "transfer", res.Events[2].Type) + require.Equal(t, "instantiate", res.Events[3].Type) + require.Equal(t, "wasm", res.Events[4].Type) + assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[4].Attributes[0]) // ensure bob doesn't exist bobAcct := data.acctKeeper.GetAccount(data.ctx, bob) @@ -287,43 +283,36 @@ func TestHandleExecute(t *testing.T) { assertExecuteResponse(t, res.Data, []byte{0xf0, 0x0b, 0xaa}) // this should be standard message event, plus x/wasm init event, plus 2 bank send event, plus a special event from the contract - require.Equal(t, 10, len(res.Events), prettyEvents(res.Events)) + require.Equal(t, 9, len(res.Events), prettyEvents(res.Events)) - assert.Equal(t, "message", res.Events[0].Type) - assertAttribute(t, "module", "wasm", res.Events[0].Attributes[0]) - assert.Equal(t, "coin_spent", res.Events[1].Type) - assert.Equal(t, "coin_received", res.Events[2].Type) + assert.Equal(t, "coin_spent", res.Events[0].Type) + assert.Equal(t, "coin_received", res.Events[1].Type) - assert.Equal(t, "coin_spent", res.Events[1].Type) - assertAttribute(t, "spender", fred.String(), res.Events[1].Attributes[0]) - assert.Equal(t, "coin_received", res.Events[2].Type) - assertAttribute(t, "receiver", contractBech32Addr, res.Events[2].Attributes[0]) - require.Equal(t, "transfer", res.Events[3].Type) - require.Len(t, res.Events[3].Attributes, 3) - assertAttribute(t, "recipient", contractBech32Addr, res.Events[3].Attributes[0]) - assertAttribute(t, "sender", fred.String(), res.Events[3].Attributes[1]) - assertAttribute(t, "amount", "5000denom", res.Events[3].Attributes[2]) + require.Equal(t, "transfer", res.Events[2].Type) + require.Len(t, res.Events[2].Attributes, 3) + assertAttribute(t, "recipient", contractBech32Addr, res.Events[2].Attributes[0]) + assertAttribute(t, "sender", fred.String(), res.Events[2].Attributes[1]) + assertAttribute(t, "amount", "5000denom", res.Events[2].Attributes[2]) - assert.Equal(t, "execute", res.Events[4].Type) + assert.Equal(t, "execute", res.Events[3].Type) // custom contract event attribute - assert.Equal(t, "wasm", res.Events[5].Type) + assert.Equal(t, "wasm", res.Events[4].Type) + assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[4].Attributes[0]) + assertAttribute(t, "action", "release", res.Events[4].Attributes[1]) + // custom contract event + assert.Equal(t, "wasm-hackatom", res.Events[5].Type) assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[5].Attributes[0]) assertAttribute(t, "action", "release", res.Events[5].Attributes[1]) - // custom contract event - assert.Equal(t, "wasm-hackatom", res.Events[6].Type) - assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[6].Attributes[0]) - assertAttribute(t, "action", "release", res.Events[6].Attributes[1]) // second transfer (this without conflicting message) - assert.Equal(t, "coin_spent", res.Events[7].Type) - assertAttribute(t, "spender", contractBech32Addr, res.Events[7].Attributes[0]) - assert.Equal(t, "coin_received", res.Events[8].Type) - assertAttribute(t, "receiver", bob.String(), res.Events[8].Attributes[0]) - assert.Equal(t, "transfer", res.Events[9].Type) - assertAttribute(t, "recipient", bob.String(), res.Events[9].Attributes[0]) - assertAttribute(t, "sender", contractBech32Addr, res.Events[9].Attributes[1]) - assertAttribute(t, "amount", "105000denom", res.Events[9].Attributes[2]) + assert.Equal(t, "coin_spent", res.Events[6].Type) + assert.Equal(t, "coin_received", res.Events[7].Type) + + assert.Equal(t, "transfer", res.Events[8].Type) + assertAttribute(t, "recipient", bob.String(), res.Events[8].Attributes[0]) + assertAttribute(t, "sender", contractBech32Addr, res.Events[8].Attributes[1]) + assertAttribute(t, "amount", "105000denom", res.Events[8].Attributes[2]) // finally, standard x/wasm tag // ensure bob now exists and got both payments released diff --git a/x/wasmplus/keeper/msg_server.go b/x/wasmplus/keeper/msg_server.go index 65feaa322e..9b2d2fd895 100644 --- a/x/wasmplus/keeper/msg_server.go +++ b/x/wasmplus/keeper/msg_server.go @@ -33,12 +33,6 @@ func (m msgServer) StoreCodeAndInstantiateContract(goCtx context.Context, return nil, err } - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - )) - var adminAddr sdk.AccAddress if msg.Admin != "" { adminAddr, err = sdk.AccAddressFromBech32(msg.Admin) diff --git a/x/wasmplus/module_test.go b/x/wasmplus/module_test.go index d48f3843c5..99656603b9 100644 --- a/x/wasmplus/module_test.go +++ b/x/wasmplus/module_test.go @@ -264,16 +264,14 @@ func TestHandleStoreAndInstantiate(t *testing.T) { require.Equal(t, uint64(1), codeID) require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", contractBech32Addr) // this should be standard x/wasm init event, nothing from contract - require.Equal(t, 4, len(res.Events), prettyEvents(res.Events)) + require.Equal(t, 3, len(res.Events), prettyEvents(res.Events)) assert.Equal(t, "store_code", res.Events[0].Type) assertAttribute(t, "code_id", "1", res.Events[0].Attributes[1]) - assert.Equal(t, "message", res.Events[1].Type) - assertAttribute(t, "module", "wasm", res.Events[1].Attributes[0]) - assert.Equal(t, "instantiate", res.Events[2].Type) + assert.Equal(t, "instantiate", res.Events[1].Type) + assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[1].Attributes[0]) + assertAttribute(t, "code_id", "1", res.Events[1].Attributes[1]) + assert.Equal(t, "wasm", res.Events[2].Type) assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[2].Attributes[0]) - assertAttribute(t, "code_id", "1", res.Events[2].Attributes[1]) - assert.Equal(t, "wasm", res.Events[3].Type) - assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[3].Attributes[0]) assertCodeList(t, q, data.ctx, 1) assertCodeBytes(t, q, data.ctx, 1, testContract) @@ -421,11 +419,9 @@ func TestHandleNonPlusWasmCreate(t *testing.T) { require.NoError(t, err) assertStoreCodeResponse(t, res.Data, 1) - require.Equal(t, 2, len(res.Events), prettyEvents(res.Events)) - assert.Equal(t, "message", res.Events[0].Type) - assertAttribute(t, "module", "wasm", res.Events[0].Attributes[0]) - assert.Equal(t, "store_code", res.Events[1].Type) - assertAttribute(t, "code_id", "1", res.Events[1].Attributes[1]) + require.Equal(t, 1, len(res.Events), prettyEvents(res.Events)) + assert.Equal(t, "store_code", res.Events[0].Type) + assertAttribute(t, "code_id", "1", res.Events[0].Attributes[1]) assertCodeList(t, q, data.ctx, 1) assertCodeBytes(t, q, data.ctx, 1, testContract)