aboutsummaryrefslogtreecommitdiffstats
path: root/common/types_test.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2016-04-01 18:03:06 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2016-04-01 18:56:54 +0800
commitd63e29241d27954d44215931e787e86dfaf230a6 (patch)
tree03aafd58c130965cdcc7bd5ccbdde70239f81556 /common/types_test.go
parent10d3466c934bd425a8c941270749a652a588527d (diff)
downloadgo-tangerine-d63e29241d27954d44215931e787e86dfaf230a6.tar
go-tangerine-d63e29241d27954d44215931e787e86dfaf230a6.tar.gz
go-tangerine-d63e29241d27954d44215931e787e86dfaf230a6.tar.bz2
go-tangerine-d63e29241d27954d44215931e787e86dfaf230a6.tar.lz
go-tangerine-d63e29241d27954d44215931e787e86dfaf230a6.tar.xz
go-tangerine-d63e29241d27954d44215931e787e86dfaf230a6.tar.zst
go-tangerine-d63e29241d27954d44215931e787e86dfaf230a6.zip
common: added Hash unmarshal json length validation
Diffstat (limited to 'common/types_test.go')
-rw-r--r--common/types_test.go22
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)
+ }
+ }
+}