mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
common/hexutil: add comprehensive test for hex syntax error detection
This commit is contained in:
parent
a8562b5f35
commit
969c6c5fea
1 changed files with 27 additions and 0 deletions
|
|
@ -158,6 +158,33 @@ func TestDecode(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecodeErrorDetection(t *testing.T) {
|
||||||
|
invalidStrings := []struct {
|
||||||
|
input string
|
||||||
|
want error
|
||||||
|
}{
|
||||||
|
{"", ErrEmptyString},
|
||||||
|
{"0", ErrMissingPrefix},
|
||||||
|
{"0x", nil}, // Empty string is a valid case
|
||||||
|
{"0x0", ErrOddLength},
|
||||||
|
{"0xgg", ErrSyntax},
|
||||||
|
{"0xG", ErrSyntax},
|
||||||
|
{"0x01zz01", ErrSyntax},
|
||||||
|
{"0x01ZZ01", ErrSyntax},
|
||||||
|
{"0x01 01", ErrSyntax},
|
||||||
|
{"0xÄÖÜ", ErrSyntax},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range invalidStrings {
|
||||||
|
_, err := Decode(test.input)
|
||||||
|
if test.want == nil && err != nil {
|
||||||
|
t.Errorf("input %s: unexpected error: %v", test.input, err)
|
||||||
|
} else if test.want != nil && (err == nil || err.Error() != test.want.Error()) {
|
||||||
|
t.Errorf("input %s: error mismatch: got %v, want %v", test.input, err, test.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEncodeBig(t *testing.T) {
|
func TestEncodeBig(t *testing.T) {
|
||||||
for _, test := range encodeBigTests {
|
for _, test := range encodeBigTests {
|
||||||
enc := EncodeBig(test.input.(*big.Int))
|
enc := EncodeBig(test.input.(*big.Int))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue