Skip to content

Commit

Permalink
3.3.0 (#750)
Browse files Browse the repository at this point in the history
* 3.3.0

* Fix UT discovery

* Fix UT

* Update template
  • Loading branch information
erikzhang authored Jun 6, 2022
1 parent 747a633 commit c7b89cd
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<Copyright>2015-2021 The Neo Project</Copyright>
<VersionPrefix>3.1.0</VersionPrefix>
<Copyright>2015-2022 The Neo Project</Copyright>
<VersionPrefix>3.3.0</VersionPrefix>
<TargetFramework>net6.0</TargetFramework>
<Authors>The Neo Project</Authors>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
<PackageReference Include="Neo" Version="3.2.1-CI01358" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
<PackageReference Include="Neo" Version="3.3.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta3.22114.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo.SmartContract.Framework" Version="3.1.0" />
<PackageReference Include="Neo.SmartContract.Framework" Version="3.3.0" />
</ItemGroup>

<PropertyGroup>
Expand Down
19 changes: 19 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Neo.Compiler.CSharp.UnitTests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Neo.Compiler.CSharp\Neo.Compiler.CSharp.csproj" />
<ProjectReference Include="..\..\src\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj">
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Compiler.CSharp.UnitTests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Test_PrivateMethod()
{
var testengine = new TestEngine();
testengine.AddEntryScript("./TestClasses/Contract1.cs");
Assert.IsTrue(Encoding.ASCII.GetString(testengine.Nef.Script).Contains("NEO3"));
Assert.IsTrue(Encoding.ASCII.GetString(testengine.Nef.Script.Span).Contains("NEO3"));
}

[TestMethod]
Expand Down
14 changes: 7 additions & 7 deletions tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Test_JaggedByteArray()
var arr = result.Pop<Array>();
Assert.AreEqual(4, arr.Count);
var element0 = (Buffer)arr[0];
CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4 }, element0.InnerBuffer);
CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4 }, element0.InnerBuffer.ToArray());
}

[TestMethod]
Expand Down Expand Up @@ -104,7 +104,7 @@ public void Test_ByteArrayOwner()
var result = testengine.ExecuteTestCaseStandard("testByteArrayOwner");

var bts = result.Pop() as Buffer;
ByteString rt = bts.InnerBuffer;
ByteString rt = bts.InnerBuffer.ToArray();
ByteString test = new byte[] { 0xf6, 0x64, 0x43, 0x49, 0x8d, 0x38, 0x78, 0xd3, 0x2b, 0x99, 0x4e, 0x4e, 0x12, 0x83, 0xc6, 0x93, 0x44, 0x21, 0xda, 0xfe };
Assert.IsTrue(ByteString.Equals(rt, test));
}
Expand Down Expand Up @@ -134,11 +134,11 @@ public void Test_DynamicArrayStringInit()
var arr = (Buffer)result.Pop().ConvertTo(StackItemType.Buffer);

Assert.AreEqual(5, arr.Size);
Assert.AreEqual(0, arr.InnerBuffer[0]);
Assert.AreEqual(0, arr.InnerBuffer[1]);
Assert.AreEqual(0, arr.InnerBuffer[2]);
Assert.AreEqual(0, arr.InnerBuffer[3]);
Assert.AreEqual(0, arr.InnerBuffer[4]);
Assert.AreEqual(0, arr.InnerBuffer.Span[0]);
Assert.AreEqual(0, arr.InnerBuffer.Span[1]);
Assert.AreEqual(0, arr.InnerBuffer.Span[2]);
Assert.AreEqual(0, arr.InnerBuffer.Span[3]);
Assert.AreEqual(0, arr.InnerBuffer.Span[4]);
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DebugInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Test_DebugInfo()
testEngine.AddEntryScript("./TestClasses/Contract_Event.cs");

