From bb75b656929e5688d2e6756461a51b7aecb66c9d Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 23 Jan 2019 12:02:18 +0100 Subject: [PATCH] tests: handle 0x-prefixed rlp hex in tests --- tests/rlp_test_util.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/rlp_test_util.go b/tests/rlp_test_util.go index 58ef8a6428..9069ec55a1 100644 --- a/tests/rlp_test_util.go +++ b/tests/rlp_test_util.go @@ -42,9 +42,22 @@ type RLPTest struct { 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. func (t *RLPTest) Run() error { - outb, err := hex.DecodeString(t.Out) + outb, err := FromHex(t.Out) if err != nil { return fmt.Errorf("invalid hex in Out") }