diff --git a/CHANGELOG.md b/CHANGELOG.md index 762ac953f9..3c3b6e3620 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ * [\#76](https://github.com/Finschia/wasmd/pull/76) add an integration test for ClearAdmin * [\#68](https://github.com/Finschia/wasmd/pull/68) add an integration test for UpdateAdmin * [\#99](https://github.com/Finschia/wasmd/pull/99) format test files +* [\#98](https://github.com/Finschia/wasmd/pull/98) refactor TestStoreAndInstantiateContract ### Bug Fixes * [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field diff --git a/x/wasmplus/keeper/msg_server_integration_test.go b/x/wasmplus/keeper/msg_server_integration_test.go index 6c9c0b9ab4..ad9ca4b5a4 100644 --- a/x/wasmplus/keeper/msg_server_integration_test.go +++ b/x/wasmplus/keeper/msg_server_integration_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" sdk "github.com/Finschia/finschia-sdk/types" @@ -29,12 +30,44 @@ func TestStoreAndInstantiateContract(t *testing.T) { specs := map[string]struct { addr string permission *wasmtypes.AccessConfig + expEvents []abci.Event expErr bool }{ "address can instantiate a contract when permission is everybody": { addr: myAddress.String(), permission: &wasmtypes.AllowEverybody, - expErr: false, + expEvents: []abci.Event{ + { + Type: "store_code", + Attributes: []abci.EventAttribute{ + { + Key: []byte("code_checksum"), + Value: []byte("2843664c3b6c1de8bdeca672267c508aeb79bb947c87f75d8053f971d8658c89"), + Index: false, + }, { + Key: []byte("code_id"), + Value: []byte("1"), + Index: false, + }, + }, + }, + createMsgEvent(myAddress), + { + Type: "instantiate", + Attributes: []abci.EventAttribute{ + { + Key: []byte("_contract_address"), + Value: []byte("link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8"), + Index: false, + }, { + Key: []byte("code_id"), + Value: []byte("1"), + Index: false, + }, + }, + }, + }, + expErr: false, }, "address cannot instantiate a contract when permission is nobody": { addr: myAddress.String(), @@ -67,25 +100,29 @@ func TestStoreAndInstantiateContract(t *testing.T) { require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &storeAndInstantiateResponse)) // check event - events := rsp.Events - assert.Equal(t, 3, len(events)) - assert.Equal(t, "store_code", events[0].Type) - assert.Equal(t, 2, len(events[0].Attributes)) - assert.Equal(t, "code_checksum", string(events[0].Attributes[0].Key)) - assert.Equal(t, "code_id", string(events[0].Attributes[1].Key)) - assert.Equal(t, "1", string(events[0].Attributes[1].Value)) - assert.Equal(t, "message", events[1].Type) - assert.Equal(t, 2, len(events[1].Attributes)) - assert.Equal(t, "module", string(events[1].Attributes[0].Key)) - assert.Equal(t, "wasm", string(events[1].Attributes[0].Value)) - assert.Equal(t, "sender", string(events[1].Attributes[1].Key)) - assert.Equal(t, "instantiate", events[2].Type) - assert.Equal(t, "_contract_address", string(events[2].Attributes[0].Key)) - assert.Equal(t, storeAndInstantiateResponse.Address, string(events[2].Attributes[0].Value)) - assert.Equal(t, "code_id", string(events[2].Attributes[1].Key)) - assert.Equal(t, "1", string(events[2].Attributes[1].Value)) + assert.Equal(t, spec.expEvents, rsp.Events) require.NoError(t, err) }) } } + +// This function is utilized to generate the msg event for event checking in integration tests +// It will be deleted in release/v0.1.x +func createMsgEvent(sender sdk.AccAddress) abci.Event { + return abci.Event{ + Type: "message", + Attributes: []abci.EventAttribute{ + { + Key: []byte("module"), + Value: []byte("wasm"), + Index: false, + }, + { + Key: []byte("sender"), + Value: []byte(sender.String()), + Index: false, + }, + }, + } +}