Skip to content

Commit

Permalink
core: remove error from runtime.GetInvocationCounter
Browse files Browse the repository at this point in the history
close #1444
  • Loading branch information
AnnaShaleva committed Oct 8, 2020
1 parent 7ddce97 commit 45bfce6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/core/interop/runtime/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pkg/core/interop_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 45bfce6

Please sign in to comment.