Skip to content

Commit

Permalink
Merge pull request #7 from phantasma-io/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TeknoPT authored Dec 14, 2023
2 parents 46d3810 + 5f0e685 commit c88c2da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Compiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ static void Main(string[] args)
return;
}

#if !DEBUG
try
#endif
{
var modules = compiler.Process(sourceCode);

Expand All @@ -256,12 +258,13 @@ static void Main(string[] args)
}
}
}
#if !DEBUG
catch (CompilerException ex)
{
Console.WriteLine(ex.Message);
System.Environment.Exit(-1);
}

#endif
Console.WriteLine("Success!");

#if DEBUG
Expand Down
1 change: 1 addition & 0 deletions Library/src/CodeGen/Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static LibraryDeclaration LoadLibrary(string name, Scope scope, ModuleKin
var reg = Compiler.Instance.AllocRegister(output, expr);
var module = expr.arguments[0].AsLiteral<Module>();
var methodName = expr.arguments[1].AsLiteral<string>();

var method = module.abi.FindMethod(methodName);
if (method == null)
{
Expand Down
9 changes: 6 additions & 3 deletions Library/tests/Contracts/EventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public paySomething(from:address, x:number)
Assert.IsTrue(result == ExecutionState.Halt);

Assert.IsTrue(vm.Stack.Count == 1);

Assert.IsTrue(vm.Events.Count() == 1);
}


[Test]
public void TestEventWithDescription()
{
Expand Down Expand Up @@ -97,6 +99,7 @@ public paySomething(from:address, x:number)
Assert.IsTrue(result == ExecutionState.Halt);

Assert.IsTrue(vm.Stack.Count == 1);

Assert.IsTrue(vm.Events.Count() == 1);

}
}
8 changes: 8 additions & 0 deletions Library/tests/TestVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
using System.Numerics;
using Phantasma.Core.Domain.Events.Structs;
using ExecutionContext = Phantasma.Core.Domain.Execution.ExecutionContext;
using Phantasma.Core.Domain.Structs;

namespace TOMBLib.Tests;

public class TestVM : VirtualMachine
{
public IEnumerable<Event> Events => _events;
private List<Event> _events = new List<Event>();

private Module module;

private Dictionary<string, Func<VirtualMachine, ExecutionState>> _interops =
Expand Down Expand Up @@ -215,6 +219,10 @@ private ExecutionState Runtime_Notify(VirtualMachine vm)
var kind = vm.Stack.Pop().AsEnum<EventKind>();
var address = vm.Stack.Pop().AsAddress();
var obj = vm.Stack.Pop();
var bytes = obj.Serialize();

// TODO contract name maybe should come from somewhere else?
_events.Add(new Event(kind, address, contract: "test", bytes));

var array = new BigInteger[] { 123, 456, 789 };

Expand Down

0 comments on commit c88c2da

Please sign in to comment.