diff --git a/.travis.yml b/.travis.yml index f08f8110bb..59b745ca31 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.402 env: - TEST_SUITE="without-cultures" @@ -25,15 +25,21 @@ before_script: - dotnet format --check --dry-run -w . -v diagnostic # check C# formatting for neo.sln - cd neo.UnitTests script: | - dotnet restore - if [[ "$TEST_SUITE" == cultures ]]; then - dotnet test + if [[ "$TEST_SUITE" == "cultures" ]]; then + dotnet test -v m --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures 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 + 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 + else + # Only test + dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures + fi fi after_success: | - if [[ "$TEST_SUITE" == "without-cultures" ]]; 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 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 6c24fcb922..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] @@ -32,14 +32,14 @@ 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); } 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..d52867e99e 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; @@ -225,7 +224,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/Network/P2P/Payloads/UT_Witness.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index 5114d524b2..1ef1e2d120 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,47 +14,6 @@ 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] @@ -73,12 +30,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 +52,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 +114,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 +125,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 +133,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 +141,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")); 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/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_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/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 @@ select new 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/UT_ProtocolSettings.cs b/neo.UnitTests/UT_ProtocolSettings.cs index a5fa189231..77c56df424 100644 --- a/neo.UnitTests/UT_ProtocolSettings.cs +++ b/neo.UnitTests/UT_ProtocolSettings.cs @@ -1,10 +1,8 @@ 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 { 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..de902a115e 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(); // Scrypt test 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] 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..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] @@ -25,7 +22,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(); } } } diff --git a/neo.UnitTests/neo.UnitTests.csproj b/neo.UnitTests/neo.UnitTests.csproj index 4cbc7f4164..2da1ba4968 100644 --- a/neo.UnitTests/neo.UnitTests.csproj +++ b/neo.UnitTests/neo.UnitTests.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp2.2 Neo.UnitTests Neo.UnitTests true @@ -15,13 +15,13 @@ - - - - - - - + + + + + + +