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

Update dev-pack with last neo changes #146

Merged
merged 20 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 2 additions & 2 deletions src/Neo.Compiler.MSIL/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static Assembly Create(Compilation comp)

if (!result.Success)
{
throw new ArgumentException();
throw new ArgumentException(string.Join(Environment.NewLine, result.Diagnostics.Select(u => u.ToString())));
}

streamDll.Position = 0;
Expand Down Expand Up @@ -175,7 +175,7 @@ private static MetadataReference[] CreateReferences(params string[] references)
MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.Numerics.dll")),
MetadataReference.CreateFromFile(typeof(System.ComponentModel.DisplayNameAttribute).Assembly.Location),
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Neo.SmartContract.Framework.SmartContract).Assembly.Location),
MetadataReference.CreateFromFile(typeof(SmartContract.Framework.SmartContract).Assembly.Location),
});
refs.AddRange(references.Select(u => MetadataReference.CreateFromFile(u)));
return refs.ToArray();
Expand Down
6 changes: 3 additions & 3 deletions src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Copyright>2015-2019 The Neo Project</Copyright>
<AssemblyTitle>Neo.Compiler.MSIL</AssemblyTitle>
<Version>2.4.1</Version>
<Authors>The Neo Project</Authors>
<TargetFrameworks>netcoreapp2.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;netstandard2.1</TargetFrameworks>
shargon marked this conversation as resolved.
Show resolved Hide resolved
<OutputType>Exe</OutputType>
<AssemblyName>neon</AssemblyName>
<PackageId>Neo.Compiler.MSIL</PackageId>
Expand All @@ -25,7 +25,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.3.1" />
<PackageReference Include="Mono.Cecil" Version="0.11.1" />
<PackageReference Include="Neo" Version="3.0.0-CI00212" />
<PackageReference Include="Neo" Version="3.0.0-CI00818" />
shargon marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
shargon marked this conversation as resolved.
Show resolved Hide resolved
<IsPackable>false</IsPackable>
<RootNamespace>Neo.Compiler.MSIL</RootNamespace>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion tests/Neo.Compiler.MSIL.UnitTests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.Utils;
using Neo.VM;
using Neo.VM.Types;
using System;

namespace Neo.Compiler.MSIL
Expand Down Expand Up @@ -62,6 +62,7 @@ public void Test_ByteArray_New()
var bequal = wantresult.Equals(result);
Assert.IsTrue(bequal);
}

[TestMethod]
public void Test_ByteArrayPick()
{
Expand Down
3 changes: 1 addition & 2 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Appcall.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.Utils;
using Neo.VM;
using Neo.VM.Types;

namespace Neo.Compiler.MSIL
{
Expand All @@ -27,7 +27,6 @@ public void Test_Appcall()

var bequal = wantresult.Equals(result);
Assert.IsTrue(bequal);

}
}
}
3 changes: 2 additions & 1 deletion tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.Utils;
using Neo.VM;
using Neo.VM.Types;

namespace Neo.Compiler.MSIL
{
Expand All @@ -27,7 +28,7 @@ public void Test_AutoEntry_private()
var testengine = new TestEngine();
testengine.AddEntryScript("./TestClasses/Contract_autoentrypoint.cs");
testengine.ScriptEntry.DumpNEF();
StackItem[] _params = new StackItem[] { "privateMethod", new StackItem[0] };
StackItem[] _params = new StackItem[] { "privateMethod", new Array() };
var result = testengine.ExecuteTestCase(_params);//new test method02

bool hadFault = (testengine.State & VMState.FAULT) > 0;
Expand Down
13 changes: 6 additions & 7 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NULL.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.Utils;
using Neo.VM;
using Neo.VM.Types;

namespace Neo.Compiler.MSIL
Expand All @@ -27,7 +26,7 @@ public void IsNull()
var item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsTrue(item.GetBoolean());
Assert.IsTrue(item.ToBoolean());

// False

Expand All @@ -36,7 +35,7 @@ public void IsNull()
item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsFalse(item.GetBoolean());
Assert.IsFalse(item.ToBoolean());
}

