aboutsummaryrefslogtreecommitdiffstats
path: root/common/types_test.go
diff options
context:
space:
mode:
authorSteven Roose <stevenroose@gmail.com>2017-12-05 02:34:15 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-12-05 02:34:15 +0800
commitafb8154eab2961996b321ac3fe5a21602e3b1aff (patch)
tree13011886b99de7a66e8d916882d731e12afbb2b1 /common/types_test.go
parent1d06e41f04d75c31334c455063e9ec7b4136bf23 (diff)
downloadgo-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.gz
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.bz2
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.lz
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.xz
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.zst
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.zip
common: improve IsHexAddress and add tests (#15551)
Also unexport isHex, hasHexPrefix because IsHexAddress is the only caller. Fixes #15550
Diffstat (limited to 'common/types_test.go')
-rw-r--r--common/types_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/types_test.go b/common/types_test.go
index 6f3b31576..db636812c 100644
--- a/common/types_test.go
+++ b/common/types_test.go
@@ -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