You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
742 B
40 lines
742 B
6 years ago
|
package utils
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"testing"
|
||
|
|
||
|
checker "gopkg.in/check.v1"
|
||
|
)
|
||
|
|
||
|
type BytesSuite struct{}
|
||
|
|
||
|
var _ = checker.Suite(&BytesSuite{})
|
||
|
|
||
|
func TestFromHex(t *testing.T) {
|
||
|
input := "0x01"
|
||
|
expected := []byte{1}
|
||
|
result := FromHex(input)
|
||
|
if !bytes.Equal(expected, result) {
|
||
|
t.Errorf("Expected %x got %x", expected, result)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestFromHexOddLength(t *testing.T) {
|
||
|
input := "0x1"
|
||
|
expected := []byte{1}
|
||
|
result := FromHex(input)
|
||
|
if !bytes.Equal(expected, result) {
|
||
|
t.Errorf("Expected %x got %x", expected, result)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestNoPrefixShortHexOddLength(t *testing.T) {
|
||
|
input := "1"
|
||
|
expected := []byte{1}
|
||
|
result := FromHex(input)
|
||
|
if !bytes.Equal(expected, result) {
|
||
|
t.Errorf("Expected %x got %x", expected, result)
|
||
|
}
|
||
|
}
|