From 45bfce60a51f329be993049136824eb9f90ffc04 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 2 Oct 2020 18:42:23 +0300 Subject: [PATCH] core: remove error from runtime.GetInvocationCounter close #1444 --- pkg/core/interop/runtime/util.go | 6 ++++-- pkg/core/interop_system_test.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/core/interop/runtime/util.go b/pkg/core/interop/runtime/util.go index f9037887f..861be68bf 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 d947fb08e..49e88acfa 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -298,9 +298,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})