Skip to content

Commit

Permalink
refactor: refactor TestStoreAndInstantiateContract (#98)
Browse files Browse the repository at this point in the history
* refactor: Changed to use abci type

* refactor: Changed to use `reflect.DeepEqual`

* chore: add this pr to change.log

* Update x/wasmplus/keeper/msg_server_integration_test.go

Co-authored-by: 170210 <85928898+170210@users.noreply.github.com>

* fix: fix import alias and the value of the address specified in spec

* fix: fix the pr title

* fix: fix comparison test code

* fix: rename import alias

* refactor: rename a valuable name

* refactor: add the test function

* fix: add the `Index` field, etc

* fix: revert

* fix: add Index flag

---------

Co-authored-by: 170210 <85928898+170210@users.noreply.github.com>
  • Loading branch information
Kynea0b and 170210 authored Aug 25, 2023
1 parent f661af0 commit 93fed34
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
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
73 changes: 55 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,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(),
Expand Down Expand Up @@ -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,
},
},
}
}

0 comments on commit 93fed34

Please sign in to comment.