From 9678d58bc80b1fb4607d93f1560510145bfef77f Mon Sep 17 00:00:00 2001 From: jimboj Date: Tue, 21 Mar 2023 15:54:50 -0600 Subject: [PATCH] add missing funcs to helpers test --- lib/runtime/wasmer/helpers_test.go | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/runtime/wasmer/helpers_test.go b/lib/runtime/wasmer/helpers_test.go index 11c605ff1b3..47ddf8cee51 100644 --- a/lib/runtime/wasmer/helpers_test.go +++ b/lib/runtime/wasmer/helpers_test.go @@ -5,11 +5,13 @@ package wasmer import ( "encoding/json" + "errors" "os" "path/filepath" "testing" "github.com/ChainSafe/gossamer/lib/genesis" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -27,3 +29,51 @@ func genesisFromRawJSON(t *testing.T, jsonFilepath string) (gen genesis.Genesis) return gen } + +func Test_pointerSize(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + ptr uint32 + size uint32 + pointerSize int64 + }{ + "0": {}, + "ptr_8_size_32": { + ptr: 8, + size: 32, + pointerSize: int64(8) | (int64(32) << 32), + }, + "ptr_max_uint32_and_size_max_uint32": { + ptr: ^uint32(0), + size: ^uint32(0), + pointerSize: ^int64(0), + }, + } + + for name, testCase := range testCases { + testCase := testCase + t.Run(name, func(t *testing.T) { + t.Parallel() + + pointerSize := toPointerSize(testCase.ptr, testCase.size) + + require.Equal(t, testCase.pointerSize, pointerSize) + + ptr, size := splitPointerSize(pointerSize) + + assert.Equal(t, testCase.ptr, ptr) + assert.Equal(t, testCase.size, size) + }) + } +} + +func Test_panicOnError(t *testing.T) { + t.Parallel() + + err := (error)(nil) + assert.NotPanics(t, func() { panicOnError(err) }) + + err = errors.New("test error") + assert.PanicsWithValue(t, err, func() { panicOnError(err) }) +}