diff options
Diffstat (limited to 'common/types_test.go')
-rw-r--r-- | common/types_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/common/types_test.go b/common/types_test.go index edf8d4d14..f2dfbf0c9 100644 --- a/common/types_test.go +++ b/common/types_test.go @@ -29,3 +29,25 @@ func TestBytesConversion(t *testing.T) { t.Errorf("expected %x got %x", exp, hash) } } + +func TestHashJsonValidation(t *testing.T) { + var h Hash + var tests = []struct { + Prefix string + Size int + Error error + }{ + {"", 2, hashJsonLengthErr}, + {"", 62, hashJsonLengthErr}, + {"", 66, hashJsonLengthErr}, + {"", 65, hashJsonLengthErr}, + {"0X", 64, nil}, + {"0x", 64, nil}, + {"0x", 62, hashJsonLengthErr}, + } + for i, test := range tests { + if err := h.UnmarshalJSON(append([]byte(test.Prefix), make([]byte, test.Size)...)); err != test.Error { + t.Error(i, "expected", test.Error, "got", err) + } + } +} |