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

test: add event checking to TestStoreCode #63

Merged
merged 5 commits into from
Aug 10, 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 @@ -6,6 +6,7 @@
* [\#61](https://github.com/Finschia/wasmd/pull/61) bumpup ibc-go to v4

### Improvements
* [\#63](https://github.com/Finschia/wasmd/pull/63) add event checking to TestStoreCode

### Bug Fixes
* [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci
Expand Down
18 changes: 17 additions & 1 deletion x/wasm/keeper/msg_server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"crypto/sha256"
_ "embed"
"encoding/hex"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -26,16 +27,31 @@ func TestStoreCode(t *testing.T) {
m.WASMByteCode = wasmContract
m.Sender = sender.String()
})
expHash := sha256.Sum256(wasmContract)

// when
rsp, err := wasmApp.MsgServiceRouter().Handler(msg)(ctx, msg)

// check event
require.Equal(t, 2, len(rsp.Events))
assert.Equal(t, "message", rsp.Events[0].Type)
assert.Equal(t, 2, len(rsp.Events[0].Attributes))
assert.Equal(t, "module", string(rsp.Events[0].Attributes[0].Key))
assert.Equal(t, "wasm", string(rsp.Events[0].Attributes[0].Value))
assert.Equal(t, "sender", string(rsp.Events[0].Attributes[1].Key))
assert.Equal(t, sender.String(), string(rsp.Events[0].Attributes[1].Value))
assert.Equal(t, "store_code", rsp.Events[1].Type)
assert.Equal(t, 2, len(rsp.Events[1].Attributes))
assert.Equal(t, "code_checksum", string(rsp.Events[1].Attributes[0].Key))
assert.Equal(t, hex.EncodeToString(expHash[:]), string(rsp.Events[1].Attributes[0].Value))
assert.Equal(t, "code_id", string(rsp.Events[1].Attributes[1].Key))
assert.Equal(t, "1", string(rsp.Events[1].Attributes[1].Value))

// then
require.NoError(t, err)
var result types.MsgStoreCodeResponse
require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &result))
assert.Equal(t, uint64(1), result.CodeID)
expHash := sha256.Sum256(wasmContract)
assert.Equal(t, expHash[:], result.Checksum)
// and
info := wasmApp.WasmKeeper.GetCodeInfo(ctx, 1)
Expand Down