-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Neo.VM; | ||
using Neo.VM.Types; | ||
|
||
namespace Neo.SmartContract | ||
{ | ||
internal class Callback | ||
{ | ||
public readonly Pointer Pointer; | ||
public readonly ExecutionContext Context; | ||
public readonly int RVcount; | ||
public readonly StackItem[] Params; | ||
|
||
public Callback(ExecutionContext context, Pointer pointer, int parcount, int rvcount) | ||
{ | ||
Context = context; | ||
Pointer = pointer; | ||
RVcount = rvcount; | ||
Params = new StackItem[parcount]; | ||
|
||
for (int x = 0; x < parcount; x++) | ||
{ | ||
Params[x] = context.EvaluationStack.Pop(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.SmartContract; | ||
using Neo.VM; | ||
using Neo.VM.Types; | ||
using System; | ||
|
||
namespace Neo.UnitTests.SmartContract | ||
{ | ||
public partial class UT_Syscalls | ||
{ | ||
[TestMethod] | ||
public void Runtime_CreateCallback() | ||
{ | ||
using var script = new ScriptBuilder(); | ||
|
||
script.EmitPush(5); | ||
script.EmitPush(2); | ||
script.EmitPush(1); | ||
script.Emit(OpCode.PUSHA, BitConverter.GetBytes(0)); | ||
script.EmitSysCall(ApplicationEngine.CreateCallback); | ||
|
||
// Execute | ||
|
||
var engine = new ApplicationEngine(TriggerType.Application, null, null, 100_000_000, false); | ||
engine.LoadScript(script.ToArray()); | ||
Assert.AreEqual(engine.Execute(), VMState.HALT); | ||
|
||
// Check the results | ||
|
||
Assert.AreEqual(1, engine.ResultStack.Count); | ||
Assert.IsTrue(engine.ResultStack.TryPop<InteropInterface>(out var item)); | ||
Assert.IsNotNull(item); | ||
|
||
Assert.IsTrue(item.TryGetInterface<Callback>(out var callback)); | ||
Assert.AreEqual(2, callback.RVcount); | ||
Assert.AreEqual(1, callback.Params.Length); | ||
Assert.AreEqual(5, callback.Params[0].GetBigInteger()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters