Skip to content

Commit

Permalink
feat(wasmer): Add SetTestVersion method to Config struct (#2823)
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Sep 15, 2022
1 parent a1e127b commit e5c9336
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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)
})
}

0 comments on commit e5c9336

Please sign in to comment.