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

feat: apply Finschia/finschia-sdk#1063 #81

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

### Improvements
* [\#81](https://github.com/Finschia/wasmd/pull/81) Apply Finschia/finschia-sdk#1063

### Bug Fixes
* [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/Finschia/wasmd
go 1.18

require (
github.com/Finschia/finschia-sdk v0.47.0-rc6
github.com/Finschia/finschia-sdk v0.47.3-0.20230810063358-e669c6fe02c2
github.com/Finschia/ibc-go/v3 v3.3.3
github.com/Finschia/ostracon v1.0.10-0.20230417090415-bc3f5693b6a1
github.com/Finschia/ostracon v1.1.0
github.com/Finschia/wasmvm v1.1.1-0.11.2.0.20230418093236-ce70a3856778
github.com/cosmos/iavl v0.19.4
github.com/dvsekhvalnov/jose2go v1.5.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Finschia/finschia-sdk v0.47.0-rc6 h1:e9DOhCsaLLD3D0+d4GhqN/oGl9tLB5ncfiddFd8Ad0Y=
github.com/Finschia/finschia-sdk v0.47.0-rc6/go.mod h1:T1eSChkSMsvtvUVwRP+RNO00nbx2ZQKzAxjtpLRQopQ=
github.com/Finschia/finschia-sdk v0.47.3-0.20230810063358-e669c6fe02c2 h1:xj1aoxPYODKR32sm7nbSworGu3nNCxkLNvDbGBeloys=
github.com/Finschia/finschia-sdk v0.47.3-0.20230810063358-e669c6fe02c2/go.mod h1:aPRyqqg+PROtpd8H4ANuiIqEEw/QgajmAUqaoIUwvT4=
github.com/Finschia/ibc-go/v3 v3.3.3 h1:geNUwG7xU0vve1Rv8qATpAk59BL5thLuUcLvJ7xnkiM=
github.com/Finschia/ibc-go/v3 v3.3.3/go.mod h1:YC5hldLSJQDoii3W2E9J07BVdTF7fesUQcATo5zQ248=
github.com/Finschia/ostracon v1.0.10-0.20230417090415-bc3f5693b6a1 h1:sY8xWugQvQmp4p+rvfB+SKwWZLRqptVaEE7S8O+qJwk=
github.com/Finschia/ostracon v1.0.10-0.20230417090415-bc3f5693b6a1/go.mod h1:nPRoQEOOp8FFp2XQ8b1dvfHgKNxp1Zb7i1p5yrLIgG4=
github.com/Finschia/ostracon v1.1.0 h1:ruiqngsoCz1kJ3fGLJHflcvxbJrbg7QGDTruqxgLZKc=
github.com/Finschia/ostracon v1.1.0/go.mod h1:nPRoQEOOp8FFp2XQ8b1dvfHgKNxp1Zb7i1p5yrLIgG4=
github.com/Finschia/wasmvm v1.1.1-0.11.2.0.20230418093236-ce70a3856778 h1:V+iocQkc3zvpgdn+nCLZ9kPM7D7u6v2Br+EkOIhvjbY=
github.com/Finschia/wasmvm v1.1.1-0.11.2.0.20230418093236-ce70a3856778/go.mod h1:uCHU7ZRQ/V+WPRXr6Ak9Uu2oe2MVeO8yGZnGKU1B3NY=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
Expand Down
41 changes: 0 additions & 41 deletions x/wasm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
75 changes: 32 additions & 43 deletions x/wasm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions x/wasmplus/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 8 additions & 12 deletions x/wasmplus/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down