diff options
author | Felix Lange <fjl@twurst.com> | 2016-11-28 07:58:22 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-11-28 18:37:13 +0800 |
commit | 37e5816bcdaaca2380ce5a56d9a0834340733b31 (patch) | |
tree | 51a11d9270c7171baf96a72e53241d175500ff3b /common/types_test.go | |
parent | 1609df327575f9e8bc849de3a649990be89f93e2 (diff) | |
download | go-tangerine-37e5816bcdaaca2380ce5a56d9a0834340733b31.tar go-tangerine-37e5816bcdaaca2380ce5a56d9a0834340733b31.tar.gz go-tangerine-37e5816bcdaaca2380ce5a56d9a0834340733b31.tar.bz2 go-tangerine-37e5816bcdaaca2380ce5a56d9a0834340733b31.tar.lz go-tangerine-37e5816bcdaaca2380ce5a56d9a0834340733b31.tar.xz go-tangerine-37e5816bcdaaca2380ce5a56d9a0834340733b31.tar.zst go-tangerine-37e5816bcdaaca2380ce5a56d9a0834340733b31.zip |
common: use package hexutil for fixed size type encoding
Diffstat (limited to 'common/types_test.go')
-rw-r--r-- | common/types_test.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/common/types_test.go b/common/types_test.go index de67cfcb5..e84780f43 100644 --- a/common/types_test.go +++ b/common/types_test.go @@ -18,7 +18,10 @@ package common import ( "math/big" + "strings" "testing" + + "github.com/ethereum/go-ethereum/common/hexutil" ) func TestBytesConversion(t *testing.T) { @@ -38,19 +41,26 @@ func TestHashJsonValidation(t *testing.T) { var tests = []struct { Prefix string Size int - Error error + Error string }{ - {"", 2, hashJsonLengthErr}, - {"", 62, hashJsonLengthErr}, - {"", 66, hashJsonLengthErr}, - {"", 65, hashJsonLengthErr}, - {"0X", 64, nil}, - {"0x", 64, nil}, - {"0x", 62, hashJsonLengthErr}, + {"", 62, hexutil.ErrMissingPrefix.Error()}, + {"0x", 66, "hex string has length 66, want 64 for Hash"}, + {"0x", 63, hexutil.ErrOddLength.Error()}, + {"0x", 0, "hex string has length 0, want 64 for Hash"}, + {"0x", 64, ""}, + {"0X", 64, ""}, } - for i, test := range tests { - if err := h.UnmarshalJSON(append([]byte(test.Prefix), make([]byte, test.Size)...)); err != test.Error { - t.Errorf("test #%d: error mismatch: have %v, want %v", i, err, test.Error) + for _, test := range tests { + input := `"` + test.Prefix + strings.Repeat("0", test.Size) + `"` + err := h.UnmarshalJSON([]byte(input)) + if err == nil { + if test.Error != "" { + t.Errorf("%s: error mismatch: have nil, want %q", input, test.Error) + } + } else { + if err.Error() != test.Error { + t.Errorf("%s: error mismatch: have %q, want %q", input, err, test.Error) + } } } } |