Skip to content

Commit

Permalink
move test helper out of common to test_helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Feb 8, 2023
1 parent 3c775b3 commit 3b056f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
12 changes: 0 additions & 12 deletions lib/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import (
"io"
"strconv"
"strings"
"testing"
)

// ErrNoPrefix is returned when trying to convert a hex-encoded string with no 0x prefix
var ErrNoPrefix = errors.New("could not byteify non 0x prefixed string")

// Signature represents a [64]byte signature
type Signature [64]byte

// StringToInts turns a string consisting of ints separated by commas into an int array
func StringToInts(in string) (res []int, err error) {
intstrs := strings.Split(in, ",")
Expand Down Expand Up @@ -90,14 +86,6 @@ func MustHexToBytes(in string) []byte {
return out
}

// MustHexTo64BArray turns a 0x prefixed hex string into a Signature
// it panic if it cannot decode the string
func MustHexTo64BArray(t *testing.T, inputHex string) (outputArray Signature) {
t.Helper()
copy(outputArray[:], MustHexToBytes(inputHex))
return outputArray
}

// BytesToHex turns a byte slice into a 0x prefixed hex string
func BytesToHex(in []byte) string {
s := hex.EncodeToString(in)
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,10 +1315,10 @@ func TestInstance_GrandpaSubmitReportEquivocationUnsignedExtrinsic(t *testing.T)
Number: 10,
}

firstSignatureArray := common.MustHexTo64BArray(t, "0xd7292caacc62504365f179892a7399f233944bf261f8a3f66260f70e0016f2d"+
firstSignatureArray := mustHexTo64BArray(t, "0xd7292caacc62504365f179892a7399f233944bf261f8a3f66260f70e0016f2d"+
"b63922726b015c82dc7131f4730fbec61f71672a571453e51029bfb469070900f")

secondSignatureArray := common.MustHexTo64BArray(t, "0xb3c408b74905dfedfffa66f99f16fe8b938fd8df76a92225228a1ca07523"+
secondSignatureArray := mustHexTo64BArray(t, "0xb3c408b74905dfedfffa66f99f16fe8b938fd8df76a92225228a1ca07523"+
"0b99a2d9e173c561952e1e378b701915ca188d2c832ef92a3fab8e455f32570c0807")

grandpaEquivocation := types.GrandpaEquivocation{
Expand Down
6 changes: 6 additions & 0 deletions lib/runtime/wasmer/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import (
// DefaultTestLogLvl is the log level used for test runtime instances
var DefaultTestLogLvl = log.Info

func mustHexTo64BArray(t *testing.T, inputHex string) (outputArray [64]byte) {
t.Helper()
copy(outputArray[:], common.MustHexToBytes(inputHex))
return outputArray
}

// NewTestInstance will create a new runtime instance using the given target runtime
func NewTestInstance(t *testing.T, targetRuntime string) *Instance {
t.Helper()
Expand Down

0 comments on commit 3b056f7

Please sign in to comment.