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: refactor TestStoreAndInstantiateContract #98

Merged
merged 14 commits into from
Aug 25, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 49 additions & 18 deletions x/wasmplus/keeper/msg_server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,12 +30,40 @@ 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{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{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(),
Expand Down Expand Up @@ -67,25 +96,27 @@ 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"),
},
170210 marked this conversation as resolved.
Show resolved Hide resolved
{
Key: []byte("sender"),
Value: []byte(sender.String()),
},
170210 marked this conversation as resolved.
Show resolved Hide resolved
},
}
}