aboutsummaryrefslogtreecommitdiffstats
path: root/common/bytes_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/bytes_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/bytes_test.go')
-rw-r--r--common/bytes_test.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/common/bytes_test.go b/common/bytes_test.go
index 71631e6dd..97dd34d15 100644
--- a/common/bytes_test.go
+++ b/common/bytes_test.go
@@ -34,19 +34,6 @@ func (s *BytesSuite) TestCopyBytes(c *checker.C) {
c.Assert(res1, checker.DeepEquals, exp1)
}
-func (s *BytesSuite) TestIsHex(c *checker.C) {
- data1 := "a9e67e"
- exp1 := false
- res1 := IsHex(data1)
- c.Assert(res1, checker.DeepEquals, exp1)
-
- data2 := "0xa9e67e00"
- exp2 := true
- res2 := IsHex(data2)
- c.Assert(res2, checker.DeepEquals, exp2)
-
-}
-
func (s *BytesSuite) TestLeftPadBytes(c *checker.C) {
val1 := []byte{1, 2, 3, 4}
exp1 := []byte{0, 0, 0, 0, 1, 2, 3, 4}
@@ -78,6 +65,27 @@ func TestFromHex(t *testing.T) {
}
}
+func TestIsHex(t *testing.T) {
+ tests := []struct {
+ input string
+ ok bool
+ }{
+ {"", true},
+ {"0", false},
+ {"00", true},
+ {"a9e67e", true},
+ {"A9E67E", true},
+ {"0xa9e67e", false},
+ {"a9e67e001", false},
+ {"0xHELLO_MY_NAME_IS_STEVEN_@#$^&*", false},
+ }
+ for _, test := range tests {
+ if ok := isHex(test.input); ok != test.ok {
+ t.Errorf("isHex(%q) = %v, want %v", test.input, ok, test.ok)
+ }
+ }
+}
+
func TestFromHexOddLength(t *testing.T) {
input := "0x1"
expected := []byte{1}