tests: handle 0x-prefixed rlp hex in tests

This commit is contained in:
Martin Holst Swende 2019-01-23 12:02:18 +01:00
parent 8439290afd
commit bb75b65692
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -42,9 +42,22 @@ type RLPTest struct {
Out string Out string
} }
// FromHex returns the bytes represented by the hexadecimal string s.
// s may be prefixed with "0x".
// This is copy-pasted from bytes.go, which does not return the error
func FromHex(s string) ([]byte, error) {
if len(s) > 1 && (s[0:2] == "0x" || s[0:2] == "0X") {
s = s[2:]
}
if len(s)%2 == 1 {
s = "0" + s
}
return hex.DecodeString(s)
}
// Run executes the test. // Run executes the test.
func (t *RLPTest) Run() error { func (t *RLPTest) Run() error {
outb, err := hex.DecodeString(t.Out) outb, err := FromHex(t.Out)
if err != nil { if err != nil {
return fmt.Errorf("invalid hex in Out") return fmt.Errorf("invalid hex in Out")
} }