diff --git a/cmd/demo/main.go b/cmd/demo/main.go index db8929b6e..5c7e3e219 100644 --- a/cmd/demo/main.go +++ b/cmd/demo/main.go @@ -8,12 +8,13 @@ import ( ) const ( - SUPPORTED_CAPABILITIES = "staking" - PRINT_DEBUG = true - MEMORY_LIMIT = 32 // MiB - CACHE_SIZE = 100 // MiB + 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] diff --git a/docs/MIGRATING.md b/docs/MIGRATING.md index 4c24cf5d0..c423c4300 100644 --- a/docs/MIGRATING.md +++ b/docs/MIGRATING.md @@ -3,3 +3,5 @@ ## 1.x -> 2.0 - `VM.Create` was removed. Use `VM.StoreCode` instead. +- The `supportedCapabilities` argument in `NewVM` changed from a comma separated + list to a list of type `[]string`. diff --git a/internal/api/lib.go b/internal/api/lib.go index ef8eb83c2..a0a222ed1 100644 --- a/internal/api/lib.go +++ b/internal/api/lib.go @@ -7,6 +7,7 @@ import "C" import ( "fmt" "runtime" + "strings" "syscall" "github.com/CosmWasm/wasmvm/types" @@ -36,9 +37,9 @@ type Cache struct { type Querier = types.Querier -func InitCache(dataDir string, supportedCapabilities string, cacheSize uint32, instanceMemoryLimit uint32) (Cache, error) { +func InitCache(dataDir string, supportedCapabilities []string, cacheSize uint32, instanceMemoryLimit uint32) (Cache, error) { dataDirBytes := []byte(dataDir) - supportedCapabilitiesBytes := []byte(supportedCapabilities) + supportedCapabilitiesBytes := []byte(strings.Join(supportedCapabilities, ",")) d := makeView(dataDirBytes) defer runtime.KeepAlive(dataDirBytes) diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index d635698ea..c08d9701d 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -18,13 +18,14 @@ import ( ) const ( - TESTING_CAPABILITIES = "staking,stargate,iterator,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3" TESTING_PRINT_DEBUG = false TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms TESTING_MEMORY_LIMIT = 32 // MiB TESTING_CACHE_SIZE = 100 // MiB ) +var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3"} + func TestInitAndReleaseCache(t *testing.T) { tmpdir, err := os.MkdirTemp("", "wasmvm-testing") require.NoError(t, err) @@ -61,7 +62,7 @@ func TestInitCacheEmptyCapabilities(t *testing.T) { tmpdir, err := os.MkdirTemp("", "wasmvm-testing") require.NoError(t, err) defer os.RemoveAll(tmpdir) - cache, err := InitCache(tmpdir, "", TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT) + cache, err := InitCache(tmpdir, []string{}, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT) require.NoError(t, err) ReleaseCache(cache) } diff --git a/lib.go b/lib.go index 3b1ef6fdf..0dfb1cd50 100644 --- a/lib.go +++ b/lib.go @@ -23,12 +23,12 @@ type VM struct { // NewVM creates a new VM. // // `dataDir` is a base directory for Wasm blobs and various caches. -// `supportedCapabilities` is a comma separated list of capabilities suppored by the chain. +// `supportedCapabilities` is a list of capabilities supported by the chain. // `memoryLimit` is the memory limit of each contract execution (in MiB) // `printDebug` is a flag to enable/disable printing debug logs from the contract to STDOUT. This should be false in production environments. // `cacheSize` sets the size in MiB of an in-memory cache for e.g. module caching. Set to 0 to disable. // `deserCost` sets the gas cost of deserializing one byte of data. -func NewVM(dataDir string, supportedCapabilities string, memoryLimit uint32, printDebug bool, cacheSize uint32) (*VM, error) { +func NewVM(dataDir string, supportedCapabilities []string, memoryLimit uint32, printDebug bool, cacheSize uint32) (*VM, error) { cache, err := api.InitCache(dataDir, supportedCapabilities, cacheSize, memoryLimit) if err != nil { return nil, err diff --git a/lib_test.go b/lib_test.go index d54592da3..9ab6daa04 100644 --- a/lib_test.go +++ b/lib_test.go @@ -15,13 +15,14 @@ import ( ) const ( - TESTING_CAPABILITIES = "staking,stargate,iterator" TESTING_PRINT_DEBUG = false TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms TESTING_MEMORY_LIMIT = 32 // MiB TESTING_CACHE_SIZE = 100 // MiB ) +var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator"} + const ( CYBERPUNK_TEST_CONTRACT = "./testdata/cyberpunk.wasm" HACKATOM_TEST_CONTRACT = "./testdata/hackatom.wasm"