Skip to content
Merged
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
13 changes: 13 additions & 0 deletions lib/runtime/wasmer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package wasmer

import (
"testing"

"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/keystore"
Expand All @@ -23,3 +25,14 @@ type Config struct {
CodeHash common.Hash
testVersion *runtime.Version
}

// SetTestVersion sets the test version for the runtime.
// WARNING: This should only be used for testing purposes.
// The *testing.T argument is only required to enforce this function
// to be used in tests only.
func (c *Config) SetTestVersion(t *testing.T, version runtime.Version) {
if t == nil {
panic("*testing.T argument cannot be nil. Please don't use this function outside of Go tests.")
}
c.testVersion = &version
}
35 changes: 35 additions & 0 deletions lib/runtime/wasmer/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2022 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package wasmer

import (
"testing"

"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_Config_SetTestVersion(t *testing.T) {
t.Run("panics with nil *testing.T", func(t *testing.T) {
var c Config
assert.PanicsWithValue(t,
"*testing.T argument cannot be nil. Please don't use this function outside of Go tests.",
func() {
c.SetTestVersion(nil, runtime.Version{})
})
})

t.Run("set test version", func(t *testing.T) {
var c Config
testVersion := runtime.Version{
StateVersion: 1,
}

c.SetTestVersion(t, testVersion)

require.NotNil(t, c.testVersion)
assert.Equal(t, testVersion, *c.testVersion)
})
}