diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 4d411ecd3..b1e00d2a8 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,8 +2,8 @@ - 2015-2021 The Neo Project - 3.1.0 + 2015-2022 The Neo Project + 3.3.0 net6.0 The Neo Project diff --git a/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj b/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj index 9d5bf20e5..00e5294a5 100644 --- a/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj +++ b/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj @@ -19,8 +19,8 @@ - - + + diff --git a/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj b/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj index 6bde14fa3..43ca1f70b 100644 --- a/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj +++ b/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj @@ -5,7 +5,7 @@ - + diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props new file mode 100644 index 000000000..c1fed5a79 --- /dev/null +++ b/tests/Directory.Build.props @@ -0,0 +1,19 @@ + + + + + net6.0 + false + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/tests/Neo.Compiler.CSharp.UnitTests/Neo.Compiler.CSharp.UnitTests.csproj b/tests/Neo.Compiler.CSharp.UnitTests/Neo.Compiler.CSharp.UnitTests.csproj index 6523bbb56..54c951ca3 100644 --- a/tests/Neo.Compiler.CSharp.UnitTests/Neo.Compiler.CSharp.UnitTests.csproj +++ b/tests/Neo.Compiler.CSharp.UnitTests/Neo.Compiler.CSharp.UnitTests.csproj @@ -1,21 +1,9 @@ - net6.0 - false Neo.Compiler.CSharp.UnitTests - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest1.cs b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest1.cs index 2923280db..009fdeae5 100644 --- a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest1.cs +++ b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest1.cs @@ -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] diff --git a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Array.cs b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Array.cs index 462ee262d..6c3de3813 100644 --- a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Array.cs +++ b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Array.cs @@ -31,7 +31,7 @@ public void Test_JaggedByteArray() var arr = result.Pop(); 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] @@ -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)); } @@ -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] diff --git a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DebugInfo.cs b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DebugInfo.cs index e5259b0ac..d20f443a0 100644 --- a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DebugInfo.cs +++ b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DebugInfo.cs @@ -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); diff --git a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Foreach.cs b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Foreach.cs index db88ec0b1..c1ec8ac14 100644 --- a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Foreach.cs +++ b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Foreach.cs @@ -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 { @@ -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"); diff --git a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Types.cs b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Types.cs index 35144c0e4..db6498643 100644 --- a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Types.cs +++ b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Types.cs @@ -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()); diff --git a/tests/Neo.SmartContract.Framework.UnitTests/AttributeTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/AttributeTest.cs index 45c0f0287..db715e199 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/AttributeTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/AttributeTest.cs @@ -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 { @@ -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) { } diff --git a/tests/Neo.SmartContract.Framework.UnitTests/HelperTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/HelperTest.cs index 509ecd615..3573ff502 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/HelperTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/HelperTest.cs @@ -122,7 +122,7 @@ public void TestAssert() var logList = new List(); var logsMethod = new System.EventHandler((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(); @@ -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); @@ -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); diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj b/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj index 8831c878b..7604ba567 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj +++ b/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj @@ -1,16 +1,9 @@ - net6.0 - false Neo.SmartContract.Framework.UnitTests - - - - - diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/BlockchainTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/BlockchainTest.cs index 05f62a763..0f71d5313 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/BlockchainTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/BlockchainTest.cs @@ -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 diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/ContractTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/ContractTest.cs index 844e5a3c1..2c5e6dd1e 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/ContractTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/ContractTest.cs @@ -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().ToJson().AsString()); // Nef + Assert.AreEqual(nef.ToJson().AsString(), itemArray[3].GetSpan().ToArray().AsSerializable().ToJson().AsString()); // Nef var ritem = new ContractManifest(); ((IInteroperable)ritem).FromStackItem(itemArray[4]); Assert.AreEqual(manifest.ToString(), ritem.ToString()); // Manifest @@ -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().ToJson().AsString()); // Nef + Assert.AreEqual(nef.ToJson().AsString(), itemArray[3].GetSpan().ToArray().AsSerializable().ToJson().AsString()); // Nef var ritem = new ContractManifest(); ((IInteroperable)ritem).FromStackItem(itemArray[4]); Assert.AreEqual(manifest.ToString(), ritem.ToString()); // Manifest @@ -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); diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/ExecutionEngineTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/ExecutionEngineTest.cs index 3ccee9857..0f260f91d 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/ExecutionEngineTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/ExecutionEngineTest.cs @@ -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) { } @@ -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] diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/JsonTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/JsonTest.cs index 22d22abf3..b97e3fdf9 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/JsonTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/JsonTest.cs @@ -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); diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/RuntimeTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/RuntimeTest.cs index 7105051bb..fcd89d192 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/RuntimeTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/RuntimeTest.cs @@ -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) { @@ -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); @@ -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); @@ -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) diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/StdLibTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/StdLibTest.cs index c4b0dfe20..e091eb1e8 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/StdLibTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/StdLibTest.cs @@ -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() { diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/StorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/StorageTest.cs index df02e42ef..024e2e377 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/StorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/StorageTest.cs @@ -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)