Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lib/wasmer): NewTestInstanceWithTrie checks if targetRuntime is a valid filepath #3012

Merged
6 changes: 6 additions & 0 deletions lib/runtime/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ var (
// GetRuntime returns the runtime file path located in the
// /tmp/gossamer/runtimes directory (depending on OS and environment).
// If the file did not exist, the runtime WASM blob is downloaded to that file.
// If the runtime argument is not defined in the constants.go and is a valid
// file path, the runtime argument is returned.
func GetRuntime(ctx context.Context, runtime string) (
runtimePath string, err error) {
if utils.PathExists(runtime) {
return runtime, nil
}

basePath := filepath.Join(os.TempDir(), "/gossamer/runtimes/")
const perm = os.FileMode(0777)
err = os.MkdirAll(basePath, perm)
Expand Down
9 changes: 6 additions & 3 deletions lib/runtime/wasmer/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ func NewTestInstance(t *testing.T, targetRuntime string) *Instance {
return NewTestInstanceWithTrie(t, targetRuntime, nil)
}

// NewTestInstanceWithTrie will create a new runtime (polkadot/test) with the supplied trie as the storage
// NewTestInstanceWithTrie returns an instance based on the target runtime string specified,
// which can be a file path or a constant from the constants defined in `lib/runtime/constants.go`.
// The instance uses the trie given as argument for its storage.
func NewTestInstanceWithTrie(t *testing.T, targetRuntime string, tt *trie.Trie) *Instance {
t.Helper()

cfg := setupConfig(t, tt, DefaultTestLogLvl, common.NoNetworkRole, targetRuntime)
runtimeFilepath, err := runtime.GetRuntime(context.Background(), targetRuntime)
targetRuntime, err := runtime.GetRuntime(context.Background(), targetRuntime)
require.NoError(t, err)

r, err := NewInstanceFromFile(runtimeFilepath, cfg)
r, err := NewInstanceFromFile(targetRuntime, cfg)
require.NoError(t, err)

return r
}

Expand Down