var debugInfo = testEngine.DebugInfo;
Assert.AreEqual(testEngine.Nef.Script.ToScriptHash().ToString(), debugInfo["hash"].GetString());
Assert.AreEqual(testEngine.Nef.Script.Span.ToScriptHash().ToString(), debugInfo["hash"].GetString());
Assert.IsTrue(debugInfo.ContainsProperty("documents"));
Assert.IsInstanceOfType(debugInfo["documents"], typeof(JArray));
Assert.IsTrue((debugInfo["documents"] as JArray).Count > 0);
Expand Down
4 changes: 2 additions & 2 deletions tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Foreach.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.CSharp.UnitTests.Utils;
using Neo.VM;
using System.Numerics;
using Neo.VM.Types;
using System.Numerics;

namespace Neo.Compiler.CSharp.UnitTests
{
Expand Down Expand Up @@ -169,7 +169,7 @@ public void objectarrayForeach_test()
Assert.AreEqual(VMState.HALT, _engine.State);
var array = result.Pop() as VM.Types.Array;
Assert.AreEqual(array.Count, 3);
ByteString firstitem = (array[0] as VM.Types.Buffer).InnerBuffer;
ByteString firstitem = (array[0] as VM.Types.Buffer).InnerBuffer.ToArray();
ByteString bytearray = new byte[] { 0x01, 0x02 };
Assert.IsTrue(VM.Types.ByteString.Equals(firstitem, bytearray));
Assert.AreEqual(array[1].GetString(), "test");
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public void UInt160_ValidateAddress()
Assert.IsFalse(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", new VM.Types.Boolean(true));
result = testengine.ExecuteTestCaseStandard("validateAddress", StackItem.True);
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());
Expand Down
9 changes: 5 additions & 4 deletions tests/Neo.SmartContract.Framework.UnitTests/AttributeTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.CSharp.UnitTests.Utils;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using System;
using System.IO;

namespace Neo.SmartContract.Framework.UnitTests
{
Expand All @@ -17,8 +18,8 @@ class DummyVerificable : IVerifiable
public int Size => 0;

public DummyVerificable(params UInt160[] hashes) { Hashes = hashes; }
public void Deserialize(BinaryReader reader) { }
public void DeserializeUnsigned(BinaryReader reader) { }
public void Deserialize(ref MemoryReader reader) { }
public void DeserializeUnsigned(ref MemoryReader reader) { }
public UInt160[] GetScriptHashesForVerifying(DataCache snapshot) => Hashes;
public void Serialize(BinaryWriter writer) { }
public void SerializeUnsigned(BinaryWriter writer) { }
Expand Down
8 changes: 4 additions & 4 deletions tests/Neo.SmartContract.Framework.UnitTests/HelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void TestAssert()
var logList = new List<string>();
var logsMethod = new System.EventHandler<LogEventArgs>((object sender, LogEventArgs e) => { logList.Add(e.Message); });
ApplicationEngine.Log += logsMethod;
var result = _engine.ExecuteTestCaseStandard("assertCall", new Boolean(true));
var result = _engine.ExecuteTestCaseStandard("assertCall", StackItem.True);
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);
var item = result.Pop();
Expand All @@ -131,7 +131,7 @@ public void TestAssert()
Assert.AreEqual(logList.Count, 0);

_engine.Reset(); logList.Clear();
result = _engine.ExecuteTestCaseStandard("assertCall", new Boolean(false));
result = _engine.ExecuteTestCaseStandard("assertCall", StackItem.False);
Assert.AreEqual(VMState.FAULT, _engine.State);
Assert.AreEqual(0, result.Count);
Assert.AreEqual(logList.Count, 1);
Expand All @@ -140,13 +140,13 @@ public void TestAssert()
// Void With extension

_engine.Reset(); logList.Clear();
result = _engine.ExecuteTestCaseStandard("voidAssertCall", new Boolean(true));
result = _engine.ExecuteTestCaseStandard("voidAssertCall", StackItem.True);
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(logList.Count, 0);
Assert.AreEqual(0, result.Count);

_engine.Reset(); logList.Clear();
result = _engine.ExecuteTestCaseStandard("voidAssertCall", new Boolean(false));
result = _engine.ExecuteTestCaseStandard("voidAssertCall", StackItem.False);
Assert.AreEqual(VMState.FAULT, _engine.State);
Assert.AreEqual(logList.Count, 0);
Assert.AreEqual(0, result.Count);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Neo.SmartContract.Framework.UnitTests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.17.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Neo.Compiler.CSharp.UnitTests\Neo.Compiler.CSharp.UnitTests.csproj" />
<ProjectReference Include="..\..\src\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void Test_GetTransaction(string method, StackItem[] foundArgs, StackItem[

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(ByteString));
CollectionAssert.AreEqual(tx.Script, item.GetSpan().ToArray());
CollectionAssert.AreEqual(tx.Script.ToArray(), item.GetSpan().ToArray());

