Skip to content

Commit

Permalink
Merge pull request #492 from CosmWasm/supportedCapabilities-slice
Browse files Browse the repository at this point in the history
Make supportedCapabilities a slice
  • Loading branch information
webmaster128 authored Jan 11, 2024
2 parents cfe359a + a31f9b7 commit aae822b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
9 changes: 5 additions & 4 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions docs/MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
5 changes: 3 additions & 2 deletions internal/api/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "C"
import (
"fmt"
"runtime"
"strings"
"syscall"

"github.com/CosmWasm/wasmvm/types"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit aae822b

Please sign in to comment.