From ed2c4b03190c8bc3908b54ebabe05e2c8dab0b1f Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 18 Aug 2023 16:38:40 +0300 Subject: [PATCH] core: improve error checks in TestNotify Ensure that the error returned from runtime.Notify is exactly the error that was expected. Signed-off-by: Anna Shaleva --- pkg/core/interop/runtime/ext_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/core/interop/runtime/ext_test.go b/pkg/core/interop/runtime/ext_test.go index 997d97728..c0764fd9f 100644 --- a/pkg/core/interop/runtime/ext_test.go +++ b/pkg/core/interop/runtime/ext_test.go @@ -5,6 +5,7 @@ import ( "math" "math/big" "path/filepath" + "strings" "testing" "github.com/nspcc-dev/neo-go/internal/contracts" @@ -643,26 +644,34 @@ func TestNotify(t *testing.T) { } t.Run("big name", func(t *testing.T) { ic := newIC(string(make([]byte, runtime.MaxEventNameLen+1)), stackitem.NewArray([]stackitem.Item{stackitem.Null{}})) - require.Error(t, runtime.Notify(ic)) + err := runtime.Notify(ic) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "event name must be less than 32"), err) }) t.Run("dynamic script", func(t *testing.T) { ic := newIC("some", stackitem.Null{}) ic.VM.LoadScriptWithHash([]byte{1}, random.Uint160(), callflag.NoneFlag) ic.VM.Estack().PushVal(stackitem.NewArray([]stackitem.Item{stackitem.Make(42)})) ic.VM.Estack().PushVal("event") - require.Error(t, runtime.Notify(ic)) + err := runtime.Notify(ic) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "notifications are not allowed in dynamic scripts"), err) }) t.Run("recursive struct", func(t *testing.T) { arr := stackitem.NewArray([]stackitem.Item{stackitem.Null{}}) arr.Append(arr) ic := newIC("event", stackitem.NewArray([]stackitem.Item{arr})) // upper array is needed to match manifest event signature. - require.Error(t, runtime.Notify(ic)) + err := runtime.Notify(ic) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "bad notification: recursive item"), err) }) t.Run("big notification", func(t *testing.T) { bs := stackitem.NewByteArray(make([]byte, runtime.MaxNotificationSize+1)) arr := stackitem.NewArray([]stackitem.Item{bs}) ic := newIC("event", arr) - require.Error(t, runtime.Notify(ic)) + err := runtime.Notify(ic) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "notification size shouldn't exceed 1024"), err) }) t.Run("good", func(t *testing.T) { arr := stackitem.NewArray([]stackitem.Item{stackitem.Make(42)})