From 41250b4ad068ee6e9484456d4fbbe031859c5439 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 11 Feb 2020 09:56:54 +0100 Subject: [PATCH 1/5] Fix SpentCoinState.Clone (#1369) --- neo.UnitTests/UT_SpentCointState.cs | 30 +++++++++++++++++++++++++++-- neo/Ledger/SpentCoinState.cs | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/neo.UnitTests/UT_SpentCointState.cs b/neo.UnitTests/UT_SpentCointState.cs index bb28ebecf3..e71e93fb4d 100644 --- a/neo.UnitTests/UT_SpentCointState.cs +++ b/neo.UnitTests/UT_SpentCointState.cs @@ -1,5 +1,6 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.IO; using Neo.Ledger; using System.Collections.Generic; using System.IO; @@ -24,6 +25,31 @@ public void TransactionHash_Get() uut.TransactionHash.Should().BeNull(); } + [TestMethod] + public void TestFromReplica() + { + uut.Items = new Dictionary(); + uut.Items.Add(1, 3); + + var a = ((ICloneable)uut).Clone(); + var b = new SpentCoinState(); + + ((ICloneable)b).FromReplica(uut); + + CollectionAssert.AreEqual(a.Items.Keys, uut.Items.Keys); + CollectionAssert.AreEqual(a.Items.Values, uut.Items.Values); + CollectionAssert.AreEqual(b.Items.Keys, uut.Items.Keys); + CollectionAssert.AreEqual(b.Items.Values, uut.Items.Values); + + a.Items.Clear(); + b.Items.Clear(); + + CollectionAssert.AreNotEqual(a.Items.Keys, uut.Items.Keys); + CollectionAssert.AreNotEqual(b.Items.Keys, uut.Items.Keys); + CollectionAssert.AreNotEqual(a.Items.Values, uut.Items.Values); + CollectionAssert.AreNotEqual(b.Items.Values, uut.Items.Values); + } + [TestMethod] public void TransactionHash_Set() { @@ -98,8 +124,8 @@ private void setupSpentCoinStateWithValues(SpentCoinState spentCoinState, out UI [TestMethod] public void DeserializeSCS() { - byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 }; - + byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 }; + using (Stream stream = new MemoryStream(dataArray)) { using (BinaryReader reader = new BinaryReader(stream)) diff --git a/neo/Ledger/SpentCoinState.cs b/neo/Ledger/SpentCoinState.cs index 62443c28d6..eef553b867 100644 --- a/neo/Ledger/SpentCoinState.cs +++ b/neo/Ledger/SpentCoinState.cs @@ -42,7 +42,7 @@ void ICloneable.FromReplica(SpentCoinState replica) { TransactionHash = replica.TransactionHash; TransactionHeight = replica.TransactionHeight; - Items = replica.Items; + Items = new Dictionary(replica.Items); } public override void Serialize(BinaryWriter writer) From dae4fa6afca33dd796906c6218d14c299cc4f60b Mon Sep 17 00:00:00 2001 From: Mirella de Medeiros Date: Tue, 3 Dec 2019 11:03:55 -0300 Subject: [PATCH 2/5] CheckWitness on invokescript 2.x --- neo/Network/RPC/RpcServer.cs | 76 +++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/neo/Network/RPC/RpcServer.cs b/neo/Network/RPC/RpcServer.cs index 0bcba6bc0a..2aa41dc11c 100644 --- a/neo/Network/RPC/RpcServer.cs +++ b/neo/Network/RPC/RpcServer.cs @@ -30,6 +30,48 @@ namespace Neo.Network.RPC { public sealed class RpcServer : IDisposable { + private class CheckWitnessHashes : IVerifiable + { + private readonly UInt160[] _scriptHashesForVerifying; + public Witness[] Witnesses { get; set; } + public int Size { get; } + + public CheckWitnessHashes(UInt160[] scriptHashesForVerifying) + { + _scriptHashesForVerifying = scriptHashesForVerifying; + } + + public void Serialize(BinaryWriter writer) + { + throw new NotImplementedException(); + } + + public void Deserialize(BinaryReader reader) + { + throw new NotImplementedException(); + } + + public void DeserializeUnsigned(BinaryReader reader) + { + throw new NotImplementedException(); + } + + public UInt160[] GetScriptHashesForVerifying(Snapshot snapshot) + { + return _scriptHashesForVerifying; + } + + public void SerializeUnsigned(BinaryWriter writer) + { + throw new NotImplementedException(); + } + + public byte[] GetMessage() + { + throw new NotImplementedException(); + } + } + public Wallet Wallet { get; set; } public Fixed8 MaxGasInvoke { get; } public int MaxConcurrentConnections { get; } @@ -73,24 +115,22 @@ public void Dispose() } } - private JObject GetInvokeResult(byte[] script) + private JObject GetInvokeResult(byte[] script, IVerifiable checkWitnessHashes = null) { - using (ApplicationEngine engine = ApplicationEngine.Run(script, extraGAS: MaxGasInvoke)) + ApplicationEngine engine = ApplicationEngine.Run(script, checkWitnessHashes, extraGAS: MaxGasInvoke); + JObject json = new JObject(); + json["script"] = script.ToHexString(); + json["state"] = engine.State; + json["gas_consumed"] = engine.GasConsumed.ToString(); + try { - JObject json = new JObject(); - json["script"] = script.ToHexString(); - json["state"] = engine.State; - json["gas_consumed"] = engine.GasConsumed.ToString(); - try - { - json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson())); - } - catch (InvalidOperationException) - { - json["stack"] = "error: recursive reference"; - } - return json; + json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson())); + } + catch (InvalidOperationException) + { + json["stack"] = "error: recursive reference"; } + return json; } private static JObject GetRelayResult(RelayResultReason reason) @@ -223,6 +263,12 @@ private JObject Process(string method, JArray _params) case "invokescript": { byte[] script = _params[0].AsString().HexToBytes(); + CheckWitnessHashes checkWitnessHashes = null; + if (_params.Count > 1) + { + UInt160[] scriptHashesForVerifying = _params.Skip(1).Select(u => UInt160.Parse(u.AsString())).ToArray(); + checkWitnessHashes = new CheckWitnessHashes(scriptHashesForVerifying); + } return InvokeScript(script); } case "listplugins": From c2c519eaac72a28f8bfe91635c2a7c8d781031f0 Mon Sep 17 00:00:00 2001 From: Mirella de Medeiros Date: Tue, 3 Dec 2019 11:16:07 -0300 Subject: [PATCH 3/5] dotnet format --- neo.UnitTests/TestVerifiable.cs | 2 +- neo.UnitTests/UT_AccountState.cs | 2 +- neo.UnitTests/UT_AssetState.cs | 2 +- neo.UnitTests/UT_ClaimTransaction.cs | 4 +- neo.UnitTests/UT_CoinReference.cs | 4 +- neo.UnitTests/UT_Consensus.cs | 4 +- neo.UnitTests/UT_ConsensusServiceMailbox.cs | 6 +- neo.UnitTests/UT_Header.cs | 6 +- neo.UnitTests/UT_Helper.cs | 6 +- neo.UnitTests/UT_InteropPrices.cs | 84 ++++++++++----------- neo.UnitTests/UT_MinerTransaction.cs | 2 +- neo.UnitTests/UT_PoolItem.cs | 12 +-- neo.UnitTests/UT_ProtocolHandlerMailbox.cs | 50 ++++++------ neo.UnitTests/UT_RemoteNodeMailbox.cs | 2 +- neo.UnitTests/UT_SpentCointState.cs | 30 +------- neo.UnitTests/UT_StorageItem.cs | 4 +- neo.UnitTests/UT_StorageKey.cs | 4 +- neo.UnitTests/UT_TaskManagerMailbox.cs | 8 +- neo.UnitTests/UT_TransactionAttribute.cs | 2 +- neo.UnitTests/UT_Witness.cs | 4 +- neo/Consensus/ConsensusContext.cs | 2 +- neo/Consensus/ConsensusService.cs | 8 +- neo/Consensus/Helper.cs | 2 +- neo/Consensus/RecoveryRequest.cs | 2 +- neo/IO/Data/LevelDB/Native.cs | 4 +- neo/Ledger/Blockchain.cs | 2 +- neo/Ledger/MemoryPool.cs | 14 ++-- 27 files changed, 123 insertions(+), 149 deletions(-) diff --git a/neo.UnitTests/TestVerifiable.cs b/neo.UnitTests/TestVerifiable.cs index ee8877aee2..554801b677 100644 --- a/neo.UnitTests/TestVerifiable.cs +++ b/neo.UnitTests/TestVerifiable.cs @@ -40,7 +40,7 @@ public void Serialize(BinaryWriter writer) public void SerializeUnsigned(BinaryWriter writer) { - writer.Write((string) testStr); + writer.Write((string)testStr); } } } \ No newline at end of file diff --git a/neo.UnitTests/UT_AccountState.cs b/neo.UnitTests/UT_AccountState.cs index 290db33040..bd9c23ef82 100644 --- a/neo.UnitTests/UT_AccountState.cs +++ b/neo.UnitTests/UT_AccountState.cs @@ -264,7 +264,7 @@ public void Serialize() byte[] requiredData = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }; data.Length.Should().Be(25); - for (int i=0; i<25; i++) + for (int i = 0; i < 25; i++) { data[i].Should().Be(requiredData[i]); } diff --git a/neo.UnitTests/UT_AssetState.cs b/neo.UnitTests/UT_AssetState.cs index a609bd86fb..2a64f81d4b 100644 --- a/neo.UnitTests/UT_AssetState.cs +++ b/neo.UnitTests/UT_AssetState.cs @@ -233,7 +233,7 @@ private void setupAssetStateWithValues(AssetState assetState, out UInt256 assetI feeAddress = new UInt160(TestUtils.GetByteArray(20, 0x21)); assetState.FeeAddress = feeAddress; - owner = ECPoint.DecodePoint(TestUtils.GetByteArray(1,0x00), ECCurve.Secp256r1); + owner = ECPoint.DecodePoint(TestUtils.GetByteArray(1, 0x00), ECCurve.Secp256r1); assetState.Owner = owner; admin = new UInt160(TestUtils.GetByteArray(20, 0x22)); diff --git a/neo.UnitTests/UT_ClaimTransaction.cs b/neo.UnitTests/UT_ClaimTransaction.cs index 32353052f2..ac6683ac4d 100644 --- a/neo.UnitTests/UT_ClaimTransaction.cs +++ b/neo.UnitTests/UT_ClaimTransaction.cs @@ -19,7 +19,7 @@ public void TestSetup() [TestMethod] public void Claims_Get() { - uut.Claims.Should().BeNull(); + uut.Claims.Should().BeNull(); } [TestMethod] @@ -101,7 +101,7 @@ public void ToJson() jObj["net_fee"].AsString().Should().Be("0"); ((JArray)jObj["scripts"]).Count.Should().Be(0); - JArray claims = (JArray) jObj["claims"]; + JArray claims = (JArray)jObj["claims"]; claims.Count.Should().Be(1); claims[0]["txid"].AsString().Should().Be("0x2020202020202020202020202020202020202020202020202020202020202042"); claims[0]["vout"].AsNumber().Should().Be(0); diff --git a/neo.UnitTests/UT_CoinReference.cs b/neo.UnitTests/UT_CoinReference.cs index 5777a9ea26..d6a268f494 100644 --- a/neo.UnitTests/UT_CoinReference.cs +++ b/neo.UnitTests/UT_CoinReference.cs @@ -130,7 +130,7 @@ public void Equals_SameHash() ushort prevIndexVal; setupCoinReferenceWithVals(uut, out prevHashVal, out prevIndexVal); CoinReference newCoinRef = new CoinReference(); - setupCoinReferenceWithVals(newCoinRef, out prevHashVal, out prevIndexVal); + setupCoinReferenceWithVals(newCoinRef, out prevHashVal, out prevIndexVal); uut.Equals(newCoinRef).Should().BeTrue(); } @@ -182,7 +182,7 @@ public void Class_GetHashCode() { UInt256 prevHashVal; ushort prevIndexVal; - setupCoinReferenceWithVals(uut, out prevHashVal, out prevIndexVal); + setupCoinReferenceWithVals(uut, out prevHashVal, out prevIndexVal); uut.GetHashCode().Should().Be(538976344); } diff --git a/neo.UnitTests/UT_Consensus.cs b/neo.UnitTests/UT_Consensus.cs index 795c1cd9ce..8144d525a0 100644 --- a/neo.UnitTests/UT_Consensus.cs +++ b/neo.UnitTests/UT_Consensus.cs @@ -93,8 +93,8 @@ public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart() Console.WriteLine($"header {header} hash {header.Hash} timstamp {timestampVal}"); - timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00 - // check basic ConsensusContext + timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00 + // check basic ConsensusContext mockConsensusContext.Object.MyIndex.Should().Be(2); //mockConsensusContext.Object.block_received_time.ToTimestamp().Should().Be(4244941697); //1968-06-01 00:00:01 diff --git a/neo.UnitTests/UT_ConsensusServiceMailbox.cs b/neo.UnitTests/UT_ConsensusServiceMailbox.cs index 4000b99f61..fded2ab54e 100644 --- a/neo.UnitTests/UT_ConsensusServiceMailbox.cs +++ b/neo.UnitTests/UT_ConsensusServiceMailbox.cs @@ -13,7 +13,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_ConsensusServiceMailbox : TestKit + public class UT_ConsensusServiceMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism @@ -42,10 +42,10 @@ public void ConsensusServiceMailbox_Test_IsHighPriority() uut.IsHighPriority(new ConsensusService.SetViewNumber()).Should().Be(true); uut.IsHighPriority(new ConsensusService.Timer()).Should().Be(true); uut.IsHighPriority(new Blockchain.PersistCompleted()).Should().Be(true); - + // any random object should not have priority object obj = null; - uut.IsHighPriority(obj).Should().Be(false); + uut.IsHighPriority(obj).Should().Be(false); } } } diff --git a/neo.UnitTests/UT_Header.cs b/neo.UnitTests/UT_Header.cs index 9819148241..92eeddba08 100644 --- a/neo.UnitTests/UT_Header.cs +++ b/neo.UnitTests/UT_Header.cs @@ -68,7 +68,7 @@ private void assertStandardHeaderTestVals(UInt256 val256, UInt256 merkRoot, UInt uut.NextConsensus.Should().Be(val160); uut.Witness.InvocationScript.Length.Should().Be(0); uut.Witness.Size.Should().Be(scriptVal.Size); - uut.Witness.VerificationScript[0].Should().Be(scriptVal.VerificationScript[0]); + uut.Witness.VerificationScript[0].Should().Be(scriptVal.VerificationScript[0]); } [TestMethod] @@ -83,11 +83,11 @@ public void Equals_SameHeader() { uut.Equals(uut).Should().BeTrue(); } - + [TestMethod] public void Equals_SameHash() { - Header newHeader = new Header(); + Header newHeader = new Header(); UInt256 prevHash = new UInt256(TestUtils.GetByteArray(32, 0x42)); UInt256 merkRoot; UInt160 val160; diff --git a/neo.UnitTests/UT_Helper.cs b/neo.UnitTests/UT_Helper.cs index c836219b88..d64d9c9173 100644 --- a/neo.UnitTests/UT_Helper.cs +++ b/neo.UnitTests/UT_Helper.cs @@ -15,7 +15,7 @@ public void GetHashData() TestVerifiable verifiable = new TestVerifiable(); byte[] res = verifiable.GetHashData(); res.Length.Should().Be(8); - byte[] requiredData = new byte[] {7, 116, 101, 115, 116, 83, 116, 114}; + byte[] requiredData = new byte[] { 7, 116, 101, 115, 116, 83, 116, 114 }; for (int i = 0; i < requiredData.Length; i++) { res[i].Should().Be(requiredData[i]); @@ -26,14 +26,14 @@ public void GetHashData() public void Sign() { TestVerifiable verifiable = new TestVerifiable(); - byte[] res = verifiable.Sign(new KeyPair(TestUtils.GetByteArray(32,0x42))); + byte[] res = verifiable.Sign(new KeyPair(TestUtils.GetByteArray(32, 0x42))); res.Length.Should().Be(64); } [TestMethod] public void ToScriptHash() { - byte[] testByteArray = TestUtils.GetByteArray(64,0x42); + byte[] testByteArray = TestUtils.GetByteArray(64, 0x42); UInt160 res = testByteArray.ToScriptHash(); res.Should().Be(UInt160.Parse("2d3b96ae1bcc5a585e075e3b81920210dec16302")); } diff --git a/neo.UnitTests/UT_InteropPrices.cs b/neo.UnitTests/UT_InteropPrices.cs index 818b95c8c4..1aafa91be0 100644 --- a/neo.UnitTests/UT_InteropPrices.cs +++ b/neo.UnitTests/UT_InteropPrices.cs @@ -26,7 +26,7 @@ public void NeoServiceFixedPriceWithReflection() { // testing reflection with public methods too MethodInfo GetPrice = typeof(NeoService).GetMethod("GetPrice", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(uint) }, null); - GetPrice.Invoke(uut, new object[]{"Neo.Runtime.CheckWitness".ToInteropMethodHash()}).Should().Be(200L); + GetPrice.Invoke(uut, new object[] { "Neo.Runtime.CheckWitness".ToInteropMethodHash() }).Should().Be(200L); } [TestMethod] @@ -206,38 +206,38 @@ public void StandardServiceFixedPrices() public void ApplicationEngineFixedPrices() { // ApplicationEngine.GetPriceForSysCall is protected, so we will access through reflection - MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[]{}, null); + MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { }, null); // System.Runtime.CheckWitness: f827ec8c (price is 200) - byte[] SyscallSystemRuntimeCheckWitnessHash = new byte[]{0x68, 0x04, 0xf8, 0x27, 0xec, 0x8c}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallSystemRuntimeCheckWitnessHash = new byte[] { 0x68, 0x04, 0xf8, 0x27, 0xec, 0x8c }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { ae.LoadScript(SyscallSystemRuntimeCheckWitnessHash); - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(200L); + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(200L); } // "System.Runtime.CheckWitness" (27 bytes -> 0x1b) - (price is 200) - byte[] SyscallSystemRuntimeCheckWitnessString = new byte[]{0x68, 0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x57, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallSystemRuntimeCheckWitnessString = new byte[] { 0x68, 0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x57, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73 }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { ae.LoadScript(SyscallSystemRuntimeCheckWitnessString); - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(200L); + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(200L); } // System.Storage.GetContext: 9bf667ce (price is 1) - byte[] SyscallSystemStorageGetContextHash = new byte[]{0x68, 0x04, 0x9b, 0xf6, 0x67, 0xce}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallSystemStorageGetContextHash = new byte[] { 0x68, 0x04, 0x9b, 0xf6, 0x67, 0xce }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { ae.LoadScript(SyscallSystemStorageGetContextHash); - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1L); + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1L); } // System.Storage.Get: 925de831 (price is 100) - byte[] SyscallSystemStorageGetHash = new byte[]{0x68, 0x04, 0x92, 0x5d, 0xe8, 0x31}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallSystemStorageGetHash = new byte[] { 0x68, 0x04, 0x92, 0x5d, 0xe8, 0x31 }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { ae.LoadScript(SyscallSystemStorageGetHash); - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(100L); + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(100L); } } @@ -245,30 +245,30 @@ public void ApplicationEngineFixedPrices() public void ApplicationEngineVariablePrices() { // ApplicationEngine.GetPriceForSysCall is protected, so we will access through reflection - MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[]{}, null); + MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { }, null); // Neo.Asset.Create: 83c5c61f - byte[] SyscallAssetCreateHash = new byte[]{0x68, 0x04, 0x83, 0xc5, 0xc6, 0x1f}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallAssetCreateHash = new byte[] { 0x68, 0x04, 0x83, 0xc5, 0xc6, 0x1f }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { ae.LoadScript(SyscallAssetCreateHash); - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Asset.Renew: 78849071 (requires push 09 push 09 before) - byte[] SyscallAssetRenewHash = new byte[]{0x59, 0x59, 0x68, 0x04, 0x78, 0x84, 0x90, 0x71}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallAssetRenewHash = new byte[] { 0x59, 0x59, 0x68, 0x04, 0x78, 0x84, 0x90, 0x71 }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallAssetRenewHash); debugger.StepInto(); // push 9 debugger.StepInto(); // push 9 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(9L * 5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(9L * 5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash00 = new byte[]{(byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallContractCreateHash00 = new byte[] { (byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash00); @@ -276,12 +276,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash01 = new byte[]{0x51, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallContractCreateHash01 = new byte[] { 0x51, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash01); @@ -289,12 +289,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(500L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(500L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash02 = new byte[]{0x52, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallContractCreateHash02 = new byte[] { 0x52, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash02); @@ -302,12 +302,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(600L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(600L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash03 = new byte[]{0x53, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallContractCreateHash03 = new byte[] { 0x53, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash03); @@ -315,12 +315,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1000L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1000L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Migrate: 471b6290 (requires push properties on fourth position) - byte[] SyscallContractMigrateHash00 = new byte[]{(byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0x47, 0x1b, 0x62, 0x90}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallContractMigrateHash00 = new byte[] { (byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0x47, 0x1b, 0x62, 0x90 }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractMigrateHash00); @@ -328,31 +328,31 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // System.Storage.Put: e63f1884 (requires push key and value) - byte[] SyscallStoragePutHash = new byte[]{0x53, 0x53, 0x00, 0x68, 0x04, 0xe6, 0x3f, 0x18, 0x84}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallStoragePutHash = new byte[] { 0x53, 0x53, 0x00, 0x68, 0x04, 0xe6, 0x3f, 0x18, 0x84 }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallStoragePutHash); debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 00 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); } // System.Storage.PutEx: 73e19b3a (requires push key and value) - byte[] SyscallStoragePutExHash = new byte[]{0x53, 0x53, 0x00, 0x68, 0x04, 0x73, 0xe1, 0x9b, 0x3a}; - using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) + byte[] SyscallStoragePutExHash = new byte[] { 0x53, 0x53, 0x00, 0x68, 0x04, 0x73, 0xe1, 0x9b, 0x3a }; + using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallStoragePutExHash); debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 00 - GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); + GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); } } } diff --git a/neo.UnitTests/UT_MinerTransaction.cs b/neo.UnitTests/UT_MinerTransaction.cs index 5b0d2156c3..c9a8150502 100644 --- a/neo.UnitTests/UT_MinerTransaction.cs +++ b/neo.UnitTests/UT_MinerTransaction.cs @@ -69,7 +69,7 @@ public void ToJson() jObj["net_fee"].AsNumber().Should().Be(0); ((JArray)jObj["scripts"]).Count.Should().Be(0); - jObj["nonce"].AsNumber().Should().Be(42); + jObj["nonce"].AsNumber().Should().Be(42); } } diff --git a/neo.UnitTests/UT_PoolItem.cs b/neo.UnitTests/UT_PoolItem.cs index 0d8a8bc19a..e7324f3b75 100644 --- a/neo.UnitTests/UT_PoolItem.cs +++ b/neo.UnitTests/UT_PoolItem.cs @@ -75,7 +75,7 @@ public void PoolItem_CompareTo_Hash() for (int testRuns = 0; testRuns < 30; testRuns++) { var tx1 = GenerateMockTxWithFirstByteOfHashGreaterThanOrEqualTo(0x80, new Fixed8(netFeeSatoshiFixed), sizeFixed); - var tx2 = GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(0x79,new Fixed8(netFeeSatoshiFixed), sizeFixed); + var tx2 = GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(0x79, new Fixed8(netFeeSatoshiFixed), sizeFixed); PoolItem pitem1 = new PoolItem(tx1.Object); PoolItem pitem2 = new PoolItem(tx2.Object); @@ -88,8 +88,8 @@ public void PoolItem_CompareTo_Hash() } // equal hashes should be equal - var tx3 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); - var tx4 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); + var tx3 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); + var tx4 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); PoolItem pitem3 = new PoolItem(tx3.Object); PoolItem pitem4 = new PoolItem(tx4.Object); @@ -102,8 +102,8 @@ public void PoolItem_CompareTo_Equals() { int sizeFixed = 500; int netFeeSatoshiFixed = 10; - var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); - var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); + var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); + var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); PoolItem pitem1 = new PoolItem(tx1.Object); PoolItem pitem2 = new PoolItem(tx2.Object); @@ -150,7 +150,7 @@ public static Transaction GenerateClaimTx() } // Generate Mock InvocationTransaction with different sizes and prices - public static Mock MockGenerateInvocationTx(Fixed8 networkFee, int size, byte[] overrideScriptBytes=null) + public static Mock MockGenerateInvocationTx(Fixed8 networkFee, int size, byte[] overrideScriptBytes = null) { var mockTx = new Mock(); mockTx.CallBase = true; diff --git a/neo.UnitTests/UT_ProtocolHandlerMailbox.cs b/neo.UnitTests/UT_ProtocolHandlerMailbox.cs index 8cf859567d..7c8937db27 100644 --- a/neo.UnitTests/UT_ProtocolHandlerMailbox.cs +++ b/neo.UnitTests/UT_ProtocolHandlerMailbox.cs @@ -15,7 +15,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_ProtocolHandlerMailbox : TestKit + public class UT_ProtocolHandlerMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism @@ -57,14 +57,14 @@ public void ProtocolHandlerMailbox_Test_IsHighPriority() uut.IsHighPriority(Message.Create("mempool", s)).Should().Be(false); uut.IsHighPriority(Message.Create("ping", s)).Should().Be(false); uut.IsHighPriority(Message.Create("pong", s)).Should().Be(false); - uut.IsHighPriority(Message.Create("tx", s)).Should().Be(false); + uut.IsHighPriority(Message.Create("tx", s)).Should().Be(false); uut.IsHighPriority(Message.Create("verack", s)).Should().Be(true); uut.IsHighPriority(Message.Create("version", s)).Should().Be(true); uut.IsHighPriority(Message.Create("alert", s)).Should().Be(true); uut.IsHighPriority(Message.Create("merkleblock", s)).Should().Be(false); uut.IsHighPriority(Message.Create("notfound", s)).Should().Be(false); uut.IsHighPriority(Message.Create("reject", s)).Should().Be(false); - + // any random command should not have priority uut.IsHighPriority(Message.Create("_", s)).Should().Be(false); @@ -91,99 +91,99 @@ public void ProtocolHandlerMailbox_Test_ShallDrop() // Version (no drop) msg = Message.Create("version", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // Verack (no drop) msg = Message.Create("verack", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); //connectivity // GetAddr (drop) msg = Message.Create("getaddr", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); // Addr (no drop) msg = Message.Create("addr", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // Ping (no drop) msg = Message.Create("ping", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // Pong (no drop) msg = Message.Create("pong", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); //synchronization // GetHeaders (drop) msg = Message.Create("getheaders", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); // Headers (no drop) msg = Message.Create("headers", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // GetBlocks (drop) msg = Message.Create("getblocks", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); // Mempool (drop) msg = Message.Create("mempool", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); // Inv (no drop) msg = Message.Create("inv", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // GetData (drop) msg = Message.Create("getdata", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); // NotFound (no drop) msg = Message.Create("notfound", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // Transaction (no drop) msg = Message.Create("tx", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // Block (no drop) msg = Message.Create("block", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // Consensus (no drop) msg = Message.Create("consensus", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // Reject (no drop) msg = Message.Create("reject", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); //SPV protocol // FilterLoad (no drop) msg = Message.Create("filterload", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // FilterAdd (no drop) msg = Message.Create("filteradd", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // FilterClear (no drop) msg = Message.Create("filterclear", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // MerkleBlock (no drop) msg = Message.Create("merkleblock", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); //others // Alert (no drop) msg = Message.Create("alert", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); + uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); // any random command should not be dropped uut.ShallDrop(Message.Create("_", s), emptyQueue).Should().Be(false); diff --git a/neo.UnitTests/UT_RemoteNodeMailbox.cs b/neo.UnitTests/UT_RemoteNodeMailbox.cs index c3e670310f..b6dad1e6cb 100644 --- a/neo.UnitTests/UT_RemoteNodeMailbox.cs +++ b/neo.UnitTests/UT_RemoteNodeMailbox.cs @@ -15,7 +15,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_RemoteNodeMailbox : TestKit + public class UT_RemoteNodeMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism diff --git a/neo.UnitTests/UT_SpentCointState.cs b/neo.UnitTests/UT_SpentCointState.cs index e71e93fb4d..df37c3cf9f 100644 --- a/neo.UnitTests/UT_SpentCointState.cs +++ b/neo.UnitTests/UT_SpentCointState.cs @@ -1,6 +1,5 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Neo.IO; using Neo.Ledger; using System.Collections.Generic; using System.IO; @@ -25,31 +24,6 @@ public void TransactionHash_Get() uut.TransactionHash.Should().BeNull(); } - [TestMethod] - public void TestFromReplica() - { - uut.Items = new Dictionary(); - uut.Items.Add(1, 3); - - var a = ((ICloneable)uut).Clone(); - var b = new SpentCoinState(); - - ((ICloneable)b).FromReplica(uut); - - CollectionAssert.AreEqual(a.Items.Keys, uut.Items.Keys); - CollectionAssert.AreEqual(a.Items.Values, uut.Items.Values); - CollectionAssert.AreEqual(b.Items.Keys, uut.Items.Keys); - CollectionAssert.AreEqual(b.Items.Values, uut.Items.Values); - - a.Items.Clear(); - b.Items.Clear(); - - CollectionAssert.AreNotEqual(a.Items.Keys, uut.Items.Keys); - CollectionAssert.AreNotEqual(b.Items.Keys, uut.Items.Keys); - CollectionAssert.AreNotEqual(a.Items.Values, uut.Items.Values); - CollectionAssert.AreNotEqual(b.Items.Values, uut.Items.Values); - } - [TestMethod] public void TransactionHash_Set() { @@ -124,8 +98,8 @@ private void setupSpentCoinStateWithValues(SpentCoinState spentCoinState, out UI [TestMethod] public void DeserializeSCS() { - byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 }; - + byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 }; + using (Stream stream = new MemoryStream(dataArray)) { using (BinaryReader reader = new BinaryReader(stream)) diff --git a/neo.UnitTests/UT_StorageItem.cs b/neo.UnitTests/UT_StorageItem.cs index 5174d23240..90810f6705 100644 --- a/neo.UnitTests/UT_StorageItem.cs +++ b/neo.UnitTests/UT_StorageItem.cs @@ -27,7 +27,7 @@ public void Value_Get() [TestMethod] public void Value_Set() { - byte[] val = new byte[] { 0x42, 0x32}; + byte[] val = new byte[] { 0x42, 0x32 }; uut.Value = val; uut.Value.Length.Should().Be(2); uut.Value[0].Should().Be(val[0]); @@ -56,7 +56,7 @@ public void Clone() StorageItem newSi = ((ICloneable)uut).Clone(); newSi.Value.Length.Should().Be(10); newSi.Value[0].Should().Be(0x42); - for (int i=1; i<10; i++) + for (int i = 1; i < 10; i++) { newSi.Value[i].Should().Be(0x20); } diff --git a/neo.UnitTests/UT_StorageKey.cs b/neo.UnitTests/UT_StorageKey.cs index 1ba8d61d26..664b1ae664 100644 --- a/neo.UnitTests/UT_StorageKey.cs +++ b/neo.UnitTests/UT_StorageKey.cs @@ -79,7 +79,7 @@ public void Equals_DiffHash_SameKey() StorageKey newSk = new StorageKey(); newSk.ScriptHash = val; newSk.Key = keyVal; - uut.ScriptHash = new UInt160(TestUtils.GetByteArray(20, 0x88)); + uut.ScriptHash = new UInt160(TestUtils.GetByteArray(20, 0x88)); uut.Key = keyVal; uut.Equals(newSk).Should().BeFalse(); @@ -95,7 +95,7 @@ public void Equals_SameHash_DiffKey() newSk.ScriptHash = val; newSk.Key = keyVal; uut.ScriptHash = val; - uut.Key = TestUtils.GetByteArray(10, 0x88); + uut.Key = TestUtils.GetByteArray(10, 0x88); uut.Equals(newSk).Should().BeFalse(); } diff --git a/neo.UnitTests/UT_TaskManagerMailbox.cs b/neo.UnitTests/UT_TaskManagerMailbox.cs index d460b7ca41..22f8fdd708 100644 --- a/neo.UnitTests/UT_TaskManagerMailbox.cs +++ b/neo.UnitTests/UT_TaskManagerMailbox.cs @@ -12,7 +12,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_TaskManagerMailbox : TestKit + public class UT_TaskManagerMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism @@ -42,12 +42,12 @@ public void Test_IsHighPriority() // low priority // -> NewTasks: generic InvPayload - uut.IsHighPriority(new TaskManager.NewTasks{ Payload = new InvPayload() }).Should().Be(false); + uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload() }).Should().Be(false); // high priority // -> NewTasks: payload Block or Consensus - uut.IsHighPriority(new TaskManager.NewTasks{ Payload = new InvPayload{ Type = InventoryType.Block } }).Should().Be(true); - uut.IsHighPriority(new TaskManager.NewTasks{ Payload = new InvPayload{ Type = InventoryType.Consensus } }).Should().Be(true); + uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Block } }).Should().Be(true); + uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Consensus } }).Should().Be(true); // any random object should not have priority object obj = null; diff --git a/neo.UnitTests/UT_TransactionAttribute.cs b/neo.UnitTests/UT_TransactionAttribute.cs index bf79f6ac01..4d3b116746 100644 --- a/neo.UnitTests/UT_TransactionAttribute.cs +++ b/neo.UnitTests/UT_TransactionAttribute.cs @@ -115,7 +115,7 @@ public void ToJson() JObject jObj = uut.ToJson(); jObj.Should().NotBeNull(); jObj["usage"].AsString().Should().Be("ECDH02"); - jObj["data"].AsString().Should().Be("42202020202020202020"); + jObj["data"].AsString().Should().Be("42202020202020202020"); } } } diff --git a/neo.UnitTests/UT_Witness.cs b/neo.UnitTests/UT_Witness.cs index 26dc8b84dd..64e94f649c 100644 --- a/neo.UnitTests/UT_Witness.cs +++ b/neo.UnitTests/UT_Witness.cs @@ -28,7 +28,7 @@ public void InvocationScript_Set() byte[] dataArray = new byte[] { 0, 32, 32, 20, 32, 32 }; uut.InvocationScript = dataArray; uut.InvocationScript.Length.Should().Be(6); - Assert.AreEqual(uut.InvocationScript.ToHexString(), "002020142020"); + Assert.AreEqual(uut.InvocationScript.ToHexString(), "002020142020"); } private void setupWitnessWithValues(Witness uut, int lenghtInvocation, int lengthVerification, out byte[] invocationScript, out byte[] verificationScript) @@ -68,7 +68,7 @@ public void ToJson() JObject json = uut.ToJson(); Assert.IsTrue(json.ContainsProperty("invocation")); - Assert.IsTrue(json.ContainsProperty("verification")); + Assert.IsTrue(json.ContainsProperty("verification")); Assert.AreEqual(json["invocation"].AsString(), "2020"); Assert.AreEqual(json["verification"].AsString(), "202020"); diff --git a/neo/Consensus/ConsensusContext.cs b/neo/Consensus/ConsensusContext.cs index 1f96f0d0ac..6a3a35df5c 100644 --- a/neo/Consensus/ConsensusContext.cs +++ b/neo/Consensus/ConsensusContext.cs @@ -305,7 +305,7 @@ public void Reset(byte viewNumber) Timestamp = 0; TransactionHashes = null; PreparationPayloads = new ConsensusPayload[Validators.Length]; - if (MyIndex >= 0) LastSeenMessage[MyIndex] = (int) BlockIndex; + if (MyIndex >= 0) LastSeenMessage[MyIndex] = (int)BlockIndex; _header = null; } diff --git a/neo/Consensus/ConsensusService.cs b/neo/Consensus/ConsensusService.cs index 79e5599603..6a63d06f2a 100644 --- a/neo/Consensus/ConsensusService.cs +++ b/neo/Consensus/ConsensusService.cs @@ -240,9 +240,9 @@ private void OnCommitReceived(ConsensusPayload payload, Commit commit) // this function increases existing timer (never decreases) with a value proportional to `maxDelayInBlockTimes`*`Blockchain.SecondsPerBlock` private void ExtendTimerByFactor(int maxDelayInBlockTimes) { - TimeSpan nextDelay = expected_delay - (TimeProvider.Current.UtcNow - clock_started) + TimeSpan.FromMilliseconds(maxDelayInBlockTimes*Blockchain.SecondsPerBlock * 1000.0 / context.M()); - if (!context.WatchOnly() && !context.ViewChanging() && !context.CommitSent() && (nextDelay > TimeSpan.Zero)) - ChangeTimer(nextDelay); + TimeSpan nextDelay = expected_delay - (TimeProvider.Current.UtcNow - clock_started) + TimeSpan.FromMilliseconds(maxDelayInBlockTimes * Blockchain.SecondsPerBlock * 1000.0 / context.M()); + if (!context.WatchOnly() && !context.ViewChanging() && !context.CommitSent() && (nextDelay > TimeSpan.Zero)) + ChangeTimer(nextDelay); } private void OnConsensusPayload(ConsensusPayload payload) @@ -271,7 +271,7 @@ private void OnConsensusPayload(ConsensusPayload payload) { return; } - context.LastSeenMessage[payload.ValidatorIndex] = (int) payload.BlockIndex; + context.LastSeenMessage[payload.ValidatorIndex] = (int)payload.BlockIndex; foreach (IP2PPlugin plugin in Plugin.P2PPlugins) if (!plugin.OnConsensusMessage(payload)) return; diff --git a/neo/Consensus/Helper.cs b/neo/Consensus/Helper.cs index 539caa73af..27050a4a11 100644 --- a/neo/Consensus/Helper.cs +++ b/neo/Consensus/Helper.cs @@ -22,7 +22,7 @@ internal static class Helper [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountCommitted(this IConsensusContext context) => context.CommitPayloads.Count(p => p != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountFailed(this IConsensusContext context) => context.LastSeenMessage.Count(p => p < (((int) context.BlockIndex) - 1)); + public static int CountFailed(this IConsensusContext context) => context.LastSeenMessage.Count(p => p < (((int)context.BlockIndex) - 1)); // Consensus States [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/neo/Consensus/RecoveryRequest.cs b/neo/Consensus/RecoveryRequest.cs index 3152264894..971b49a324 100644 --- a/neo/Consensus/RecoveryRequest.cs +++ b/neo/Consensus/RecoveryRequest.cs @@ -13,7 +13,7 @@ public class RecoveryRequest : ConsensusMessage public override int Size => base.Size + sizeof(uint); //Timestamp - + public RecoveryRequest() : base(ConsensusMessageType.RecoveryRequest) { } public override void Deserialize(BinaryReader reader) diff --git a/neo/IO/Data/LevelDB/Native.cs b/neo/IO/Data/LevelDB/Native.cs index fc3ccd6387..b51460e799 100644 --- a/neo/IO/Data/LevelDB/Native.cs +++ b/neo/IO/Data/LevelDB/Native.cs @@ -232,10 +232,10 @@ public static extern IntPtr /* leveldb_comparator_t* */ leveldb_comparator_create( IntPtr /* void* */ state, IntPtr /* void (*)(void*) */ destructor, - IntPtr + IntPtr /* int (*compare)(void*, const char* a, size_t alen, - const char* b, size_t blen) */ + const char* b, size_t blen) */ compare, IntPtr /* const char* (*)(void*) */ name); diff --git a/neo/Ledger/Blockchain.cs b/neo/Ledger/Blockchain.cs index fa5aa2d185..366c9633a3 100644 --- a/neo/Ledger/Blockchain.cs +++ b/neo/Ledger/Blockchain.cs @@ -313,7 +313,7 @@ private RelayResultReason OnNewBlock(Block block) block_cache_unverified.Remove(blockToPersist.Index); Persist(blockToPersist); - if (blocksPersisted++ < blocksToPersistList.Count - (2 + Math.Max(0,(15 - SecondsPerBlock)))) continue; + if (blocksPersisted++ < blocksToPersistList.Count - (2 + Math.Max(0, (15 - SecondsPerBlock)))) continue; // Empirically calibrated for relaying the most recent 2 blocks persisted with 15s network // Increase in the rate of 1 block per second in configurations with faster blocks diff --git a/neo/Ledger/MemoryPool.cs b/neo/Ledger/MemoryPool.cs index 9c367fd8fc..89933e7021 100644 --- a/neo/Ledger/MemoryPool.cs +++ b/neo/Ledger/MemoryPool.cs @@ -19,12 +19,12 @@ public class MemoryPool : IReadOnlyCollection private const int BlocksTillRebroadcastHighPriorityPoolTx = 10; private int RebroadcastMultiplierThreshold => Capacity / 10; - private static readonly double MaxSecondsToReverifyHighPrioTx = (double) Blockchain.SecondsPerBlock / 3; - private static readonly double MaxSecondsToReverifyLowPrioTx = (double) Blockchain.SecondsPerBlock / 5; + private static readonly double MaxSecondsToReverifyHighPrioTx = (double)Blockchain.SecondsPerBlock / 3; + private static readonly double MaxSecondsToReverifyLowPrioTx = (double)Blockchain.SecondsPerBlock / 5; // These two are not expected to be hit, they are just safegaurds. - private static readonly double MaxSecondsToReverifyHighPrioTxPerIdle = (double) Blockchain.SecondsPerBlock / 15; - private static readonly double MaxSecondsToReverifyLowPrioTxPerIdle = (double) Blockchain.SecondsPerBlock / 30; + private static readonly double MaxSecondsToReverifyHighPrioTxPerIdle = (double)Blockchain.SecondsPerBlock / 15; + private static readonly double MaxSecondsToReverifyLowPrioTxPerIdle = (double)Blockchain.SecondsPerBlock / 30; private readonly NeoSystem _system; @@ -211,9 +211,9 @@ public IEnumerable GetSortedVerifiedTransactions() _txRwLock.EnterReadLock(); try { - return _sortedHighPrioTransactions.Reverse().Select(p => p.Tx) - .Concat(_sortedLowPrioTransactions.Reverse().Select(p => p.Tx)) - .ToArray(); + return _sortedHighPrioTransactions.Reverse().Select(p => p.Tx) + .Concat(_sortedLowPrioTransactions.Reverse().Select(p => p.Tx)) + .ToArray(); } finally { From 5f37d4b7712e2bb163f3d92b4905915face78a64 Mon Sep 17 00:00:00 2001 From: Mirella de Medeiros Date: Wed, 22 Jan 2020 15:44:11 -0300 Subject: [PATCH 4/5] scripthash param in invoke method --- neo/Network/RPC/RpcServer.cs | 57 +++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/neo/Network/RPC/RpcServer.cs b/neo/Network/RPC/RpcServer.cs index 2aa41dc11c..52dbf474af 100644 --- a/neo/Network/RPC/RpcServer.cs +++ b/neo/Network/RPC/RpcServer.cs @@ -117,20 +117,23 @@ public void Dispose() private JObject GetInvokeResult(byte[] script, IVerifiable checkWitnessHashes = null) { - ApplicationEngine engine = ApplicationEngine.Run(script, checkWitnessHashes, extraGAS: MaxGasInvoke); - JObject json = new JObject(); - json["script"] = script.ToHexString(); - json["state"] = engine.State; - json["gas_consumed"] = engine.GasConsumed.ToString(); - try + using (ApplicationEngine engine = ApplicationEngine.Run(script, checkWitnessHashes, extraGAS: MaxGasInvoke)) { - json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson())); - } - catch (InvalidOperationException) - { - json["stack"] = "error: recursive reference"; + JObject json = new JObject(); + json["script"] = script.ToHexString(); + json["state"] = engine.State; + json["gas_consumed"] = engine.GasConsumed.ToString(); + try + { + json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson())); + } + catch (InvalidOperationException) + { + json["stack"] = "error: recursive reference"; + } + + return json; } - return json; } private static JObject GetRelayResult(RelayResultReason reason) @@ -251,14 +254,26 @@ private JObject Process(string method, JArray _params) { UInt160 script_hash = UInt160.Parse(_params[0].AsString()); ContractParameter[] parameters = ((JArray)_params[1]).Select(p => ContractParameter.FromJson(p)).ToArray(); - return Invoke(script_hash, parameters); + CheckWitnessHashes checkWitnessHashes = null; + if (_params.Count > 2) + { + UInt160[] scriptHashesForVerifying = _params.Skip(2).Select(u => UInt160.Parse(u.AsString())).ToArray(); + checkWitnessHashes = new CheckWitnessHashes(scriptHashesForVerifying); + } + return Invoke(script_hash, parameters, checkWitnessHashes); } case "invokefunction": { UInt160 script_hash = UInt160.Parse(_params[0].AsString()); string operation = _params[1].AsString(); ContractParameter[] args = _params.Count >= 3 ? ((JArray)_params[2]).Select(p => ContractParameter.FromJson(p)).ToArray() : new ContractParameter[0]; - return InvokeFunction(script_hash, operation, args); + CheckWitnessHashes checkWitnessHashes = null; + if (_params.Count > 3) + { + UInt160[] scriptHashesForVerifying = _params.Skip(3).Select(u => UInt160.Parse(u.AsString())).ToArray(); + checkWitnessHashes = new CheckWitnessHashes(scriptHashesForVerifying); + } + return InvokeFunction(script_hash, operation, args, checkWitnessHashes); } case "invokescript": { @@ -269,7 +284,7 @@ private JObject Process(string method, JArray _params) UInt160[] scriptHashesForVerifying = _params.Skip(1).Select(u => UInt160.Parse(u.AsString())).ToArray(); checkWitnessHashes = new CheckWitnessHashes(scriptHashesForVerifying); } - return InvokeScript(script); + return InvokeScript(script, checkWitnessHashes); } case "listplugins": { @@ -666,29 +681,29 @@ private JObject GetVersion() return json; } - private JObject Invoke(UInt160 script_hash, ContractParameter[] parameters) + private JObject Invoke(UInt160 script_hash, ContractParameter[] parameters, IVerifiable checkWitnessHashes = null) { byte[] script; using (ScriptBuilder sb = new ScriptBuilder()) { script = sb.EmitAppCall(script_hash, parameters).ToArray(); } - return GetInvokeResult(script); + return GetInvokeResult(script, checkWitnessHashes); } - private JObject InvokeFunction(UInt160 script_hash, string operation, ContractParameter[] args) + private JObject InvokeFunction(UInt160 script_hash, string operation, ContractParameter[] args, IVerifiable checkWitnessHashes = null) { byte[] script; using (ScriptBuilder sb = new ScriptBuilder()) { script = sb.EmitAppCall(script_hash, operation, args).ToArray(); } - return GetInvokeResult(script); + return GetInvokeResult(script, checkWitnessHashes); } - private JObject InvokeScript(byte[] script) + private JObject InvokeScript(byte[] script, IVerifiable checkWitnessHashes = null) { - return GetInvokeResult(script); + return GetInvokeResult(script, checkWitnessHashes); } private JObject ListPlugins() From 3ff25ccb207f8145d97d2e7110d31a2e02e27512 Mon Sep 17 00:00:00 2001 From: Mirella de Medeiros Date: Tue, 18 Feb 2020 10:14:08 -0300 Subject: [PATCH 5/5] Revert dotnet format --- neo.UnitTests/TestVerifiable.cs | 2 +- neo.UnitTests/UT_AccountState.cs | 2 +- neo.UnitTests/UT_AssetState.cs | 2 +- neo.UnitTests/UT_ClaimTransaction.cs | 4 +- neo.UnitTests/UT_CoinReference.cs | 4 +- neo.UnitTests/UT_Consensus.cs | 4 +- neo.UnitTests/UT_ConsensusServiceMailbox.cs | 6 +- neo.UnitTests/UT_Header.cs | 6 +- neo.UnitTests/UT_Helper.cs | 6 +- neo.UnitTests/UT_InteropPrices.cs | 84 ++++++++++----------- neo.UnitTests/UT_MinerTransaction.cs | 2 +- neo.UnitTests/UT_PoolItem.cs | 12 +-- neo.UnitTests/UT_ProtocolHandlerMailbox.cs | 50 ++++++------ neo.UnitTests/UT_RemoteNodeMailbox.cs | 2 +- neo.UnitTests/UT_SpentCointState.cs | 30 +++++++- neo.UnitTests/UT_StorageItem.cs | 4 +- neo.UnitTests/UT_StorageKey.cs | 4 +- neo.UnitTests/UT_TaskManagerMailbox.cs | 8 +- neo.UnitTests/UT_TransactionAttribute.cs | 2 +- neo.UnitTests/UT_Witness.cs | 4 +- neo/Consensus/ConsensusContext.cs | 2 +- neo/Consensus/ConsensusService.cs | 8 +- neo/Consensus/Helper.cs | 2 +- neo/Consensus/RecoveryRequest.cs | 2 +- neo/IO/Data/LevelDB/Native.cs | 4 +- neo/Ledger/Blockchain.cs | 2 +- neo/Ledger/MemoryPool.cs | 14 ++-- 27 files changed, 149 insertions(+), 123 deletions(-) diff --git a/neo.UnitTests/TestVerifiable.cs b/neo.UnitTests/TestVerifiable.cs index 554801b677..ee8877aee2 100644 --- a/neo.UnitTests/TestVerifiable.cs +++ b/neo.UnitTests/TestVerifiable.cs @@ -40,7 +40,7 @@ public void Serialize(BinaryWriter writer) public void SerializeUnsigned(BinaryWriter writer) { - writer.Write((string)testStr); + writer.Write((string) testStr); } } } \ No newline at end of file diff --git a/neo.UnitTests/UT_AccountState.cs b/neo.UnitTests/UT_AccountState.cs index bd9c23ef82..290db33040 100644 --- a/neo.UnitTests/UT_AccountState.cs +++ b/neo.UnitTests/UT_AccountState.cs @@ -264,7 +264,7 @@ public void Serialize() byte[] requiredData = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }; data.Length.Should().Be(25); - for (int i = 0; i < 25; i++) + for (int i=0; i<25; i++) { data[i].Should().Be(requiredData[i]); } diff --git a/neo.UnitTests/UT_AssetState.cs b/neo.UnitTests/UT_AssetState.cs index 2a64f81d4b..a609bd86fb 100644 --- a/neo.UnitTests/UT_AssetState.cs +++ b/neo.UnitTests/UT_AssetState.cs @@ -233,7 +233,7 @@ private void setupAssetStateWithValues(AssetState assetState, out UInt256 assetI feeAddress = new UInt160(TestUtils.GetByteArray(20, 0x21)); assetState.FeeAddress = feeAddress; - owner = ECPoint.DecodePoint(TestUtils.GetByteArray(1, 0x00), ECCurve.Secp256r1); + owner = ECPoint.DecodePoint(TestUtils.GetByteArray(1,0x00), ECCurve.Secp256r1); assetState.Owner = owner; admin = new UInt160(TestUtils.GetByteArray(20, 0x22)); diff --git a/neo.UnitTests/UT_ClaimTransaction.cs b/neo.UnitTests/UT_ClaimTransaction.cs index ac6683ac4d..32353052f2 100644 --- a/neo.UnitTests/UT_ClaimTransaction.cs +++ b/neo.UnitTests/UT_ClaimTransaction.cs @@ -19,7 +19,7 @@ public void TestSetup() [TestMethod] public void Claims_Get() { - uut.Claims.Should().BeNull(); + uut.Claims.Should().BeNull(); } [TestMethod] @@ -101,7 +101,7 @@ public void ToJson() jObj["net_fee"].AsString().Should().Be("0"); ((JArray)jObj["scripts"]).Count.Should().Be(0); - JArray claims = (JArray)jObj["claims"]; + JArray claims = (JArray) jObj["claims"]; claims.Count.Should().Be(1); claims[0]["txid"].AsString().Should().Be("0x2020202020202020202020202020202020202020202020202020202020202042"); claims[0]["vout"].AsNumber().Should().Be(0); diff --git a/neo.UnitTests/UT_CoinReference.cs b/neo.UnitTests/UT_CoinReference.cs index d6a268f494..5777a9ea26 100644 --- a/neo.UnitTests/UT_CoinReference.cs +++ b/neo.UnitTests/UT_CoinReference.cs @@ -130,7 +130,7 @@ public void Equals_SameHash() ushort prevIndexVal; setupCoinReferenceWithVals(uut, out prevHashVal, out prevIndexVal); CoinReference newCoinRef = new CoinReference(); - setupCoinReferenceWithVals(newCoinRef, out prevHashVal, out prevIndexVal); + setupCoinReferenceWithVals(newCoinRef, out prevHashVal, out prevIndexVal); uut.Equals(newCoinRef).Should().BeTrue(); } @@ -182,7 +182,7 @@ public void Class_GetHashCode() { UInt256 prevHashVal; ushort prevIndexVal; - setupCoinReferenceWithVals(uut, out prevHashVal, out prevIndexVal); + setupCoinReferenceWithVals(uut, out prevHashVal, out prevIndexVal); uut.GetHashCode().Should().Be(538976344); } diff --git a/neo.UnitTests/UT_Consensus.cs b/neo.UnitTests/UT_Consensus.cs index 8144d525a0..795c1cd9ce 100644 --- a/neo.UnitTests/UT_Consensus.cs +++ b/neo.UnitTests/UT_Consensus.cs @@ -93,8 +93,8 @@ public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart() Console.WriteLine($"header {header} hash {header.Hash} timstamp {timestampVal}"); - timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00 - // check basic ConsensusContext + timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00 + // check basic ConsensusContext mockConsensusContext.Object.MyIndex.Should().Be(2); //mockConsensusContext.Object.block_received_time.ToTimestamp().Should().Be(4244941697); //1968-06-01 00:00:01 diff --git a/neo.UnitTests/UT_ConsensusServiceMailbox.cs b/neo.UnitTests/UT_ConsensusServiceMailbox.cs index fded2ab54e..4000b99f61 100644 --- a/neo.UnitTests/UT_ConsensusServiceMailbox.cs +++ b/neo.UnitTests/UT_ConsensusServiceMailbox.cs @@ -13,7 +13,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_ConsensusServiceMailbox : TestKit + public class UT_ConsensusServiceMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism @@ -42,10 +42,10 @@ public void ConsensusServiceMailbox_Test_IsHighPriority() uut.IsHighPriority(new ConsensusService.SetViewNumber()).Should().Be(true); uut.IsHighPriority(new ConsensusService.Timer()).Should().Be(true); uut.IsHighPriority(new Blockchain.PersistCompleted()).Should().Be(true); - + // any random object should not have priority object obj = null; - uut.IsHighPriority(obj).Should().Be(false); + uut.IsHighPriority(obj).Should().Be(false); } } } diff --git a/neo.UnitTests/UT_Header.cs b/neo.UnitTests/UT_Header.cs index 92eeddba08..9819148241 100644 --- a/neo.UnitTests/UT_Header.cs +++ b/neo.UnitTests/UT_Header.cs @@ -68,7 +68,7 @@ private void assertStandardHeaderTestVals(UInt256 val256, UInt256 merkRoot, UInt uut.NextConsensus.Should().Be(val160); uut.Witness.InvocationScript.Length.Should().Be(0); uut.Witness.Size.Should().Be(scriptVal.Size); - uut.Witness.VerificationScript[0].Should().Be(scriptVal.VerificationScript[0]); + uut.Witness.VerificationScript[0].Should().Be(scriptVal.VerificationScript[0]); } [TestMethod] @@ -83,11 +83,11 @@ public void Equals_SameHeader() { uut.Equals(uut).Should().BeTrue(); } - + [TestMethod] public void Equals_SameHash() { - Header newHeader = new Header(); + Header newHeader = new Header(); UInt256 prevHash = new UInt256(TestUtils.GetByteArray(32, 0x42)); UInt256 merkRoot; UInt160 val160; diff --git a/neo.UnitTests/UT_Helper.cs b/neo.UnitTests/UT_Helper.cs index d64d9c9173..c836219b88 100644 --- a/neo.UnitTests/UT_Helper.cs +++ b/neo.UnitTests/UT_Helper.cs @@ -15,7 +15,7 @@ public void GetHashData() TestVerifiable verifiable = new TestVerifiable(); byte[] res = verifiable.GetHashData(); res.Length.Should().Be(8); - byte[] requiredData = new byte[] { 7, 116, 101, 115, 116, 83, 116, 114 }; + byte[] requiredData = new byte[] {7, 116, 101, 115, 116, 83, 116, 114}; for (int i = 0; i < requiredData.Length; i++) { res[i].Should().Be(requiredData[i]); @@ -26,14 +26,14 @@ public void GetHashData() public void Sign() { TestVerifiable verifiable = new TestVerifiable(); - byte[] res = verifiable.Sign(new KeyPair(TestUtils.GetByteArray(32, 0x42))); + byte[] res = verifiable.Sign(new KeyPair(TestUtils.GetByteArray(32,0x42))); res.Length.Should().Be(64); } [TestMethod] public void ToScriptHash() { - byte[] testByteArray = TestUtils.GetByteArray(64, 0x42); + byte[] testByteArray = TestUtils.GetByteArray(64,0x42); UInt160 res = testByteArray.ToScriptHash(); res.Should().Be(UInt160.Parse("2d3b96ae1bcc5a585e075e3b81920210dec16302")); } diff --git a/neo.UnitTests/UT_InteropPrices.cs b/neo.UnitTests/UT_InteropPrices.cs index 1aafa91be0..818b95c8c4 100644 --- a/neo.UnitTests/UT_InteropPrices.cs +++ b/neo.UnitTests/UT_InteropPrices.cs @@ -26,7 +26,7 @@ public void NeoServiceFixedPriceWithReflection() { // testing reflection with public methods too MethodInfo GetPrice = typeof(NeoService).GetMethod("GetPrice", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(uint) }, null); - GetPrice.Invoke(uut, new object[] { "Neo.Runtime.CheckWitness".ToInteropMethodHash() }).Should().Be(200L); + GetPrice.Invoke(uut, new object[]{"Neo.Runtime.CheckWitness".ToInteropMethodHash()}).Should().Be(200L); } [TestMethod] @@ -206,38 +206,38 @@ public void StandardServiceFixedPrices() public void ApplicationEngineFixedPrices() { // ApplicationEngine.GetPriceForSysCall is protected, so we will access through reflection - MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { }, null); + MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[]{}, null); // System.Runtime.CheckWitness: f827ec8c (price is 200) - byte[] SyscallSystemRuntimeCheckWitnessHash = new byte[] { 0x68, 0x04, 0xf8, 0x27, 0xec, 0x8c }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallSystemRuntimeCheckWitnessHash = new byte[]{0x68, 0x04, 0xf8, 0x27, 0xec, 0x8c}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { ae.LoadScript(SyscallSystemRuntimeCheckWitnessHash); - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(200L); + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(200L); } // "System.Runtime.CheckWitness" (27 bytes -> 0x1b) - (price is 200) - byte[] SyscallSystemRuntimeCheckWitnessString = new byte[] { 0x68, 0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x57, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73 }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallSystemRuntimeCheckWitnessString = new byte[]{0x68, 0x1b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x57, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { ae.LoadScript(SyscallSystemRuntimeCheckWitnessString); - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(200L); + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(200L); } // System.Storage.GetContext: 9bf667ce (price is 1) - byte[] SyscallSystemStorageGetContextHash = new byte[] { 0x68, 0x04, 0x9b, 0xf6, 0x67, 0xce }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallSystemStorageGetContextHash = new byte[]{0x68, 0x04, 0x9b, 0xf6, 0x67, 0xce}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { ae.LoadScript(SyscallSystemStorageGetContextHash); - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1L); + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1L); } // System.Storage.Get: 925de831 (price is 100) - byte[] SyscallSystemStorageGetHash = new byte[] { 0x68, 0x04, 0x92, 0x5d, 0xe8, 0x31 }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallSystemStorageGetHash = new byte[]{0x68, 0x04, 0x92, 0x5d, 0xe8, 0x31}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { ae.LoadScript(SyscallSystemStorageGetHash); - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(100L); + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(100L); } } @@ -245,30 +245,30 @@ public void ApplicationEngineFixedPrices() public void ApplicationEngineVariablePrices() { // ApplicationEngine.GetPriceForSysCall is protected, so we will access through reflection - MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { }, null); + MethodInfo GetPriceForSysCall = typeof(ApplicationEngine).GetMethod("GetPriceForSysCall", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[]{}, null); // Neo.Asset.Create: 83c5c61f - byte[] SyscallAssetCreateHash = new byte[] { 0x68, 0x04, 0x83, 0xc5, 0xc6, 0x1f }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallAssetCreateHash = new byte[]{0x68, 0x04, 0x83, 0xc5, 0xc6, 0x1f}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { ae.LoadScript(SyscallAssetCreateHash); - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Asset.Renew: 78849071 (requires push 09 push 09 before) - byte[] SyscallAssetRenewHash = new byte[] { 0x59, 0x59, 0x68, 0x04, 0x78, 0x84, 0x90, 0x71 }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallAssetRenewHash = new byte[]{0x59, 0x59, 0x68, 0x04, 0x78, 0x84, 0x90, 0x71}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallAssetRenewHash); debugger.StepInto(); // push 9 debugger.StepInto(); // push 9 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(9L * 5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(9L * 5000L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash00 = new byte[] { (byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallContractCreateHash00 = new byte[]{(byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash00); @@ -276,12 +276,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash01 = new byte[] { 0x51, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallContractCreateHash01 = new byte[]{0x51, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash01); @@ -289,12 +289,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(500L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(500L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash02 = new byte[] { 0x52, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallContractCreateHash02 = new byte[]{0x52, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash02); @@ -302,12 +302,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(600L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(600L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Create: f66ca56e (requires push properties on fourth position) - byte[] SyscallContractCreateHash03 = new byte[] { 0x53, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallContractCreateHash03 = new byte[]{0x53, 0x00, 0x00, 0x00, 0x68, 0x04, 0xf6, 0x6c, 0xa5, 0x6e}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractCreateHash03); @@ -315,12 +315,12 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1000L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1000L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // Neo.Contract.Migrate: 471b6290 (requires push properties on fourth position) - byte[] SyscallContractMigrateHash00 = new byte[] { (byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0x47, 0x1b, 0x62, 0x90 }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallContractMigrateHash00 = new byte[]{(byte)ContractPropertyState.NoProperty, 0x00, 0x00, 0x00, 0x68, 0x04, 0x47, 0x1b, 0x62, 0x90}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallContractMigrateHash00); @@ -328,31 +328,31 @@ public void ApplicationEngineVariablePrices() debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 debugger.StepInto(); // push 0 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(100L * 100000000L / 100000); // assuming private ae.ratio = 100000 } // System.Storage.Put: e63f1884 (requires push key and value) - byte[] SyscallStoragePutHash = new byte[] { 0x53, 0x53, 0x00, 0x68, 0x04, 0xe6, 0x3f, 0x18, 0x84 }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallStoragePutHash = new byte[]{0x53, 0x53, 0x00, 0x68, 0x04, 0xe6, 0x3f, 0x18, 0x84}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallStoragePutHash); debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 00 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); } // System.Storage.PutEx: 73e19b3a (requires push key and value) - byte[] SyscallStoragePutExHash = new byte[] { 0x53, 0x53, 0x00, 0x68, 0x04, 0x73, 0xe1, 0x9b, 0x3a }; - using (ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero)) + byte[] SyscallStoragePutExHash = new byte[]{0x53, 0x53, 0x00, 0x68, 0x04, 0x73, 0xe1, 0x9b, 0x3a}; + using ( ApplicationEngine ae = new ApplicationEngine(TriggerType.Application, null, null, Fixed8.Zero) ) { Debugger debugger = new Debugger(ae); ae.LoadScript(SyscallStoragePutExHash); debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 03 (length 1) debugger.StepInto(); // push 00 - GetPriceForSysCall.Invoke(ae, new object[] { }).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); + GetPriceForSysCall.Invoke(ae, new object[]{}).Should().Be(1000L); //((1+1-1) / 1024 + 1) * 1000); } } } diff --git a/neo.UnitTests/UT_MinerTransaction.cs b/neo.UnitTests/UT_MinerTransaction.cs index c9a8150502..5b0d2156c3 100644 --- a/neo.UnitTests/UT_MinerTransaction.cs +++ b/neo.UnitTests/UT_MinerTransaction.cs @@ -69,7 +69,7 @@ public void ToJson() jObj["net_fee"].AsNumber().Should().Be(0); ((JArray)jObj["scripts"]).Count.Should().Be(0); - jObj["nonce"].AsNumber().Should().Be(42); + jObj["nonce"].AsNumber().Should().Be(42); } } diff --git a/neo.UnitTests/UT_PoolItem.cs b/neo.UnitTests/UT_PoolItem.cs index e7324f3b75..0d8a8bc19a 100644 --- a/neo.UnitTests/UT_PoolItem.cs +++ b/neo.UnitTests/UT_PoolItem.cs @@ -75,7 +75,7 @@ public void PoolItem_CompareTo_Hash() for (int testRuns = 0; testRuns < 30; testRuns++) { var tx1 = GenerateMockTxWithFirstByteOfHashGreaterThanOrEqualTo(0x80, new Fixed8(netFeeSatoshiFixed), sizeFixed); - var tx2 = GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(0x79, new Fixed8(netFeeSatoshiFixed), sizeFixed); + var tx2 = GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(0x79,new Fixed8(netFeeSatoshiFixed), sizeFixed); PoolItem pitem1 = new PoolItem(tx1.Object); PoolItem pitem2 = new PoolItem(tx2.Object); @@ -88,8 +88,8 @@ public void PoolItem_CompareTo_Hash() } // equal hashes should be equal - var tx3 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); - var tx4 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); + var tx3 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); + var tx4 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); PoolItem pitem3 = new PoolItem(tx3.Object); PoolItem pitem4 = new PoolItem(tx4.Object); @@ -102,8 +102,8 @@ public void PoolItem_CompareTo_Equals() { int sizeFixed = 500; int netFeeSatoshiFixed = 10; - var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); - var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] { 0x13, 0x37 }); + var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); + var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37}); PoolItem pitem1 = new PoolItem(tx1.Object); PoolItem pitem2 = new PoolItem(tx2.Object); @@ -150,7 +150,7 @@ public static Transaction GenerateClaimTx() } // Generate Mock InvocationTransaction with different sizes and prices - public static Mock MockGenerateInvocationTx(Fixed8 networkFee, int size, byte[] overrideScriptBytes = null) + public static Mock MockGenerateInvocationTx(Fixed8 networkFee, int size, byte[] overrideScriptBytes=null) { var mockTx = new Mock(); mockTx.CallBase = true; diff --git a/neo.UnitTests/UT_ProtocolHandlerMailbox.cs b/neo.UnitTests/UT_ProtocolHandlerMailbox.cs index 7c8937db27..8cf859567d 100644 --- a/neo.UnitTests/UT_ProtocolHandlerMailbox.cs +++ b/neo.UnitTests/UT_ProtocolHandlerMailbox.cs @@ -15,7 +15,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_ProtocolHandlerMailbox : TestKit + public class UT_ProtocolHandlerMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism @@ -57,14 +57,14 @@ public void ProtocolHandlerMailbox_Test_IsHighPriority() uut.IsHighPriority(Message.Create("mempool", s)).Should().Be(false); uut.IsHighPriority(Message.Create("ping", s)).Should().Be(false); uut.IsHighPriority(Message.Create("pong", s)).Should().Be(false); - uut.IsHighPriority(Message.Create("tx", s)).Should().Be(false); + uut.IsHighPriority(Message.Create("tx", s)).Should().Be(false); uut.IsHighPriority(Message.Create("verack", s)).Should().Be(true); uut.IsHighPriority(Message.Create("version", s)).Should().Be(true); uut.IsHighPriority(Message.Create("alert", s)).Should().Be(true); uut.IsHighPriority(Message.Create("merkleblock", s)).Should().Be(false); uut.IsHighPriority(Message.Create("notfound", s)).Should().Be(false); uut.IsHighPriority(Message.Create("reject", s)).Should().Be(false); - + // any random command should not have priority uut.IsHighPriority(Message.Create("_", s)).Should().Be(false); @@ -91,99 +91,99 @@ public void ProtocolHandlerMailbox_Test_ShallDrop() // Version (no drop) msg = Message.Create("version", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // Verack (no drop) msg = Message.Create("verack", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); //connectivity // GetAddr (drop) msg = Message.Create("getaddr", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); // Addr (no drop) msg = Message.Create("addr", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // Ping (no drop) msg = Message.Create("ping", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // Pong (no drop) msg = Message.Create("pong", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); //synchronization // GetHeaders (drop) msg = Message.Create("getheaders", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); // Headers (no drop) msg = Message.Create("headers", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // GetBlocks (drop) msg = Message.Create("getblocks", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); // Mempool (drop) msg = Message.Create("mempool", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); // Inv (no drop) msg = Message.Create("inv", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // GetData (drop) msg = Message.Create("getdata", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); // NotFound (no drop) msg = Message.Create("notfound", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // Transaction (no drop) msg = Message.Create("tx", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // Block (no drop) msg = Message.Create("block", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // Consensus (no drop) msg = Message.Create("consensus", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // Reject (no drop) msg = Message.Create("reject", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); //SPV protocol // FilterLoad (no drop) msg = Message.Create("filterload", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // FilterAdd (no drop) msg = Message.Create("filteradd", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // FilterClear (no drop) msg = Message.Create("filterclear", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // MerkleBlock (no drop) msg = Message.Create("merkleblock", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); //others // Alert (no drop) msg = Message.Create("alert", s); uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); // any random command should not be dropped uut.ShallDrop(Message.Create("_", s), emptyQueue).Should().Be(false); diff --git a/neo.UnitTests/UT_RemoteNodeMailbox.cs b/neo.UnitTests/UT_RemoteNodeMailbox.cs index b6dad1e6cb..c3e670310f 100644 --- a/neo.UnitTests/UT_RemoteNodeMailbox.cs +++ b/neo.UnitTests/UT_RemoteNodeMailbox.cs @@ -15,7 +15,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_RemoteNodeMailbox : TestKit + public class UT_RemoteNodeMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism diff --git a/neo.UnitTests/UT_SpentCointState.cs b/neo.UnitTests/UT_SpentCointState.cs index df37c3cf9f..e71e93fb4d 100644 --- a/neo.UnitTests/UT_SpentCointState.cs +++ b/neo.UnitTests/UT_SpentCointState.cs @@ -1,5 +1,6 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.IO; using Neo.Ledger; using System.Collections.Generic; using System.IO; @@ -24,6 +25,31 @@ public void TransactionHash_Get() uut.TransactionHash.Should().BeNull(); } + [TestMethod] + public void TestFromReplica() + { + uut.Items = new Dictionary(); + uut.Items.Add(1, 3); + + var a = ((ICloneable)uut).Clone(); + var b = new SpentCoinState(); + + ((ICloneable)b).FromReplica(uut); + + CollectionAssert.AreEqual(a.Items.Keys, uut.Items.Keys); + CollectionAssert.AreEqual(a.Items.Values, uut.Items.Values); + CollectionAssert.AreEqual(b.Items.Keys, uut.Items.Keys); + CollectionAssert.AreEqual(b.Items.Values, uut.Items.Values); + + a.Items.Clear(); + b.Items.Clear(); + + CollectionAssert.AreNotEqual(a.Items.Keys, uut.Items.Keys); + CollectionAssert.AreNotEqual(b.Items.Keys, uut.Items.Keys); + CollectionAssert.AreNotEqual(a.Items.Values, uut.Items.Values); + CollectionAssert.AreNotEqual(b.Items.Values, uut.Items.Values); + } + [TestMethod] public void TransactionHash_Set() { @@ -98,8 +124,8 @@ private void setupSpentCoinStateWithValues(SpentCoinState spentCoinState, out UI [TestMethod] public void DeserializeSCS() { - byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 }; - + byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 }; + using (Stream stream = new MemoryStream(dataArray)) { using (BinaryReader reader = new BinaryReader(stream)) diff --git a/neo.UnitTests/UT_StorageItem.cs b/neo.UnitTests/UT_StorageItem.cs index 90810f6705..5174d23240 100644 --- a/neo.UnitTests/UT_StorageItem.cs +++ b/neo.UnitTests/UT_StorageItem.cs @@ -27,7 +27,7 @@ public void Value_Get() [TestMethod] public void Value_Set() { - byte[] val = new byte[] { 0x42, 0x32 }; + byte[] val = new byte[] { 0x42, 0x32}; uut.Value = val; uut.Value.Length.Should().Be(2); uut.Value[0].Should().Be(val[0]); @@ -56,7 +56,7 @@ public void Clone() StorageItem newSi = ((ICloneable)uut).Clone(); newSi.Value.Length.Should().Be(10); newSi.Value[0].Should().Be(0x42); - for (int i = 1; i < 10; i++) + for (int i=1; i<10; i++) { newSi.Value[i].Should().Be(0x20); } diff --git a/neo.UnitTests/UT_StorageKey.cs b/neo.UnitTests/UT_StorageKey.cs index 664b1ae664..1ba8d61d26 100644 --- a/neo.UnitTests/UT_StorageKey.cs +++ b/neo.UnitTests/UT_StorageKey.cs @@ -79,7 +79,7 @@ public void Equals_DiffHash_SameKey() StorageKey newSk = new StorageKey(); newSk.ScriptHash = val; newSk.Key = keyVal; - uut.ScriptHash = new UInt160(TestUtils.GetByteArray(20, 0x88)); + uut.ScriptHash = new UInt160(TestUtils.GetByteArray(20, 0x88)); uut.Key = keyVal; uut.Equals(newSk).Should().BeFalse(); @@ -95,7 +95,7 @@ public void Equals_SameHash_DiffKey() newSk.ScriptHash = val; newSk.Key = keyVal; uut.ScriptHash = val; - uut.Key = TestUtils.GetByteArray(10, 0x88); + uut.Key = TestUtils.GetByteArray(10, 0x88); uut.Equals(newSk).Should().BeFalse(); } diff --git a/neo.UnitTests/UT_TaskManagerMailbox.cs b/neo.UnitTests/UT_TaskManagerMailbox.cs index 22f8fdd708..d460b7ca41 100644 --- a/neo.UnitTests/UT_TaskManagerMailbox.cs +++ b/neo.UnitTests/UT_TaskManagerMailbox.cs @@ -12,7 +12,7 @@ namespace Neo.UnitTests { [TestClass] - public class UT_TaskManagerMailbox : TestKit + public class UT_TaskManagerMailbox : TestKit { private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism @@ -42,12 +42,12 @@ public void Test_IsHighPriority() // low priority // -> NewTasks: generic InvPayload - uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload() }).Should().Be(false); + uut.IsHighPriority(new TaskManager.NewTasks{ Payload = new InvPayload() }).Should().Be(false); // high priority // -> NewTasks: payload Block or Consensus - uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Block } }).Should().Be(true); - uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Consensus } }).Should().Be(true); + uut.IsHighPriority(new TaskManager.NewTasks{ Payload = new InvPayload{ Type = InventoryType.Block } }).Should().Be(true); + uut.IsHighPriority(new TaskManager.NewTasks{ Payload = new InvPayload{ Type = InventoryType.Consensus } }).Should().Be(true); // any random object should not have priority object obj = null; diff --git a/neo.UnitTests/UT_TransactionAttribute.cs b/neo.UnitTests/UT_TransactionAttribute.cs index 4d3b116746..bf79f6ac01 100644 --- a/neo.UnitTests/UT_TransactionAttribute.cs +++ b/neo.UnitTests/UT_TransactionAttribute.cs @@ -115,7 +115,7 @@ public void ToJson() JObject jObj = uut.ToJson(); jObj.Should().NotBeNull(); jObj["usage"].AsString().Should().Be("ECDH02"); - jObj["data"].AsString().Should().Be("42202020202020202020"); + jObj["data"].AsString().Should().Be("42202020202020202020"); } } } diff --git a/neo.UnitTests/UT_Witness.cs b/neo.UnitTests/UT_Witness.cs index 64e94f649c..26dc8b84dd 100644 --- a/neo.UnitTests/UT_Witness.cs +++ b/neo.UnitTests/UT_Witness.cs @@ -28,7 +28,7 @@ public void InvocationScript_Set() byte[] dataArray = new byte[] { 0, 32, 32, 20, 32, 32 }; uut.InvocationScript = dataArray; uut.InvocationScript.Length.Should().Be(6); - Assert.AreEqual(uut.InvocationScript.ToHexString(), "002020142020"); + Assert.AreEqual(uut.InvocationScript.ToHexString(), "002020142020"); } private void setupWitnessWithValues(Witness uut, int lenghtInvocation, int lengthVerification, out byte[] invocationScript, out byte[] verificationScript) @@ -68,7 +68,7 @@ public void ToJson() JObject json = uut.ToJson(); Assert.IsTrue(json.ContainsProperty("invocation")); - Assert.IsTrue(json.ContainsProperty("verification")); + Assert.IsTrue(json.ContainsProperty("verification")); Assert.AreEqual(json["invocation"].AsString(), "2020"); Assert.AreEqual(json["verification"].AsString(), "202020"); diff --git a/neo/Consensus/ConsensusContext.cs b/neo/Consensus/ConsensusContext.cs index 6a3a35df5c..1f96f0d0ac 100644 --- a/neo/Consensus/ConsensusContext.cs +++ b/neo/Consensus/ConsensusContext.cs @@ -305,7 +305,7 @@ public void Reset(byte viewNumber) Timestamp = 0; TransactionHashes = null; PreparationPayloads = new ConsensusPayload[Validators.Length]; - if (MyIndex >= 0) LastSeenMessage[MyIndex] = (int)BlockIndex; + if (MyIndex >= 0) LastSeenMessage[MyIndex] = (int) BlockIndex; _header = null; } diff --git a/neo/Consensus/ConsensusService.cs b/neo/Consensus/ConsensusService.cs index 6a63d06f2a..79e5599603 100644 --- a/neo/Consensus/ConsensusService.cs +++ b/neo/Consensus/ConsensusService.cs @@ -240,9 +240,9 @@ private void OnCommitReceived(ConsensusPayload payload, Commit commit) // this function increases existing timer (never decreases) with a value proportional to `maxDelayInBlockTimes`*`Blockchain.SecondsPerBlock` private void ExtendTimerByFactor(int maxDelayInBlockTimes) { - TimeSpan nextDelay = expected_delay - (TimeProvider.Current.UtcNow - clock_started) + TimeSpan.FromMilliseconds(maxDelayInBlockTimes * Blockchain.SecondsPerBlock * 1000.0 / context.M()); - if (!context.WatchOnly() && !context.ViewChanging() && !context.CommitSent() && (nextDelay > TimeSpan.Zero)) - ChangeTimer(nextDelay); + TimeSpan nextDelay = expected_delay - (TimeProvider.Current.UtcNow - clock_started) + TimeSpan.FromMilliseconds(maxDelayInBlockTimes*Blockchain.SecondsPerBlock * 1000.0 / context.M()); + if (!context.WatchOnly() && !context.ViewChanging() && !context.CommitSent() && (nextDelay > TimeSpan.Zero)) + ChangeTimer(nextDelay); } private void OnConsensusPayload(ConsensusPayload payload) @@ -271,7 +271,7 @@ private void OnConsensusPayload(ConsensusPayload payload) { return; } - context.LastSeenMessage[payload.ValidatorIndex] = (int)payload.BlockIndex; + context.LastSeenMessage[payload.ValidatorIndex] = (int) payload.BlockIndex; foreach (IP2PPlugin plugin in Plugin.P2PPlugins) if (!plugin.OnConsensusMessage(payload)) return; diff --git a/neo/Consensus/Helper.cs b/neo/Consensus/Helper.cs index 27050a4a11..539caa73af 100644 --- a/neo/Consensus/Helper.cs +++ b/neo/Consensus/Helper.cs @@ -22,7 +22,7 @@ internal static class Helper [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountCommitted(this IConsensusContext context) => context.CommitPayloads.Count(p => p != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountFailed(this IConsensusContext context) => context.LastSeenMessage.Count(p => p < (((int)context.BlockIndex) - 1)); + public static int CountFailed(this IConsensusContext context) => context.LastSeenMessage.Count(p => p < (((int) context.BlockIndex) - 1)); // Consensus States [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/neo/Consensus/RecoveryRequest.cs b/neo/Consensus/RecoveryRequest.cs index 971b49a324..3152264894 100644 --- a/neo/Consensus/RecoveryRequest.cs +++ b/neo/Consensus/RecoveryRequest.cs @@ -13,7 +13,7 @@ public class RecoveryRequest : ConsensusMessage public override int Size => base.Size + sizeof(uint); //Timestamp - + public RecoveryRequest() : base(ConsensusMessageType.RecoveryRequest) { } public override void Deserialize(BinaryReader reader) diff --git a/neo/IO/Data/LevelDB/Native.cs b/neo/IO/Data/LevelDB/Native.cs index b51460e799..fc3ccd6387 100644 --- a/neo/IO/Data/LevelDB/Native.cs +++ b/neo/IO/Data/LevelDB/Native.cs @@ -232,10 +232,10 @@ public static extern IntPtr /* leveldb_comparator_t* */ leveldb_comparator_create( IntPtr /* void* */ state, IntPtr /* void (*)(void*) */ destructor, - IntPtr + IntPtr /* int (*compare)(void*, const char* a, size_t alen, - const char* b, size_t blen) */ + const char* b, size_t blen) */ compare, IntPtr /* const char* (*)(void*) */ name); diff --git a/neo/Ledger/Blockchain.cs b/neo/Ledger/Blockchain.cs index 366c9633a3..fa5aa2d185 100644 --- a/neo/Ledger/Blockchain.cs +++ b/neo/Ledger/Blockchain.cs @@ -313,7 +313,7 @@ private RelayResultReason OnNewBlock(Block block) block_cache_unverified.Remove(blockToPersist.Index); Persist(blockToPersist); - if (blocksPersisted++ < blocksToPersistList.Count - (2 + Math.Max(0, (15 - SecondsPerBlock)))) continue; + if (blocksPersisted++ < blocksToPersistList.Count - (2 + Math.Max(0,(15 - SecondsPerBlock)))) continue; // Empirically calibrated for relaying the most recent 2 blocks persisted with 15s network // Increase in the rate of 1 block per second in configurations with faster blocks diff --git a/neo/Ledger/MemoryPool.cs b/neo/Ledger/MemoryPool.cs index 89933e7021..9c367fd8fc 100644 --- a/neo/Ledger/MemoryPool.cs +++ b/neo/Ledger/MemoryPool.cs @@ -19,12 +19,12 @@ public class MemoryPool : IReadOnlyCollection private const int BlocksTillRebroadcastHighPriorityPoolTx = 10; private int RebroadcastMultiplierThreshold => Capacity / 10; - private static readonly double MaxSecondsToReverifyHighPrioTx = (double)Blockchain.SecondsPerBlock / 3; - private static readonly double MaxSecondsToReverifyLowPrioTx = (double)Blockchain.SecondsPerBlock / 5; + private static readonly double MaxSecondsToReverifyHighPrioTx = (double) Blockchain.SecondsPerBlock / 3; + private static readonly double MaxSecondsToReverifyLowPrioTx = (double) Blockchain.SecondsPerBlock / 5; // These two are not expected to be hit, they are just safegaurds. - private static readonly double MaxSecondsToReverifyHighPrioTxPerIdle = (double)Blockchain.SecondsPerBlock / 15; - private static readonly double MaxSecondsToReverifyLowPrioTxPerIdle = (double)Blockchain.SecondsPerBlock / 30; + private static readonly double MaxSecondsToReverifyHighPrioTxPerIdle = (double) Blockchain.SecondsPerBlock / 15; + private static readonly double MaxSecondsToReverifyLowPrioTxPerIdle = (double) Blockchain.SecondsPerBlock / 30; private readonly NeoSystem _system; @@ -211,9 +211,9 @@ public IEnumerable GetSortedVerifiedTransactions() _txRwLock.EnterReadLock(); try { - return _sortedHighPrioTransactions.Reverse().Select(p => p.Tx) - .Concat(_sortedLowPrioTransactions.Reverse().Select(p => p.Tx)) - .ToArray(); + return _sortedHighPrioTransactions.Reverse().Select(p => p.Tx) + .Concat(_sortedLowPrioTransactions.Reverse().Select(p => p.Tx)) + .ToArray(); } finally {