// Sender

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Test_CreateCallDestroy()
Assert.AreEqual(1, itemArray[0].GetInteger()); // Id
Assert.AreEqual(0, itemArray[1].GetInteger()); // UpdateCounter
Assert.AreEqual(hash.ToArray(), itemArray[2]); // Hash
Assert.AreEqual(nef.ToJson().AsString(), itemArray[3].GetSpan().AsSerializable<NefFile>().ToJson().AsString()); // Nef
Assert.AreEqual(nef.ToJson().AsString(), itemArray[3].GetSpan().ToArray().AsSerializable<NefFile>().ToJson().AsString()); // Nef
var ritem = new ContractManifest();
((IInteroperable)ritem).FromStackItem(itemArray[4]);
Assert.AreEqual(manifest.ToString(), ritem.ToString()); // Manifest
Expand Down Expand Up @@ -124,7 +124,7 @@ public void Test_Update()
Assert.AreEqual(1, itemArray[0].GetInteger()); // Id
Assert.AreEqual(0, itemArray[1].GetInteger()); // UpdateCounter
Assert.AreEqual(hash.ToArray(), itemArray[2]); // Hash
Assert.AreEqual(nef.ToJson().AsString(), itemArray[3].GetSpan().AsSerializable<NefFile>().ToJson().AsString()); // Nef
Assert.AreEqual(nef.ToJson().AsString(), itemArray[3].GetSpan().ToArray().AsSerializable<NefFile>().ToJson().AsString()); // Nef
var ritem = new ContractManifest();
((IInteroperable)ritem).FromStackItem(itemArray[4]);
Assert.AreEqual(manifest.ToString(), ritem.ToString()); // Manifest
Expand All @@ -137,7 +137,7 @@ public void Test_Update()
nef.Tokens = engine.Nef.Tokens;
nef.CheckSum = NefFile.ComputeChecksum(nef);
result = _engine.ExecuteTestCaseStandard("call", hash.ToArray(), "oldContract", (byte)CallFlags.All,
new Array(new StackItem[] { nef.ToArray(), manifestUpdate.ToJson().ToString() }));
new Array(_engine.ReferenceCounter, new StackItem[] { nef.ToArray(), manifestUpdate.ToJson().ToString() }));
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class DummyVerificable : IVerifiable, IInteroperable

public int Size => 0;

public void Deserialize(BinaryReader reader)
public void Deserialize(ref MemoryReader reader)
{
}

public void DeserializeUnsigned(BinaryReader reader)
public void DeserializeUnsigned(ref MemoryReader reader)
{
}

