Skip to content

Commit

Permalink
revert to older contracts in wazero branch
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Dec 26, 2024
1 parent ccc48d7 commit 55b631f
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 193 deletions.
39 changes: 39 additions & 0 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1483,3 +1483,42 @@ func mockInfoBinNoAssert(sender types.HumanAddress) []byte {
}
return res
}

func TestHappyPath(t *testing.T) {
cache, cleanup := withCache(t)
defer cleanup()

checksum := createReflectContract(t, cache)

// set up contract
gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT)
igasMeter := types.GasMeter(gasMeter)
store := NewLookup(gasMeter)
api := NewMockAPI()
initBalance := types.Array[types.Coin]{types.NewCoin(1234, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, initBalance)
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
msg := []byte(`{"text": "my initial message"}`)

// call instantiate
res, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)

// call execute
execMsg := []byte(`{"capitalize": {}}`)
res, _, err = Execute(cache, checksum, env, info, execMsg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)

// call query
queryMsg := []byte(`{"get_text": {}}`)
data, _, err := Query(cache, checksum, env, queryMsg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
var qResult types.QueryResult
err = json.Unmarshal(data, &qResult)
require.NoError(t, err)
require.Equal(t, "", qResult.Err)
require.Equal(t, `{"text":"MY INITIAL MESSAGE"}`, string(qResult.Ok))

Check failure on line 1523 in internal/api/lib_test.go

View workflow job for this annotation

GitHub Actions / lint

encoded-compare: use require.JSONEq (testifylint)
}
6 changes: 4 additions & 2 deletions internal/api/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func MockEnv() types.Env {

func MockEnvBin(tb testing.TB) []byte {
tb.Helper()
bin, err := json.Marshal(MockEnv())
env := MockEnv()
bin, err := json.Marshal(env)
require.NoError(tb, err)
return bin
}
Expand All @@ -58,7 +59,8 @@ func MockInfoWithFunds(sender types.HumanAddress) types.MessageInfo {

func MockInfoBin(tb testing.TB, sender types.HumanAddress) []byte {
tb.Helper()
bin, err := json.Marshal(MockInfoWithFunds(sender))
info := MockInfoWithFunds(sender)
bin, err := json.Marshal(info)
require.NoError(tb, err)
return bin
}
Expand Down
4 changes: 3 additions & 1 deletion internal/runtime/wasmruntime.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// file: internal/runtime/wasm_runtime.go
package runtime

import "github.com/CosmWasm/wasmvm/v2/types"
import (
"github.com/CosmWasm/wasmvm/v2/types"
)

type WasmRuntime interface {
// InitCache sets up any runtime-specific cache or resources. Returns a handle.
Expand Down
Loading

0 comments on commit 55b631f

Please sign in to comment.