Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event name, callback support and base64 syscalls #302

Merged
merged 23 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Neo.SmartContract.Framework/Services/Neo/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public static extern long GasLeft
[Syscall("System.Runtime.CheckWitness")]
public static extern bool CheckWitness(byte[] hashOrPubkey);

[Syscall("System.Runtime.Notify")]
public static extern void Notify(string eventName, params object[] state);

[Syscall("System.Runtime.Log")]
public static extern void Log(string message);
}
Expand Down
12 changes: 10 additions & 2 deletions tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract2.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using System;
using System.ComponentModel;

namespace Neo.Compiler.MSIL.UnitTests.TestClasses
{
public class Contract2 : SmartContract.Framework.SmartContract
{
public delegate void mydelegate(object arg);

[DisplayName("event")]
public static event mydelegate notify;

public static byte UnitTest_002(object arg1, object arg2)
{
Neo.SmartContract.Framework.Services.Neo.Runtime.Notify("event", arg1);
Neo.SmartContract.Framework.Services.Neo.Runtime.Notify("event", arg2);
notify(arg1);
notify(arg2);
var nb = new byte[] { 1, 2, 3, 4 };
return nb[2];
}
Expand Down
15 changes: 11 additions & 4 deletions tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using System.ComponentModel;

namespace Neo.Compiler.MSIL.UnitTests.TestClasses
{
class Contract_shift : SmartContract.Framework.SmartContract
{
public delegate void mydelegate(int arg);

[DisplayName("event")]
public static event mydelegate notify;

public static object Main()
{
int v = 8;
var v1 = v << 1;
var v2 = v << -1;
var v3 = v >> 1;
var v4 = v >> -1;
SmartContract.Framework.Services.Neo.Runtime.Notify("1", v1);
SmartContract.Framework.Services.Neo.Runtime.Notify("2", v2);
SmartContract.Framework.Services.Neo.Runtime.Notify("3", v3);
SmartContract.Framework.Services.Neo.Runtime.Notify("4", v4);
notify(v1);
notify(v2);
notify(v3);
notify(v4);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using System.ComponentModel;

namespace Neo.Compiler.MSIL.UnitTests.TestClasses
{
class Contract_shift_bigint : SmartContract.Framework.SmartContract
{
public delegate void mydelegate(System.Numerics.BigInteger arg);

[DisplayName("event")]
public static event mydelegate notify;

public static object Main()
{
System.Numerics.BigInteger v = 8;
var v1 = v << 0;
var v2 = v << 1;
var v3 = v >> 1;
var v4 = v >> 2;
SmartContract.Framework.Services.Neo.Runtime.Notify("1", v1);
SmartContract.Framework.Services.Neo.Runtime.Notify("2", v2);
SmartContract.Framework.Services.Neo.Runtime.Notify("3", v3);
SmartContract.Framework.Services.Neo.Runtime.Notify("4", v4);
notify(v1);
notify(v2);
notify(v3);
notify(v4);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,6 @@ public void Test_CheckWitness()
Assert.IsFalse(item.ToBoolean());
}

[TestMethod]
public void Test_Notify()
{
var list = new List<NotifyEventArgs>();
var method = new EventHandler<NotifyEventArgs>((s, e) => list.Add(e));

ApplicationEngine.Notify += method;
var result = _engine.ExecuteTestCaseStandard("notify", new ByteString(Encoding.UTF8.GetBytes("NotifyTest")));
ApplicationEngine.Notify -= method;

Assert.AreEqual(1, list.Count);

var item = list[0];
var array = item.State;
Assert.AreEqual("NotifyTest", item.EventName);
Assert.AreEqual(0, item.State.Count);
}

[TestMethod]
public void Test_GetNotificationsCount()
{
Expand Down
1 change: 1 addition & 0 deletions tests/Neo.SmartContract.Framework.UnitTests/SyscallTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void TestAllSyscalls()
if (syscall.Value.Name == "Neo.Native.Tokens.GAS") continue;
if (syscall.Value.Name == "Neo.Native.Policy") continue;
if (syscall.Value.Name == "Neo.Native.Call") continue;
if (syscall.Value.Name == "System.Runtime.Notify") continue;

if (list.Remove(syscall.Value.Name)) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public static void Log(string message)
Runtime.Log(message);
}

public static void Notify(string message)
{
Runtime.Notify(message, new object[0]);
}

public static bool CheckWitness(byte[] hashOrPubkey)
{
return Runtime.CheckWitness(hashOrPubkey);
Expand Down