Skip to content

Commit

Permalink
fix: reflect comment
Browse files Browse the repository at this point in the history
- change sender address
- move non-execute parts outside the loop
- change to use MsgExecuteContractFixture
  • Loading branch information
da1suk8 committed Aug 22, 2023
1 parent f51d04d commit eb647b8
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions x/wasm/keeper/msg_server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,39 @@ func TestExecuteContract(t *testing.T) {
_, _, otherAddr = testdata.KeyTestPubAddr()
)

// setup
_, _, sender := testdata.KeyTestPubAddr()
msg := types.MsgStoreCodeFixture(func(m *types.MsgStoreCode) {
m.WASMByteCode = hackatomContract
m.Sender = sender.String()
})

// store code
rsp, err := wasmApp.MsgServiceRouter().Handler(msg)(ctx, msg)
require.NoError(t, err)
var storeCodeResponse types.MsgStoreCodeResponse
require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &storeCodeResponse))

// instantiate contract
initMsg := keeper.HackatomExampleInitMsg{
Verifier: myAddress,
Beneficiary: otherAddr,
}
initMsgBz, err := json.Marshal(initMsg)
require.NoError(t, err)
msgInstantiate := types.MsgInstantiateContractFixture(func(m *types.MsgInstantiateContract) {
m.Sender = sender.String()
m.Admin = myAddress.String()
m.CodeID = storeCodeResponse.CodeID
m.Label = "test"
m.Msg = initMsgBz
m.Funds = sdk.Coins{}
})
rsp, err = wasmApp.MsgServiceRouter().Handler(msgInstantiate)(ctx, msgInstantiate)
require.NoError(t, err)
var instantiateResponse types.MsgInstantiateContractResponse
require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &instantiateResponse))

specs := map[string]struct {
addr string
expErr bool
Expand All @@ -359,45 +392,14 @@ func TestExecuteContract(t *testing.T) {
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
xCtx, _ := ctx.CacheContext()
// setup
_, _, sender := testdata.KeyTestPubAddr()
msg := types.MsgStoreCodeFixture(func(m *types.MsgStoreCode) {
m.WASMByteCode = hackatomContract
m.Sender = sender.String()
})

// store code
rsp, err := wasmApp.MsgServiceRouter().Handler(msg)(xCtx, msg)
require.NoError(t, err)
var storeCodeResponse types.MsgStoreCodeResponse
require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &storeCodeResponse))

// instantiate contract
initMsg := keeper.HackatomExampleInitMsg{
Verifier: myAddress,
Beneficiary: otherAddr,
}
initMsgBz, err := json.Marshal(initMsg)
require.NoError(t, err)
msgInstantiate := &types.MsgInstantiateContract{
Sender: spec.addr,
Admin: myAddress.String(),
CodeID: storeCodeResponse.CodeID,
Label: "test",
Msg: initMsgBz,
Funds: sdk.Coins{},
}
rsp, err = wasmApp.MsgServiceRouter().Handler(msgInstantiate)(xCtx, msgInstantiate)
require.NoError(t, err)
var instantiateResponse types.MsgInstantiateContractResponse
require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &instantiateResponse))

msgExecuteContract := &types.MsgExecuteContract{
Sender: spec.addr,
Msg: []byte(`{"release":{}}`),
Contract: instantiateResponse.Address,
Funds: sdk.Coins{},
}
// when
msgExecuteContract := types.MsgExecuteContractFixture(func(m *types.MsgExecuteContract) {
m.Sender = spec.addr
m.Msg = []byte(`{"release":{}}`)
m.Contract = instantiateResponse.Address
m.Funds = sdk.Coins{}
})
rsp, err = wasmApp.MsgServiceRouter().Handler(msgExecuteContract)(xCtx, msgExecuteContract)

// then
Expand Down

0 comments on commit eb647b8

Please sign in to comment.