mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
tests: handle 0x-prefixed rlp hex in tests
This commit is contained in:
parent
8439290afd
commit
bb75b65692
1 changed files with 14 additions and 1 deletions
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue