From a0d2f95e42eb34ffb2b5639bf9f0e29a1bc23340 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 29 Oct 2024 12:07:04 +0300 Subject: [PATCH] stackitem: extend ToJSON test Inspired by https://github.com/neo-project/neo/pull/3558, although this PR fixes different implementation of stackitem serializatior that is used outside of VM. Signed-off-by: Anna Shaleva --- pkg/vm/stackitem/json_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/vm/stackitem/json_test.go b/pkg/vm/stackitem/json_test.go index c0f980fde..890248a03 100644 --- a/pkg/vm/stackitem/json_test.go +++ b/pkg/vm/stackitem/json_test.go @@ -203,6 +203,18 @@ func TestToJSONCornerCases(t *testing.T) { m.Add(Make([]byte{0xe9}), Make(true)) testToJSON(t, ErrInvalidValue, m) }) + t.Run("circular reference", func(t *testing.T) { + m := NewMap() + m.Add(Make("one"), Make(true)) + + // No circular reference, ensure it can be properly serialized. + arr := NewArray([]Item{m, m}) + testToJSON(t, nil, arr) + + // With circular reference, error expected. + m.Add(Make("two"), arr) + testToJSON(t, ErrTooBig, arr) + }) } // getBigArray returns array takes up a lot of storage when serialized.