common: improve IsHexAddress and add tests (#15551)
Also unexport isHex, hasHexPrefix because IsHexAddress is the only caller. Fixes #15550
This commit is contained in:
committed by
Felix Lange
parent
1d06e41f04
commit
afb8154eab
@ -35,6 +35,30 @@ func TestBytesConversion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsHexAddress(t *testing.T) {
|
||||
tests := []struct {
|
||||
str string
|
||||
exp bool
|
||||
}{
|
||||
{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
||||
{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
||||
{"0X5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
||||
{"0XAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
|
||||
{"0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
|
||||
{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed1", false},
|
||||
{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beae", false},
|
||||
{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed11", false},
|
||||
{"0xxaaeb6053f3e94c9b9a09f33669435e7ef1beaed", false},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if result := IsHexAddress(test.str); result != test.exp {
|
||||
t.Errorf("IsHexAddress(%s) == %v; expected %v",
|
||||
test.str, result, test.exp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHashJsonValidation(t *testing.T) {
|
||||
var tests = []struct {
|
||||
Prefix string
|
||||
|
Reference in New Issue
Block a user