From 855709b237302cf4cb2523103f957d9eaa30f39e Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 12:15:34 +0100 Subject: [PATCH 01/18] Update references --- src/Neo.Compiler.MSIL/Compiler.cs | 4 +-- .../Neo.Compiler.MSIL.csproj | 6 ++--- .../Neo.SmartContract.Framework.csproj | 9 +++---- .../Neo.Compiler.MSIL.UnitTests.csproj | 2 +- .../Neo.Compiler.MSIL.UnitTests/UnitTest1.cs | 3 ++- .../UnitTest_Appcall.cs | 3 +-- .../UnitTest_AutoEntrypoint.cs | 3 ++- .../UnitTest_NULL.cs | 13 +++++---- .../UnitTest_Shift.cs | 4 +-- .../UnitTest_StaticVar.cs | 2 +- .../UnitTest_Switch.cs | 2 +- .../Utils/TestDataCache.cs | 6 ++--- .../Utils/TestEngine.cs | 21 +++++++-------- .../Utils/TestSnapshot.cs | 8 +++--- ...o.SmartContract.Framework.UnitTests.csproj | 2 +- .../Services/Neo/AccountTest.cs | 4 +-- .../Services/Neo/BlockchainTest.cs | 27 ++++++++++--------- .../Services/Neo/ContractTest.cs | 1 + .../Services/Neo/CryptoTest.cs | 24 ++++++++--------- .../Services/Neo/JsonTest.cs | 2 +- .../Services/Neo/RuntimeTest.cs | 7 ++--- .../Services/Neo/StorageTest.cs | 4 +-- .../Services/System/ExecutionEngineTest.cs | 8 +++--- .../TestBlockchain.cs | 24 ++++------------- 24 files changed, 88 insertions(+), 101 deletions(-) diff --git a/src/Neo.Compiler.MSIL/Compiler.cs b/src/Neo.Compiler.MSIL/Compiler.cs index 190d961c3..69a3eab48 100644 --- a/src/Neo.Compiler.MSIL/Compiler.cs +++ b/src/Neo.Compiler.MSIL/Compiler.cs @@ -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; @@ -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(); diff --git a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj index d5570adb0..d77f250e2 100644 --- a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj +++ b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj @@ -1,11 +1,11 @@ - + 2015-2019 The Neo Project Neo.Compiler.MSIL 2.4.1 The Neo Project - netcoreapp2.0;netstandard2.0 + netcoreapp3.0;netstandard2.1 Exe neon Neo.Compiler.MSIL @@ -25,7 +25,7 @@ - + diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index 6bea14b11..9aa3010ed 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -1,11 +1,11 @@ - + 2016-2017 The Neo Project Neo.SmartContract.Framework 2.9.3 The Neo Project - netstandard1.6 + netstandard2.1 Neo.SmartContract.Framework Neo.SmartContract.Framework NEO;AntShares;Blockchain;Smart Contract;VM @@ -13,13 +13,12 @@ MIT git https://github.com/neo-project/neo-devpack-dotnet.git - 1.6.0 The Neo Project Neo.SmartContract.Framework - - RELEASE;NETSTANDARD1_6 + + RELEASE none False diff --git a/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj b/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj index 13bb70ffa..8cd3ee725 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj +++ b/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp3.0 false Neo.Compiler.MSIL diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest1.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest1.cs index a505e2813..b33763e48 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest1.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest1.cs @@ -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 @@ -62,6 +62,7 @@ public void Test_ByteArray_New() var bequal = wantresult.Equals(result); Assert.IsTrue(bequal); } + [TestMethod] public void Test_ByteArrayPick() { diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Appcall.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Appcall.cs index 53e455229..84060c345 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Appcall.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Appcall.cs @@ -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 { @@ -27,7 +27,6 @@ public void Test_Appcall() var bequal = wantresult.Equals(result); Assert.IsTrue(bequal); - } } } diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs index e15e0a880..69c552778 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs @@ -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 { @@ -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; diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NULL.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NULL.cs index 06bf04490..a2f2ac276 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NULL.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NULL.cs @@ -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 @@ -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 @@ -36,7 +35,7 @@ public void IsNull() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); } [TestMethod] @@ -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 @@ -58,7 +57,7 @@ public void EqualNull() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); // True @@ -67,7 +66,7 @@ public void EqualNull() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsTrue(item.GetBoolean()); + Assert.IsTrue(item.ToBoolean()); // False @@ -76,7 +75,7 @@ public void EqualNull() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); } } } diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs index bb7b1bfaf..aba95b14b 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs @@ -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 { @@ -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); } } diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticVar.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticVar.cs index 1e0e06379..e420c346e 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticVar.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticVar.cs @@ -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 { diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs index 058f7799a..32fa2a61d 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs @@ -22,7 +22,7 @@ public void Test_InvalidSwitch() public void Test_ValidSwitch() { TestEngine testengine; - RandomAccessStack result; + EvaluationStack result; // Test cases diff --git a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestDataCache.cs b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestDataCache.cs index 3418aed1f..82f5094df 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestDataCache.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestDataCache.cs @@ -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); } @@ -28,9 +28,9 @@ protected override void AddInternal(TKey key, TValue value) dic.Add(key, value); } - protected override IEnumerable> 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) diff --git a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs index 1f19c0321..598647983 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs @@ -3,6 +3,7 @@ using Neo.SmartContract; using Neo.SmartContract.Native; using Neo.VM; +using Neo.VM.Types; using System; using System.Collections.Generic; @@ -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(); @@ -70,12 +71,11 @@ public ContractMethod GetMethod(string methodname) return new ContractMethod(this, methodname); } - public RandomAccessStack 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; @@ -91,7 +91,7 @@ public RandomAccessStack ExecuteTestCaseStandard(string methodname, p return this.ResultStack; } - public RandomAccessStack ExecuteTestCase(params StackItem[] args) + public EvaluationStack ExecuteTestCase(params StackItem[] args) { //var engine = new ExecutionEngine(); this.InvocationStack.Peek().InstructionPointer = 0; @@ -114,8 +114,7 @@ public RandomAccessStack 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) @@ -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) { @@ -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++) @@ -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(); diff --git a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs index da339f414..9ec8775a4 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs @@ -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 _Blocks = new TestDataCache(); private DataCache _Transactions = new TestDataCache(); private DataCache _Contracts = new TestDataCache(); private DataCache _Storages = new TestDataCache(); - private DataCache _HeaderHashList = new TestDataCache(); + private DataCache, HeaderHashList> _HeaderHashList = new TestDataCache, HeaderHashList>(); private MetaDataCache _BlockHashIndex = new TestMetaDataCache(); private MetaDataCache _HeaderHashIndex = new TestMetaDataCache(); @@ -24,7 +24,7 @@ public class TestSnapshot : Snapshot public override DataCache Storages => _Storages; - public override DataCache HeaderHashList => _HeaderHashList; + public override DataCache, HeaderHashList> HeaderHashList => _HeaderHashList; public override MetaDataCache BlockHashIndex => _BlockHashIndex; 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 fd3a9f671..a05b451f0 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj +++ b/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp3.0 false diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/AccountTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/AccountTest.cs index d285e9b20..d5940bec0 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/AccountTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/AccountTest.cs @@ -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 @@ -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()); } } } diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs index 44dad0a85..581d66166 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Compiler.MSIL.Utils; +using Neo.IO; using Neo.Ledger; using Neo.Persistence; using Neo.VM; @@ -15,16 +16,16 @@ public class BlockchainTest { private Network.P2P.Payloads.Block _block; private TestEngine _engine; - private Store _store; + private IStore _store; [TestInitialize] public void Init() { _store = TestBlockchain.GetStore(); - var snapshot = _store.GetSnapshot(); + var snapshot = new SnapshotView(_store); _block = Blockchain.GenesisBlock; - _engine = new TestEngine(snapshot: snapshot); + _engine = new TestEngine(snapshot: snapshot.Clone()); _engine.AddEntryScript("./TestClasses/Contract_Blockchain.cs"); } @@ -129,7 +130,7 @@ public void Test_GetTransaction(string method, StackItem[] foundArgs, StackItem[ var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - CollectionAssert.AreEqual(tx.Hash.ToArray(), item.GetByteArray()); + CollectionAssert.AreEqual(tx.Hash.ToArray(), item.GetSpan().ToArray()); // NetworkFee @@ -195,7 +196,7 @@ public void Test_GetTransaction(string method, StackItem[] foundArgs, StackItem[ item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - CollectionAssert.AreEqual(tx.Script, item.GetByteArray()); + CollectionAssert.AreEqual(tx.Script, item.GetSpan().ToArray()); // Sender @@ -206,7 +207,7 @@ public void Test_GetTransaction(string method, StackItem[] foundArgs, StackItem[ item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - CollectionAssert.AreEqual(tx.Sender.ToArray(), item.GetByteArray()); + CollectionAssert.AreEqual(tx.Sender.ToArray(), item.GetSpan().ToArray()); } private StackItem[] Concat(StackItem[] a, ByteArray b) @@ -241,7 +242,7 @@ public void Test_GetBlock(string method, StackItem foundArg, StackItem notFoundA item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - CollectionAssert.AreEqual(_block.Hash.ToArray(), item.GetByteArray()); + CollectionAssert.AreEqual(_block.Hash.ToArray(), item.GetSpan().ToArray()); // Index @@ -263,7 +264,7 @@ public void Test_GetBlock(string method, StackItem foundArg, StackItem notFoundA item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - CollectionAssert.AreEqual(_block.MerkleRoot.ToArray(), item.GetByteArray()); + CollectionAssert.AreEqual(_block.MerkleRoot.ToArray(), item.GetSpan().ToArray()); // NextConsensus @@ -274,7 +275,7 @@ public void Test_GetBlock(string method, StackItem foundArg, StackItem notFoundA item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - CollectionAssert.AreEqual(_block.NextConsensus.ToArray(), item.GetByteArray()); + CollectionAssert.AreEqual(_block.NextConsensus.ToArray(), item.GetSpan().ToArray()); // PrevHash @@ -285,7 +286,7 @@ public void Test_GetBlock(string method, StackItem foundArg, StackItem notFoundA item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - CollectionAssert.AreEqual(_block.PrevHash.ToArray(), item.GetByteArray()); + CollectionAssert.AreEqual(_block.PrevHash.ToArray(), item.GetSpan().ToArray()); // Timestamp @@ -359,7 +360,7 @@ public void GetContract() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(VM.Types.Boolean)); - Assert.AreEqual(contract.HasStorage, item.GetBoolean()); + Assert.AreEqual(contract.HasStorage, item.ToBoolean()); // Found + IsPayable @@ -370,7 +371,7 @@ public void GetContract() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(VM.Types.Boolean)); - Assert.AreEqual(contract.Payable, item.GetBoolean()); + Assert.AreEqual(contract.Payable, item.ToBoolean()); // Found + IsPayable @@ -381,7 +382,7 @@ public void GetContract() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(VM.Types.ByteArray)); - CollectionAssert.AreEqual(contract.Script, item.GetByteArray()); + CollectionAssert.AreEqual(contract.Script, item.GetSpan().ToArray()); // Found + Uknown property diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/ContractTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/ContractTest.cs index 4e4db05da..85360d271 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/ContractTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/ContractTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Compiler.MSIL.Utils; +using Neo.IO; using Neo.SmartContract.Manifest; using Neo.VM; using Neo.VM.Types; diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/CryptoTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/CryptoTest.cs index 9d9c80b65..733df0881 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/CryptoTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/CryptoTest.cs @@ -50,7 +50,7 @@ public static KeyPair GenerateKey(int privateKeyLength) [TestMethod] public void Test_VerifySignature() { - byte[] signature = Crypto.Default.Sign(_engine.ScriptContainer.GetHashData(), + byte[] signature = Crypto.Sign(_engine.ScriptContainer.GetHashData(), _key.PrivateKey, _key.PublicKey.EncodePoint(false).Skip(1).ToArray()); // False @@ -63,7 +63,7 @@ public void Test_VerifySignature() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); // True @@ -75,13 +75,13 @@ public void Test_VerifySignature() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsTrue(item.GetBoolean()); + Assert.IsTrue(item.ToBoolean()); } [TestMethod] public void Test_VerifySignatures() { - byte[] signature = Crypto.Default.Sign(_engine.ScriptContainer.GetHashData(), + byte[] signature = Crypto.Sign(_engine.ScriptContainer.GetHashData(), _key.PrivateKey, _key.PublicKey.EncodePoint(false).Skip(1).ToArray()); // False @@ -95,7 +95,7 @@ public void Test_VerifySignatures() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); // True @@ -108,13 +108,13 @@ public void Test_VerifySignatures() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsTrue(item.GetBoolean()); + Assert.IsTrue(item.ToBoolean()); } [TestMethod] public void Test_VerifySignaturesWithMessage() { - byte[] signature = Crypto.Default.Sign(_engine.ScriptContainer.GetHashData(), + byte[] signature = Crypto.Sign(_engine.ScriptContainer.GetHashData(), _key.PrivateKey, _key.PublicKey.EncodePoint(false).Skip(1).ToArray()); // False @@ -129,7 +129,7 @@ public void Test_VerifySignaturesWithMessage() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); // True @@ -143,13 +143,13 @@ public void Test_VerifySignaturesWithMessage() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsTrue(item.GetBoolean()); + Assert.IsTrue(item.ToBoolean()); } [TestMethod] public void Test_VerifySignatureWithMessage() { - byte[] signature = Crypto.Default.Sign(_engine.ScriptContainer.GetHashData(), + byte[] signature = Crypto.Sign(_engine.ScriptContainer.GetHashData(), _key.PrivateKey, _key.PublicKey.EncodePoint(false).Skip(1).ToArray()); // False @@ -163,7 +163,7 @@ public void Test_VerifySignatureWithMessage() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); // True @@ -176,7 +176,7 @@ public void Test_VerifySignatureWithMessage() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(Boolean)); - Assert.IsTrue(item.GetBoolean()); + Assert.IsTrue(item.ToBoolean()); } } } diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/JsonTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/JsonTest.cs index 3f240d764..be9da27fc 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/JsonTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/JsonTest.cs @@ -61,7 +61,7 @@ public void Test_SerializeDeserialize() Assert.IsInstanceOfType(entry, typeof(Null)); entry = ((Array)item)[1]; Assert.IsInstanceOfType(entry, typeof(Boolean)); - Assert.AreEqual(true, entry.GetBoolean()); + Assert.AreEqual(true, entry.ToBoolean()); entry = ((Array)item)[2]; Assert.IsInstanceOfType(entry, typeof(ByteArray)); Assert.AreEqual("asd", entry.GetString()); diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/RuntimeTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/RuntimeTest.cs index 66bd0e8a4..205744c96 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/RuntimeTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/RuntimeTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Compiler.MSIL.Utils; +using Neo.IO; using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.VM; @@ -25,7 +26,7 @@ public void Deserialize(BinaryReader reader) { } public void DeserializeUnsigned(BinaryReader reader) { } - public UInt160[] GetScriptHashesForVerifying(Snapshot snapshot) + public UInt160[] GetScriptHashesForVerifying(StoreView snapshot) { return new UInt160[] { @@ -166,7 +167,7 @@ public void Test_CheckWitness() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(VM.Types.Boolean)); - Assert.IsTrue(item.GetBoolean()); + Assert.IsTrue(item.ToBoolean()); // False @@ -178,7 +179,7 @@ public void Test_CheckWitness() item = result.Pop(); Assert.IsInstanceOfType(item, typeof(VM.Types.Boolean)); - Assert.IsFalse(item.GetBoolean()); + Assert.IsFalse(item.ToBoolean()); } [TestMethod] diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs index 6dc240fed..e7e44cea6 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs @@ -16,7 +16,7 @@ private void Put(TestEngine testengine, string method, byte[] prefix, byte[] key var rItem = result.Pop(); Assert.IsInstanceOfType(rItem, typeof(Integer)); - Assert.AreEqual(1, rItem.GetBigInteger()); + Assert.AreEqual(1, ((Integer)rItem).ToBigInteger()); Assert.AreEqual(1, testengine.Snapshot.Storages.GetChangeSet() .Count(a => @@ -33,7 +33,7 @@ private byte[] Get(TestEngine testengine, string method, byte[] prefix, byte[] k var rItem = result.Pop(); Assert.IsInstanceOfType(rItem, typeof(ByteArray)); Assert.AreEqual(1, testengine.Snapshot.Storages.GetChangeSet().Count(a => a.Key.Key.SequenceEqual(Concat(prefix, key)))); - return rItem.GetByteArray(); + return ((ByteArray)rItem).ToByteArray().ToArray(); } private void Delete(TestEngine testengine, string method, byte[] prefix, byte[] key) diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/System/ExecutionEngineTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/System/ExecutionEngineTest.cs index c1eaf3997..d50b96ac3 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/System/ExecutionEngineTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/System/ExecutionEngineTest.cs @@ -25,7 +25,7 @@ public void DeserializeUnsigned(BinaryReader reader) { } - public UInt160[] GetScriptHashesForVerifying(Snapshot snapshot) + public UInt160[] GetScriptHashesForVerifying(StoreView snapshot) { throw new global::System.NotImplementedException(); } @@ -58,7 +58,7 @@ public void CallingScriptHashTest() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - Assert.AreEqual("3632c01ec5cc1961ba49d8033798e469f6a6f697", item.GetByteArray().ToHexString()); + Assert.AreEqual("3632c01ec5cc1961ba49d8033798e469f6a6f697", item.GetSpan().ToHexString()); } [TestMethod] @@ -71,7 +71,7 @@ public void EntryScriptHashTest() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - Assert.AreEqual("3632c01ec5cc1961ba49d8033798e469f6a6f697", item.GetByteArray().ToHexString()); + Assert.AreEqual("3632c01ec5cc1961ba49d8033798e469f6a6f697", item.GetSpan().ToHexString()); } [TestMethod] @@ -84,7 +84,7 @@ public void ExecutingScriptHashTest() var item = result.Pop(); Assert.IsInstanceOfType(item, typeof(ByteArray)); - Assert.AreEqual("3632c01ec5cc1961ba49d8033798e469f6a6f697", item.GetByteArray().ToHexString()); + Assert.AreEqual("3632c01ec5cc1961ba49d8033798e469f6a6f697", item.GetSpan().ToHexString()); } [TestMethod] diff --git a/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs b/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs index eebf125c5..d02a30415 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs @@ -1,5 +1,3 @@ -using Moq; -using Neo.Compiler.MSIL.Utils; using Neo.Ledger; using Neo.Persistence; @@ -8,12 +6,12 @@ namespace Neo.SmartContract.Framework.UnitTests public static class TestBlockchain { private static NeoSystem TheNeoSystem; - private static Mock _Store; + private static IStore _Store; - public static Store GetStore() + public static IStore GetStore() { if (_Store == null) InitializeMockNeoSystem(); - return _Store.Object; + return _Store; } static TestBlockchain() @@ -26,20 +24,8 @@ public static NeoSystem InitializeMockNeoSystem() { if (TheNeoSystem == null) { - var mockSnapshot = new TestSnapshot(); - - _Store = new Mock(); - - _Store.Setup(p => p.GetBlocks()).Returns(mockSnapshot.Blocks); - _Store.Setup(p => p.GetTransactions()).Returns(mockSnapshot.Transactions); - _Store.Setup(p => p.GetContracts()).Returns(mockSnapshot.Contracts); - _Store.Setup(p => p.GetStorages()).Returns(mockSnapshot.Storages); - _Store.Setup(p => p.GetHeaderHashList()).Returns(mockSnapshot.HeaderHashList); - _Store.Setup(p => p.GetBlockHashIndex()).Returns(mockSnapshot.BlockHashIndex); - _Store.Setup(p => p.GetHeaderHashIndex()).Returns(mockSnapshot.HeaderHashIndex); - _Store.Setup(p => p.GetSnapshot()).Returns(mockSnapshot.Clone()); - - TheNeoSystem = new NeoSystem(_Store.Object); + _Store = new MemoryStore(); + TheNeoSystem = new NeoSystem(null); // Ensure that blockchain is loaded From 3646d7f4610f1c1707c33743d219cb987d724c22 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 12:41:02 +0100 Subject: [PATCH 02/18] Update --- .../Neo.SmartContract.Framework.csproj | 7 +++-- .../Services/Neo/BlockchainTest.cs | 6 ++-- .../Services/Neo/StorageTest.cs | 11 ++++++-- .../TestBlockchain.cs | 28 +++---------------- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index 9aa3010ed..e4ce53325 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -5,7 +5,7 @@ Neo.SmartContract.Framework 2.9.3 The Neo Project - netstandard2.1 + netstandard1.6 Neo.SmartContract.Framework Neo.SmartContract.Framework NEO;AntShares;Blockchain;Smart Contract;VM @@ -13,12 +13,13 @@ MIT git https://github.com/neo-project/neo-devpack-dotnet.git + 1.6.0 The Neo Project Neo.SmartContract.Framework - - RELEASE + + RELEASE;NETSTANDARD1_6 none False diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs index 581d66166..2db8e03ce 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/BlockchainTest.cs @@ -2,7 +2,6 @@ using Neo.Compiler.MSIL.Utils; using Neo.IO; using Neo.Ledger; -using Neo.Persistence; using Neo.VM; using Neo.VM.Types; using System.Linq; @@ -16,13 +15,12 @@ public class BlockchainTest { private Network.P2P.Payloads.Block _block; private TestEngine _engine; - private IStore _store; [TestInitialize] public void Init() { - _store = TestBlockchain.GetStore(); - var snapshot = new SnapshotView(_store); + var _ = TestBlockchain.TheNeoSystem; + var snapshot = Blockchain.Singleton.GetSnapshot(); _block = Blockchain.GenesisBlock; _engine = new TestEngine(snapshot: snapshot.Clone()); diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs index e7e44cea6..1cf0eadfb 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/Neo/StorageTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Compiler.MSIL.Utils; +using Neo.Ledger; using Neo.VM.Types; using System; using System.Collections.Generic; @@ -13,6 +14,7 @@ public class StorageTest private void Put(TestEngine testengine, string method, byte[] prefix, byte[] key, byte[] value) { var result = testengine.ExecuteTestCaseStandard(method, new ByteArray(key), new ByteArray(value)); + Assert.AreEqual(VM.VMState.HALT, testengine.State); var rItem = result.Pop(); Assert.IsInstanceOfType(rItem, typeof(Integer)); @@ -29,6 +31,7 @@ private void Put(TestEngine testengine, string method, byte[] prefix, byte[] key private byte[] Get(TestEngine testengine, string method, byte[] prefix, byte[] key) { var result = testengine.ExecuteTestCaseStandard(method, new ByteArray(key)); + Assert.AreEqual(VM.VMState.HALT, testengine.State); Assert.AreEqual(1, result.Count); var rItem = result.Pop(); Assert.IsInstanceOfType(rItem, typeof(ByteArray)); @@ -39,6 +42,7 @@ private byte[] Get(TestEngine testengine, string method, byte[] prefix, byte[] k private void Delete(TestEngine testengine, string method, byte[] prefix, byte[] key) { var result = testengine.ExecuteTestCaseStandard(method, new ByteArray(key)); + Assert.AreEqual(VM.VMState.HALT, testengine.State); Assert.AreEqual(1, result.Count); var rItem = result.Pop(); Assert.IsInstanceOfType(rItem, typeof(ByteArray)); @@ -53,12 +57,15 @@ private byte[] Concat(byte[] prefix, params byte[] key) return l.ToArray(); } - TestEngine testengine; + private TestEngine testengine; [TestInitialize] public void Init() { - testengine = new TestEngine(); + var _ = TestBlockchain.TheNeoSystem; + var snapshot = Blockchain.Singleton.GetSnapshot(); + + testengine = new TestEngine(snapshot: snapshot.Clone()); testengine.AddEntryScript("./TestClasses/Contract_Storage.cs"); Assert.AreEqual(ContractFeatures.HasStorage, testengine.ScriptEntry.converterIL.outModule.attributes .Where(u => u.AttributeType.Name == "FeaturesAttribute") diff --git a/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs b/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs index d02a30415..1a38d0089 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/TestBlockchain.cs @@ -1,38 +1,18 @@ using Neo.Ledger; -using Neo.Persistence; namespace Neo.SmartContract.Framework.UnitTests { public static class TestBlockchain { - private static NeoSystem TheNeoSystem; - private static IStore _Store; - - public static IStore GetStore() - { - if (_Store == null) InitializeMockNeoSystem(); - return _Store; - } + public static readonly NeoSystem TheNeoSystem; static TestBlockchain() { - InitializeMockNeoSystem(); - GetStore(); - } - - public static NeoSystem InitializeMockNeoSystem() - { - if (TheNeoSystem == null) - { - _Store = new MemoryStore(); - TheNeoSystem = new NeoSystem(null); - - // Ensure that blockchain is loaded + TheNeoSystem = new NeoSystem(); - var blockchain = Blockchain.Singleton; - } + // Ensure that blockchain is loaded - return TheNeoSystem; + var _ = Blockchain.Singleton; } } } From eb53774a183283eb00bcd59d88cbf122d0423028 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 12:43:55 +0100 Subject: [PATCH 03/18] Clean file --- .../Neo.SmartContract.Framework.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index e4ce53325..6bea14b11 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -1,4 +1,4 @@ - + 2016-2017 The Neo Project From 29003b9e84a1d4e15752a8ab91db0803f9de4713 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 13:14:28 +0100 Subject: [PATCH 04/18] Update tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj Co-Authored-By: Erik Zhang --- ...o.SmartContract.Framework.UnitTests.csproj | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) 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 a05b451f0..f0b534b78 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj +++ b/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj @@ -1,26 +1,26 @@ - - - - netcoreapp3.0 - false - - - - - - - - - - - - - - + + + + netcoreapp3.1 + false + + + + + + + + + + + + + + PreserveNewest - - - + + + From 8fcc2d8b8c43f17be831200be705866dbe5676bf Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 13:14:36 +0100 Subject: [PATCH 05/18] Update tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj Co-Authored-By: Erik Zhang --- .../Neo.Compiler.MSIL.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj b/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj index 8cd3ee725..80e9b1d6b 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj +++ b/tests/Neo.Compiler.MSIL.UnitTests/Neo.Compiler.MSIL.UnitTests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.0 + netcoreapp3.1 false Neo.Compiler.MSIL From 7b91507e6d023ced8e5214508e2c26d9de39c4fa Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 13:14:48 +0100 Subject: [PATCH 06/18] Update src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj Co-Authored-By: Erik Zhang --- src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj index d77f250e2..e0ea90a15 100644 --- a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj +++ b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj @@ -5,7 +5,7 @@ Neo.Compiler.MSIL 2.4.1 The Neo Project - netcoreapp3.0;netstandard2.1 + netcoreapp3.1;netstandard2.1 Exe neon Neo.Compiler.MSIL From 0c64481944acefe3336ad119ca4f354dc183d5c4 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 13:44:16 +0100 Subject: [PATCH 07/18] Add Reference Counter --- tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs index 598647983..5f86408c2 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestEngine.cs @@ -74,7 +74,7 @@ public ContractMethod GetMethod(string methodname) public EvaluationStack ExecuteTestCaseStandard(string methodname, params StackItem[] args) { this.InvocationStack.Peek().InstructionPointer = 0; - this.Push(new VM.Types.Array(args)); + this.Push(new VM.Types.Array(this.ReferenceCounter, args)); this.Push(methodname); while (true) { From bf647c246148cdaefc4a484246d4e33bf97f48da Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 13:51:31 +0100 Subject: [PATCH 08/18] Clean file --- .../Neo.SmartContract.Framework.csproj | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index 6bea14b11..8de864ee7 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -1,27 +1,27 @@ - - - - 2016-2017 The Neo Project - Neo.SmartContract.Framework - 2.9.3 - The Neo Project - netstandard1.6 - Neo.SmartContract.Framework - Neo.SmartContract.Framework - NEO;AntShares;Blockchain;Smart Contract;VM - https://github.com/neo-project/neo-devpack-dotnet - MIT - git - https://github.com/neo-project/neo-devpack-dotnet.git - 1.6.0 - The Neo Project - Neo.SmartContract.Framework - - - - RELEASE;NETSTANDARD1_6 - none - False - - - + + + + 2016-2017 The Neo Project + Neo.SmartContract.Framework + 2.9.3 + The Neo Project + netstandard1.6 + Neo.SmartContract.Framework + Neo.SmartContract.Framework + NEO;AntShares;Blockchain;Smart Contract;VM + https://github.com/neo-project/neo-devpack-dotnet + MIT + git + https://github.com/neo-project/neo-devpack-dotnet.git + 1.6.0 + The Neo Project + Neo.SmartContract.Framework + + + + RELEASE;NETSTANDARD1_6 + none + False + + + From 361f2fd74cc7392a4574b790ab231eafd4b3697c Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 13:52:21 +0100 Subject: [PATCH 09/18] Clean files --- .../Neo.SmartContract.Framework.csproj | 54 +++++++++---------- ...o.SmartContract.Framework.UnitTests.csproj | 52 +++++++++--------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index 8de864ee7..6bea14b11 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -1,27 +1,27 @@ - - - - 2016-2017 The Neo Project - Neo.SmartContract.Framework - 2.9.3 - The Neo Project - netstandard1.6 - Neo.SmartContract.Framework - Neo.SmartContract.Framework - NEO;AntShares;Blockchain;Smart Contract;VM - https://github.com/neo-project/neo-devpack-dotnet - MIT - git - https://github.com/neo-project/neo-devpack-dotnet.git - 1.6.0 - The Neo Project - Neo.SmartContract.Framework - - - - RELEASE;NETSTANDARD1_6 - none - False - - - + + + + 2016-2017 The Neo Project + Neo.SmartContract.Framework + 2.9.3 + The Neo Project + netstandard1.6 + Neo.SmartContract.Framework + Neo.SmartContract.Framework + NEO;AntShares;Blockchain;Smart Contract;VM + https://github.com/neo-project/neo-devpack-dotnet + MIT + git + https://github.com/neo-project/neo-devpack-dotnet.git + 1.6.0 + The Neo Project + Neo.SmartContract.Framework + + + + RELEASE;NETSTANDARD1_6 + none + False + + + 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 f0b534b78..915338757 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj +++ b/tests/Neo.SmartContract.Framework.UnitTests/Neo.SmartContract.Framework.UnitTests.csproj @@ -1,26 +1,26 @@ - - - - netcoreapp3.1 - false - - - - - - - - - - - - - - - - - PreserveNewest - - - - + + + + netcoreapp3.1 + false + + + + + + + + + + + + + + + + + PreserveNewest + + + + From 2655430eeb9e26aea4b0176b369167db9bef2497 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 13:55:15 +0100 Subject: [PATCH 10/18] Fix travis in order to know the error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5f3436e73..53196ae25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: dist: bionic mono: none -dotnet: 2.2.402 +dotnet: 3.0.100 install: - dotnet tool install -g dotnet-format From cc4f58dcc56a9025f0b910b1038c6c8db8470abe Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 15:14:07 +0100 Subject: [PATCH 11/18] Update packages --- src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj index e0ea90a15..4c674e159 100644 --- a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj +++ b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj @@ -22,8 +22,8 @@ - - + + From e2ed02ad66a4baff0d693f034a2bfdbd45383611 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 5 Dec 2019 15:57:31 +0100 Subject: [PATCH 12/18] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 53196ae25..cfc7d28d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: dist: bionic mono: none -dotnet: 3.0.100 +dotnet: 3.1.100 install: - dotnet tool install -g dotnet-format From d6319609f1930070570b6c03d2caac71df8a187b Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 6 Dec 2019 20:25:13 +0100 Subject: [PATCH 13/18] End changes --- src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj | 4 ++-- tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs | 3 +-- tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj index 4c674e159..4f8e02f5a 100644 --- a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj +++ b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj @@ -1,4 +1,4 @@ - + 2015-2019 The Neo Project @@ -25,7 +25,7 @@ - + diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs index 69c552778..967e3d2a4 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_AutoEntrypoint.cs @@ -28,8 +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 Array() }; - var result = testengine.ExecuteTestCase(_params);//new test method02 + var result = testengine.ExecuteTestCaseStandard("privateMethod");//new test method02 bool hadFault = (testengine.State & VMState.FAULT) > 0; Assert.AreEqual(0, result.Count);//because no methodname had found, it do not return anything. diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs index 3d3522573..6b2df40b7 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Switch.cs @@ -13,7 +13,7 @@ public class UnitTest_Switch [TestMethod] public void Test_SwitchLong() { - RandomAccessStack result; + EvaluationStack result; TestEngine testengine = new TestEngine(); testengine.AddEntryScript("./TestClasses/Contract_SwitchLong.cs"); @@ -59,7 +59,7 @@ public void Test_SwitchLong_Release() [TestMethod] public void Test_Switch6() { - RandomAccessStack result; + EvaluationStack result; TestEngine testengine = new TestEngine(); testengine.AddEntryScript("./TestClasses/Contract_Switch6.cs"); From f3a303eccd0c23d415f195c10bf0ae1a4a76f630 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 6 Dec 2019 20:28:41 +0100 Subject: [PATCH 14/18] dotnet-format --- tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs index 9ec8775a4..58fc01313 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/Utils/TestSnapshot.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Caching; using Neo.Ledger; using Neo.Network.P2P.Payloads; From a8f875f27c348090a2050617b66d1293615e562b Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 6 Dec 2019 20:40:00 +0100 Subject: [PATCH 15/18] Fix shift UT --- .../TestClasses/Contract_shift.cs | 12 ++++------ .../TestClasses/Contract_shift_bigint.cs | 9 ++++---- .../UnitTest_Shift.cs | 23 ++++++++++++++++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift.cs b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift.cs index 086140065..aa5a1087e 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace Neo.Compiler.MSIL.TestClasses { class Contract_shift : SmartContract.Framework.SmartContract @@ -13,10 +9,10 @@ public static object Main(string method, object[] args) var v2 = v << -1; var v3 = v >> 1; var v4 = v >> -1; - Neo.SmartContract.Framework.Services.Neo.Runtime.Log((string)(object)v1); - Neo.SmartContract.Framework.Services.Neo.Runtime.Log((string)(object)v2); - Neo.SmartContract.Framework.Services.Neo.Runtime.Log((string)(object)v3); - Neo.SmartContract.Framework.Services.Neo.Runtime.Log((string)(object)v4); + SmartContract.Framework.Services.Neo.Runtime.Notify(v1); + SmartContract.Framework.Services.Neo.Runtime.Notify(v2); + SmartContract.Framework.Services.Neo.Runtime.Notify(v3); + SmartContract.Framework.Services.Neo.Runtime.Notify(v4); return false; } } diff --git a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift_bigint.cs b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift_bigint.cs index 70eb28d5b..1cd8240ae 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift_bigint.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_shift_bigint.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace Neo.Compiler.MSIL.TestClasses { class Contract_shift_bigint : SmartContract.Framework.SmartContract @@ -13,7 +9,10 @@ public static object Main(string method, object[] args) var v2 = v << -1; var v3 = v >> 1; var v4 = v >> -1; - Neo.SmartContract.Framework.Services.Neo.Runtime.Notify(v1, v2, v3, v4); + SmartContract.Framework.Services.Neo.Runtime.Notify(v1); + SmartContract.Framework.Services.Neo.Runtime.Notify(v2); + SmartContract.Framework.Services.Neo.Runtime.Notify(v3); + SmartContract.Framework.Services.Neo.Runtime.Notify(v4); return false; } } diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs index aba95b14b..6863c7e08 100644 --- a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Shift.cs @@ -1,6 +1,9 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Compiler.MSIL.Utils; -using Neo.VM.Types; +using Neo.SmartContract; +using System; +using System.Collections.Generic; +using System.Numerics; namespace Neo.Compiler.MSIL { @@ -10,19 +13,33 @@ public class UnitTest_Shift [TestMethod] public void Test_Shift() { + var list = new List(); + var method = new EventHandler((sender, e) => list.Add(((VM.Types.Integer)((VM.Types.Array)e.State)[0]).ToBigInteger())); + ApplicationEngine.Notify += method; + var testengine = new TestEngine(); testengine.AddEntryScript("./TestClasses/Contract_shift.cs"); testengine.ScriptEntry.DumpNEF(); var result = testengine.ExecuteTestCaseStandard("testfunc"); + ApplicationEngine.Notify -= method; + + CollectionAssert.AreEqual(new BigInteger[] { 16, 17179869184, 4, 0 }, list); } + [TestMethod] public void Test_Shift_BigInteger() { + var list = new List(); + var method = new EventHandler((sender, e) => list.Add(((VM.Types.Integer)((VM.Types.Array)e.State)[0]).ToBigInteger())); + ApplicationEngine.Notify += method; + var testengine = new TestEngine(); testengine.AddEntryScript("./TestClasses/Contract_shift_bigint.cs"); testengine.ScriptEntry.DumpNEF(); - StackItem[] _params = new StackItem[] { "testfunc", new Array() }; - var result = testengine.ExecuteTestCase(_params); + var result = testengine.ExecuteTestCaseStandard("testfunc"); + ApplicationEngine.Notify -= method; + + CollectionAssert.AreEqual(new BigInteger[] { 16, 4, 4, 16 }, list); } } } From 27a0cc7d75ff7e77cf981ebb7105fbcb92570ba2 Mon Sep 17 00:00:00 2001 From: erikzhang Date: Mon, 9 Dec 2019 10:17:40 +0800 Subject: [PATCH 16/18] Update version --- src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj | 2 +- .../Neo.SmartContract.Framework.csproj | 2 +- templates/Template.CSharp/ProjectTemplate.csproj | 4 ++-- templates/Template.VB/ProjectTemplate.vbproj | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj index 4f8e02f5a..d2f4e4917 100644 --- a/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj +++ b/src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj @@ -3,7 +3,7 @@ 2015-2019 The Neo Project Neo.Compiler.MSIL - 2.4.1 + 3.0.0-preview1 The Neo Project netcoreapp3.1;netstandard2.1 Exe diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index 6bea14b11..b2b4cc0aa 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -3,7 +3,7 @@ 2016-2017 The Neo Project Neo.SmartContract.Framework - 2.9.3 + 3.0.0-preview1 The Neo Project netstandard1.6 Neo.SmartContract.Framework diff --git a/templates/Template.CSharp/ProjectTemplate.csproj b/templates/Template.CSharp/ProjectTemplate.csproj index baa72ae57..b007437ba 100644 --- a/templates/Template.CSharp/ProjectTemplate.csproj +++ b/templates/Template.CSharp/ProjectTemplate.csproj @@ -1,11 +1,11 @@ - netstandard2.0 + netstandard2.1 - + diff --git a/templates/Template.VB/ProjectTemplate.vbproj b/templates/Template.VB/ProjectTemplate.vbproj index 8f96476e8..56fc03d98 100644 --- a/templates/Template.VB/ProjectTemplate.vbproj +++ b/templates/Template.VB/ProjectTemplate.vbproj @@ -2,11 +2,11 @@ $safeprojectname$ - netstandard2.0 + netstandard2.1 - + From 0b9efb58f611086c34199fc75f1b2087cd2ba6f2 Mon Sep 17 00:00:00 2001 From: erikzhang Date: Mon, 9 Dec 2019 10:36:42 +0800 Subject: [PATCH 17/18] Update framework --- .../Neo.SmartContract.Framework.csproj | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index b2b4cc0aa..1c93103cf 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -1,11 +1,11 @@ - 2016-2017 The Neo Project + 2016-2019 The Neo Project Neo.SmartContract.Framework 3.0.0-preview1 The Neo Project - netstandard1.6 + netstandard2.1 Neo.SmartContract.Framework Neo.SmartContract.Framework NEO;AntShares;Blockchain;Smart Contract;VM @@ -13,15 +13,8 @@ MIT git https://github.com/neo-project/neo-devpack-dotnet.git - 1.6.0 The Neo Project Neo.SmartContract.Framework - - RELEASE;NETSTANDARD1_6 - none - False - - From 3368ebd17c9263cad89f988bd43782de7d42c15a Mon Sep 17 00:00:00 2001 From: erikzhang Date: Mon, 9 Dec 2019 11:08:26 +0800 Subject: [PATCH 18/18] Fix UT --- src/Neo.Compiler.MSIL/Compiler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Neo.Compiler.MSIL/Compiler.cs b/src/Neo.Compiler.MSIL/Compiler.cs index 2577e9b15..11efca855 100644 --- a/src/Neo.Compiler.MSIL/Compiler.cs +++ b/src/Neo.Compiler.MSIL/Compiler.cs @@ -175,6 +175,7 @@ private static MetadataReference[] CreateReferences(params string[] references) var refs = new List(new MetadataReference[] { MetadataReference.CreateFromFile(Path.Combine(coreDir, "mscorlib.dll")), + MetadataReference.CreateFromFile(Path.Combine(coreDir, "netstandard.dll")), MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.dll")), MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.Numerics.dll")), MetadataReference.CreateFromFile(typeof(System.ComponentModel.DisplayNameAttribute).Assembly.Location),