Expand Down Expand Up @@ -59,7 +59,7 @@ public void Init()
{
_engine = new TestEngine(TriggerType.Application, new DummyVerificable());
_engine.AddEntryScript("./TestClasses/Contract_ExecutionEngine.cs");
scriptHash = _engine.Nef.Script.ToScriptHash().ToArray().ToHexString();
scriptHash = _engine.Nef.Script.Span.ToScriptHash().ToArray().ToHexString();
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void Test_SerializeDeserialize()
// Serialize

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("serialize", new Array(new StackItem[]{
StackItem.Null, new Boolean(true), new ByteString(Encoding.ASCII.GetBytes("asd"))
result = _engine.ExecuteTestCaseStandard("serialize", new Array(_engine.ReferenceCounter, new StackItem[]{
StackItem.Null, StackItem.True, new ByteString(Encoding.ASCII.GetBytes("asd"))
}));
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class DummyVerificable : IVerifiable

public int Size => 0;

public void Deserialize(BinaryReader reader) { }
public void Deserialize(ref MemoryReader reader) { }

public void DeserializeUnsigned(BinaryReader reader) { }
public void DeserializeUnsigned(ref MemoryReader reader) { }

public UInt160[] GetScriptHashesForVerifying(DataCache snapshot)
{
Expand Down Expand Up @@ -229,8 +229,8 @@ public void Test_CheckWitness()
public void Test_GetNotificationsCount()
{
_engine.ClearNotifications();
_engine.SendTestNotification(UInt160.Zero, "", new VM.Types.Array(new StackItem[] { new Integer(0x01) }));
_engine.SendTestNotification(UInt160.Parse("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), "", new VM.Types.Array(new StackItem[] { new Integer(0x02) }));
_engine.SendTestNotification(UInt160.Zero, "", new VM.Types.Array(_engine.ReferenceCounter, new StackItem[] { new Integer(0x01) }));
_engine.SendTestNotification(UInt160.Parse("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), "", new VM.Types.Array(_engine.ReferenceCounter, new StackItem[] { new Integer(0x02) }));

var result = _engine.ExecuteTestCaseStandard("getNotificationsCount", new VM.Types.ByteString(UInt160.Parse("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").ToArray()));
Assert.AreEqual(1, result.Count);
Expand All @@ -252,8 +252,8 @@ public void Test_GetNotificationsCount()
public void Test_GetNotifications()
{
_engine.ClearNotifications();
_engine.SendTestNotification(UInt160.Zero, "", new VM.Types.Array(new StackItem[] { new Integer(0x01) }));
_engine.SendTestNotification(UInt160.Parse("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), "", new VM.Types.Array(new StackItem[] { new Integer(0x02) }));
_engine.SendTestNotification(UInt160.Zero, "", new VM.Types.Array(_engine.ReferenceCounter, new StackItem[] { new Integer(0x01) }));
_engine.SendTestNotification(UInt160.Parse("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), "", new VM.Types.Array(_engine.ReferenceCounter, new StackItem[] { new Integer(0x02) }));

var result = _engine.ExecuteTestCaseStandard("getNotifications", new VM.Types.ByteString(UInt160.Parse("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").ToArray()));
Assert.AreEqual(1, result.Count);
Expand Down Expand Up @@ -481,7 +481,7 @@ public void Test_GetTransactionScript()

var item = engine.ResultStack.Pop();
Assert.IsInstanceOfType(item, typeof(ByteString));
Assert.AreEqual(tx.Script.ToHexString(), item.GetSpan().ToHexString());
Assert.AreEqual(tx.Script.Span.ToHexString(), item.GetSpan().ToHexString());
}

private static Transaction BuildTransaction(UInt160 sender, byte[] script)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Init()

_engine = new TestEngine(TriggerType.Application, snapshot: snapshot);
Assert.IsTrue(_engine.AddEntryScript("./TestClasses/Contract_StdLib.cs").Success);
scriptHash = _engine.Nef.Script.ToScriptHash();
scriptHash = _engine.Nef.Script.Span.ToScriptHash();

snapshot.ContractAdd(new ContractState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static void Put(TestEngine testengine, string method, byte[] prefix, byt
testengine.Snapshot.GetChangeSet()
.Count(a =>
a.Key.Key.Span.SequenceEqual(Concat(prefix, key)) &&
a.Item.Value.SequenceEqual(value)));
a.Item.Value.Span.SequenceEqual(value)));
}

private static byte[] Get(TestEngine testengine, string method, byte[] prefix, byte[] key)
Expand Down

0 comments on commit c7b89cd

Please sign in to comment.