[TestMethod]
Expand All @@ -49,7 +48,7 @@ public void EqualNull()
var item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsTrue(item.GetBoolean());
Assert.IsTrue(item.ToBoolean());

// False

Expand All @@ -58,7 +57,7 @@ public void EqualNull()
item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsFalse(item.GetBoolean());
Assert.IsFalse(item.ToBoolean());

// True

Expand All @@ -67,7 +66,7 @@ public void EqualNull()
item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsTrue(item.GetBoolean());
Assert.IsTrue(item.ToBoolean());

// False

Expand All @@ -76,7 +75,7 @@ public void EqualNull()
item = result.Pop();

Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.IsFalse(item.GetBoolean());
Assert.IsFalse(item.ToBoolean());
}
}
}
4 changes: 2 additions & 2 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.Utils;
using Neo.VM;
using Neo.VM.Types;

namespace Neo.Compiler.MSIL
{
Expand All @@ -21,7 +21,7 @@ public void Test_Shift_BigInteger()
var testengine = new TestEngine();
testengine.AddEntryScript("./TestClasses/Contract_shift_bigint.cs");
testengine.ScriptEntry.DumpNEF();
StackItem[] _params = new StackItem[] { "testfunc", new StackItem[0] };
StackItem[] _params = new StackItem[] { "testfunc", new Array() };
var result = testengine.ExecuteTestCase(_params);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticVar.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.Utils;
using Neo.VM;
using Neo.VM.Types;

namespace Neo.Compiler.MSIL
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Test_InvalidSwitch()
public void Test_ValidSwitch()
{
TestEngine testengine;
RandomAccessStack<StackItem> result;
EvaluationStack result;

// Test cases

Expand Down
6 changes: 3 additions & 3 deletions tests/Neo.Compiler.MSIL.UnitTests/Utils/TestDataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public TestDataCache(TKey key, TValue value)
{
dic.Add(key, value);
}
public override void DeleteInternal(TKey key)
protected override void DeleteInternal(TKey key)
{
dic.Remove(key);
}
Expand All @@ -28,9 +28,9 @@ protected override void AddInternal(TKey key, TValue value)
dic.Add(key, value);
}

protected override IEnumerable<KeyValuePair<TKey, TValue>> FindInternal(byte[] key_prefix)
protected override IEnumerable<(TKey Key, TValue Value)> FindInternal(byte[] key_prefix)
{
return dic.ToList();
return dic.Select(u => (u.Key, u.Value));
}

protected override TValue GetInternal(TKey key)
Expand Down
21 changes: 10 additions & 11 deletions tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.Collections.Generic;

Expand All @@ -19,7 +20,7 @@ public class TestEngine : ApplicationEngine

public BuildScript ScriptEntry { get; private set; }

public TestEngine(TriggerType trigger = TriggerType.Application, IVerifiable verificable = null, Snapshot snapshot = null)
public TestEngine(TriggerType trigger = TriggerType.Application, IVerifiable verificable = null, StoreView snapshot = null)
: base(trigger, verificable, snapshot == null ? new TestSnapshot() : snapshot, 0, true)
{
Scripts = new Dictionary<string, BuildScript>();
Expand Down Expand Up @@ -70,12 +71,11 @@ public ContractMethod GetMethod(string methodname)
return new ContractMethod(this, methodname);
}

public RandomAccessStack<StackItem> ExecuteTestCaseStandard(string methodname, params StackItem[] args)
public EvaluationStack ExecuteTestCaseStandard(string methodname, params StackItem[] args)
{
//var engine = new ExecutionEngine();
this.InvocationStack.Peek().InstructionPointer = 0;
this.CurrentContext.EvaluationStack.Push(args);
this.CurrentContext.EvaluationStack.Push(methodname);
this.Push(new VM.Types.Array(args));
this.Push(methodname);
while (true)
{
var bfault = (this.State & VMState.FAULT) > 0;
Expand All @@ -91,7 +91,7 @@ public RandomAccessStack<StackItem> ExecuteTestCaseStandard(string methodname, p
return this.ResultStack;
}

public RandomAccessStack<StackItem> ExecuteTestCase(params StackItem[] args)
public EvaluationStack ExecuteTestCase(params StackItem[] args)
{
//var engine = new ExecutionEngine();
this.InvocationStack.Peek().InstructionPointer = 0;
Expand All @@ -114,8 +114,7 @@ public RandomAccessStack<StackItem> ExecuteTestCase(params StackItem[] args)
this.CurrentContext.CurrentInstruction.OpCode);
this.ExecuteNext();
}
var stack = this.ResultStack;
return stack;
return this.ResultStack;
}

protected override bool OnSysCall(uint method)
Expand Down Expand Up @@ -203,7 +202,7 @@ private void DumpItemShort(StackItem item, int space = 0)
{
var spacestr = "";
for (var i = 0; i < space; i++) spacestr += " ";
var line = NeonTestTool.Bytes2HexString(item.GetByteArray());
var line = NeonTestTool.Bytes2HexString(item.GetSpan().ToArray());

if (item is Neo.VM.Types.ByteArray)
{
Expand All @@ -222,7 +221,7 @@ private void DumpItem(StackItem item, int space = 0)
for (var i = 0; i < space; i++) spacestr += " ";
Console.WriteLine(spacestr + "got Param:" + item.GetType().ToString());

if (item is Neo.VM.Types.Array || item is Neo.VM.Types.Struct)
if (item is VM.Types.Array || item is Neo.VM.Types.Struct)
{
var array = item as Neo.VM.Types.Array;
for (var i = 0; i < array.Count; i++)
Expand All @@ -245,8 +244,8 @@ private void DumpItem(StackItem item, int space = 0)
else
{
Console.WriteLine(spacestr + "--as num:" + item.GetBigInteger());
Console.WriteLine(spacestr + "--as bin:" + NeonTestTool.Bytes2HexString(item.GetSpan().ToArray()));

Console.WriteLine(spacestr + "--as bin:" + NeonTestTool.Bytes2HexString(item.GetByteArray()));
if (item is Neo.VM.Types.ByteArray)
{
var str = item.GetString();
Expand Down
8 changes: 4 additions & 4 deletions tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Neo.IO;
using Neo.IO.Caching;
using Neo.IO.Wrappers;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;

namespace Neo.Compiler.MSIL.Utils
{
public class TestSnapshot : Snapshot
public class TestSnapshot : StoreView
{
private DataCache<UInt256, TrimmedBlock> _Blocks = new TestDataCache<UInt256, TrimmedBlock>();
private DataCache<UInt256, TransactionState> _Transactions = new TestDataCache<UInt256, TransactionState>();
private DataCache<UInt160, ContractState> _Contracts = new TestDataCache<UInt160, ContractState>();
private DataCache<StorageKey, StorageItem> _Storages = new TestDataCache<StorageKey, StorageItem>();
private DataCache<UInt32Wrapper, HeaderHashList> _HeaderHashList = new TestDataCache<UInt32Wrapper, HeaderHashList>();
private DataCache<SerializableWrapper<uint>, HeaderHashList> _HeaderHashList = new TestDataCache<SerializableWrapper<uint>, HeaderHashList>();
private MetaDataCache<HashIndexState> _BlockHashIndex = new TestMetaDataCache<HashIndexState>();
private MetaDataCache<HashIndexState> _HeaderHashIndex = new TestMetaDataCache<HashIndexState>();

Expand All @@ -24,7 +24,7 @@ public class TestSnapshot : Snapshot

public override DataCache<StorageKey, StorageItem> Storages => _Storages;

public override DataCache<UInt32Wrapper, HeaderHashList> HeaderHashList => _HeaderHashList;
public override DataCache<SerializableWrapper<uint>, HeaderHashList> HeaderHashList => _HeaderHashList;

public override MetaDataCache<HashIndexState> BlockHashIndex => _BlockHashIndex;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
shargon marked this conversation as resolved.
Show resolved Hide resolved
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Test_AccountIsStandard()

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.AreEqual(true, item.GetBoolean());
Assert.AreEqual(true, item.ToBoolean());

// No standard

Expand All @@ -57,7 +57,7 @@ public void Test_AccountIsStandard()

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.AreEqual(false, item.GetBoolean());
Assert.AreEqual(false, item.ToBoolean());
}
}
}
Loading