mirror of https://github.com/status-im/op-geth.git
Merge pull request #15577 from karalabe/common-hexconvert-singlebyte
common: fix hex utils to handle 1 byte address conversions
This commit is contained in:
commit
e37f7be97e
|
@ -35,13 +35,12 @@ func FromHex(s string) []byte {
|
||||||
if s[0:2] == "0x" || s[0:2] == "0X" {
|
if s[0:2] == "0x" || s[0:2] == "0X" {
|
||||||
s = s[2:]
|
s = s[2:]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if len(s)%2 == 1 {
|
if len(s)%2 == 1 {
|
||||||
s = "0" + s
|
s = "0" + s
|
||||||
}
|
}
|
||||||
return Hex2Bytes(s)
|
return Hex2Bytes(s)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy bytes
|
// Copy bytes
|
||||||
//
|
//
|
||||||
|
|
|
@ -86,3 +86,12 @@ func TestFromHexOddLength(t *testing.T) {
|
||||||
t.Errorf("Expected %x got %x", 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue