Skip to content
Merged
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
23 changes: 23 additions & 0 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -36,6 +37,28 @@ func TestInitAndReleaseCache(t *testing.T) {
ReleaseCache(cache)
}

// wasmd expectes us to create the base directory
// https://github.com/CosmWasm/wasmd/blob/v0.30.0/x/wasm/keeper/keeper.go#L128
func TestInitCacheWorksForNonExistentDir(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "wasmvm-testing")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)

createMe := filepath.Join(tmpdir, "does-not-yet-exist")
cache, err := InitCache(createMe, TESTING_FEATURES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
require.NoError(t, err)
ReleaseCache(cache)
}

func TestInitCacheErrorsForBrokenDir(t *testing.T) {
// Use colon to make this fail on Windows
// https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3
// On Unix we should not have permission to create this.
cannotBeCreated := "/foo:bar"
_, err := InitCache(cannotBeCreated, TESTING_FEATURES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
require.ErrorContains(t, err, "Error creating state directory")
}

func TestInitCacheEmptyFeatures(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "wasmvm-testing")
require.NoError(t, err)
Expand Down