From f89f0300f6d75371e3fbbe2826c56892e36e0dd0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 17 Jul 2021 22:35:59 +0300 Subject: [PATCH] stackitem: improve test coverage a bit --- pkg/vm/stackitem/serialization_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/vm/stackitem/serialization_test.go b/pkg/vm/stackitem/serialization_test.go index 91da8bd6e..fc0a88338 100644 --- a/pkg/vm/stackitem/serialization_test.go +++ b/pkg/vm/stackitem/serialization_test.go @@ -154,6 +154,25 @@ func TestSerialize(t *testing.T) { }) } +func TestEmptyDeserialization(t *testing.T) { + empty := []byte{} + _, err := Deserialize(empty) + require.Error(t, err) +} + +func TestMapDeserializationError(t *testing.T) { + m := NewMap() + m.Add(Make(1), Make(1)) + m.Add(Make(2), nil) // Bad value + m.Add(Make(3), Make(3)) + + w := io.NewBufBinWriter() + EncodeBinaryProtected(m, w.BinWriter) + require.NoError(t, w.Err) + _, err := Deserialize(w.Bytes()) + require.True(t, errors.Is(err, ErrInvalidType), err) +} + func TestDeserializeTooManyElements(t *testing.T) { item := Make(0) for i := 0; i < MaxDeserialized-1; i++ { // 1 for zero inner element.