From 1f3b1dd1710416275b0a9524eaf418564ac205f9 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 10:56:51 +0200 Subject: [PATCH 01/27] Speed up --- neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs | 62 ++++++++++---------- neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs | 3 +- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs b/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs index e2f4ca13f4..ed84b1bad3 100644 --- a/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs +++ b/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs @@ -11,46 +11,46 @@ namespace Neo.UnitTests.Wallets.NEP6 [TestClass] public class UT_NEP6Account { - NEP6Account account; - UInt160 hash; - NEP6Wallet wallet; - private static string nep2; - private static KeyPair keyPair; + NEP6Account _account; + UInt160 _hash; + NEP6Wallet _wallet; + private static string _nep2; + private static KeyPair _keyPair; [ClassInitialize] public static void ClassSetup(TestContext context) { byte[] privateKey = { 0x01,0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; - keyPair = new KeyPair(privateKey); - nep2 = keyPair.Export("Satoshi", 0, 0, 0); + _keyPair = new KeyPair(privateKey); + _nep2 = _keyPair.Export("Satoshi", 0, 0, 0); } [TestInitialize] public void TestSetup() { - wallet = TestUtils.GenerateTestWallet(); + _wallet = TestUtils.GenerateTestWallet(); byte[] array1 = { 0x01 }; - hash = new UInt160(Crypto.Default.Hash160(array1)); - account = new NEP6Account(wallet, hash); + _hash = new UInt160(Crypto.Default.Hash160(array1)); + _account = new NEP6Account(_wallet, _hash); } [TestMethod] public void TestConstructorWithNep2Key() { - account.ScriptHash.Should().Be(hash); - account.Decrypted.Should().BeTrue(); - account.HasKey.Should().BeFalse(); + _account.ScriptHash.Should().Be(_hash); + _account.Decrypted.Should().BeTrue(); + _account.HasKey.Should().BeFalse(); } [TestMethod] public void TestConstructorWithKeyPair() { - NEP6Wallet wallet = new NEP6Wallet("a"); + var wallet = TestUtils.GenerateTestWallet(); byte[] array1 = { 0x01 }; var hash = new UInt160(Crypto.Default.Hash160(array1)); string password = "hello world"; - NEP6Account account = new NEP6Account(wallet, hash, keyPair, password); + NEP6Account account = new NEP6Account(wallet, hash, _keyPair, password); account.ScriptHash.Should().Be(hash); account.Decrypted.Should().BeTrue(); account.HasKey.Should().BeTrue(); @@ -67,7 +67,7 @@ public void TestFromJson() json["lock"] = false; json["contract"] = null; json["extra"] = null; - NEP6Account account = NEP6Account.FromJson(json, wallet); + NEP6Account account = NEP6Account.FromJson(json, _wallet); account.ScriptHash.Should().Be("ARxgjcH2K1yeW5f5ryuRQNaBzSa9TZzmVS".ToScriptHash()); account.Label.Should().BeNull(); account.IsDefault.Should().BeTrue(); @@ -78,7 +78,7 @@ public void TestFromJson() json["key"] = "6PYRjVE1gAbCRyv81FTiFz62cxuPGw91vMjN4yPa68bnoqJtioreTznezn"; json["label"] = "label"; - account = NEP6Account.FromJson(json, wallet); + account = NEP6Account.FromJson(json, _wallet); account.Label.Should().Be("label"); account.HasKey.Should().BeTrue(); } @@ -86,18 +86,18 @@ public void TestFromJson() [TestMethod] public void TestGetKey() { - account.GetKey().Should().BeNull(); - wallet.Unlock("Satoshi"); - account = new NEP6Account(wallet, hash, nep2); - account.GetKey().Should().Be(keyPair); + _account.GetKey().Should().BeNull(); + _wallet.Unlock("Satoshi"); + _account = new NEP6Account(_wallet, _hash, _nep2); + _account.GetKey().Should().Be(_keyPair); } [TestMethod] public void TestGetKeyWithString() { - account.GetKey("Satoshi").Should().BeNull(); - account = new NEP6Account(wallet, hash, nep2); - account.GetKey("Satoshi").Should().Be(keyPair); + _account.GetKey("Satoshi").Should().BeNull(); + _account = new NEP6Account(_wallet, _hash, _nep2); + _account.GetKey("Satoshi").Should().Be(_keyPair); } [TestMethod] @@ -114,8 +114,8 @@ public void TestToJson() }; nep6contract["parameters"] = array; nep6contract["deployed"] = false; - account.Contract = NEP6Contract.FromJson(nep6contract); - JObject json = account.ToJson(); + _account.Contract = NEP6Contract.FromJson(nep6contract); + JObject json = _account.ToJson(); json["address"].Should().Equals("AZk5bAanTtD6AvpeesmYgL8CLRYUt5JQsX"); json["label"].Should().BeNull(); json["isDefault"].ToString().Should().Be("false"); @@ -124,17 +124,17 @@ public void TestToJson() json["contract"]["script"].ToString().Should().Be("\"2103603f3880eb7aea0ad4500893925e4a42fea48a44ee6f898a10b3c7ce05d2a267ac\""); json["extra"].Should().BeNull(); - account.Contract = null; - json = account.ToJson(); + _account.Contract = null; + json = _account.ToJson(); json["contract"].Should().BeNull(); } [TestMethod] public void TestVerifyPassword() { - account = new NEP6Account(wallet, hash, nep2); - account.VerifyPassword("Satoshi").Should().BeTrue(); - account.VerifyPassword("b").Should().BeFalse(); + _account = new NEP6Account(_wallet, _hash, _nep2); + _account.VerifyPassword("Satoshi").Should().BeTrue(); + _account.VerifyPassword("b").Should().BeFalse(); } } } diff --git a/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs b/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs index 6a8c16dbb6..d78111d8f4 100644 --- a/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs +++ b/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs @@ -326,11 +326,12 @@ public void TestMigrate() string path = GetRandomPath(); UserWallet uw = UserWallet.Create(path, "123"); uw.CreateAccount(keyPair.PrivateKey); - string npath = Path.Combine(path, "w.json"); + string npath = CreateWalletFile(); // Speedup with 0 Scrypt values NEP6Wallet nw = NEP6Wallet.Migrate(npath, path, "123"); bool result = nw.Contains(testScriptHash); Assert.AreEqual(true, result); if (File.Exists(path)) File.Delete(path); + if (File.Exists(npath)) File.Delete(npath); } [TestMethod] From 45917456c8ad302cb850f64f8c2a2787d7d729bc Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 10:59:27 +0200 Subject: [PATCH 02/27] Update UT_NEP6Wallet.cs --- neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs b/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs index d78111d8f4..de902a115e 100644 --- a/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs +++ b/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs @@ -326,7 +326,7 @@ public void TestMigrate() string path = GetRandomPath(); UserWallet uw = UserWallet.Create(path, "123"); uw.CreateAccount(keyPair.PrivateKey); - string npath = CreateWalletFile(); // Speedup with 0 Scrypt values + string npath = CreateWalletFile(); // Scrypt test values NEP6Wallet nw = NEP6Wallet.Migrate(npath, path, "123"); bool result = nw.Contains(testScriptHash); Assert.AreEqual(true, result); From e905be3d5277676f09efb113d2c43fa3bc229323 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 11:21:17 +0200 Subject: [PATCH 03/27] Speed ut --- .../Network/P2P/Payloads/UT_Witness.cs | 78 +++++-------------- 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index 5114d524b2..65dee6d2b3 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -3,12 +3,10 @@ using Neo.IO; using Neo.IO.Json; using Neo.Network.P2P.Payloads; -using Neo.Persistence; using Neo.SmartContract; using Neo.Wallets; using Neo.Wallets.NEP6; using System; -using System.IO; using System.Linq; namespace Neo.UnitTests.Network.P2P.Payloads @@ -16,53 +14,13 @@ namespace Neo.UnitTests.Network.P2P.Payloads [TestClass] public class UT_Witness { - class DummyVerificable : IVerifiable - { - private UInt160 _hash; - - public Witness[] Witnesses { get; set; } - - public int Size => 1; - - public DummyVerificable(UInt160 hash) - { - _hash = hash; - } - - public void Deserialize(BinaryReader reader) - { - DeserializeUnsigned(reader); - Witnesses = reader.ReadSerializableArray(16); - } - - public void DeserializeUnsigned(BinaryReader reader) - { - reader.ReadByte(); - } - - public UInt160[] GetScriptHashesForVerifying(Snapshot snapshot) - { - return new UInt160[] { _hash }; - } - - public void Serialize(BinaryWriter writer) - { - SerializeUnsigned(writer); - writer.Write(Witnesses); - } - - public void SerializeUnsigned(BinaryWriter writer) - { - writer.Write((byte)1); - } - } - Witness uut; [TestInitialize] public void TestSetup() { uut = new Witness(); + } [TestMethod] @@ -73,12 +31,6 @@ public void InvocationScript_Get() private Witness PrepareDummyWitness(int maxAccounts) { - var store = TestBlockchain.GetStore(); - var wallet = TestUtils.GenerateTestWallet(); - var snapshot = store.GetSnapshot(); - - // Prepare - var address = new WalletAccount[maxAccounts]; var wallets = new NEP6Wallet[maxAccounts]; var walletsUnlocks = new IDisposable[maxAccounts]; @@ -101,7 +53,19 @@ private Witness PrepareDummyWitness(int maxAccounts) // Sign - var data = new ContractParametersContext(new DummyVerificable(multiSignContract.ScriptHash)); + var data = new ContractParametersContext(new Transaction() + { + Cosigners = new Cosigner[0], + Sender = multiSignContract.ScriptHash, + Attributes = new TransactionAttribute[0], + NetworkFee = 0, + Nonce = 0, + Script = new byte[0], + SystemFee = 0, + ValidUntilBlock = 0, + Version = 0, + Witnesses = new Witness[0] + }); for (int x = 0; x < maxAccounts; x++) { @@ -151,7 +115,7 @@ public void InvocationScript_Set() Assert.AreEqual(uut.InvocationScript.ToHexString(), "002020142020"); } - private void setupWitnessWithValues(Witness uut, int lenghtInvocation, int lengthVerification, out byte[] invocationScript, out byte[] verificationScript) + private void SetupWitnessWithValues(Witness uut, int lenghtInvocation, int lengthVerification, out byte[] invocationScript, out byte[] verificationScript) { invocationScript = TestUtils.GetByteArray(lenghtInvocation, 0x20); verificationScript = TestUtils.GetByteArray(lengthVerification, 0x20); @@ -162,9 +126,7 @@ private void setupWitnessWithValues(Witness uut, int lenghtInvocation, int lengt [TestMethod] public void SizeWitness_Small_Arrary() { - byte[] invocationScript; - byte[] verificationScript; - setupWitnessWithValues(uut, 252, 253, out invocationScript, out verificationScript); + SetupWitnessWithValues(uut, 252, 253, out _, out _); uut.Size.Should().Be(509); // (1 + 252*1) + (1 + 2 + 253*1) } @@ -172,9 +134,7 @@ public void SizeWitness_Small_Arrary() [TestMethod] public void SizeWitness_Large_Arrary() { - byte[] invocationScript; - byte[] verificationScript; - setupWitnessWithValues(uut, 65535, 65536, out invocationScript, out verificationScript); + SetupWitnessWithValues(uut, 65535, 65536, out _, out _); uut.Size.Should().Be(131079); // (1 + 2 + 65535*1) + (1 + 4 + 65536*1) } @@ -182,9 +142,7 @@ public void SizeWitness_Large_Arrary() [TestMethod] public void ToJson() { - byte[] invocationScript; - byte[] verificationScript; - setupWitnessWithValues(uut, 2, 3, out invocationScript, out verificationScript); + SetupWitnessWithValues(uut, 2, 3, out _, out _); JObject json = uut.ToJson(); Assert.IsTrue(json.ContainsProperty("invocation")); From 420c8ecce2c2bcf31110c78da61e627114d819c0 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 11:30:05 +0200 Subject: [PATCH 04/27] More speed up --- neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs | 2 +- neo/IO/Caching/Cache.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs b/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs index 6c24fcb922..f88412af97 100644 --- a/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs +++ b/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs @@ -32,7 +32,7 @@ public void TestGenerateSignature() { ECDsa sa = new ECDsa(key.PrivateKey, key.PublicKey.Curve); byte[] message = System.Text.Encoding.Default.GetBytes("HelloWorld"); - for (int i = 0; i < 30; i++) + for (int i = 0; i < 10; i++) { BigInteger[] result = sa.GenerateSignature(message); result.Length.Should().Be(2); diff --git a/neo/IO/Caching/Cache.cs b/neo/IO/Caching/Cache.cs index b5095231f3..a5e0e22f57 100644 --- a/neo/IO/Caching/Cache.cs +++ b/neo/IO/Caching/Cache.cs @@ -92,7 +92,7 @@ private void AddInternal(TKey key, TValue item) if (InnerDictionary.Count >= max_capacity) { //TODO: Perform a performance test on the PLINQ query to determine which algorithm is better here (parallel or not) - foreach (CacheItem item_del in InnerDictionary.Values.AsParallel().OrderBy(p => p.Time).Take(InnerDictionary.Count - max_capacity + 1)) + foreach (CacheItem item_del in InnerDictionary.Values.OrderBy(p => p.Time).Take(InnerDictionary.Count - max_capacity + 1)) { RemoveInternal(item_del); } From f8854c850c8be0dc795e79947216059d28723788 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 11:34:27 +0200 Subject: [PATCH 05/27] Format --- neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index 65dee6d2b3..edac5ec68e 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -20,7 +20,7 @@ public class UT_Witness public void TestSetup() { uut = new Witness(); - + } [TestMethod] From 8d996439d7cf9a029a2b5f94dc8f33c2745a51ea Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 11:35:12 +0200 Subject: [PATCH 06/27] Remove blank line --- neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index edac5ec68e..1ef1e2d120 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -20,7 +20,6 @@ public class UT_Witness public void TestSetup() { uut = new Witness(); - } [TestMethod] From 789c461bed8afb47f45b7062c18047321d55a889 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 11:39:57 +0200 Subject: [PATCH 07/27] Reduce travis verbosity --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f08f8110bb..11e1f77248 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,10 +27,10 @@ before_script: script: | dotnet restore if [[ "$TEST_SUITE" == cultures ]]; then - dotnet test + dotnet test -v m else find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild - dotnet test -v n --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover fi after_success: | if [[ "$TEST_SUITE" == "without-cultures" ]]; then From 6dc60d6454e5f0a951f28ecb57662a670aa7da0e Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 12:09:47 +0200 Subject: [PATCH 08/27] Coverage only on linux --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 11e1f77248..059dcac68a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ script: | dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover fi after_success: | - if [[ "$TEST_SUITE" == "without-cultures" ]]; then + if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)" bash <(curl -s https://codecov.io/bash) -v fi From 097fc633d22eadf8291187155a781b0ef509555a Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 12:17:58 +0200 Subject: [PATCH 09/27] CollectCoverage only if is needed --- .travis.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 059dcac68a..5782662c21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,14 +26,20 @@ before_script: - cd neo.UnitTests script: | dotnet restore - if [[ "$TEST_SUITE" == cultures ]]; then + if [[ "$TEST_SUITE" == "cultures" ]]; then dotnet test -v m else - find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild - dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then + # Calculate coverage + find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild + dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + else + dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures + fi fi after_success: | - if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then + if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then + # Send coverage echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)" bash <(curl -s https://codecov.io/bash) -v fi From 5104726499134dad2ec7657d4f5c711680a84bd0 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 12:20:01 +0200 Subject: [PATCH 10/27] Update .travis.yml --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5782662c21..7eb2844d05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,10 +30,11 @@ script: | dotnet test -v m else if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then - # Calculate coverage + # Test & Calculate coverage find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover else + # Only test dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures fi fi From c5d164bf529c29ab00045cbe0f92af3013669fd8 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 12:53:50 +0200 Subject: [PATCH 11/27] Already build --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7eb2844d05..9340905e63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,15 +27,15 @@ before_script: script: | dotnet restore if [[ "$TEST_SUITE" == "cultures" ]]; then - dotnet test -v m + dotnet test -v m --no-build else if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then # Test & Calculate coverage find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild - dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet test -v m --no-build --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover else # Only test - dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v m --no-build --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures fi fi after_success: | From 61786c2f556ec5e2077bb81be7ed4774aafd510e Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 13:11:59 +0200 Subject: [PATCH 12/27] no-restore --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9340905e63..5334ebd9f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,15 +27,15 @@ before_script: script: | dotnet restore if [[ "$TEST_SUITE" == "cultures" ]]; then - dotnet test -v m --no-build + dotnet test -v m --no-restore else if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then # Test & Calculate coverage find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild - dotnet test -v m --no-build --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet test -v m --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover else # Only test - dotnet test -v m --no-build --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v m --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures fi fi after_success: | From 2842660ac20b2491a0e64f819548fb6748a22e6a Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 13:17:43 +0200 Subject: [PATCH 13/27] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5334ebd9f2..ab1016c642 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ before_script: script: | dotnet restore if [[ "$TEST_SUITE" == "cultures" ]]; then - dotnet test -v m --no-restore + dotnet test -v m --no-restore --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures else if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then # Test & Calculate coverage From 2f496dd206f1910c6ba14944ed2c672cbb45bbb0 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 13:35:44 +0200 Subject: [PATCH 14/27] Back verbosity --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab1016c642..f7d6740aa4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,18 +24,18 @@ before_script: - echo "Checking format..." - dotnet format --check --dry-run -w . -v diagnostic # check C# formatting for neo.sln - cd neo.UnitTests + - dotnet restore script: | - dotnet restore if [[ "$TEST_SUITE" == "cultures" ]]; then - dotnet test -v m --no-restore --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v n --no-restore --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures else if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then # Test & Calculate coverage find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild - dotnet test -v m --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet test -v n --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover else # Only test - dotnet test -v m --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v n --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures fi fi after_success: | From 7183f286823b42f224894e7678e9c21203326257 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 13:52:51 +0200 Subject: [PATCH 15/27] Update netcore version --- neo.UnitTests/UT_Culture.cs | 11 ++++++++--- neo.UnitTests/neo.UnitTests.csproj | 10 +++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/neo.UnitTests/UT_Culture.cs b/neo.UnitTests/UT_Culture.cs index 37a44b24ef..a16de9717a 100644 --- a/neo.UnitTests/UT_Culture.cs +++ b/neo.UnitTests/UT_Culture.cs @@ -1,9 +1,9 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Collections.Generic; +using System.Collections; using System.Globalization; using System.Linq; using System.Reflection; -using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Neo.UnitTests { @@ -83,7 +83,12 @@ where t.GetCustomAttribute() != null && t.GetCustomAttribute public class UnitTestContext : TestContext { - public override IDictionary Properties => throw new NotImplementedException(); + public override IDictionary Properties => throw new NotImplementedException(); + + public override void AddResultFile(string fileName) + { + Console.WriteLine(fileName); + } public override void WriteLine(string message) { diff --git a/neo.UnitTests/neo.UnitTests.csproj b/neo.UnitTests/neo.UnitTests.csproj index 4cbc7f4164..0215135b1b 100644 --- a/neo.UnitTests/neo.UnitTests.csproj +++ b/neo.UnitTests/neo.UnitTests.csproj @@ -1,8 +1,8 @@ - + Exe - netcoreapp2.0 + netcoreapp2.2 Neo.UnitTests Neo.UnitTests true @@ -16,9 +16,9 @@ - - - + + + From 67d6dc04fbd563e165f68d86299bc1d10320dab7 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 13:54:00 +0200 Subject: [PATCH 16/27] Remove BOM --- neo.UnitTests/neo.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo.UnitTests/neo.UnitTests.csproj b/neo.UnitTests/neo.UnitTests.csproj index 0215135b1b..932aeac49c 100644 --- a/neo.UnitTests/neo.UnitTests.csproj +++ b/neo.UnitTests/neo.UnitTests.csproj @@ -1,4 +1,4 @@ - + Exe From ec8f77cf4a219b53a83cb0d241b1eadff64d6f21 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 14:04:12 +0200 Subject: [PATCH 17/27] Update nugets --- neo.UnitTests/neo.UnitTests.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neo.UnitTests/neo.UnitTests.csproj b/neo.UnitTests/neo.UnitTests.csproj index 932aeac49c..2da1ba4968 100644 --- a/neo.UnitTests/neo.UnitTests.csproj +++ b/neo.UnitTests/neo.UnitTests.csproj @@ -15,13 +15,13 @@ - + - - - + + + From 5f5e2565a0a89c75f048c969c9ef454396e3f7f4 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 14:20:44 +0200 Subject: [PATCH 18/27] Fix fluent update --- neo.UnitTests/Consensus/UT_Consensus.cs | 34 ++++---- neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs | 6 +- .../Cryptography/ECC/UT_ECFieldElement.cs | 4 +- neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs | 24 +++--- neo.UnitTests/Cryptography/UT_Base58.cs | 2 +- neo.UnitTests/Cryptography/UT_BloomFilter.cs | 4 +- neo.UnitTests/Cryptography/UT_Crypto.cs | 2 +- .../Cryptography/UT_Cryptography_Helper.cs | 30 +++---- neo.UnitTests/Cryptography/UT_MerkleTree.cs | 2 +- neo.UnitTests/IO/Caching/UT_Cache.cs | 10 +-- neo.UnitTests/IO/Caching/UT_CloneCache.cs | 2 +- neo.UnitTests/IO/Caching/UT_DataCache.cs | 8 +- neo.UnitTests/IO/Caching/UT_FIFOSet.cs | 6 +- .../IO/Caching/UT_ReflectionCache.cs | 2 +- neo.UnitTests/IO/Json/UT_JArray.cs | 4 +- neo.UnitTests/IO/Json/UT_JBoolean.cs | 6 +- neo.UnitTests/IO/Json/UT_JNumber.cs | 8 +- neo.UnitTests/IO/Json/UT_JObject.cs | 12 +-- neo.UnitTests/IO/UT_IOHelper.cs | 14 ++-- neo.UnitTests/Ledger/UT_MemoryPool.cs | 82 +++++++++---------- .../Network/P2P/Payloads/UT_Transaction.cs | 2 +- .../SmartContract/Native/UT_PolicyContract.cs | 4 +- neo.UnitTests/UT_BigDecimal.cs | 4 +- neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs | 6 +- neo.UnitTests/Wallets/UT_AssetDescriptor.cs | 2 +- neo.UnitTests/Wallets/UT_KeyPair.cs | 2 +- neo.UnitTests/Wallets/UT_Wallet.cs | 28 +++---- neo.UnitTests/Wallets/UT_Wallets_Helper.cs | 4 +- 28 files changed, 157 insertions(+), 157 deletions(-) diff --git a/neo.UnitTests/Consensus/UT_Consensus.cs b/neo.UnitTests/Consensus/UT_Consensus.cs index 14c287bcff..c8d8fbf6c4 100644 --- a/neo.UnitTests/Consensus/UT_Consensus.cs +++ b/neo.UnitTests/Consensus/UT_Consensus.cs @@ -215,17 +215,17 @@ public void TestSerializeAndDeserializeConsensusContext() copiedContext.Block.PrevHash.Should().Be(consensusContext.Block.PrevHash); copiedContext.Block.Index.Should().Be(consensusContext.Block.Index); copiedContext.ViewNumber.Should().Be(consensusContext.ViewNumber); - copiedContext.Validators.ShouldAllBeEquivalentTo(consensusContext.Validators); + copiedContext.Validators.Should().BeEquivalentTo(consensusContext.Validators); copiedContext.MyIndex.Should().Be(consensusContext.MyIndex); copiedContext.Block.ConsensusData.PrimaryIndex.Should().Be(consensusContext.Block.ConsensusData.PrimaryIndex); copiedContext.Block.Timestamp.Should().Be(consensusContext.Block.Timestamp); copiedContext.Block.NextConsensus.Should().Be(consensusContext.Block.NextConsensus); - copiedContext.TransactionHashes.ShouldAllBeEquivalentTo(consensusContext.TransactionHashes); - copiedContext.Transactions.ShouldAllBeEquivalentTo(consensusContext.Transactions); - copiedContext.Transactions.Values.ShouldAllBeEquivalentTo(consensusContext.Transactions.Values); - copiedContext.PreparationPayloads.ShouldAllBeEquivalentTo(consensusContext.PreparationPayloads); - copiedContext.CommitPayloads.ShouldAllBeEquivalentTo(consensusContext.CommitPayloads); - copiedContext.ChangeViewPayloads.ShouldAllBeEquivalentTo(consensusContext.ChangeViewPayloads); + copiedContext.TransactionHashes.Should().BeEquivalentTo(consensusContext.TransactionHashes); + copiedContext.Transactions.Should().BeEquivalentTo(consensusContext.Transactions); + copiedContext.Transactions.Values.Should().BeEquivalentTo(consensusContext.Transactions.Values); + copiedContext.PreparationPayloads.Should().BeEquivalentTo(consensusContext.PreparationPayloads); + copiedContext.CommitPayloads.Should().BeEquivalentTo(consensusContext.CommitPayloads); + copiedContext.ChangeViewPayloads.Should().BeEquivalentTo(consensusContext.ChangeViewPayloads); } [TestMethod] @@ -315,9 +315,9 @@ public void TestSerializeAndDeserializeRecoveryMessageWithChangeViewsAndNoPrepar var copiedMsg = TestUtils.CopyMsgBySerialization(msg, new RecoveryMessage()); ; - copiedMsg.ChangeViewMessages.ShouldAllBeEquivalentTo(msg.ChangeViewMessages); + copiedMsg.ChangeViewMessages.Should().BeEquivalentTo(msg.ChangeViewMessages); copiedMsg.PreparationHash.Should().Be(msg.PreparationHash); - copiedMsg.PreparationMessages.ShouldAllBeEquivalentTo(msg.PreparationMessages); + copiedMsg.PreparationMessages.Should().BeEquivalentTo(msg.PreparationMessages); copiedMsg.CommitMessages.Count.Should().Be(0); } @@ -409,10 +409,10 @@ public void TestSerializeAndDeserializeRecoveryMessageWithChangeViewsAndPrepareR var copiedMsg = TestUtils.CopyMsgBySerialization(msg, new RecoveryMessage()); ; - copiedMsg.ChangeViewMessages.ShouldAllBeEquivalentTo(msg.ChangeViewMessages); - copiedMsg.PrepareRequestMessage.ShouldBeEquivalentTo(msg.PrepareRequestMessage); + copiedMsg.ChangeViewMessages.Should().BeEquivalentTo(msg.ChangeViewMessages); + copiedMsg.PrepareRequestMessage.Should().BeEquivalentTo(msg.PrepareRequestMessage); copiedMsg.PreparationHash.Should().Be(null); - copiedMsg.PreparationMessages.ShouldAllBeEquivalentTo(msg.PreparationMessages); + copiedMsg.PreparationMessages.Should().BeEquivalentTo(msg.PreparationMessages); copiedMsg.CommitMessages.Count.Should().Be(0); } @@ -470,9 +470,9 @@ public void TestSerializeAndDeserializeRecoveryMessageWithoutChangeViewsWithoutC var copiedMsg = TestUtils.CopyMsgBySerialization(msg, new RecoveryMessage()); ; copiedMsg.ChangeViewMessages.Count.Should().Be(0); - copiedMsg.PrepareRequestMessage.ShouldBeEquivalentTo(msg.PrepareRequestMessage); + copiedMsg.PrepareRequestMessage.Should().BeEquivalentTo(msg.PrepareRequestMessage); copiedMsg.PreparationHash.Should().Be(null); - copiedMsg.PreparationMessages.ShouldAllBeEquivalentTo(msg.PreparationMessages); + copiedMsg.PreparationMessages.Should().BeEquivalentTo(msg.PreparationMessages); copiedMsg.CommitMessages.Count.Should().Be(0); } @@ -550,10 +550,10 @@ public void TestSerializeAndDeserializeRecoveryMessageWithoutChangeViewsWithComm var copiedMsg = TestUtils.CopyMsgBySerialization(msg, new RecoveryMessage()); ; copiedMsg.ChangeViewMessages.Count.Should().Be(0); - copiedMsg.PrepareRequestMessage.ShouldBeEquivalentTo(msg.PrepareRequestMessage); + copiedMsg.PrepareRequestMessage.Should().BeEquivalentTo(msg.PrepareRequestMessage); copiedMsg.PreparationHash.Should().Be(null); - copiedMsg.PreparationMessages.ShouldAllBeEquivalentTo(msg.PreparationMessages); - copiedMsg.CommitMessages.ShouldAllBeEquivalentTo(msg.CommitMessages); + copiedMsg.PreparationMessages.Should().BeEquivalentTo(msg.PreparationMessages); + copiedMsg.CommitMessages.Should().BeEquivalentTo(msg.CommitMessages); } private static ConsensusPayload MakeSignedPayload(ConsensusContext context, ConsensusMessage message, ushort validatorIndex, byte[] witnessInvocationScript) diff --git a/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs b/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs index f88412af97..62206741cb 100644 --- a/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs +++ b/neo.UnitTests/Cryptography/ECC/UT_ECDsa.cs @@ -22,9 +22,9 @@ public void TestSetup() public void TestECDsaConstructor() { Action action = () => new ECDsa(key.PublicKey); - action.ShouldNotThrow(); + action.Should().NotThrow(); action = () => new ECDsa(key.PrivateKey, key.PublicKey.Curve); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [TestMethod] @@ -39,7 +39,7 @@ public void TestGenerateSignature() } sa = new ECDsa(key.PublicKey); Action action = () => sa.GenerateSignature(message); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs b/neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs index 90a31b495d..6b2965b41f 100644 --- a/neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs +++ b/neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs @@ -16,11 +16,11 @@ public void TestECFieldElementConstructor() { BigInteger input = new BigInteger(100); Action action = () => new ECFieldElement(input, ECCurve.Secp256k1); - action.ShouldNotThrow(); + action.Should().NotThrow(); input = ECCurve.Secp256k1.Q; action = () => new ECFieldElement(input, ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs b/neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs index 26d71cc3e6..b38df0fa44 100644 --- a/neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs +++ b/neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs @@ -57,9 +57,9 @@ public void TestECPointConstructor() point.Y.Should().Be(Y); point.Curve.Should().Be(ECCurve.Secp256k1); Action action = () => new ECPoint(X, null, ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); action = () => new ECPoint(null, Y, ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -67,13 +67,13 @@ public void TestDecodePoint() { byte[] input1 = { 0 }; Action action = () => ECPoint.DecodePoint(input1, ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); byte[] input2 = { 4, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152, 72, 58, 218, 119, 38, 163, 196, 101, 93, 164, 251, 252, 14, 17, 8, 168, 253, 23, 180, 72, 166, 133, 84, 25, 156, 71, 208, 143, 251, 16, 212, 184 }; ECPoint.DecodePoint(input2, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); action = () => ECPoint.DecodePoint(input2.Take(32).ToArray(), ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); byte[] input3 = { 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152 }; byte[] input4 = { 3, 107, 23, 209, 242, 225, 44, 66, 71, 248, 188, 230, 229, 99, 164, 64, 242, 119, 3, 125, 129, 45, 235, 51, 160, 244, 161, 57, 69, 216, 152, 194, 150 }; @@ -81,7 +81,7 @@ public void TestDecodePoint() ECPoint.DecodePoint(input4, ECCurve.Secp256r1).Should().Be(ECCurve.Secp256r1.G); action = () => ECPoint.DecodePoint(input3.Take(input3.Length - 1).ToArray(), ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -89,13 +89,13 @@ public void TestDeserializeFrom() { byte[] input1 = { 0 }; Action action = () => ECPoint.DeserializeFrom(new BinaryReader(new MemoryStream(input1)), ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); byte[] input2 = { 4, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152, 72, 58, 218, 119, 38, 163, 196, 101, 93, 164, 251, 252, 14, 17, 8, 168, 253, 23, 180, 72, 166, 133, 84, 25, 156, 71, 208, 143, 251, 16, 212, 184 }; ECPoint.DeserializeFrom(new BinaryReader(new MemoryStream(input2)), ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); action = () => ECPoint.DeserializeFrom(new BinaryReader(new MemoryStream(input2.Take(32).ToArray())), ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); - action.ShouldThrow(); + action.Should().Throw(); byte[] input3 = { 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152 }; ECPoint.DeserializeFrom(new BinaryReader(new MemoryStream(input3)), ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); @@ -103,7 +103,7 @@ public void TestDeserializeFrom() ECPoint.DeserializeFrom(new BinaryReader(new MemoryStream(input4)), ECCurve.Secp256r1).Should().Be(ECCurve.Secp256r1.G); action = () => ECPoint.DeserializeFrom(new BinaryReader(new MemoryStream(input3.Take(input3.Length - 1).ToArray())), ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -178,7 +178,7 @@ public void TestFromBytes() { byte[] input1 = { 0 }; Action action = () => ECPoint.FromBytes(input1, ECCurve.Secp256k1); - action.ShouldThrow(); + action.Should().Throw(); byte[] input2 = { 4, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152, 72, 58, 218, 119, 38, 163, 196, 101, 93, 164, 251, 252, 14, 17, 8, 168, 253, 23, 180, 72, 166, 133, 84, 25, 156, 71, 208, 143, 251, 16, 212, 184 }; @@ -293,14 +293,14 @@ public void TestOpMultiply() ECPoint p = null; byte[] n = new byte[] { 1 }; Action action = () => p = p * n; - action.ShouldThrow(); + action.Should().Throw(); p = ECCurve.Secp256k1.G; n = null; - action.ShouldThrow(); + action.Should().Throw(); n = new byte[] { 1 }; - action.ShouldThrow(); + action.Should().Throw(); p = ECCurve.Secp256k1.Infinity; n = new byte[32]; diff --git a/neo.UnitTests/Cryptography/UT_Base58.cs b/neo.UnitTests/Cryptography/UT_Base58.cs index 1a539cc42c..5f2d750382 100644 --- a/neo.UnitTests/Cryptography/UT_Base58.cs +++ b/neo.UnitTests/Cryptography/UT_Base58.cs @@ -25,7 +25,7 @@ public void TestDecode() Base58.Decode(encoded1).Should().BeEquivalentTo(decoded1); Base58.Decode(encoded2).Should().BeEquivalentTo(decoded2); Action action = () => Base58.Decode(encoded1 + "l").Should().BeEquivalentTo(decoded1); - action.ShouldThrow(); + action.Should().Throw(); } } } diff --git a/neo.UnitTests/Cryptography/UT_BloomFilter.cs b/neo.UnitTests/Cryptography/UT_BloomFilter.cs index 5deabe1b8e..7ed470e3e1 100644 --- a/neo.UnitTests/Cryptography/UT_BloomFilter.cs +++ b/neo.UnitTests/Cryptography/UT_BloomFilter.cs @@ -27,12 +27,12 @@ public void TestBloomFIlterConstructorGetKMTweak() int m = -7, n = 10; uint nTweak = 123456; Action action = () => new BloomFilter(m, n, nTweak); - action.ShouldThrow(); + action.Should().Throw(); m = 7; n = -10; action = () => new BloomFilter(m, n, nTweak); - action.ShouldThrow(); + action.Should().Throw(); n = 10; BloomFilter filter = new BloomFilter(m, n, nTweak); diff --git a/neo.UnitTests/Cryptography/UT_Crypto.cs b/neo.UnitTests/Cryptography/UT_Crypto.cs index c46f25aa69..0fff2a26c3 100644 --- a/neo.UnitTests/Cryptography/UT_Crypto.cs +++ b/neo.UnitTests/Cryptography/UT_Crypto.cs @@ -58,7 +58,7 @@ public void TestVerifySignature() wrongKey = new byte[36]; Action action = () => Crypto.Default.VerifySignature(message, signature, wrongKey).Should().BeFalse(); - action.ShouldThrow(); + action.Should().Throw(); } } } diff --git a/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs b/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs index 67ed2a920d..58071f4994 100644 --- a/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs +++ b/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs @@ -46,27 +46,27 @@ public void TestAesEncrypt() byte[] nullData = null; Action action = () => nullData.AesEncrypt(key, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] nullKey = null; action = () => data.AesEncrypt(nullKey, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] nullIv = null; action = () => data.AesEncrypt(key, nullIv); - action.ShouldThrow(); + action.Should().Throw(); byte[] wrongData = Encoding.ASCII.GetBytes("000000000000000000000000000000001"); ; action = () => wrongData.AesEncrypt(key, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] wrongKey = Encoding.ASCII.GetBytes("123456781234567812345678123456780"); ; action = () => data.AesEncrypt(wrongKey, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] wrongIv = Encoding.ASCII.GetBytes("12345678123456780"); ; action = () => data.AesEncrypt(key, wrongIv); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -83,27 +83,27 @@ public void TestAesDecrypt() byte[] nullData = null; Action action = () => nullData.AesDecrypt(key, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] nullKey = null; action = () => data.AesDecrypt(nullKey, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] nullIv = null; action = () => data.AesDecrypt(key, nullIv); - action.ShouldThrow(); + action.Should().Throw(); byte[] wrongData = Encoding.ASCII.GetBytes("00000000000000001"); ; action = () => wrongData.AesDecrypt(key, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] wrongKey = Encoding.ASCII.GetBytes("123456781234567812345678123456780"); ; action = () => data.AesDecrypt(wrongKey, iv); - action.ShouldThrow(); + action.Should().Throw(); byte[] wrongIv = Encoding.ASCII.GetBytes("12345678123456780"); ; action = () => data.AesDecrypt(key, wrongIv); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -116,11 +116,11 @@ public void TestBase58CheckDecode() input = "3v"; Action action = () => input.Base58CheckDecode(); - action.ShouldThrow(); + action.Should().Throw(); input = "3vQB7B6MrGQZaxCuFg4og"; action = () => input.Base58CheckDecode(); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -215,7 +215,7 @@ public void TestToArray() SecureString nullString = null; Action action = () => nullString.ToArray(); - action.ShouldThrow(); + action.Should().Throw(); var zeroString = new SecureString(); var result = zeroString.ToArray(); diff --git a/neo.UnitTests/Cryptography/UT_MerkleTree.cs b/neo.UnitTests/Cryptography/UT_MerkleTree.cs index 4b56380957..870405caf8 100644 --- a/neo.UnitTests/Cryptography/UT_MerkleTree.cs +++ b/neo.UnitTests/Cryptography/UT_MerkleTree.cs @@ -23,7 +23,7 @@ public void TestBuildAndDepthFirstSearch() { IReadOnlyList hashNull = new UInt256[] { }; Action action = () => new MerkleTree(hashNull); - action.ShouldThrow(); + action.Should().Throw(); byte[] array1 = { 0x01 }; var hash1 = GetByteArrayHash(array1); diff --git a/neo.UnitTests/IO/Caching/UT_Cache.cs b/neo.UnitTests/IO/Caching/UT_Cache.cs index 930547f314..65728bd82d 100644 --- a/neo.UnitTests/IO/Caching/UT_Cache.cs +++ b/neo.UnitTests/IO/Caching/UT_Cache.cs @@ -140,13 +140,13 @@ public void TestCopyTo() string[] temp = new string[2]; Action action = () => cache.CopyTo(null, 1); - action.ShouldThrow(); + action.Should().Throw(); action = () => cache.CopyTo(temp, -1); - action.ShouldThrow(); + action.Should().Throw(); action = () => cache.CopyTo(temp, 1); - action.ShouldThrow(); + action.Should().Throw(); cache.CopyTo(temp, 0); temp[0].Should().Be("hello"); @@ -207,7 +207,7 @@ public void TestArrayIndexAccess() { string temp = cache["non exist string".GetHashCode()]; }; - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -250,7 +250,7 @@ public void TestDispose() { int count = cache.Count; }; - action.ShouldThrow(); + action.Should().Throw(); } } } diff --git a/neo.UnitTests/IO/Caching/UT_CloneCache.cs b/neo.UnitTests/IO/Caching/UT_CloneCache.cs index afa550e45c..b75a70ee97 100644 --- a/neo.UnitTests/IO/Caching/UT_CloneCache.cs +++ b/neo.UnitTests/IO/Caching/UT_CloneCache.cs @@ -89,7 +89,7 @@ public void TestGetInternal() { var item = cloneCache[new MyKey("key4")]; }; - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/IO/Caching/UT_DataCache.cs b/neo.UnitTests/IO/Caching/UT_DataCache.cs index f21624814d..437f2b92f1 100644 --- a/neo.UnitTests/IO/Caching/UT_DataCache.cs +++ b/neo.UnitTests/IO/Caching/UT_DataCache.cs @@ -175,7 +175,7 @@ public void TestAccessByNotFoundKey() { var item = myDataCache[new MyKey("key1")]; }; - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -188,7 +188,7 @@ public void TestAccessByDeletedKey() { var item = myDataCache[new MyKey("key1")]; }; - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -198,14 +198,14 @@ public void TestAdd() myDataCache[new MyKey("key1")].Should().Be(new MyValue("value1")); Action action = () => myDataCache.Add(new MyKey("key1"), new MyValue("value1")); - action.ShouldThrow(); + action.Should().Throw(); myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.Delete(new MyKey("key2")); // trackable.State = TrackState.Deleted myDataCache.Add(new MyKey("key2"), new MyValue("value2")); // trackable.State = TrackState.Changed action = () => myDataCache.Add(new MyKey("key2"), new MyValue("value2")); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/IO/Caching/UT_FIFOSet.cs b/neo.UnitTests/IO/Caching/UT_FIFOSet.cs index 9b781858ee..e6e01710d9 100644 --- a/neo.UnitTests/IO/Caching/UT_FIFOSet.cs +++ b/neo.UnitTests/IO/Caching/UT_FIFOSet.cs @@ -58,13 +58,13 @@ public void FIFOSetTest() public void TestConstructor() { Action action1 = () => new FIFOSet(-1); - action1.ShouldThrow(); + action1.Should().Throw(); Action action2 = () => new FIFOSet(1, -1); - action2.ShouldThrow(); + action2.Should().Throw(); Action action3 = () => new FIFOSet(1, 2); - action3.ShouldThrow(); + action3.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/IO/Caching/UT_ReflectionCache.cs b/neo.UnitTests/IO/Caching/UT_ReflectionCache.cs index e51f6f81d6..4e1fcce634 100644 --- a/neo.UnitTests/IO/Caching/UT_ReflectionCache.cs +++ b/neo.UnitTests/IO/Caching/UT_ReflectionCache.cs @@ -43,7 +43,7 @@ public void TestCreateFromEnum() public void TestCreateFromObjectNotEnum() { Action action = () => ReflectionCache.CreateFromEnum(); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/IO/Json/UT_JArray.cs b/neo.UnitTests/IO/Json/UT_JArray.cs index 5b7a30c9ae..913fb9b10b 100644 --- a/neo.UnitTests/IO/Json/UT_JArray.cs +++ b/neo.UnitTests/IO/Json/UT_JArray.cs @@ -80,7 +80,7 @@ public void TestSetItem() Assert.AreEqual(jArray[0], bob); Action action = () => jArray[1] = alice; - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -100,7 +100,7 @@ public void TestClear() jArray.Clear(); Action action = () => jArray[0].ToString(); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/IO/Json/UT_JBoolean.cs b/neo.UnitTests/IO/Json/UT_JBoolean.cs index 8e5f4acdd6..302d48c52a 100644 --- a/neo.UnitTests/IO/Json/UT_JBoolean.cs +++ b/neo.UnitTests/IO/Json/UT_JBoolean.cs @@ -39,7 +39,7 @@ public void TestParse() TextReader tr3 = new StringReader("aaa"); Action action = () => JBoolean.Parse(tr3); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -51,7 +51,7 @@ public void TestParseFalse() TextReader tr2 = new StringReader("aaa"); Action action = () => JBoolean.ParseFalse(tr2); - action.ShouldThrow(); + action.Should().Throw(); TextReader tr3 = new StringReader("\t\rfalse"); JBoolean ret3 = JBoolean.ParseFalse(tr3); @@ -67,7 +67,7 @@ public void TestParseTrue() TextReader tr2 = new StringReader("aaa"); Action action = () => JBoolean.ParseTrue(tr2); - action.ShouldThrow(); + action.Should().Throw(); TextReader tr3 = new StringReader(" true"); JBoolean ret3 = JBoolean.ParseTrue(tr3); diff --git a/neo.UnitTests/IO/Json/UT_JNumber.cs b/neo.UnitTests/IO/Json/UT_JNumber.cs index 16adbe9d80..e3cbe6d300 100644 --- a/neo.UnitTests/IO/Json/UT_JNumber.cs +++ b/neo.UnitTests/IO/Json/UT_JNumber.cs @@ -39,10 +39,10 @@ public void TestAsBoolean() public void TestAsString() { Action action1 = () => new JNumber(double.PositiveInfinity).AsString(); - action1.ShouldThrow(); + action1.Should().Throw(); Action action2 = () => new JNumber(double.NegativeInfinity).AsString(); - action2.ShouldThrow(); + action2.Should().Throw(); } [TestMethod] @@ -58,10 +58,10 @@ public void TestTryGetEnum() public void TestParse() { Action action1 = () => JNumber.Parse(new StringReader("100.a")); - action1.ShouldThrow(); + action1.Should().Throw(); Action action2 = () => JNumber.Parse(new StringReader("100.+")); - action2.ShouldThrow(); + action2.Should().Throw(); } } } diff --git a/neo.UnitTests/IO/Json/UT_JObject.cs b/neo.UnitTests/IO/Json/UT_JObject.cs index 990363bcb1..9645b04011 100644 --- a/neo.UnitTests/IO/Json/UT_JObject.cs +++ b/neo.UnitTests/IO/Json/UT_JObject.cs @@ -54,14 +54,14 @@ public void TestAsNumber() public void TestParse() { Action action = () => JObject.Parse(new StringReader(""), -1); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] public void TestParseNull() { Action action = () => JObject.Parse(new StringReader("naaa")); - action.ShouldThrow(); + action.Should().Throw(); JObject.Parse(new StringReader("null")).Should().BeNull(); } @@ -70,16 +70,16 @@ public void TestParseNull() public void TestParseObject() { Action action1 = () => JObject.Parse(new StringReader("{\"k1\":\"v1\",\"k1\":\"v2\"}"), 100); - action1.ShouldThrow(); + action1.Should().Throw(); Action action2 = () => JObject.Parse(new StringReader("{\"k1\",\"k1\"}"), 100); - action2.ShouldThrow(); + action2.Should().Throw(); Action action3 = () => JObject.Parse(new StringReader("{\"k1\":\"v1\""), 100); - action3.ShouldThrow(); + action3.Should().Throw(); Action action4 = () => JObject.Parse(new StringReader("aaa"), 100); - action4.ShouldThrow(); + action4.Should().Throw(); JObject.Parse(new StringReader("{\"k1\":\"v1\"}"), 100).ToString().Should().Be("{\"k1\":\"v1\"}"); } diff --git a/neo.UnitTests/IO/UT_IOHelper.cs b/neo.UnitTests/IO/UT_IOHelper.cs index 350cc31425..114ceffc8d 100644 --- a/neo.UnitTests/IO/UT_IOHelper.cs +++ b/neo.UnitTests/IO/UT_IOHelper.cs @@ -40,7 +40,7 @@ public void TestAsSerializable() else { Action action = () => Neo.IO.Helper.AsSerializable(new byte[0], typeof(Double)); - action.ShouldThrow(); + action.Should().Throw(); } } } @@ -245,7 +245,7 @@ public void TestReadBytesWithGrouping() stream.Seek(0, SeekOrigin.Begin); BinaryReader reader = new BinaryReader(stream); Action action = () => Neo.IO.Helper.ReadBytesWithGrouping(reader); - action.ShouldThrow(); + action.Should().Throw(); } } } @@ -332,7 +332,7 @@ public void TestReadVarInt() stream.Seek(0, SeekOrigin.Begin); BinaryReader reader = new BinaryReader(stream); Action action = () => Neo.IO.Helper.ReadVarInt(reader, 0xFFFFFFFF); - action.ShouldThrow(); + action.Should().Throw(); } } } @@ -432,21 +432,21 @@ public void TestWriteFixedString() MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); Action action = () => Neo.IO.Helper.WriteFixedString(writer, null, 0); - action.ShouldThrow(); + action.Should().Throw(); } else if (i == 1) { MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); Action action = () => Neo.IO.Helper.WriteFixedString(writer, "AA", Encoding.UTF8.GetBytes("AA").Length - 1); - action.ShouldThrow(); + action.Should().Throw(); } else if (i == 2) { MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); Action action = () => Neo.IO.Helper.WriteFixedString(writer, "拉拉", Encoding.UTF8.GetBytes("拉拉").Length - 1); - action.ShouldThrow(); + action.Should().Throw(); } else if (i == 3) { @@ -485,7 +485,7 @@ public void TestWriteVarInt() MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); Action action = () => Neo.IO.Helper.WriteVarInt(writer, -1); - action.ShouldThrow(); + action.Should().Throw(); } else if (i == 1) { diff --git a/neo.UnitTests/Ledger/UT_MemoryPool.cs b/neo.UnitTests/Ledger/UT_MemoryPool.cs index e9a451952c..27c4d37715 100644 --- a/neo.UnitTests/Ledger/UT_MemoryPool.cs +++ b/neo.UnitTests/Ledger/UT_MemoryPool.cs @@ -45,11 +45,11 @@ public void TestSetup() _unit.LoadPolicy(TestBlockchain.GetStore().GetSnapshot()); // Verify capacity equals the amount specified - _unit.Capacity.ShouldBeEquivalentTo(100); + _unit.Capacity.Should().Be(100); - _unit.VerifiedCount.ShouldBeEquivalentTo(0); - _unit.UnVerifiedCount.ShouldBeEquivalentTo(0); - _unit.Count.ShouldBeEquivalentTo(0); + _unit.VerifiedCount.Should().Be(0); + _unit.UnVerifiedCount.Should().Be(0); + _unit.Count.Should().Be(0); _unit2 = new MemoryPool(TheNeoSystem, 0); plugin = new TestIMemoryPoolTxObserverPlugin(); } @@ -122,10 +122,10 @@ public void CapacityTest() Console.WriteLine($"VerifiedCount: {_unit.VerifiedCount} Count {_unit.SortedTxCount}"); - _unit.SortedTxCount.ShouldBeEquivalentTo(100); - _unit.VerifiedCount.ShouldBeEquivalentTo(100); - _unit.UnVerifiedCount.ShouldBeEquivalentTo(0); - _unit.Count.ShouldBeEquivalentTo(100); + _unit.SortedTxCount.Should().Be(100); + _unit.VerifiedCount.Should().Be(100); + _unit.UnVerifiedCount.Should().Be(0); + _unit.Count.Should().Be(100); } [TestMethod] @@ -133,7 +133,7 @@ public void BlockPersistMovesTxToUnverifiedAndReverification() { AddTransactions(70); - _unit.SortedTxCount.ShouldBeEquivalentTo(70); + _unit.SortedTxCount.Should().Be(70); var block = new Block { @@ -142,32 +142,32 @@ public void BlockPersistMovesTxToUnverifiedAndReverification() }; _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot()); _unit.InvalidateVerifiedTransactions(); - _unit.SortedTxCount.ShouldBeEquivalentTo(0); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(60); + _unit.SortedTxCount.Should().Be(0); + _unit.UnverifiedSortedTxCount.Should().Be(60); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot()); - _unit.SortedTxCount.ShouldBeEquivalentTo(10); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(50); + _unit.SortedTxCount.Should().Be(10); + _unit.UnverifiedSortedTxCount.Should().Be(50); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot()); - _unit.SortedTxCount.ShouldBeEquivalentTo(20); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(40); + _unit.SortedTxCount.Should().Be(20); + _unit.UnverifiedSortedTxCount.Should().Be(40); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot()); - _unit.SortedTxCount.ShouldBeEquivalentTo(30); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(30); + _unit.SortedTxCount.Should().Be(30); + _unit.UnverifiedSortedTxCount.Should().Be(30); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot()); - _unit.SortedTxCount.ShouldBeEquivalentTo(40); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(20); + _unit.SortedTxCount.Should().Be(40); + _unit.UnverifiedSortedTxCount.Should().Be(20); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot()); - _unit.SortedTxCount.ShouldBeEquivalentTo(50); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(10); + _unit.SortedTxCount.Should().Be(50); + _unit.UnverifiedSortedTxCount.Should().Be(10); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot()); - _unit.SortedTxCount.ShouldBeEquivalentTo(60); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(0); + _unit.SortedTxCount.Should().Be(60); + _unit.UnverifiedSortedTxCount.Should().Be(0); } private void VerifyTransactionsSortedDescending(IEnumerable transactions) @@ -200,21 +200,21 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() var sortedVerifiedTxs = _unit.GetSortedVerifiedTransactions().ToList(); // verify all 100 transactions are returned in sorted order - sortedVerifiedTxs.Count.ShouldBeEquivalentTo(100); + sortedVerifiedTxs.Count.Should().Be(100); VerifyTransactionsSortedDescending(sortedVerifiedTxs); // move all to unverified var block = new Block { Transactions = new Transaction[0] }; _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot()); _unit.InvalidateVerifiedTransactions(); - _unit.SortedTxCount.ShouldBeEquivalentTo(0); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(100); + _unit.SortedTxCount.Should().Be(0); + _unit.UnverifiedSortedTxCount.Should().Be(100); // We can verify the order they are re-verified by reverifying 2 at a time while (_unit.UnVerifiedCount > 0) { _unit.GetVerifiedAndUnverifiedTransactions(out var sortedVerifiedTransactions, out var sortedUnverifiedTransactions); - sortedVerifiedTransactions.Count().ShouldBeEquivalentTo(0); + sortedVerifiedTransactions.Count().Should().Be(0); var sortedUnverifiedArray = sortedUnverifiedTransactions.ToArray(); VerifyTransactionsSortedDescending(sortedUnverifiedArray); var maxTransaction = sortedUnverifiedArray.First(); @@ -223,15 +223,15 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() // reverify 1 high priority and 1 low priority transaction _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, Blockchain.Singleton.GetSnapshot()); var verifiedTxs = _unit.GetSortedVerifiedTransactions().ToArray(); - verifiedTxs.Length.ShouldBeEquivalentTo(1); - verifiedTxs[0].ShouldBeEquivalentTo(maxTransaction); + verifiedTxs.Length.Should().Be(1); + verifiedTxs[0].Should().BeEquivalentTo(maxTransaction); var blockWith2Tx = new Block { Transactions = new[] { maxTransaction, minTransaction } }; // verify and remove the 2 transactions from the verified pool _unit.UpdatePoolForBlockPersisted(blockWith2Tx, Blockchain.Singleton.GetSnapshot()); _unit.InvalidateVerifiedTransactions(); - _unit.SortedTxCount.ShouldBeEquivalentTo(0); + _unit.SortedTxCount.Should().Be(0); } - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(0); + _unit.UnverifiedSortedTxCount.Should().Be(0); } void VerifyCapacityThresholdForAttemptingToAddATransaction() @@ -239,9 +239,9 @@ void VerifyCapacityThresholdForAttemptingToAddATransaction() var sortedVerified = _unit.GetSortedVerifiedTransactions().ToArray(); var txBarelyWontFit = CreateTransactionWithFee(sortedVerified.Last().NetworkFee - 1); - _unit.CanTransactionFitInPool(txBarelyWontFit).ShouldBeEquivalentTo(false); + _unit.CanTransactionFitInPool(txBarelyWontFit).Should().Be(false); var txBarelyFits = CreateTransactionWithFee(sortedVerified.Last().NetworkFee + 1); - _unit.CanTransactionFitInPool(txBarelyFits).ShouldBeEquivalentTo(true); + _unit.CanTransactionFitInPool(txBarelyFits).Should().Be(true); } [TestMethod] @@ -268,9 +268,9 @@ public void CapacityTestWithUnverifiedHighProirtyTransactions() var block = new Block { Transactions = new Transaction[0] }; _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot()); - _unit.CanTransactionFitInPool(CreateTransaction()).ShouldBeEquivalentTo(true); + _unit.CanTransactionFitInPool(CreateTransaction()).Should().Be(true); AddTransactions(1); - _unit.CanTransactionFitInPool(CreateTransactionWithFee(0)).ShouldBeEquivalentTo(false); + _unit.CanTransactionFitInPool(CreateTransactionWithFee(0)).Should().Be(false); } [TestMethod] @@ -278,11 +278,11 @@ public void TestInvalidateAll() { AddTransactions(30); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(0); - _unit.SortedTxCount.ShouldBeEquivalentTo(30); + _unit.UnverifiedSortedTxCount.Should().Be(0); + _unit.SortedTxCount.Should().Be(30); _unit.InvalidateAllTransactions(); - _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(30); - _unit.SortedTxCount.ShouldBeEquivalentTo(0); + _unit.UnverifiedSortedTxCount.Should().Be(30); + _unit.SortedTxCount.Should().Be(0); } [TestMethod] @@ -392,11 +392,11 @@ public void TestTryGetValue() var tx1 = CreateTransaction(); _unit.TryAdd(tx1.Hash, tx1); _unit.TryGetValue(tx1.Hash, out Transaction tx).Should().BeTrue(); - tx.ShouldBeEquivalentTo(tx1); + tx.Should().BeEquivalentTo(tx1); _unit.InvalidateVerifiedTransactions(); _unit.TryGetValue(tx1.Hash, out tx).Should().BeTrue(); - tx.ShouldBeEquivalentTo(tx1); + tx.Should().BeEquivalentTo(tx1); var tx2 = CreateTransaction(); _unit.TryGetValue(tx2.Hash, out tx).Should().BeFalse(); diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index 74efe64dd2..34ea464d78 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -225,7 +225,7 @@ public void FeeIsSignatureContractDetailed() // 'from' is always required as witness // if not included on cosigner with a scope, its scope should be considered 'CalledByEntry' data.ScriptHashes.Count.Should().Be(1); - data.ScriptHashes[0].ShouldBeEquivalentTo(acc.ScriptHash); + data.ScriptHashes[0].Should().BeEquivalentTo(acc.ScriptHash); // will sign tx bool signed = wallet.Sign(data); Assert.IsTrue(signed); diff --git a/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs b/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs index 8442904f5b..940230660a 100644 --- a/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs +++ b/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs @@ -200,7 +200,7 @@ public void Check_Block_UnblockAccount() ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts"); ret.Should().BeOfType(); ((VM.Types.Array)ret).Count.Should().Be(1); - ((VM.Types.Array)ret)[0].GetByteArray().ShouldBeEquivalentTo(UInt160.Zero.ToArray()); + ((VM.Types.Array)ret)[0].GetByteArray().Should().BeEquivalentTo(UInt160.Zero.ToArray()); // Unblock without signature @@ -212,7 +212,7 @@ public void Check_Block_UnblockAccount() ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts"); ret.Should().BeOfType(); ((VM.Types.Array)ret).Count.Should().Be(1); - ((VM.Types.Array)ret)[0].GetByteArray().ShouldBeEquivalentTo(UInt160.Zero.ToArray()); + ((VM.Types.Array)ret)[0].GetByteArray().Should().BeEquivalentTo(UInt160.Zero.ToArray()); // Unblock with signature diff --git a/neo.UnitTests/UT_BigDecimal.cs b/neo.UnitTests/UT_BigDecimal.cs index 2d359da891..cdde9f9e89 100644 --- a/neo.UnitTests/UT_BigDecimal.cs +++ b/neo.UnitTests/UT_BigDecimal.cs @@ -21,7 +21,7 @@ public void TestChangeDecimals() BigDecimal result3 = originalValue.ChangeDecimals(5); result3.Value.Should().Be(originalValue.Value); Action action = () => originalValue.ChangeDecimals(2); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] @@ -69,7 +69,7 @@ public void TestParse() s = "abcdEfg"; Action action = () => BigDecimal.Parse(s, decimals); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs b/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs index dcba52bc11..87993f12cd 100644 --- a/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs +++ b/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs @@ -46,7 +46,7 @@ public void TestGetName() public void TestGetVersion() { Action action = () => wallet.Version.ToString(); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [TestMethod] @@ -66,7 +66,7 @@ public void TestCreateAndOpenSecureString() ss.AppendChar('d'); Action action = () => UserWallet.Open(myPath, ss); - action.ShouldThrow(); + action.Should().Throw(); TestUtils.DeleteFile(myPath); } @@ -84,7 +84,7 @@ public void TestOpen() w1.Should().NotBeNull(); Action action = () => UserWallet.Open(path, "123"); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/Wallets/UT_AssetDescriptor.cs b/neo.UnitTests/Wallets/UT_AssetDescriptor.cs index 14eb6766b1..697e631200 100644 --- a/neo.UnitTests/Wallets/UT_AssetDescriptor.cs +++ b/neo.UnitTests/Wallets/UT_AssetDescriptor.cs @@ -25,7 +25,7 @@ public void TestConstructorWithNonexistAssetId() { var descriptor = new Neo.Wallets.AssetDescriptor(UInt160.Parse("01ff00ff00ff00ff00ff00ff00ff00ff00ff00a4")); }; - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/Wallets/UT_KeyPair.cs b/neo.UnitTests/Wallets/UT_KeyPair.cs index 57f06bb5a9..cb2bb20a6e 100644 --- a/neo.UnitTests/Wallets/UT_KeyPair.cs +++ b/neo.UnitTests/Wallets/UT_KeyPair.cs @@ -35,7 +35,7 @@ public void TestConstructor() for (int i = 0; i < privateKey31.Length; i++) privateKey31[i] = (byte)random.Next(256); Action action = () => new KeyPair(privateKey31); - action.ShouldThrow(); + action.Should().Throw(); } [TestMethod] diff --git a/neo.UnitTests/Wallets/UT_Wallet.cs b/neo.UnitTests/Wallets/UT_Wallet.cs index c09f8e26c2..ed48a047e5 100644 --- a/neo.UnitTests/Wallets/UT_Wallet.cs +++ b/neo.UnitTests/Wallets/UT_Wallet.cs @@ -112,7 +112,7 @@ public void TestContains() { MyWallet wallet = new MyWallet(); Action action = () => wallet.Contains(UInt160.Zero); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [TestMethod] @@ -178,7 +178,7 @@ public void TestGetAccount2() { MyWallet wallet = new MyWallet(); Action action = () => wallet.GetAccount(UInt160.Zero); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [TestMethod] @@ -186,7 +186,7 @@ public void TestGetAccounts() { MyWallet wallet = new MyWallet(); Action action = () => wallet.GetAccounts(); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [TestMethod] @@ -254,16 +254,16 @@ public void TestGetBalance() public void TestGetPrivateKeyFromNEP2() { Action action = () => Wallet.GetPrivateKeyFromNEP2(null, null, 0, 0, 0); - action.ShouldThrow(); + action.Should().Throw(); action = () => Wallet.GetPrivateKeyFromNEP2("TestGetPrivateKeyFromNEP2", null, 0, 0, 0); - action.ShouldThrow(); + action.Should().Throw(); action = () => Wallet.GetPrivateKeyFromNEP2("3vQB7B6MrGQZaxCuFg4oh", "TestGetPrivateKeyFromNEP2", 0, 0, 0); - action.ShouldThrow(); + action.Should().Throw(); action = () => Wallet.GetPrivateKeyFromNEP2(nep2Key, "Test", 0, 0, 0); - action.ShouldThrow(); + action.Should().Throw(); Wallet.GetPrivateKeyFromNEP2(nep2Key, "pwd", 0, 0, 0).Should().BeEquivalentTo(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); } @@ -272,10 +272,10 @@ public void TestGetPrivateKeyFromNEP2() public void TestGetPrivateKeyFromWIF() { Action action = () => Wallet.GetPrivateKeyFromWIF(null); - action.ShouldThrow(); + action.Should().Throw(); action = () => Wallet.GetPrivateKeyFromWIF("3vQB7B6MrGQZaxCuFg4oh"); - action.ShouldThrow(); + action.Should().Throw(); Wallet.GetPrivateKeyFromWIF("L3tgppXLgdaeqSGSFw1Go3skBiy8vQAM7YMXvTHsKQtE16PBncSU").Should().BeEquivalentTo(new byte[] { 199, 19, 77, 111, 216, 231, 61, 129, 158, 130, 117, 92, 100, 201, 55, 136, 216, 219, 9, 97, 146, 158, 2, 90, 83, 54, 60, 76, 192, 42, 105, 98 }); } @@ -311,7 +311,7 @@ public void TestMakeTransaction1() Value = new BigDecimal(1,8) } }, UInt160.Zero); - action.ShouldThrow(); + action.Should().Throw(); action = () => wallet.MakeTransaction(new TransferOutput[] { @@ -322,7 +322,7 @@ public void TestMakeTransaction1() Value = new BigDecimal(1,8) } }, account.ScriptHash); - action.ShouldThrow(); + action.Should().Throw(); action = () => wallet.MakeTransaction(new TransferOutput[] { @@ -333,7 +333,7 @@ public void TestMakeTransaction1() Value = new BigDecimal(1,8) } }, account.ScriptHash); - action.ShouldThrow(); + action.Should().Throw(); // Fake balance var snapshot = store.GetSnapshot(); @@ -393,7 +393,7 @@ public void TestMakeTransaction2() { MyWallet wallet = new MyWallet(); Action action = () => wallet.MakeTransaction(new byte[] { }, UInt160.Zero, new TransactionAttribute[] { }); - action.ShouldThrow(); + action.Should().Throw(); Contract contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 }); WalletAccount account = wallet.CreateAccount(contract, glkey.PrivateKey); @@ -430,7 +430,7 @@ public void TestVerifyPassword() { MyWallet wallet = new MyWallet(); Action action = () => wallet.VerifyPassword("Test"); - action.ShouldNotThrow(); + action.Should().NotThrow(); } } } diff --git a/neo.UnitTests/Wallets/UT_Wallets_Helper.cs b/neo.UnitTests/Wallets/UT_Wallets_Helper.cs index 4abf10d9ed..c14b4566b3 100644 --- a/neo.UnitTests/Wallets/UT_Wallets_Helper.cs +++ b/neo.UnitTests/Wallets/UT_Wallets_Helper.cs @@ -17,7 +17,7 @@ public void TestToScriptHash() "AZk5bAanTtD6AvpeesmYgL8CLRYUt5JQsX".ToScriptHash().Should().Be(scriptHash); Action action = () => "3vQB7B6MrGQZaxCuFg4oh".ToScriptHash(); - action.ShouldThrow(); + action.Should().Throw(); var address = scriptHash.ToAddress(); byte[] data = new byte[21]; @@ -26,7 +26,7 @@ public void TestToScriptHash() Buffer.BlockCopy(scriptHash.ToArray(), 0, data, 1, 20); address = data.Base58CheckEncode(); action = () => address.ToScriptHash(); - action.ShouldThrow(); + action.Should().Throw(); } } } From 57654badb4dffbd4e8ed509016a04acf87f5000e Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 19:03:34 +0200 Subject: [PATCH 19/27] Paralellize --- neo.UnitTests/IO/Caching/UT_Cache.cs | 22 +++++--- neo.UnitTests/IO/Caching/UT_CloneCache.cs | 24 +++++---- neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs | 17 +++--- neo.UnitTests/IO/Caching/UT_DataCache.cs | 21 +++++--- neo.UnitTests/IO/Caching/UT_MetaDataCache.cs | 13 ++--- neo.UnitTests/Ledger/UT_MemoryPool.cs | 54 +++++++++++++------ .../Network/P2P/Payloads/UT_Block.cs | 26 +++++---- .../Network/P2P/Payloads/UT_Transaction.cs | 9 ++-- .../Network/RPC/UT_TransactionManager.cs | 2 +- neo.UnitTests/Properties/AssemblyInfo.cs | 3 ++ .../Native/Tokens/UT_GasToken.cs | 2 +- .../SmartContract/UT_InteropService.cs | 2 +- neo.UnitTests/SmartContract/UT_Syscalls.cs | 5 +- neo.UnitTests/TestBlockchain.cs | 6 +++ neo.UnitTests/UT_Culture.cs | 2 +- neo.UnitTests/UT_DataCache.cs | 6 +-- neo.UnitTests/UT_ProtocolSettings.cs | 9 +++- neo.UnitTests/Wallets/UT_AssetDescriptor.cs | 3 -- 18 files changed, 139 insertions(+), 87 deletions(-) create mode 100644 neo.UnitTests/Properties/AssemblyInfo.cs diff --git a/neo.UnitTests/IO/Caching/UT_Cache.cs b/neo.UnitTests/IO/Caching/UT_Cache.cs index 65728bd82d..80431798e9 100644 --- a/neo.UnitTests/IO/Caching/UT_Cache.cs +++ b/neo.UnitTests/IO/Caching/UT_Cache.cs @@ -57,18 +57,12 @@ public IEnumerator MyGetEnumerator() [TestClass] public class UT_Cache { - MyCache cache; readonly int max_capacity = 4; - [TestInitialize] - public void init() - { - cache = new MyCache(max_capacity); - } - [TestMethod] public void TestCount() { + var cache = new MyCache(max_capacity); cache.Count.Should().Be(0); cache.Add("hello"); @@ -82,12 +76,14 @@ public void TestCount() [TestMethod] public void TestIsReadOnly() { + var cache = new MyCache(max_capacity); cache.IsReadOnly.Should().BeFalse(); } [TestMethod] public void TestAddAndAddInternal() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Contains("hello").Should().BeTrue(); cache.Contains("world").Should().BeFalse(); @@ -99,6 +95,7 @@ public void TestAddAndAddInternal() public void TestAddRange() { string[] range = { "hello", "world" }; + var cache = new MyCache(max_capacity); cache.AddRange(range); cache.Count.Should().Be(2); cache.Contains("hello").Should().BeTrue(); @@ -109,6 +106,7 @@ public void TestAddRange() [TestMethod] public void TestClear() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); cache.Count.Should().Be(2); @@ -119,6 +117,7 @@ public void TestClear() [TestMethod] public void TestContainsKey() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Contains("hello").Should().BeTrue(); cache.Contains("world").Should().BeFalse(); @@ -127,6 +126,7 @@ public void TestContainsKey() [TestMethod] public void TestContainsValue() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Contains("hello".GetHashCode()).Should().BeTrue(); cache.Contains("world".GetHashCode()).Should().BeFalse(); @@ -135,6 +135,7 @@ public void TestContainsValue() [TestMethod] public void TestCopyTo() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); string[] temp = new string[2]; @@ -156,6 +157,7 @@ public void TestCopyTo() [TestMethod] public void TestRemoveKey() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Remove("hello".GetHashCode()).Should().BeTrue(); cache.Remove("world".GetHashCode()).Should().BeFalse(); @@ -178,6 +180,7 @@ public void TestRemoveDisposableKey() [TestMethod] public void TestRemoveValue() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Remove("hello").Should().BeTrue(); cache.Remove("world").Should().BeFalse(); @@ -187,6 +190,7 @@ public void TestRemoveValue() [TestMethod] public void TestTryGet() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.TryGet("hello".GetHashCode(), out string output).Should().BeTrue(); output.Should().Be("hello"); @@ -198,6 +202,7 @@ public void TestTryGet() [TestMethod] public void TestArrayIndexAccess() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); cache["hello".GetHashCode()].Should().Be("hello"); @@ -213,6 +218,7 @@ public void TestArrayIndexAccess() [TestMethod] public void TestGetEnumerator() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); int i = 0; @@ -230,6 +236,7 @@ public void TestGetEnumerator() public void TestOverMaxCapacity() { int i = 1; + var cache = new MyCache(max_capacity); for (; i <= max_capacity; i++) { cache.Add(i.ToString()); @@ -242,6 +249,7 @@ public void TestOverMaxCapacity() [TestMethod] public void TestDispose() { + var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); cache.Dispose(); diff --git a/neo.UnitTests/IO/Caching/UT_CloneCache.cs b/neo.UnitTests/IO/Caching/UT_CloneCache.cs index b75a70ee97..2d56ff8bcc 100644 --- a/neo.UnitTests/IO/Caching/UT_CloneCache.cs +++ b/neo.UnitTests/IO/Caching/UT_CloneCache.cs @@ -11,25 +11,19 @@ namespace Neo.UnitTests.IO.Caching [TestClass] public class UT_CloneCache { - CloneCache cloneCache; - MyDataCache myDataCache; - - [TestInitialize] - public void Init() - { - myDataCache = new MyDataCache(); - cloneCache = new CloneCache(myDataCache); - } - [TestMethod] public void TestCloneCache() { + var myDataCache = new MyDataCache(); + var cloneCache = new CloneCache(myDataCache); cloneCache.Should().NotBeNull(); } [TestMethod] public void TestAddInternal() { + var myDataCache = new MyDataCache(); + var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); cloneCache[new MyKey("key1")].Should().Be(new MyValue("value1")); @@ -40,6 +34,8 @@ public void TestAddInternal() [TestMethod] public void TestDeleteInternal() { + var myDataCache = new MyDataCache(); + var cloneCache = new CloneCache(myDataCache); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); cloneCache.Delete(new MyKey("key1")); // trackable.State = TrackState.Deleted cloneCache.Commit(); @@ -51,6 +47,8 @@ public void TestDeleteInternal() [TestMethod] public void TestFindInternal() { + var myDataCache = new MyDataCache(); + var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -77,6 +75,8 @@ public void TestFindInternal() [TestMethod] public void TestGetInternal() { + var myDataCache = new MyDataCache(); + var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -95,6 +95,8 @@ public void TestGetInternal() [TestMethod] public void TestTryGetInternal() { + var myDataCache = new MyDataCache(); + var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -108,6 +110,8 @@ public void TestTryGetInternal() [TestMethod] public void TestUpdateInternal() { + var myDataCache = new MyDataCache(); + var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); diff --git a/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs b/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs index 591ea8ea05..03625c5ca3 100644 --- a/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs +++ b/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs @@ -7,25 +7,19 @@ namespace Neo.UnitTests.IO.Caching [TestClass] public class UT_CloneMetaCache { - MyMetaCache myMetaCache; - CloneMetaCache cloneMetaCache; - - [TestInitialize] - public void Init() - { - myMetaCache = new MyMetaCache(() => new MyValue()); - cloneMetaCache = new CloneMetaCache(myMetaCache); - } - [TestMethod] public void TestConstructor() { + var myMetaCache = new MyMetaCache(() => new MyValue()); + var cloneMetaCache = new CloneMetaCache(myMetaCache); cloneMetaCache.Should().NotBeNull(); } [TestMethod] public void TestTryGetInternal() { + var myMetaCache = new MyMetaCache(() => new MyValue()); + var cloneMetaCache = new CloneMetaCache(myMetaCache); MyValue value = myMetaCache.GetAndChange(); value.Value = "value1"; @@ -35,6 +29,9 @@ public void TestTryGetInternal() [TestMethod] public void TestUpdateInternal() { + var myMetaCache = new MyMetaCache(() => new MyValue()); + var cloneMetaCache = new CloneMetaCache(myMetaCache); + MyValue value = myMetaCache.GetAndChange(); value.Value = "value1"; diff --git a/neo.UnitTests/IO/Caching/UT_DataCache.cs b/neo.UnitTests/IO/Caching/UT_DataCache.cs index 437f2b92f1..5698619634 100644 --- a/neo.UnitTests/IO/Caching/UT_DataCache.cs +++ b/neo.UnitTests/IO/Caching/UT_DataCache.cs @@ -147,17 +147,10 @@ protected override void UpdateInternal(TKey key, TValue value) [TestClass] public class UT_DataCache { - MyDataCache myDataCache; - - [TestInitialize] - public void Initialize() - { - myDataCache = new MyDataCache(); - } - [TestMethod] public void TestAccessByKey() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); @@ -171,6 +164,7 @@ public void TestAccessByKey() [TestMethod] public void TestAccessByNotFoundKey() { + var myDataCache = new MyDataCache(); Action action = () => { var item = myDataCache[new MyKey("key1")]; @@ -181,6 +175,7 @@ public void TestAccessByNotFoundKey() [TestMethod] public void TestAccessByDeletedKey() { + var myDataCache = new MyDataCache(); myDataCache.InnerDict.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Delete(new MyKey("key1")); @@ -194,6 +189,7 @@ public void TestAccessByDeletedKey() [TestMethod] public void TestAdd() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache[new MyKey("key1")].Should().Be(new MyValue("value1")); @@ -211,6 +207,7 @@ public void TestAdd() [TestMethod] public void TestCommit() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); @@ -230,12 +227,14 @@ public void TestCommit() [TestMethod] public void TestCreateSnapshot() { + var myDataCache = new MyDataCache(); myDataCache.CreateSnapshot().Should().NotBeNull(); } [TestMethod] public void TestDelete() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Delete(new MyKey("key1")); myDataCache.InnerDict.ContainsKey(new MyKey("key1")).Should().BeFalse(); @@ -249,6 +248,7 @@ public void TestDelete() [TestMethod] public void TestDeleteWhere() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); @@ -266,6 +266,7 @@ public void TestDeleteWhere() [TestMethod] public void TestFind() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); @@ -284,6 +285,7 @@ public void TestFind() [TestMethod] public void TestGetChangeSet() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.Add(new MyKey("key2"), new MyValue("value2")); // trackable.State = TrackState.Added @@ -306,6 +308,7 @@ public void TestGetChangeSet() [TestMethod] public void TestGetAndChange() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -320,6 +323,7 @@ public void TestGetAndChange() [TestMethod] public void TestGetOrAdd() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -334,6 +338,7 @@ public void TestGetOrAdd() [TestMethod] public void TestTryGet() { + var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); diff --git a/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs b/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs index 1ed84a5a0e..ae2d84f328 100644 --- a/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs +++ b/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs @@ -32,23 +32,18 @@ protected override void UpdateInternal(T item) [TestClass] public class UT_MetaDataCache { - MyMetaCache myMetaCache; - - [TestInitialize] - public void SetUp() - { - myMetaCache = new MyMetaCache(() => new MyValue()); - } - [TestMethod] public void TestContructor() { + var myMetaCache = new MyMetaCache(() => new MyValue()); myMetaCache.Should().NotBeNull(); } [TestMethod] public void TestCommitAndAddInternal() { + var myMetaCache = new MyMetaCache(() => new MyValue()); + MyValue value = myMetaCache.Get(); value.Should().NotBeNull(); value.Value.Should().BeNull(); @@ -59,6 +54,7 @@ public void TestCommitAndAddInternal() public void TestCommitAndUpdateInternal() { + var myMetaCache = new MyMetaCache(() => new MyValue()); MyValue value = myMetaCache.GetAndChange(); value.Value = "value1"; @@ -70,6 +66,7 @@ public void TestCommitAndUpdateInternal() [TestMethod] public void TestCreateSnapshot() { + var myMetaCache = new MyMetaCache(() => new MyValue()); myMetaCache.CreateSnapshot().Should().NotBeNull(); } } diff --git a/neo.UnitTests/Ledger/UT_MemoryPool.cs b/neo.UnitTests/Ledger/UT_MemoryPool.cs index 27c4d37715..edc77e219b 100644 --- a/neo.UnitTests/Ledger/UT_MemoryPool.cs +++ b/neo.UnitTests/Ledger/UT_MemoryPool.cs @@ -24,6 +24,7 @@ public void TransactionsRemoved(MemoryPoolTxRemovalReason reason, IEnumerable transac } [TestMethod] + [DoNotParallelize] public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() { AddTransactions(100); + var snapshot = Blockchain.Singleton.GetSnapshot().Clone(); var sortedVerifiedTxs = _unit.GetSortedVerifiedTransactions().ToList(); // verify all 100 transactions are returned in sorted order sortedVerifiedTxs.Count.Should().Be(100); @@ -205,7 +213,7 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() // move all to unverified var block = new Block { Transactions = new Transaction[0] }; - _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot()); + _unit.UpdatePoolForBlockPersisted(block, snapshot); _unit.InvalidateVerifiedTransactions(); _unit.SortedTxCount.Should().Be(0); _unit.UnverifiedSortedTxCount.Should().Be(100); @@ -221,13 +229,13 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() var minTransaction = sortedUnverifiedArray.Last(); // reverify 1 high priority and 1 low priority transaction - _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, Blockchain.Singleton.GetSnapshot()); + _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, snapshot); var verifiedTxs = _unit.GetSortedVerifiedTransactions().ToArray(); verifiedTxs.Length.Should().Be(1); verifiedTxs[0].Should().BeEquivalentTo(maxTransaction); var blockWith2Tx = new Block { Transactions = new[] { maxTransaction, minTransaction } }; // verify and remove the 2 transactions from the verified pool - _unit.UpdatePoolForBlockPersisted(blockWith2Tx, Blockchain.Singleton.GetSnapshot()); + _unit.UpdatePoolForBlockPersisted(blockWith2Tx, snapshot); _unit.InvalidateVerifiedTransactions(); _unit.SortedTxCount.Should().Be(0); } @@ -245,6 +253,7 @@ void VerifyCapacityThresholdForAttemptingToAddATransaction() } [TestMethod] + [DoNotParallelize] public void VerifyCanTransactionFitInPoolWorksAsIntended() { AddTransactions(100); @@ -256,6 +265,7 @@ public void VerifyCanTransactionFitInPoolWorksAsIntended() } [TestMethod] + [DoNotParallelize] public void CapacityTestWithUnverifiedHighProirtyTransactions() { // Verify that unverified high priority transactions will not be pushed out of the queue by incoming @@ -265,8 +275,9 @@ public void CapacityTestWithUnverifiedHighProirtyTransactions() AddTransactions(99); // move all to unverified + var snapshot = Blockchain.Singleton.GetSnapshot().Clone(); var block = new Block { Transactions = new Transaction[0] }; - _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot()); + _unit.UpdatePoolForBlockPersisted(block, snapshot); _unit.CanTransactionFitInPool(CreateTransaction()).Should().Be(true); AddTransactions(1); @@ -274,6 +285,7 @@ public void CapacityTestWithUnverifiedHighProirtyTransactions() } [TestMethod] + [DoNotParallelize] public void TestInvalidateAll() { AddTransactions(30); @@ -286,6 +298,7 @@ public void TestInvalidateAll() } [TestMethod] + [DoNotParallelize] public void TestContainsKey() { AddTransactions(10); @@ -298,6 +311,7 @@ public void TestContainsKey() } [TestMethod] + [DoNotParallelize] public void TestGetEnumerator() { AddTransactions(10); @@ -311,6 +325,7 @@ public void TestGetEnumerator() } [TestMethod] + [DoNotParallelize] public void TestIEnumerableGetEnumerator() { AddTransactions(10); @@ -325,6 +340,7 @@ public void TestIEnumerableGetEnumerator() } [TestMethod] + [DoNotParallelize] public void TestGetVerifiedTransactions() { var tx1 = CreateTransaction(); @@ -340,12 +356,15 @@ public void TestGetVerifiedTransactions() } [TestMethod] + [DoNotParallelize] public void TestReVerifyTopUnverifiedTransactionsIfNeeded() { + var snapshot = Blockchain.Singleton.GetSnapshot().Clone(); + NeoSystem TheNeoSystem = TestBlockchain.InitializeMockNeoSystem(); var s = Blockchain.Singleton.Height; _unit = new MemoryPool(TheNeoSystem, 600); - _unit.LoadPolicy(TestBlockchain.GetStore().GetSnapshot()); + _unit.LoadPolicy(snapshot); AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(100000001)); @@ -361,23 +380,24 @@ public void TestReVerifyTopUnverifiedTransactionsIfNeeded() _unit.VerifiedCount.Should().Be(511); _unit.UnVerifiedCount.Should().Be(4); - var result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, Blockchain.Singleton.GetSnapshot()); + var result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, snapshot); result.Should().BeTrue(); _unit.VerifiedCount.Should().Be(512); _unit.UnVerifiedCount.Should().Be(3); - result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(2, Blockchain.Singleton.GetSnapshot()); + result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(2, snapshot); result.Should().BeTrue(); _unit.VerifiedCount.Should().Be(514); _unit.UnVerifiedCount.Should().Be(1); - result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(3, Blockchain.Singleton.GetSnapshot()); + result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(3, snapshot); result.Should().BeFalse(); _unit.VerifiedCount.Should().Be(515); _unit.UnVerifiedCount.Should().Be(0); } [TestMethod] + [DoNotParallelize] public void TestTryAdd() { var tx1 = CreateTransaction(); @@ -387,6 +407,7 @@ public void TestTryAdd() } [TestMethod] + [DoNotParallelize] public void TestTryGetValue() { var tx1 = CreateTransaction(); @@ -403,6 +424,7 @@ public void TestTryGetValue() } [TestMethod] + [DoNotParallelize] public void TestUpdatePoolForBlockPersisted() { var mockSnapshot = new Mock(); diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs index f27421dd74..9e860015a6 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs @@ -10,23 +10,17 @@ namespace Neo.UnitTests.Network.P2P.Payloads [TestClass] public class UT_Block { - Block uut; - - [TestInitialize] - public void TestSetup() - { - uut = new Block(); - } - [TestMethod] public void Transactions_Get() { + var uut = new Block(); uut.Transactions.Should().BeNull(); } [TestMethod] public void Header_Get() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var merkRootVal, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 0); @@ -41,6 +35,7 @@ public void Header_Get() [TestMethod] public void Size_Get() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 0); // blockbase 4 + 64 + 1 + 32 + 4 + 4 + 20 + 4 @@ -51,6 +46,7 @@ public void Size_Get() [TestMethod] public void Size_Get_1_Transaction() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 0); @@ -65,6 +61,7 @@ public void Size_Get_1_Transaction() [TestMethod] public void Size_Get_3_Transaction() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 0); @@ -81,6 +78,7 @@ public void Size_Get_3_Transaction() [TestMethod] public void Serialize() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 1); @@ -91,6 +89,7 @@ public void Serialize() [TestMethod] public void Deserialize() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(new Block(), val256, out var merkRoot, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 1); @@ -103,10 +102,10 @@ public void Deserialize() merkRoot = uut.MerkleRoot; } - assertStandardBlockTestVals(val256, merkRoot, val160, timestampVal, indexVal, scriptVal, transactionsVal); + assertStandardBlockTestVals(uut, val256, merkRoot, val160, timestampVal, indexVal, scriptVal, transactionsVal); } - private void assertStandardBlockTestVals(UInt256 val256, UInt256 merkRoot, UInt160 val160, ulong timestampVal, uint indexVal, Witness scriptVal, Transaction[] transactionsVal, bool testTransactions = true) + private void assertStandardBlockTestVals(Block uut, UInt256 val256, UInt256 merkRoot, UInt160 val160, ulong timestampVal, uint indexVal, Witness scriptVal, Transaction[] transactionsVal, bool testTransactions = true) { uut.PrevHash.Should().Be(val256); uut.MerkleRoot.Should().Be(merkRoot); @@ -126,12 +125,14 @@ private void assertStandardBlockTestVals(UInt256 val256, UInt256 merkRoot, UInt1 [TestMethod] public void Equals_SameObj() { + var uut = new Block(); uut.Equals(uut).Should().BeTrue(); } [TestMethod] public void Equals_DiffObj() { + var uut = new Block(); Block newBlock = new Block(); UInt256 val256 = UInt256.Zero; UInt256 prevHash = new UInt256(TestUtils.GetByteArray(32, 0x42)); @@ -150,13 +151,14 @@ public void Equals_DiffObj() [TestMethod] public void Equals_Null() { + var uut = new Block(); uut.Equals(null).Should().BeFalse(); } [TestMethod] public void Equals_SameHash() { - + var uut = new Block(); Block newBlock = new Block(); UInt256 prevHash = new UInt256(TestUtils.GetByteArray(32, 0x42)); UInt256 merkRoot; @@ -174,6 +176,7 @@ public void Equals_SameHash() [TestMethod] public void RebuildMerkleRoot_Updates() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; UInt256 merkRoot; UInt160 val160; @@ -194,6 +197,7 @@ public void RebuildMerkleRoot_Updates() [TestMethod] public void ToJson() { + var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var merkRoot, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 1); diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index 34ea464d78..0929346410 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -11,7 +11,6 @@ using Neo.SmartContract.Native.Tokens; using Neo.VM; using Neo.Wallets; -using Neo.Wallets.NEP6; using System; using System.Numerics; @@ -20,19 +19,18 @@ namespace Neo.UnitTests.Network.P2P.Payloads [TestClass] public class UT_Transaction { - Transaction uut; Store store; [TestInitialize] public void TestSetup() { - uut = new Transaction(); store = TestBlockchain.GetStore(); } [TestMethod] public void Script_Get() { + var uut = new Transaction(); uut.Script.Should().BeNull(); } @@ -40,6 +38,7 @@ public void Script_Get() public void Script_Set() { byte[] val = TestUtils.GetByteArray(32, 0x42); + var uut = new Transaction(); uut.Script = val; uut.Script.Length.Should().Be(32); for (int i = 0; i < val.Length; i++) @@ -51,6 +50,7 @@ public void Script_Set() [TestMethod] public void Gas_Get() { + var uut = new Transaction(); uut.SystemFee.Should().Be(0); } @@ -58,6 +58,7 @@ public void Gas_Get() public void Gas_Set() { long val = 4200000000; + var uut = new Transaction(); uut.SystemFee = val; uut.SystemFee.Should().Be(val); } @@ -65,6 +66,7 @@ public void Gas_Set() [TestMethod] public void Size_Get() { + var uut = new Transaction(); uut.Script = TestUtils.GetByteArray(32, 0x42); uut.Sender = UInt160.Zero; uut.Attributes = new TransactionAttribute[0]; @@ -1072,6 +1074,7 @@ public void FeeIsSignatureContract_TestScope_Global_Default() [TestMethod] public void ToJson() { + var uut = new Transaction(); uut.Script = TestUtils.GetByteArray(32, 0x42); uut.Sender = UInt160.Zero; uut.SystemFee = 4200000000; diff --git a/neo.UnitTests/Network/RPC/UT_TransactionManager.cs b/neo.UnitTests/Network/RPC/UT_TransactionManager.cs index ee55f81bb9..96b7131888 100644 --- a/neo.UnitTests/Network/RPC/UT_TransactionManager.cs +++ b/neo.UnitTests/Network/RPC/UT_TransactionManager.cs @@ -158,7 +158,7 @@ public void TestSignMulti() .Sign(); var store = TestBlockchain.GetStore(); - var snapshot = store.GetSnapshot(); + var snapshot = store.GetSnapshot().Clone(); var tx = txManager.Tx; Assert.IsTrue(tx.VerifyWitnesses(snapshot, tx.NetworkFee)); diff --git a/neo.UnitTests/Properties/AssemblyInfo.cs b/neo.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..337ef2a0ca --- /dev/null +++ b/neo.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.ClassLevel)] diff --git a/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs b/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs index 0202e9d6d0..9a9147c2bb 100644 --- a/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs +++ b/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs @@ -132,7 +132,7 @@ public void Check_BalanceOfTransferAndBurn() [TestMethod] public void Check_BadScript() { - var engine = new ApplicationEngine(TriggerType.Application, null, Store.GetSnapshot(), 0); + var engine = new ApplicationEngine(TriggerType.Application, null, Store.GetSnapshot().Clone(), 0); var script = new ScriptBuilder(); script.Emit(OpCode.NOP); diff --git a/neo.UnitTests/SmartContract/UT_InteropService.cs b/neo.UnitTests/SmartContract/UT_InteropService.cs index 6a33a32abc..df626a4ed6 100644 --- a/neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/neo.UnitTests/SmartContract/UT_InteropService.cs @@ -18,7 +18,7 @@ public void TestSetup() public void Runtime_GetNotifications_Test() { UInt160 scriptHash2; - var snapshot = TestBlockchain.GetStore().GetSnapshot(); + var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); using (var script = new ScriptBuilder()) { diff --git a/neo.UnitTests/SmartContract/UT_Syscalls.cs b/neo.UnitTests/SmartContract/UT_Syscalls.cs index 65066b9079..44060bf62c 100644 --- a/neo.UnitTests/SmartContract/UT_Syscalls.cs +++ b/neo.UnitTests/SmartContract/UT_Syscalls.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.IO.Caching; using Neo.Ledger; using Neo.SmartContract; using Neo.VM; @@ -12,8 +13,8 @@ public class UT_Syscalls [TestMethod] public void System_Runtime_GetInvocationCounter() { - var snapshot = TestBlockchain.GetStore().GetSnapshot(); - var contracts = (TestDataCache)snapshot.Contracts; + var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); + var contracts = (CloneCache)snapshot.Contracts; // Call System.Runtime.GetInvocationCounter syscall diff --git a/neo.UnitTests/TestBlockchain.cs b/neo.UnitTests/TestBlockchain.cs index 290e054d10..5740c13b08 100644 --- a/neo.UnitTests/TestBlockchain.cs +++ b/neo.UnitTests/TestBlockchain.cs @@ -17,6 +17,12 @@ public static Store GetStore() return _Store.Object; } + static TestBlockchain() + { + InitializeMockNeoSystem(); + GetStore(); + } + public static NeoSystem InitializeMockNeoSystem() { if (TheNeoSystem == null) diff --git a/neo.UnitTests/UT_Culture.cs b/neo.UnitTests/UT_Culture.cs index a16de9717a..4bd7c14b41 100644 --- a/neo.UnitTests/UT_Culture.cs +++ b/neo.UnitTests/UT_Culture.cs @@ -7,7 +7,7 @@ namespace Neo.UnitTests { - [TestClass] + //[TestClass] public class UT_Culture { // This test runs all the other unit tests in the project, with a variety of cultures diff --git a/neo.UnitTests/UT_DataCache.cs b/neo.UnitTests/UT_DataCache.cs index a428e72d8d..3c1da6133e 100644 --- a/neo.UnitTests/UT_DataCache.cs +++ b/neo.UnitTests/UT_DataCache.cs @@ -17,7 +17,7 @@ public void TestSetup() [TestMethod] public void TestCachedFind_Between() { - var snapshot = TestBlockchain.GetStore().GetSnapshot(); + var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); var storages = snapshot.Storages; var cache = new CloneCache(storages); @@ -60,7 +60,7 @@ public void TestCachedFind_Between() [TestMethod] public void TestCachedFind_Last() { - var snapshot = TestBlockchain.GetStore().GetSnapshot(); + var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); var storages = snapshot.Storages; var cache = new CloneCache(storages); @@ -98,7 +98,7 @@ public void TestCachedFind_Last() [TestMethod] public void TestCachedFind_Empty() { - var snapshot = TestBlockchain.GetStore().GetSnapshot(); + var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); var storages = snapshot.Storages; var cache = new CloneCache(storages); diff --git a/neo.UnitTests/UT_ProtocolSettings.cs b/neo.UnitTests/UT_ProtocolSettings.cs index a5fa189231..7c11c01c48 100644 --- a/neo.UnitTests/UT_ProtocolSettings.cs +++ b/neo.UnitTests/UT_ProtocolSettings.cs @@ -1,14 +1,13 @@ using FluentAssertions; using Microsoft.Extensions.Configuration; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; using System.Collections.Generic; using System.Reflection; -using System.Text; namespace Neo.UnitTests { [TestClass] + [DoNotParallelize] public class UT_ProtocolSettings { // since ProtocolSettings.Default is designed to be writable only once, use reflection to @@ -21,18 +20,21 @@ static void ResetProtocolSettings() } [TestInitialize] + [DoNotParallelize] public void Initialize() { ResetProtocolSettings(); } [TestCleanup] + [DoNotParallelize] public void Cleanup() { ResetProtocolSettings(); } [TestMethod] + [DoNotParallelize] public void Default_Magic_should_be_mainnet_Magic_value() { var mainNetMagic = 0x4F454Eu; @@ -40,6 +42,7 @@ public void Default_Magic_should_be_mainnet_Magic_value() } [TestMethod] + [DoNotParallelize] public void Can_initialize_ProtocolSettings() { var expectedMagic = 12345u; @@ -55,6 +58,7 @@ public void Can_initialize_ProtocolSettings() } [TestMethod] + [DoNotParallelize] public void Cant_initialize_ProtocolSettings_after_default_settings_used() { var mainNetMagic = 0x4F454Eu; @@ -72,6 +76,7 @@ public void Cant_initialize_ProtocolSettings_after_default_settings_used() } [TestMethod] + [DoNotParallelize] public void Cant_initialize_ProtocolSettings_twice() { var expectedMagic = 12345u; diff --git a/neo.UnitTests/Wallets/UT_AssetDescriptor.cs b/neo.UnitTests/Wallets/UT_AssetDescriptor.cs index 697e631200..937a0d89f7 100644 --- a/neo.UnitTests/Wallets/UT_AssetDescriptor.cs +++ b/neo.UnitTests/Wallets/UT_AssetDescriptor.cs @@ -9,13 +9,10 @@ namespace Neo.UnitTests.Wallets [TestClass] public class UT_AssetDescriptor { - private Store Store; - [TestInitialize] public void TestSetup() { TestBlockchain.InitializeMockNeoSystem(); - Store = TestBlockchain.GetStore(); } [TestMethod] From 284385008aceb111bc1c805a08e358aa22f28ce6 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 19:07:44 +0200 Subject: [PATCH 20/27] format --- neo.UnitTests/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo.UnitTests/Properties/AssemblyInfo.cs b/neo.UnitTests/Properties/AssemblyInfo.cs index 337ef2a0ca..903504edce 100644 --- a/neo.UnitTests/Properties/AssemblyInfo.cs +++ b/neo.UnitTests/Properties/AssemblyInfo.cs @@ -1,3 +1,3 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - +using Microsoft.VisualStudio.TestTools.UnitTesting; + [assembly: Parallelize(Workers = 0, Scope = ExecutionScope.ClassLevel)] From 39c7e5908d8dc9d530318f0ec399572161089b4b Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 20:03:58 +0200 Subject: [PATCH 21/27] Update .travis.yml --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7d6740aa4..0c58c94418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ dist: bionic osx_image: xcode9.1 mono: none -dotnet: 2.2.300 +dotnet: 2.2.301 env: - TEST_SUITE="without-cultures" @@ -24,18 +24,17 @@ before_script: - echo "Checking format..." - dotnet format --check --dry-run -w . -v diagnostic # check C# formatting for neo.sln - cd neo.UnitTests - - dotnet restore script: | if [[ "$TEST_SUITE" == "cultures" ]]; then - dotnet test -v n --no-restore --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v n --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures else if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then # Test & Calculate coverage find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild - dotnet test -v n --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet test -v n --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover else # Only test - dotnet test -v n --no-restore --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v n --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures fi fi after_success: | From c69e452b85108baacf10d6824febfc2da4819bba Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 20:08:27 +0200 Subject: [PATCH 22/27] Fix --- neo.UnitTests/UT_Culture.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo.UnitTests/UT_Culture.cs b/neo.UnitTests/UT_Culture.cs index 4bd7c14b41..a16de9717a 100644 --- a/neo.UnitTests/UT_Culture.cs +++ b/neo.UnitTests/UT_Culture.cs @@ -7,7 +7,7 @@ namespace Neo.UnitTests { - //[TestClass] + [TestClass] public class UT_Culture { // This test runs all the other unit tests in the project, with a variety of cultures From fa0e87c0d469bb0d9698f2939ec2bef9e144cddd Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 20:14:58 +0200 Subject: [PATCH 23/27] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0c58c94418..0f8d7abc95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ dist: bionic osx_image: xcode9.1 mono: none -dotnet: 2.2.301 +dotnet: 2.2.402 env: - TEST_SUITE="without-cultures" From 14bc4743dbe535b98f64a674281a35a282a39f97 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 20:51:09 +0200 Subject: [PATCH 24/27] Min verbose --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0f8d7abc95..59b745ca31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,15 +26,15 @@ before_script: - cd neo.UnitTests script: | if [[ "$TEST_SUITE" == "cultures" ]]; then - dotnet test -v n --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v m --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures else if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then # Test & Calculate coverage find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild - dotnet test -v n --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover else # Only test - dotnet test -v n --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures + dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures fi fi after_success: | From 8cd9e222d03bd0622e4afe5fec82c29defbd345c Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 22:52:29 +0200 Subject: [PATCH 25/27] Remove parallel execution --- neo.UnitTests/IO/Caching/UT_Cache.cs | 22 +++----- neo.UnitTests/IO/Caching/UT_CloneCache.cs | 24 ++++----- neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs | 17 +++--- neo.UnitTests/IO/Caching/UT_DataCache.cs | 21 +++----- neo.UnitTests/IO/Caching/UT_MetaDataCache.cs | 13 +++-- neo.UnitTests/Ledger/UT_MemoryPool.cs | 54 ++++++------------- .../Network/P2P/Payloads/UT_Block.cs | 26 ++++----- .../Network/P2P/Payloads/UT_Transaction.cs | 8 +-- .../Network/RPC/UT_TransactionManager.cs | 2 +- neo.UnitTests/Properties/AssemblyInfo.cs | 3 -- .../Native/Tokens/UT_GasToken.cs | 2 +- .../SmartContract/UT_InteropService.cs | 2 +- neo.UnitTests/SmartContract/UT_Syscalls.cs | 5 +- neo.UnitTests/UT_DataCache.cs | 6 +-- neo.UnitTests/UT_ProtocolSettings.cs | 7 --- 15 files changed, 80 insertions(+), 132 deletions(-) delete mode 100644 neo.UnitTests/Properties/AssemblyInfo.cs diff --git a/neo.UnitTests/IO/Caching/UT_Cache.cs b/neo.UnitTests/IO/Caching/UT_Cache.cs index 80431798e9..65728bd82d 100644 --- a/neo.UnitTests/IO/Caching/UT_Cache.cs +++ b/neo.UnitTests/IO/Caching/UT_Cache.cs @@ -57,12 +57,18 @@ public IEnumerator MyGetEnumerator() [TestClass] public class UT_Cache { + MyCache cache; readonly int max_capacity = 4; + [TestInitialize] + public void init() + { + cache = new MyCache(max_capacity); + } + [TestMethod] public void TestCount() { - var cache = new MyCache(max_capacity); cache.Count.Should().Be(0); cache.Add("hello"); @@ -76,14 +82,12 @@ public void TestCount() [TestMethod] public void TestIsReadOnly() { - var cache = new MyCache(max_capacity); cache.IsReadOnly.Should().BeFalse(); } [TestMethod] public void TestAddAndAddInternal() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Contains("hello").Should().BeTrue(); cache.Contains("world").Should().BeFalse(); @@ -95,7 +99,6 @@ public void TestAddAndAddInternal() public void TestAddRange() { string[] range = { "hello", "world" }; - var cache = new MyCache(max_capacity); cache.AddRange(range); cache.Count.Should().Be(2); cache.Contains("hello").Should().BeTrue(); @@ -106,7 +109,6 @@ public void TestAddRange() [TestMethod] public void TestClear() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); cache.Count.Should().Be(2); @@ -117,7 +119,6 @@ public void TestClear() [TestMethod] public void TestContainsKey() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Contains("hello").Should().BeTrue(); cache.Contains("world").Should().BeFalse(); @@ -126,7 +127,6 @@ public void TestContainsKey() [TestMethod] public void TestContainsValue() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Contains("hello".GetHashCode()).Should().BeTrue(); cache.Contains("world".GetHashCode()).Should().BeFalse(); @@ -135,7 +135,6 @@ public void TestContainsValue() [TestMethod] public void TestCopyTo() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); string[] temp = new string[2]; @@ -157,7 +156,6 @@ public void TestCopyTo() [TestMethod] public void TestRemoveKey() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Remove("hello".GetHashCode()).Should().BeTrue(); cache.Remove("world".GetHashCode()).Should().BeFalse(); @@ -180,7 +178,6 @@ public void TestRemoveDisposableKey() [TestMethod] public void TestRemoveValue() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Remove("hello").Should().BeTrue(); cache.Remove("world").Should().BeFalse(); @@ -190,7 +187,6 @@ public void TestRemoveValue() [TestMethod] public void TestTryGet() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.TryGet("hello".GetHashCode(), out string output).Should().BeTrue(); output.Should().Be("hello"); @@ -202,7 +198,6 @@ public void TestTryGet() [TestMethod] public void TestArrayIndexAccess() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); cache["hello".GetHashCode()].Should().Be("hello"); @@ -218,7 +213,6 @@ public void TestArrayIndexAccess() [TestMethod] public void TestGetEnumerator() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); int i = 0; @@ -236,7 +230,6 @@ public void TestGetEnumerator() public void TestOverMaxCapacity() { int i = 1; - var cache = new MyCache(max_capacity); for (; i <= max_capacity; i++) { cache.Add(i.ToString()); @@ -249,7 +242,6 @@ public void TestOverMaxCapacity() [TestMethod] public void TestDispose() { - var cache = new MyCache(max_capacity); cache.Add("hello"); cache.Add("world"); cache.Dispose(); diff --git a/neo.UnitTests/IO/Caching/UT_CloneCache.cs b/neo.UnitTests/IO/Caching/UT_CloneCache.cs index 2d56ff8bcc..b75a70ee97 100644 --- a/neo.UnitTests/IO/Caching/UT_CloneCache.cs +++ b/neo.UnitTests/IO/Caching/UT_CloneCache.cs @@ -11,19 +11,25 @@ namespace Neo.UnitTests.IO.Caching [TestClass] public class UT_CloneCache { + CloneCache cloneCache; + MyDataCache myDataCache; + + [TestInitialize] + public void Init() + { + myDataCache = new MyDataCache(); + cloneCache = new CloneCache(myDataCache); + } + [TestMethod] public void TestCloneCache() { - var myDataCache = new MyDataCache(); - var cloneCache = new CloneCache(myDataCache); cloneCache.Should().NotBeNull(); } [TestMethod] public void TestAddInternal() { - var myDataCache = new MyDataCache(); - var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); cloneCache[new MyKey("key1")].Should().Be(new MyValue("value1")); @@ -34,8 +40,6 @@ public void TestAddInternal() [TestMethod] public void TestDeleteInternal() { - var myDataCache = new MyDataCache(); - var cloneCache = new CloneCache(myDataCache); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); cloneCache.Delete(new MyKey("key1")); // trackable.State = TrackState.Deleted cloneCache.Commit(); @@ -47,8 +51,6 @@ public void TestDeleteInternal() [TestMethod] public void TestFindInternal() { - var myDataCache = new MyDataCache(); - var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -75,8 +77,6 @@ public void TestFindInternal() [TestMethod] public void TestGetInternal() { - var myDataCache = new MyDataCache(); - var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -95,8 +95,6 @@ public void TestGetInternal() [TestMethod] public void TestTryGetInternal() { - var myDataCache = new MyDataCache(); - var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -110,8 +108,6 @@ public void TestTryGetInternal() [TestMethod] public void TestUpdateInternal() { - var myDataCache = new MyDataCache(); - var cloneCache = new CloneCache(myDataCache); cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); diff --git a/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs b/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs index 03625c5ca3..591ea8ea05 100644 --- a/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs +++ b/neo.UnitTests/IO/Caching/UT_CloneMetaCache.cs @@ -7,19 +7,25 @@ namespace Neo.UnitTests.IO.Caching [TestClass] public class UT_CloneMetaCache { + MyMetaCache myMetaCache; + CloneMetaCache cloneMetaCache; + + [TestInitialize] + public void Init() + { + myMetaCache = new MyMetaCache(() => new MyValue()); + cloneMetaCache = new CloneMetaCache(myMetaCache); + } + [TestMethod] public void TestConstructor() { - var myMetaCache = new MyMetaCache(() => new MyValue()); - var cloneMetaCache = new CloneMetaCache(myMetaCache); cloneMetaCache.Should().NotBeNull(); } [TestMethod] public void TestTryGetInternal() { - var myMetaCache = new MyMetaCache(() => new MyValue()); - var cloneMetaCache = new CloneMetaCache(myMetaCache); MyValue value = myMetaCache.GetAndChange(); value.Value = "value1"; @@ -29,9 +35,6 @@ public void TestTryGetInternal() [TestMethod] public void TestUpdateInternal() { - var myMetaCache = new MyMetaCache(() => new MyValue()); - var cloneMetaCache = new CloneMetaCache(myMetaCache); - MyValue value = myMetaCache.GetAndChange(); value.Value = "value1"; diff --git a/neo.UnitTests/IO/Caching/UT_DataCache.cs b/neo.UnitTests/IO/Caching/UT_DataCache.cs index 5698619634..437f2b92f1 100644 --- a/neo.UnitTests/IO/Caching/UT_DataCache.cs +++ b/neo.UnitTests/IO/Caching/UT_DataCache.cs @@ -147,10 +147,17 @@ protected override void UpdateInternal(TKey key, TValue value) [TestClass] public class UT_DataCache { + MyDataCache myDataCache; + + [TestInitialize] + public void Initialize() + { + myDataCache = new MyDataCache(); + } + [TestMethod] public void TestAccessByKey() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); @@ -164,7 +171,6 @@ public void TestAccessByKey() [TestMethod] public void TestAccessByNotFoundKey() { - var myDataCache = new MyDataCache(); Action action = () => { var item = myDataCache[new MyKey("key1")]; @@ -175,7 +181,6 @@ public void TestAccessByNotFoundKey() [TestMethod] public void TestAccessByDeletedKey() { - var myDataCache = new MyDataCache(); myDataCache.InnerDict.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Delete(new MyKey("key1")); @@ -189,7 +194,6 @@ public void TestAccessByDeletedKey() [TestMethod] public void TestAdd() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache[new MyKey("key1")].Should().Be(new MyValue("value1")); @@ -207,7 +211,6 @@ public void TestAdd() [TestMethod] public void TestCommit() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); @@ -227,14 +230,12 @@ public void TestCommit() [TestMethod] public void TestCreateSnapshot() { - var myDataCache = new MyDataCache(); myDataCache.CreateSnapshot().Should().NotBeNull(); } [TestMethod] public void TestDelete() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Delete(new MyKey("key1")); myDataCache.InnerDict.ContainsKey(new MyKey("key1")).Should().BeFalse(); @@ -248,7 +249,6 @@ public void TestDelete() [TestMethod] public void TestDeleteWhere() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); @@ -266,7 +266,6 @@ public void TestDeleteWhere() [TestMethod] public void TestFind() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); @@ -285,7 +284,6 @@ public void TestFind() [TestMethod] public void TestGetChangeSet() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.Add(new MyKey("key2"), new MyValue("value2")); // trackable.State = TrackState.Added @@ -308,7 +306,6 @@ public void TestGetChangeSet() [TestMethod] public void TestGetAndChange() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -323,7 +320,6 @@ public void TestGetAndChange() [TestMethod] public void TestGetOrAdd() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); @@ -338,7 +334,6 @@ public void TestGetOrAdd() [TestMethod] public void TestTryGet() { - var myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); // trackable.State = TrackState.Added myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); diff --git a/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs b/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs index ae2d84f328..1ed84a5a0e 100644 --- a/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs +++ b/neo.UnitTests/IO/Caching/UT_MetaDataCache.cs @@ -32,18 +32,23 @@ protected override void UpdateInternal(T item) [TestClass] public class UT_MetaDataCache { + MyMetaCache myMetaCache; + + [TestInitialize] + public void SetUp() + { + myMetaCache = new MyMetaCache(() => new MyValue()); + } + [TestMethod] public void TestContructor() { - var myMetaCache = new MyMetaCache(() => new MyValue()); myMetaCache.Should().NotBeNull(); } [TestMethod] public void TestCommitAndAddInternal() { - var myMetaCache = new MyMetaCache(() => new MyValue()); - MyValue value = myMetaCache.Get(); value.Should().NotBeNull(); value.Value.Should().BeNull(); @@ -54,7 +59,6 @@ public void TestCommitAndAddInternal() public void TestCommitAndUpdateInternal() { - var myMetaCache = new MyMetaCache(() => new MyValue()); MyValue value = myMetaCache.GetAndChange(); value.Value = "value1"; @@ -66,7 +70,6 @@ public void TestCommitAndUpdateInternal() [TestMethod] public void TestCreateSnapshot() { - var myMetaCache = new MyMetaCache(() => new MyValue()); myMetaCache.CreateSnapshot().Should().NotBeNull(); } } diff --git a/neo.UnitTests/Ledger/UT_MemoryPool.cs b/neo.UnitTests/Ledger/UT_MemoryPool.cs index edc77e219b..cd3aace173 100644 --- a/neo.UnitTests/Ledger/UT_MemoryPool.cs +++ b/neo.UnitTests/Ledger/UT_MemoryPool.cs @@ -24,7 +24,6 @@ public void TransactionsRemoved(MemoryPoolTxRemovalReason reason, IEnumerable transac } [TestMethod] - [DoNotParallelize] public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() { AddTransactions(100); - var snapshot = Blockchain.Singleton.GetSnapshot().Clone(); var sortedVerifiedTxs = _unit.GetSortedVerifiedTransactions().ToList(); // verify all 100 transactions are returned in sorted order sortedVerifiedTxs.Count.Should().Be(100); @@ -213,7 +205,7 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() // move all to unverified var block = new Block { Transactions = new Transaction[0] }; - _unit.UpdatePoolForBlockPersisted(block, snapshot); + _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot()); _unit.InvalidateVerifiedTransactions(); _unit.SortedTxCount.Should().Be(0); _unit.UnverifiedSortedTxCount.Should().Be(100); @@ -229,13 +221,13 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() var minTransaction = sortedUnverifiedArray.Last(); // reverify 1 high priority and 1 low priority transaction - _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, snapshot); + _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, Blockchain.Singleton.GetSnapshot()); var verifiedTxs = _unit.GetSortedVerifiedTransactions().ToArray(); verifiedTxs.Length.Should().Be(1); verifiedTxs[0].Should().BeEquivalentTo(maxTransaction); var blockWith2Tx = new Block { Transactions = new[] { maxTransaction, minTransaction } }; // verify and remove the 2 transactions from the verified pool - _unit.UpdatePoolForBlockPersisted(blockWith2Tx, snapshot); + _unit.UpdatePoolForBlockPersisted(blockWith2Tx, Blockchain.Singleton.GetSnapshot()); _unit.InvalidateVerifiedTransactions(); _unit.SortedTxCount.Should().Be(0); } @@ -253,7 +245,6 @@ void VerifyCapacityThresholdForAttemptingToAddATransaction() } [TestMethod] - [DoNotParallelize] public void VerifyCanTransactionFitInPoolWorksAsIntended() { AddTransactions(100); @@ -265,7 +256,6 @@ public void VerifyCanTransactionFitInPoolWorksAsIntended() } [TestMethod] - [DoNotParallelize] public void CapacityTestWithUnverifiedHighProirtyTransactions() { // Verify that unverified high priority transactions will not be pushed out of the queue by incoming @@ -275,9 +265,8 @@ public void CapacityTestWithUnverifiedHighProirtyTransactions() AddTransactions(99); // move all to unverified - var snapshot = Blockchain.Singleton.GetSnapshot().Clone(); var block = new Block { Transactions = new Transaction[0] }; - _unit.UpdatePoolForBlockPersisted(block, snapshot); + _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot()); _unit.CanTransactionFitInPool(CreateTransaction()).Should().Be(true); AddTransactions(1); @@ -285,7 +274,6 @@ public void CapacityTestWithUnverifiedHighProirtyTransactions() } [TestMethod] - [DoNotParallelize] public void TestInvalidateAll() { AddTransactions(30); @@ -298,7 +286,6 @@ public void TestInvalidateAll() } [TestMethod] - [DoNotParallelize] public void TestContainsKey() { AddTransactions(10); @@ -311,7 +298,6 @@ public void TestContainsKey() } [TestMethod] - [DoNotParallelize] public void TestGetEnumerator() { AddTransactions(10); @@ -325,7 +311,6 @@ public void TestGetEnumerator() } [TestMethod] - [DoNotParallelize] public void TestIEnumerableGetEnumerator() { AddTransactions(10); @@ -340,7 +325,6 @@ public void TestIEnumerableGetEnumerator() } [TestMethod] - [DoNotParallelize] public void TestGetVerifiedTransactions() { var tx1 = CreateTransaction(); @@ -356,15 +340,12 @@ public void TestGetVerifiedTransactions() } [TestMethod] - [DoNotParallelize] public void TestReVerifyTopUnverifiedTransactionsIfNeeded() { - var snapshot = Blockchain.Singleton.GetSnapshot().Clone(); - NeoSystem TheNeoSystem = TestBlockchain.InitializeMockNeoSystem(); var s = Blockchain.Singleton.Height; _unit = new MemoryPool(TheNeoSystem, 600); - _unit.LoadPolicy(snapshot); + _unit.LoadPolicy(Blockchain.Singleton.GetSnapshot()); AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(100000001)); @@ -380,24 +361,23 @@ public void TestReVerifyTopUnverifiedTransactionsIfNeeded() _unit.VerifiedCount.Should().Be(511); _unit.UnVerifiedCount.Should().Be(4); - var result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, snapshot); + var result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, Blockchain.Singleton.GetSnapshot()); result.Should().BeTrue(); _unit.VerifiedCount.Should().Be(512); _unit.UnVerifiedCount.Should().Be(3); - result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(2, snapshot); + result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(2, Blockchain.Singleton.GetSnapshot()); result.Should().BeTrue(); _unit.VerifiedCount.Should().Be(514); _unit.UnVerifiedCount.Should().Be(1); - result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(3, snapshot); + result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(3, Blockchain.Singleton.GetSnapshot()); result.Should().BeFalse(); _unit.VerifiedCount.Should().Be(515); _unit.UnVerifiedCount.Should().Be(0); } [TestMethod] - [DoNotParallelize] public void TestTryAdd() { var tx1 = CreateTransaction(); @@ -407,7 +387,6 @@ public void TestTryAdd() } [TestMethod] - [DoNotParallelize] public void TestTryGetValue() { var tx1 = CreateTransaction(); @@ -424,7 +403,6 @@ public void TestTryGetValue() } [TestMethod] - [DoNotParallelize] public void TestUpdatePoolForBlockPersisted() { var mockSnapshot = new Mock(); diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs index 9e860015a6..f27421dd74 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs @@ -10,17 +10,23 @@ namespace Neo.UnitTests.Network.P2P.Payloads [TestClass] public class UT_Block { + Block uut; + + [TestInitialize] + public void TestSetup() + { + uut = new Block(); + } + [TestMethod] public void Transactions_Get() { - var uut = new Block(); uut.Transactions.Should().BeNull(); } [TestMethod] public void Header_Get() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var merkRootVal, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 0); @@ -35,7 +41,6 @@ public void Header_Get() [TestMethod] public void Size_Get() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 0); // blockbase 4 + 64 + 1 + 32 + 4 + 4 + 20 + 4 @@ -46,7 +51,6 @@ public void Size_Get() [TestMethod] public void Size_Get_1_Transaction() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 0); @@ -61,7 +65,6 @@ public void Size_Get_1_Transaction() [TestMethod] public void Size_Get_3_Transaction() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 0); @@ -78,7 +81,6 @@ public void Size_Get_3_Transaction() [TestMethod] public void Serialize() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 1); @@ -89,7 +91,6 @@ public void Serialize() [TestMethod] public void Deserialize() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(new Block(), val256, out var merkRoot, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 1); @@ -102,10 +103,10 @@ public void Deserialize() merkRoot = uut.MerkleRoot; } - assertStandardBlockTestVals(uut, val256, merkRoot, val160, timestampVal, indexVal, scriptVal, transactionsVal); + assertStandardBlockTestVals(val256, merkRoot, val160, timestampVal, indexVal, scriptVal, transactionsVal); } - private void assertStandardBlockTestVals(Block uut, UInt256 val256, UInt256 merkRoot, UInt160 val160, ulong timestampVal, uint indexVal, Witness scriptVal, Transaction[] transactionsVal, bool testTransactions = true) + private void assertStandardBlockTestVals(UInt256 val256, UInt256 merkRoot, UInt160 val160, ulong timestampVal, uint indexVal, Witness scriptVal, Transaction[] transactionsVal, bool testTransactions = true) { uut.PrevHash.Should().Be(val256); uut.MerkleRoot.Should().Be(merkRoot); @@ -125,14 +126,12 @@ private void assertStandardBlockTestVals(Block uut, UInt256 val256, UInt256 merk [TestMethod] public void Equals_SameObj() { - var uut = new Block(); uut.Equals(uut).Should().BeTrue(); } [TestMethod] public void Equals_DiffObj() { - var uut = new Block(); Block newBlock = new Block(); UInt256 val256 = UInt256.Zero; UInt256 prevHash = new UInt256(TestUtils.GetByteArray(32, 0x42)); @@ -151,14 +150,13 @@ public void Equals_DiffObj() [TestMethod] public void Equals_Null() { - var uut = new Block(); uut.Equals(null).Should().BeFalse(); } [TestMethod] public void Equals_SameHash() { - var uut = new Block(); + Block newBlock = new Block(); UInt256 prevHash = new UInt256(TestUtils.GetByteArray(32, 0x42)); UInt256 merkRoot; @@ -176,7 +174,6 @@ public void Equals_SameHash() [TestMethod] public void RebuildMerkleRoot_Updates() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; UInt256 merkRoot; UInt160 val160; @@ -197,7 +194,6 @@ public void RebuildMerkleRoot_Updates() [TestMethod] public void ToJson() { - var uut = new Block(); UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var merkRoot, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 1); diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index 0929346410..d52867e99e 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -19,18 +19,19 @@ namespace Neo.UnitTests.Network.P2P.Payloads [TestClass] public class UT_Transaction { + Transaction uut; Store store; [TestInitialize] public void TestSetup() { + uut = new Transaction(); store = TestBlockchain.GetStore(); } [TestMethod] public void Script_Get() { - var uut = new Transaction(); uut.Script.Should().BeNull(); } @@ -38,7 +39,6 @@ public void Script_Get() public void Script_Set() { byte[] val = TestUtils.GetByteArray(32, 0x42); - var uut = new Transaction(); uut.Script = val; uut.Script.Length.Should().Be(32); for (int i = 0; i < val.Length; i++) @@ -50,7 +50,6 @@ public void Script_Set() [TestMethod] public void Gas_Get() { - var uut = new Transaction(); uut.SystemFee.Should().Be(0); } @@ -58,7 +57,6 @@ public void Gas_Get() public void Gas_Set() { long val = 4200000000; - var uut = new Transaction(); uut.SystemFee = val; uut.SystemFee.Should().Be(val); } @@ -66,7 +64,6 @@ public void Gas_Set() [TestMethod] public void Size_Get() { - var uut = new Transaction(); uut.Script = TestUtils.GetByteArray(32, 0x42); uut.Sender = UInt160.Zero; uut.Attributes = new TransactionAttribute[0]; @@ -1074,7 +1071,6 @@ public void FeeIsSignatureContract_TestScope_Global_Default() [TestMethod] public void ToJson() { - var uut = new Transaction(); uut.Script = TestUtils.GetByteArray(32, 0x42); uut.Sender = UInt160.Zero; uut.SystemFee = 4200000000; diff --git a/neo.UnitTests/Network/RPC/UT_TransactionManager.cs b/neo.UnitTests/Network/RPC/UT_TransactionManager.cs index 96b7131888..ee55f81bb9 100644 --- a/neo.UnitTests/Network/RPC/UT_TransactionManager.cs +++ b/neo.UnitTests/Network/RPC/UT_TransactionManager.cs @@ -158,7 +158,7 @@ public void TestSignMulti() .Sign(); var store = TestBlockchain.GetStore(); - var snapshot = store.GetSnapshot().Clone(); + var snapshot = store.GetSnapshot(); var tx = txManager.Tx; Assert.IsTrue(tx.VerifyWitnesses(snapshot, tx.NetworkFee)); diff --git a/neo.UnitTests/Properties/AssemblyInfo.cs b/neo.UnitTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 903504edce..0000000000 --- a/neo.UnitTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.ClassLevel)] diff --git a/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs b/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs index 9a9147c2bb..0202e9d6d0 100644 --- a/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs +++ b/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs @@ -132,7 +132,7 @@ public void Check_BalanceOfTransferAndBurn() [TestMethod] public void Check_BadScript() { - var engine = new ApplicationEngine(TriggerType.Application, null, Store.GetSnapshot().Clone(), 0); + var engine = new ApplicationEngine(TriggerType.Application, null, Store.GetSnapshot(), 0); var script = new ScriptBuilder(); script.Emit(OpCode.NOP); diff --git a/neo.UnitTests/SmartContract/UT_InteropService.cs b/neo.UnitTests/SmartContract/UT_InteropService.cs index df626a4ed6..6a33a32abc 100644 --- a/neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/neo.UnitTests/SmartContract/UT_InteropService.cs @@ -18,7 +18,7 @@ public void TestSetup() public void Runtime_GetNotifications_Test() { UInt160 scriptHash2; - var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); + var snapshot = TestBlockchain.GetStore().GetSnapshot(); using (var script = new ScriptBuilder()) { diff --git a/neo.UnitTests/SmartContract/UT_Syscalls.cs b/neo.UnitTests/SmartContract/UT_Syscalls.cs index 44060bf62c..65066b9079 100644 --- a/neo.UnitTests/SmartContract/UT_Syscalls.cs +++ b/neo.UnitTests/SmartContract/UT_Syscalls.cs @@ -1,5 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Neo.IO.Caching; using Neo.Ledger; using Neo.SmartContract; using Neo.VM; @@ -13,8 +12,8 @@ public class UT_Syscalls [TestMethod] public void System_Runtime_GetInvocationCounter() { - var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); - var contracts = (CloneCache)snapshot.Contracts; + var snapshot = TestBlockchain.GetStore().GetSnapshot(); + var contracts = (TestDataCache)snapshot.Contracts; // Call System.Runtime.GetInvocationCounter syscall diff --git a/neo.UnitTests/UT_DataCache.cs b/neo.UnitTests/UT_DataCache.cs index 3c1da6133e..a428e72d8d 100644 --- a/neo.UnitTests/UT_DataCache.cs +++ b/neo.UnitTests/UT_DataCache.cs @@ -17,7 +17,7 @@ public void TestSetup() [TestMethod] public void TestCachedFind_Between() { - var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); + var snapshot = TestBlockchain.GetStore().GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache(storages); @@ -60,7 +60,7 @@ public void TestCachedFind_Between() [TestMethod] public void TestCachedFind_Last() { - var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); + var snapshot = TestBlockchain.GetStore().GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache(storages); @@ -98,7 +98,7 @@ public void TestCachedFind_Last() [TestMethod] public void TestCachedFind_Empty() { - var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone(); + var snapshot = TestBlockchain.GetStore().GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache(storages); diff --git a/neo.UnitTests/UT_ProtocolSettings.cs b/neo.UnitTests/UT_ProtocolSettings.cs index 7c11c01c48..77c56df424 100644 --- a/neo.UnitTests/UT_ProtocolSettings.cs +++ b/neo.UnitTests/UT_ProtocolSettings.cs @@ -7,7 +7,6 @@ namespace Neo.UnitTests { [TestClass] - [DoNotParallelize] public class UT_ProtocolSettings { // since ProtocolSettings.Default is designed to be writable only once, use reflection to @@ -20,21 +19,18 @@ static void ResetProtocolSettings() } [TestInitialize] - [DoNotParallelize] public void Initialize() { ResetProtocolSettings(); } [TestCleanup] - [DoNotParallelize] public void Cleanup() { ResetProtocolSettings(); } [TestMethod] - [DoNotParallelize] public void Default_Magic_should_be_mainnet_Magic_value() { var mainNetMagic = 0x4F454Eu; @@ -42,7 +38,6 @@ public void Default_Magic_should_be_mainnet_Magic_value() } [TestMethod] - [DoNotParallelize] public void Can_initialize_ProtocolSettings() { var expectedMagic = 12345u; @@ -58,7 +53,6 @@ public void Can_initialize_ProtocolSettings() } [TestMethod] - [DoNotParallelize] public void Cant_initialize_ProtocolSettings_after_default_settings_used() { var mainNetMagic = 0x4F454Eu; @@ -76,7 +70,6 @@ public void Cant_initialize_ProtocolSettings_after_default_settings_used() } [TestMethod] - [DoNotParallelize] public void Cant_initialize_ProtocolSettings_twice() { var expectedMagic = 12345u; From cf53dcae27fc1cffd921d867e4c8e2680456883d Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 1 Oct 2019 22:55:17 +0200 Subject: [PATCH 26/27] Fix change --- neo.UnitTests/Ledger/UT_MemoryPool.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo.UnitTests/Ledger/UT_MemoryPool.cs b/neo.UnitTests/Ledger/UT_MemoryPool.cs index cd3aace173..27c4d37715 100644 --- a/neo.UnitTests/Ledger/UT_MemoryPool.cs +++ b/neo.UnitTests/Ledger/UT_MemoryPool.cs @@ -345,7 +345,7 @@ public void TestReVerifyTopUnverifiedTransactionsIfNeeded() NeoSystem TheNeoSystem = TestBlockchain.InitializeMockNeoSystem(); var s = Blockchain.Singleton.Height; _unit = new MemoryPool(TheNeoSystem, 600); - _unit.LoadPolicy(Blockchain.Singleton.GetSnapshot()); + _unit.LoadPolicy(TestBlockchain.GetStore().GetSnapshot()); AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(100000001)); From b5ae4736b6caf5111c36c1bbc2cca0a6bea9b65a Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 2 Oct 2019 15:50:01 +0200 Subject: [PATCH 27/27] Revert AsParallel() --- neo/IO/Caching/Cache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/IO/Caching/Cache.cs b/neo/IO/Caching/Cache.cs index a5e0e22f57..b5095231f3 100644 --- a/neo/IO/Caching/Cache.cs +++ b/neo/IO/Caching/Cache.cs @@ -92,7 +92,7 @@ private void AddInternal(TKey key, TValue item) if (InnerDictionary.Count >= max_capacity) { //TODO: Perform a performance test on the PLINQ query to determine which algorithm is better here (parallel or not) - foreach (CacheItem item_del in InnerDictionary.Values.OrderBy(p => p.Time).Take(InnerDictionary.Count - max_capacity + 1)) + foreach (CacheItem item_del in InnerDictionary.Values.AsParallel().OrderBy(p => p.Time).Take(InnerDictionary.Count - max_capacity + 1)) { RemoveInternal(item_del); }