forked from cerc-io/laconicd-deprecated
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
_ "embed"
|
|
"testing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
"github.com/cerc-io/laconicd/app"
|
|
"github.com/cerc-io/laconicd/x/wasm/types"
|
|
)
|
|
|
|
//go:embed testdata/reflect.wasm
|
|
var wasmContract []byte
|
|
|
|
func TestStoreCode(t *testing.T) {
|
|
wasmApp := app.Setup(false)
|
|
ctx := wasmApp.BaseApp.NewContext(false, tmproto.Header{})
|
|
_, _, sender := testdata.KeyTestPubAddr()
|
|
msg := types.MsgStoreCodeFixture(func(m *types.MsgStoreCode) {
|
|
m.WASMByteCode = wasmContract
|
|
m.Sender = sender.String()
|
|
})
|
|
|
|
// when
|
|
rsp, err := wasmApp.MsgServiceRouter().Handler(msg)(ctx, msg)
|
|
|
|
// then
|
|
require.NoError(t, err)
|
|
var result types.MsgStoreCodeResponse
|
|
require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &result))
|
|
assert.Equal(t, uint64(1), result.CodeID)
|
|
expHash := sha256.Sum256(wasmContract)
|
|
assert.Equal(t, expHash[:], result.Checksum)
|
|
// and
|
|
info := wasmApp.WasmKeeper.GetCodeInfo(ctx, 1)
|
|
assert.NotNil(t, info)
|
|
assert.Equal(t, expHash[:], info.CodeHash)
|
|
assert.Equal(t, sender.String(), info.Creator)
|
|
assert.Equal(t, types.DefaultParams().InstantiateDefaultPermission.With(sender), info.InstantiateConfig)
|
|
}
|