Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 26 additions & 34 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,47 @@ package main

import (
"fmt"
"math"
"os"

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

const (
PRINT_DEBUG = true
MEMORY_LIMIT = 32 // MiB
CACHE_SIZE = 100 // MiB
)

var SUPPORTED_CAPABILITIES = []string{"staking"}

// This is just a demo to ensure we can compile a static go binary
func main() {
file := os.Args[1]

if file == "version" {
libwasmvmVersion, err := wasmvm.LibwasmvmVersion()
if err != nil {
panic(err)
}
fmt.Printf("libwasmvm: %s\n", libwasmvmVersion)
return
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <wasmFile>\n", os.Args[0])
os.Exit(1)
}

fmt.Printf("Running %s...\n", file)
bz, err := os.ReadFile(file)
if err != nil {
panic(err)
wasmFile := os.Args[1]

config := types.VMConfig{
WasmLimits: types.WasmLimits{},
Cache: types.CacheOptions{
BaseDir: os.TempDir(),
AvailableCapabilities: []string{"staking", "stargate", "iterator"},
MemoryCacheSizeBytes: types.NewSizeKibi(100 * 1024), // 100 MiB
InstanceMemoryLimitBytes: types.NewSizeKibi(32 * 1024), // 32 MiB
},
}
fmt.Println("Loaded!")

err = os.MkdirAll("tmp", 0o755)
vm, err := wasmvm.NewVM(config)
if err != nil {
panic(err)
fmt.Fprintf(os.Stderr, "Failed to create VM: %v\n", err)
os.Exit(1)
}
vm, err := wasmvm.NewVM("tmp", SUPPORTED_CAPABILITIES, MEMORY_LIMIT, PRINT_DEBUG, CACHE_SIZE)
defer vm.Cleanup()

code, err := os.ReadFile(wasmFile)
if err != nil {
panic(err)
fmt.Fprintf(os.Stderr, "Failed to read Wasm file: %v\n", err)
os.Exit(1)
}

checksum, _, err := vm.StoreCode(bz, math.MaxUint64)
checksum, _, err := vm.StoreCode(code, 500_000_000_000)
if err != nil {
panic(err)
fmt.Fprintf(os.Stderr, "Failed to store code: %v\n", err)
os.Exit(1)
}
fmt.Printf("Stored code with checksum: %X\n", checksum)

vm.Cleanup()
fmt.Println("finished")
fmt.Printf("Code stored with checksum: %X\n", checksum)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/CosmWasm/wasmvm/v2

go 1.21
go 1.23

require (
github.com/google/btree v1.0.0
github.com/shamaton/msgpack/v2 v2.2.0
github.com/stretchr/testify v1.8.1
golang.org/x/sys v0.16.0
github.com/tetratelabs/wazero v1.8.2
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
github.com/tetratelabs/wazero v1.8.2 h1:yIgLR/b2bN31bjxwXHD8a3d+BogigR952csSDdLYEv4=
github.com/tetratelabs/wazero v1.8.2/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 0 additions & 2 deletions ibc_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build cgo && !nolink_libwasmvm

package cosmwasm

import (
Expand Down
47 changes: 0 additions & 47 deletions internal/api/api_test.go

This file was deleted.

Loading
Loading