core: remove error from runtime.GetInvocationCounter

close #1444
This commit is contained in:
Anna Shaleva 2020-10-02 18:42:23 +03:00
parent 7ddce97f11
commit 45bfce60a5
2 changed files with 8 additions and 4 deletions

View file

@ -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

View file

@ -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})