Skip to content

Commit

Permalink
add missing funcs to helpers test
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Mar 21, 2023
1 parent e26781e commit 9678d58
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/runtime/wasmer/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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) })
}

0 comments on commit 9678d58

Please sign in to comment.