Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(wasm): specify wasm event types #254

Merged
merged 6 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions x/wasm/internal/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (m msgServer) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*t
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeStoreCode,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
whylee259 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -62,7 +62,7 @@ func (m msgServer) InstantiateContract(goCtx context.Context, msg *types.MsgInst
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeInstantiateContract,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", msg.CodeID)),
Expand All @@ -87,7 +87,7 @@ func (m msgServer) StoreCodeAndInstantiateContract(goCtx context.Context, msg *t
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeStoreCode,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
Expand All @@ -106,7 +106,7 @@ func (m msgServer) StoreCodeAndInstantiateContract(goCtx context.Context, msg *t
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeInstantiateContract,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
Expand Down Expand Up @@ -137,7 +137,7 @@ func (m msgServer) ExecuteContract(goCtx context.Context, msg *types.MsgExecuteC
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeExecuteContract,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyContract, msg.Contract),
Expand Down Expand Up @@ -166,7 +166,7 @@ func (m msgServer) MigrateContract(goCtx context.Context, msg *types.MsgMigrateC
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeMigrateContract,
brew0722 marked this conversation as resolved.
Show resolved Hide resolved
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyContract, msg.Contract),
Expand Down Expand Up @@ -197,7 +197,7 @@ func (m msgServer) UpdateAdmin(goCtx context.Context, msg *types.MsgUpdateAdmin)
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeUpdateAdmin,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyContract, msg.Contract),
Expand All @@ -222,7 +222,7 @@ func (m msgServer) ClearAdmin(goCtx context.Context, msg *types.MsgClearAdmin) (
}

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeClearAdmin,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyContract, msg.Contract),
Expand Down
8 changes: 4 additions & 4 deletions x/wasm/internal/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func handleStoreCodeProposal(ctx sdk.Context, k governing, p types.StoreCodeProp
}

ourEvent := sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeStoreCode,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
)
Expand All @@ -100,7 +100,7 @@ func handleInstantiateProposal(ctx sdk.Context, k governing, p types.Instantiate
}

ourEvent := sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeInstantiateContract,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", p.CodeID)),
sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()),
Expand Down Expand Up @@ -128,7 +128,7 @@ func handleMigrateProposal(ctx sdk.Context, k governing, p types.MigrateContract
}

ourEvent := sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeMigrateContract,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeyContract, p.Contract),
)
Expand Down Expand Up @@ -162,7 +162,7 @@ func handleUpdateAdminProposal(ctx sdk.Context, k governing, p types.UpdateAdmin
}

ourEvent := sdk.NewEvent(
sdk.EventTypeMessage,
types.EventTypeUpdateAdmin,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeyContract, p.Contract),
)
Expand Down
6 changes: 6 additions & 0 deletions x/wasm/internal/types/events.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package types

const (
EventTypeStoreCode = "store_code"
EventTypeInstantiateContract = "instantiate_contract"
EventTypeExecuteContract = "execute_contract"
EventTypeMigrateContract = "migrate_contract"
EventTypeUpdateAdmin = "update_admin"
EventTypeClearAdmin = "clear_admin"
EventTypePinCode = "pin_code"
EventTypeUnpinCode = "unpin_code"
EventTypeUpdateContractStatus = "update_contract_status"
Expand Down
10 changes: 5 additions & 5 deletions x/wasm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestHandleInstantiate(t *testing.T) {
require.Equal(t, 2, len(res.Events), prettyEvents(res.Events))
assert.Equal(t, "wasm", res.Events[0].Type)
assertAttribute(t, "contract_address", contractBech32Addr, res.Events[0].Attributes[0])
assert.Equal(t, "message", res.Events[1].Type)
assert.Equal(t, "instantiate_contract", res.Events[1].Type)
assertAttribute(t, "module", "wasm", res.Events[1].Attributes[0])

assertCodeList(t, q, data.ctx, 1)
Expand Down Expand Up @@ -235,12 +235,12 @@ func TestHandleStoreAndInstantiate(t *testing.T) {
require.Equal(t, "link18vd8fpwxzck93qlwghaj6arh4p7c5n89fvcmzu", contractBech32Addr)
// this should be standard x/wasm init event, nothing from contract
require.Equal(t, 3, len(res.Events), prettyEvents(res.Events))
assert.Equal(t, "message", res.Events[0].Type)
assert.Equal(t, "store_code", res.Events[0].Type)
assertAttribute(t, "module", "wasm", res.Events[0].Attributes[0])
assertAttribute(t, "code_id", "1", res.Events[0].Attributes[2])
assert.Equal(t, "wasm", res.Events[1].Type)
assertAttribute(t, "contract_address", contractBech32Addr, res.Events[1].Attributes[0])
assert.Equal(t, "message", res.Events[2].Type)
assert.Equal(t, "instantiate_contract", res.Events[2].Type)
assertAttribute(t, "module", "wasm", res.Events[2].Attributes[0])
assertAttribute(t, "code_id", "1", res.Events[2].Attributes[2])
assertAttribute(t, "contract_address", contractBech32Addr, res.Events[2].Attributes[3])
Expand Down Expand Up @@ -418,7 +418,7 @@ func TestHandleExecute(t *testing.T) {
assert.Equal(t, "transfer", res.Events[0].Type)
assert.Equal(t, "wasm", res.Events[1].Type)
assertAttribute(t, "contract_address", contractBech32Addr, res.Events[1].Attributes[0])
assert.Equal(t, "message", res.Events[2].Type)
assert.Equal(t, "instantiate_contract", res.Events[2].Type)
assertAttribute(t, "module", "wasm", res.Events[2].Attributes[0])

// ensure bob doesn't exist
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestHandleExecute(t *testing.T) {
assertAttribute(t, "sender", contractBech32Addr, res.Events[2].Attributes[1])
assertAttribute(t, "amount", "105000denom", res.Events[2].Attributes[2])
// finally, standard x/wasm tag
assert.Equal(t, "message", res.Events[3].Type)
assert.Equal(t, "execute_contract", res.Events[3].Type)
assertAttribute(t, "module", "wasm", res.Events[3].Attributes[0])

// ensure bob now exists and got both payments released
Expand Down