diff --git a/pkg/core/interop/runtime/util.go b/pkg/core/interop/runtime/util.go index f9037887f7..861be68bfe 100644 --- a/pkg/core/interop/runtime/util.go +++ b/pkg/core/interop/runtime/util.go @@ -58,9 +58,11 @@ func GetNotifications(ic *interop.Context) error { // GetInvocationCounter returns how many times current contract was invoked during current tx execution. func GetInvocationCounter(ic *interop.Context) error { - count, ok := ic.Invocations[ic.VM.GetCurrentScriptHash()] + currentScriptHash := ic.VM.GetCurrentScriptHash() + count, ok := ic.Invocations[currentScriptHash] if !ok { - return errors.New("current contract wasn't invoked from others") + count = 1 + ic.Invocations[currentScriptHash] = count } ic.VM.Estack().PushVal(count) return nil diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index eac5a680c8..20bfe58cc2 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -294,9 +294,11 @@ func TestRuntimeGetInvocationCounter(t *testing.T) { ic.Invocations[hash.Hash160([]byte{2})] = 42 - t.Run("Zero", func(t *testing.T) { + t.Run("No invocations", func(t *testing.T) { v.LoadScript([]byte{1}) - require.Error(t, runtime.GetInvocationCounter(ic)) + // do not return an error in this case. + require.NoError(t, runtime.GetInvocationCounter(ic)) + require.EqualValues(t, 1, v.Estack().Pop().BigInt().Int64()) }) t.Run("NonZero", func(t *testing.T) { v.LoadScript([]byte{2})