Pull out some test helpers for genesis_test

This commit is contained in:
Ethan Frey
2021-01-08 17:43:47 +01:00
parent 202c19530e
commit 013491aa9d
3 changed files with 49 additions and 32 deletions

View File

@@ -154,9 +154,7 @@ func TestHandleInstantiate(t *testing.T) {
}
res, err := h(data.ctx, msg)
require.NoError(t, err)
var pStoreResp MsgStoreCodeResponse
require.NoError(t, pStoreResp.Unmarshal(res.Data))
require.Equal(t, pStoreResp.CodeID, "1")
assertStoreCodeResponse(t, res.Data, 1)
_, _, bob := keyPubAddr()
_, _, fred := keyPubAddr()
@@ -177,9 +175,7 @@ func TestHandleInstantiate(t *testing.T) {
}
res, err = h(data.ctx, &initCmd)
require.NoError(t, err)
var pInstResp MsgInstantiateContractResponse
require.NoError(t, pInstResp.Unmarshal(res.Data))
contractBech32Addr := pInstResp.Address
contractBech32Addr := parseInitResponse(t, res.Data)
require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", contractBech32Addr)
// this should be standard x/wasm init event, nothing from contract
@@ -218,9 +214,7 @@ func TestHandleExecute(t *testing.T) {
}
res, err := h(data.ctx, msg)
require.NoError(t, err)
var pStoreResp MsgStoreCodeResponse
require.NoError(t, pStoreResp.Unmarshal(res.Data))
require.Equal(t, pStoreResp.CodeID, "1")
assertStoreCodeResponse(t, res.Data, 1)
_, _, bob := keyPubAddr()
initMsg := initMsg{
@@ -238,9 +232,7 @@ func TestHandleExecute(t *testing.T) {
}
res, err = h(data.ctx, &initCmd)
require.NoError(t, err)
var pInstResp MsgInstantiateContractResponse
require.NoError(t, pInstResp.Unmarshal(res.Data))
contractBech32Addr := pInstResp.Address
contractBech32Addr := parseInitResponse(t, res.Data)
require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", contractBech32Addr)
// this should be standard x/wasm init event, plus a bank send event (2), with no custom contract events
@@ -275,9 +267,8 @@ func TestHandleExecute(t *testing.T) {
}
res, err = h(data.ctx, &execCmd)
require.NoError(t, err)
var pExecResp MsgExecuteContractResponse
require.NoError(t, pExecResp.Unmarshal(res.Data))
require.NotEmpty(t, pExecResp.Data)
// from https://github.com/CosmWasm/cosmwasm/blob/master/contracts/hackatom/src/contract.rs#L167
assertExecuteResponse(t, res.Data, []byte{0xf0, 0x0b, 0xaa})
// this should be standard x/wasm init event, plus 2 bank send event, plus a special event from the contract
require.Equal(t, 4, len(res.Events), prettyEvents(res.Events))
@@ -358,9 +349,7 @@ func TestHandleExecuteEscrow(t *testing.T) {
}
res, err = h(data.ctx, &initCmd)
require.NoError(t, err)
var pInstResp MsgInstantiateContractResponse
require.NoError(t, pInstResp.Unmarshal(res.Data))
contractBech32Addr := pInstResp.Address
contractBech32Addr := parseInitResponse(t, res.Data)
require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", contractBech32Addr)
handleMsg := map[string]interface{}{
@@ -377,9 +366,8 @@ func TestHandleExecuteEscrow(t *testing.T) {
}
res, err = h(data.ctx, &execCmd)
require.NoError(t, err)
var pExecResp MsgExecuteContractResponse
require.NoError(t, pExecResp.Unmarshal(res.Data))
require.NotEmpty(t, pExecResp.Data)
// from https://github.com/CosmWasm/cosmwasm/blob/master/contracts/hackatom/src/contract.rs#L167
assertExecuteResponse(t, res.Data, []byte{0xf0, 0x0b, 0xaa})
// ensure bob now exists and got both payments released
bobAcct := data.acctKeeper.GetAccount(data.ctx, bob)