forked from TrueCloudLab/neoneo-go
parent
7ddce97f11
commit
45bfce60a5
2 changed files with 8 additions and 4 deletions
|
@ -58,9 +58,11 @@ func GetNotifications(ic *interop.Context) error {
|
||||||
|
|
||||||
// GetInvocationCounter returns how many times current contract was invoked during current tx execution.
|
// GetInvocationCounter returns how many times current contract was invoked during current tx execution.
|
||||||
func GetInvocationCounter(ic *interop.Context) error {
|
func GetInvocationCounter(ic *interop.Context) error {
|
||||||
count, ok := ic.Invocations[ic.VM.GetCurrentScriptHash()]
|
currentScriptHash := ic.VM.GetCurrentScriptHash()
|
||||||
|
count, ok := ic.Invocations[currentScriptHash]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("current contract wasn't invoked from others")
|
count = 1
|
||||||
|
ic.Invocations[currentScriptHash] = count
|
||||||
}
|
}
|
||||||
ic.VM.Estack().PushVal(count)
|
ic.VM.Estack().PushVal(count)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -298,9 +298,11 @@ func TestRuntimeGetInvocationCounter(t *testing.T) {
|
||||||
|
|
||||||
ic.Invocations[hash.Hash160([]byte{2})] = 42
|
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})
|
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) {
|
t.Run("NonZero", func(t *testing.T) {
|
||||||
v.LoadScript([]byte{2})
|
v.LoadScript([]byte{2})
|
||||||
|
|
Loading…
Reference in a new issue