From 77de11ed3c8ebe132795b052a6d769a66fae4008 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 30 Jan 2025 19:52:32 +0800 Subject: [PATCH 1/5] remove FluentAssertions --- tests/Directory.Build.props | 1 - .../Net/UT_IpAddressExtensions.cs | 10 +- .../UT_AssemblyExtensions.cs | 4 +- .../UT_BigIntegerExtensions.cs | 97 ++-- .../UT_ByteArrayComparer.cs | 39 +- .../Neo.Extensions.Tests/UT_ByteExtensions.cs | 23 +- .../UT_DateTimeExtensions.cs | 6 +- .../UT_RandomExtensions.cs | 9 +- .../UT_StringExtensions.cs | 13 +- tests/Neo.Json.UnitTests/UT_JArray.cs | 151 +++--- tests/Neo.Json.UnitTests/UT_JBoolean.cs | 8 +- tests/Neo.Json.UnitTests/UT_JNumber.cs | 49 +- tests/Neo.Json.UnitTests/UT_JObject.cs | 40 +- tests/Neo.Json.UnitTests/UT_JPath.cs | 2 + .../UT_OrderedDictionary.cs | 57 +- tests/Neo.Json.UnitTests/Usings.cs | 1 - tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 11 +- tests/Neo.Network.RPC.Tests/UT_Utility.cs | 39 +- .../TestUtils.cs | 4 +- .../UT_RpcServer.Blockchain.cs | 43 +- .../UT_RpcServer.Node.cs | 11 +- .../UT_RpcServer.Utilities.cs | 1 - .../Cryptography/ECC/UT_ECFieldElement.cs | 51 +- .../Cryptography/ECC/UT_ECPoint.cs | 211 ++++---- tests/Neo.UnitTests/Cryptography/UT_Base58.cs | 15 +- .../Cryptography/UT_BloomFilter.cs | 35 +- tests/Neo.UnitTests/Cryptography/UT_Crypto.cs | 28 +- .../Cryptography/UT_Cryptography_Helper.cs | 33 +- .../Neo.UnitTests/Cryptography/UT_Ed25519.cs | 39 +- .../Cryptography/UT_MerkleTree.cs | 15 +- .../Cryptography/UT_MerkleTreeNode.cs | 62 --- .../Cryptography/UT_Murmur128.cs | 15 +- .../Neo.UnitTests/Cryptography/UT_Murmur32.cs | 53 -- .../Cryptography/UT_RIPEMD160Managed.cs | 8 +- .../Extensions/NativeContractExtensions.cs | 1 - .../Nep17NativeContractExtensions.cs | 20 +- tests/Neo.UnitTests/IO/Caching/UT_Cache.cs | 96 ++-- .../IO/Caching/UT_ECPointCache.cs | 7 +- .../IO/Caching/UT_HashSetCache.cs | 19 +- .../IO/Caching/UT_IndexedQueue.cs | 61 ++- .../IO/Caching/UT_KeyedCollectionSlim.cs | 20 +- .../IO/Caching/UT_ReflectionCache.cs | 19 +- .../Neo.UnitTests/IO/Caching/UT_RelayCache.cs | 7 +- tests/Neo.UnitTests/IO/UT_IOHelper.cs | 11 +- tests/Neo.UnitTests/IO/UT_MemoryReader.cs | 25 +- .../Neo.UnitTests/Ledger/UT_HashIndexState.cs | 5 +- tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs | 31 +- tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs | 281 +++++----- tests/Neo.UnitTests/Ledger/UT_PoolItem.cs | 23 +- tests/Neo.UnitTests/Ledger/UT_StorageItem.cs | 31 +- tests/Neo.UnitTests/Ledger/UT_StorageKey.cs | 27 +- .../Ledger/UT_TransactionState.cs | 12 +- .../UT_TransactionVerificationContext.cs | 23 +- tests/Neo.UnitTests/Ledger/UT_TrimmedBlock.cs | 23 +- .../Capabilities/UT_ArchivalNodeCapability.cs | 3 +- .../P2P/Capabilities/UT_FullNodeCapability.cs | 5 +- .../P2P/Capabilities/UT_ServerCapability.cs | 5 +- .../P2P/Capabilities/UT_UnknownCapability.cs | 1 - .../Network/P2P/Payloads/UT_AddrPayload.cs | 5 +- .../Network/P2P/Payloads/UT_Block.cs | 95 ++-- .../Network/P2P/Payloads/UT_Conflicts.cs | 16 +- .../P2P/Payloads/UT_ExtensiblePayload.cs | 3 +- .../P2P/Payloads/UT_FilterAddPayload.cs | 5 +- .../P2P/Payloads/UT_FilterLoadPayload.cs | 5 +- .../P2P/Payloads/UT_GetBlockByIndexPayload.cs | 5 +- .../P2P/Payloads/UT_GetBlocksPayload.cs | 5 +- .../Network/P2P/Payloads/UT_Header.cs | 51 +- .../Network/P2P/Payloads/UT_HeadersPayload.cs | 5 +- .../P2P/Payloads/UT_HighPriorityAttribute.cs | 3 +- .../Network/P2P/Payloads/UT_InvPayload.cs | 5 +- .../P2P/Payloads/UT_MerkleBlockPayload.cs | 8 +- .../P2P/Payloads/UT_NetworkAddressWithTime.cs | 11 +- .../Network/P2P/Payloads/UT_NotValidBefore.cs | 3 +- .../Network/P2P/Payloads/UT_Signers.cs | 21 +- .../Network/P2P/Payloads/UT_Transaction.cs | 125 +++-- .../Network/P2P/Payloads/UT_VersionPayload.cs | 5 +- .../Network/P2P/Payloads/UT_Witness.cs | 21 +- .../Network/P2P/UT_ChannelsConfig.cs | 23 +- tests/Neo.UnitTests/Network/P2P/UT_Message.cs | 49 +- .../Network/P2P/UT_RemoteNode.cs | 3 +- .../Network/P2P/UT_RemoteNodeMailbox.cs | 139 +++-- .../Network/P2P/UT_TaskManagerMailbox.cs | 13 +- .../Network/P2P/UT_TaskSession.cs | 1 - .../Persistence/UT_CloneCache.cs | 53 +- .../Neo.UnitTests/Persistence/UT_DataCache.cs | 179 ++++--- tests/Neo.UnitTests/Plugins/UT_Plugin.cs | 21 +- .../Iterators/UT_StorageIterator.cs | 12 +- .../UT_ContractPermissionDescriptor.cs | 3 +- .../Manifest/UT_WildCardContainer.cs | 28 +- .../SmartContract/Native/UT_CryptoLib.cs | 66 ++- .../SmartContract/Native/UT_FungibleToken.cs | 3 +- .../SmartContract/Native/UT_GasToken.cs | 50 +- .../SmartContract/Native/UT_NativeContract.cs | 8 +- .../SmartContract/Native/UT_NeoToken.cs | 492 +++++++++--------- .../SmartContract/Native/UT_PolicyContract.cs | 101 ++-- .../SmartContract/Native/UT_RoleManagement.cs | 17 +- .../SmartContract/Native/UT_StdLib.cs | 5 +- .../UT_ApplicationEngine.Contract.cs | 5 +- .../UT_ApplicationEngine.Runtime.cs | 51 +- .../SmartContract/UT_ApplicationEngine.cs | 19 +- .../UT_ApplicationEngineProvider.cs | 5 +- .../SmartContract/UT_BinarySerializer.cs | 9 +- .../SmartContract/UT_Contract.cs | 7 +- .../SmartContract/UT_ContractParameter.cs | 16 +- .../UT_ContractParameterContext.cs | 41 +- .../SmartContract/UT_ContractState.cs | 15 +- .../SmartContract/UT_InteropPrices.cs | 15 +- .../SmartContract/UT_InteropService.NEO.cs | 25 +- .../SmartContract/UT_InteropService.cs | 128 ++--- .../Neo.UnitTests/SmartContract/UT_NefFile.cs | 9 +- .../SmartContract/UT_NotifyEventArgs.cs | 3 +- tests/Neo.UnitTests/TestUtils.cs | 3 +- tests/Neo.UnitTests/UT_BigDecimal.cs | 159 +++--- tests/Neo.UnitTests/UT_Helper.cs | 37 +- tests/Neo.UnitTests/UT_NeoSystem.cs | 7 +- tests/Neo.UnitTests/UT_ProtocolSettings.cs | 131 ++--- tests/Neo.UnitTests/UT_UInt160.cs | 8 +- tests/Neo.UnitTests/UT_UInt256.cs | 5 +- tests/Neo.UnitTests/UT_UIntBenchmarks.cs | 29 +- tests/Neo.UnitTests/VM/UT_Helper.cs | 6 +- .../Wallets/NEP6/UT_NEP6Account.cs | 73 ++- .../Wallets/NEP6/UT_NEP6Contract.cs | 29 +- .../Wallets/NEP6/UT_NEP6Wallet.cs | 21 +- .../Wallets/NEP6/UT_ScryptParameters.cs | 25 +- .../Wallets/UT_AssetDescriptor.cs | 23 +- tests/Neo.UnitTests/Wallets/UT_KeyPair.cs | 27 +- tests/Neo.UnitTests/Wallets/UT_Wallet.cs | 96 ++-- .../Neo.UnitTests/Wallets/UT_WalletAccount.cs | 7 +- .../Wallets/UT_Wallets_Helper.cs | 7 +- 129 files changed, 2251 insertions(+), 2393 deletions(-) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index bd6c200710..2753f78406 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -15,7 +15,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Neo.Extensions.Tests/Net/UT_IpAddressExtensions.cs b/tests/Neo.Extensions.Tests/Net/UT_IpAddressExtensions.cs index f30590df99..7a47ffb954 100644 --- a/tests/Neo.Extensions.Tests/Net/UT_IpAddressExtensions.cs +++ b/tests/Neo.Extensions.Tests/Net/UT_IpAddressExtensions.cs @@ -9,7 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using System.Net; @@ -22,10 +22,10 @@ public class UT_IpAddressExtensions public void TestUnmapForIPAddress() { var addr = new IPAddress(new byte[] { 127, 0, 0, 1 }); - addr.UnMap().Should().Be(addr); + Assert.AreEqual(addr, addr.UnMap()); var addr2 = addr.MapToIPv6(); - addr2.UnMap().Should().Be(addr); + Assert.AreEqual(addr, addr2.UnMap()); } [TestMethod] @@ -33,11 +33,11 @@ public void TestUnmapForIPEndPoin() { var addr = new IPAddress(new byte[] { 127, 0, 0, 1 }); var endPoint = new IPEndPoint(addr, 8888); - endPoint.UnMap().Should().Be(endPoint); + Assert.AreEqual(endPoint, endPoint.UnMap()); var addr2 = addr.MapToIPv6(); var endPoint2 = new IPEndPoint(addr2, 8888); - endPoint2.UnMap().Should().Be(endPoint); + Assert.AreEqual(endPoint, endPoint2.UnMap()); } } } diff --git a/tests/Neo.Extensions.Tests/UT_AssemblyExtensions.cs b/tests/Neo.Extensions.Tests/UT_AssemblyExtensions.cs index 41c765b45e..52b2d740ba 100644 --- a/tests/Neo.Extensions.Tests/UT_AssemblyExtensions.cs +++ b/tests/Neo.Extensions.Tests/UT_AssemblyExtensions.cs @@ -9,7 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Linq; @@ -27,7 +27,7 @@ public void TestGetVersion() .Where(u => u.FullName == "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null") .FirstOrDefault(); string version = asm?.GetVersion() ?? ""; - version.Should().Be("0.0.0"); + Assert.AreEqual("0.0.0", version); } } } diff --git a/tests/Neo.Extensions.Tests/UT_BigIntegerExtensions.cs b/tests/Neo.Extensions.Tests/UT_BigIntegerExtensions.cs index a7db332839..b5190bec42 100644 --- a/tests/Neo.Extensions.Tests/UT_BigIntegerExtensions.cs +++ b/tests/Neo.Extensions.Tests/UT_BigIntegerExtensions.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Neo.Extensions; using Neo.Json; using System; @@ -25,53 +24,53 @@ public class UT_BigIntegerExtensions public void TestGetLowestSetBit() { var big1 = new BigInteger(0); - big1.GetLowestSetBit().Should().Be(-1); + Assert.AreEqual(-1, big1.GetLowestSetBit()); var big2 = new BigInteger(512); - big2.GetLowestSetBit().Should().Be(9); + Assert.AreEqual(9, big2.GetLowestSetBit()); var big3 = new BigInteger(int.MinValue); - big3.GetLowestSetBit().Should().Be(31); + Assert.AreEqual(31, big3.GetLowestSetBit()); var big4 = new BigInteger(long.MinValue); - big4.GetLowestSetBit().Should().Be(63); + Assert.AreEqual(63, big4.GetLowestSetBit()); var big5 = new BigInteger(-18); - big5.GetLowestSetBit().Should().Be(1); + Assert.AreEqual(1, big5.GetLowestSetBit()); var big6 = BigInteger.Pow(2, 1000); - big6.GetLowestSetBit().Should().Be(1000); + Assert.AreEqual(1000, big6.GetLowestSetBit()); } [TestMethod] public void TestGetLowestSetBit_EdgeCases() { - BigInteger.MinusOne.GetLowestSetBit().Should().Be(0); - BigInteger.One.GetLowestSetBit().Should().Be(0); - new BigInteger(ulong.MaxValue).GetLowestSetBit().Should().Be(0); - (BigInteger.One << 1000).GetLowestSetBit().Should().Be(1000); + Assert.AreEqual(0, BigInteger.MinusOne.GetLowestSetBit()); + Assert.AreEqual(0, BigInteger.One.GetLowestSetBit()); + Assert.AreEqual(0, new BigInteger(ulong.MaxValue).GetLowestSetBit()); + Assert.AreEqual(1000, (BigInteger.One << 1000).GetLowestSetBit()); } [TestMethod] public void TestToByteArrayStandard() { BigInteger number = BigInteger.Zero; - number.ToByteArrayStandard().Should().BeEmpty(); + CollectionAssert.AreEqual(Array.Empty(), number.ToByteArrayStandard()); number = BigInteger.One; - number.ToByteArrayStandard().Should().Equal(new byte[] { 0x01 }); + CollectionAssert.AreEqual(new byte[] { 0x01 }, number.ToByteArrayStandard()); number = new BigInteger(256); // Binary: 100000000 - number.ToByteArrayStandard().Should().Equal(new byte[] { 0x00, 0x01 }); + CollectionAssert.AreEqual(new byte[] { 0x00, 0x01 }, number.ToByteArrayStandard()); } [TestMethod] public void TestToByteArrayStandard_EdgeCases() { - BigInteger.MinusOne.ToByteArrayStandard().Should().Equal(new byte[] { 0xFF }); - new BigInteger(byte.MaxValue).ToByteArrayStandard().Should().Equal(new byte[] { 0xFF, 0x00 }); - new BigInteger(ushort.MaxValue).ToByteArrayStandard().Should().Equal(new byte[] { 0xFF, 0xFF, 0x00 }); - new BigInteger(JNumber.MIN_SAFE_INTEGER).ToByteArrayStandard().Should().Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0 }); + CollectionAssert.AreEqual(new byte[] { 0xFF }, BigInteger.MinusOne.ToByteArrayStandard()); + CollectionAssert.AreEqual(new byte[] { 0xFF, 0x00 }, new BigInteger(byte.MaxValue).ToByteArrayStandard()); + CollectionAssert.AreEqual(new byte[] { 0xFF, 0xFF, 0x00 }, new BigInteger(ushort.MaxValue).ToByteArrayStandard()); + CollectionAssert.AreEqual(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0 }, new BigInteger(JNumber.MIN_SAFE_INTEGER).ToByteArrayStandard()); } [TestMethod] @@ -80,35 +79,35 @@ public void TestMod() var x = new BigInteger(-13); var y = new BigInteger(5); var result = x.Mod(y); - result.Should().Be(2); // -13 % 5 is -3, but Mod method should return 2 + Assert.AreEqual(2, result); // -13 % 5 is -3, but Mod method should return 2 } [TestMethod] public void TestMod_EdgeCases() { // Test case 1: Mod of zero - BigInteger.Zero.Mod(5).Should().Be(0, "Mod of zero should always be zero"); + Assert.AreEqual(0, BigInteger.Zero.Mod(5), "Mod of zero should always be zero"); // Test case 2: Mod of -1 - BigInteger.MinusOne.Mod(5).Should().Be(4, "Mod of -1 should return the modulus minus 1"); + Assert.AreEqual(4, BigInteger.MinusOne.Mod(5), "Mod of -1 should return the modulus minus 1"); // Test case 3: Mod with large numbers BigInteger minValue = new BigInteger(long.MinValue); BigInteger maxValue = new BigInteger(long.MaxValue); - minValue.Mod(maxValue).Should().Be(9223372036854775806, "Mod with large numbers should be calculated correctly"); + Assert.AreEqual(9223372036854775806, minValue.Mod(maxValue), "Mod with large numbers should be calculated correctly"); // Test case 4: Comparing Mod with % operator BigInteger result = minValue.Mod(maxValue); - result.Should().NotBe(long.MinValue % long.MaxValue, "Mod should always return non-negative values, unlike % operator"); + Assert.AreNotEqual(long.MinValue % long.MaxValue, result, "Mod should always return non-negative values, unlike % operator"); // Test case 5: Verifying % operator behavior - (long.MinValue % long.MaxValue).Should().Be((long)(minValue % maxValue), "% operator should behave consistently for BigInteger and long"); + Assert.AreEqual((long)(minValue % maxValue), long.MinValue % long.MaxValue, "% operator should behave consistently for BigInteger and long"); // Test case 6: Mod with prime numbers - new BigInteger(17).Mod(19).Should().Be(17, "Mod with a larger prime should return the original number"); + Assert.AreEqual(17, new BigInteger(17).Mod(19), "Mod with a larger prime should return the original number"); // Test case 7: Mod with powers of 2 - new BigInteger(1024).Mod(16).Should().Be(0, "Mod with powers of 2 should utilize bitwise operations efficiently"); + Assert.AreEqual(0, new BigInteger(1024).Mod(16), "Mod with powers of 2 should utilize bitwise operations efficiently"); } [TestMethod] @@ -117,60 +116,54 @@ public void TestModInverse() var a = new BigInteger(3); var n = new BigInteger(11); var result = a.ModInverse(n); - result.Should().Be(4); // 3 * 4 % 11 == 1 + Assert.AreEqual(4, result); // 3 * 4 % 11 == 1 a = new BigInteger(1); n = new BigInteger(11); result = a.ModInverse(n); - result.Should().Be(1); // 1 * 1 % 11 == 1 + Assert.AreEqual(1, result); // 1 * 1 % 11 == 1 a = new BigInteger(13); n = new BigInteger(11); result = a.ModInverse(n); - result.Should().Be(6); // 13 % 11 = 2, and 2 * 6 % 11 == 1 + Assert.AreEqual(6, result); // 13 % 11 = 2, and 2 * 6 % 11 == 1 a = new BigInteger(6); n = new BigInteger(12); // 6 and 12 are not coprime - Action act = () => a.ModInverse(n); - act.Should().Throw() - .WithMessage("No modular inverse exists for the given inputs."); + Assert.ThrowsException(() => a.ModInverse(n)); } [TestMethod] public void TestModInverse_EdgeCases() { - Action act = () => BigInteger.Zero.ModInverse(11); - act.Should().Throw(); + Assert.ThrowsException(() => BigInteger.Zero.ModInverse(11)); - BigInteger.One.ModInverse(2).Should().Be(1); + Assert.AreEqual(1, BigInteger.One.ModInverse(2)); - act = () => new BigInteger(2).ModInverse(4); - act.Should().Throw(); + Assert.ThrowsException(() => new BigInteger(2).ModInverse(4)); - new BigInteger(long.MaxValue - 1).ModInverse(long.MaxValue).Should().Be(long.MaxValue - 1); + Assert.AreEqual(long.MaxValue - 1, new BigInteger(long.MaxValue - 1).ModInverse(long.MaxValue)); } [TestMethod] public void TestBit() { var bigInteger = new BigInteger(5); // Binary: 101 - var result = bigInteger.TestBit(2); - result.Should().BeTrue(); // Bit at index 2 is set (1) + Assert.IsTrue(bigInteger.TestBit(2)); // Bit at index 2 is set (1) bigInteger = new BigInteger(5); // Binary: 101 - result = bigInteger.TestBit(1); - result.Should().BeFalse(); // Bit at index 1 is not set (0) + Assert.IsFalse(bigInteger.TestBit(1)); // Bit at index 1 is not set (0) } [TestMethod] public void TestBit_EdgeCases() { - BigInteger.Zero.TestBit(0).Should().BeFalse(); - BigInteger.Zero.TestBit(100).Should().BeFalse(); - BigInteger.MinusOne.TestBit(0).Should().BeTrue(); - BigInteger.MinusOne.TestBit(1000).Should().BeTrue(); - (BigInteger.One << 1000).TestBit(1000).Should().BeTrue(); - (BigInteger.One << 1000).TestBit(999).Should().BeFalse(); + Assert.IsFalse(BigInteger.Zero.TestBit(0)); + Assert.IsFalse(BigInteger.Zero.TestBit(100)); + Assert.IsTrue(BigInteger.MinusOne.TestBit(0)); + Assert.IsTrue(BigInteger.MinusOne.TestBit(1000)); + Assert.IsTrue((BigInteger.One << 1000).TestBit(1000)); + Assert.IsFalse((BigInteger.One << 1000).TestBit(999)); } [TestMethod] @@ -178,15 +171,15 @@ public void TestSum() { var bigIntegers = new List { 1, 2, 3, 4 }; var result = bigIntegers.Sum(); - result.Should().Be(10); + Assert.AreEqual(10, result); } [TestMethod] public void TestSum_EdgeCases() { - new List().Sum().Should().Be(0); - new List { JNumber.MIN_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum().Should().Be(0); - new List { JNumber.MAX_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum().Should().Be(JNumber.MAX_SAFE_INTEGER * 2); + Assert.AreEqual(0, new List().Sum()); + Assert.AreEqual(0, new List { JNumber.MIN_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum()); + Assert.AreEqual(JNumber.MAX_SAFE_INTEGER * 2, new List { JNumber.MAX_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum()); } } } diff --git a/tests/Neo.Extensions.Tests/UT_ByteArrayComparer.cs b/tests/Neo.Extensions.Tests/UT_ByteArrayComparer.cs index 0764b78167..839c9130e3 100644 --- a/tests/Neo.Extensions.Tests/UT_ByteArrayComparer.cs +++ b/tests/Neo.Extensions.Tests/UT_ByteArrayComparer.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using System; namespace Neo.Extensions.Tests @@ -22,64 +21,64 @@ public void TestCompare() { ByteArrayComparer comparer = ByteArrayComparer.Default; byte[]? x = null, y = null; - comparer.Compare(x, y).Should().Be(0); + Assert.AreEqual(0, comparer.Compare(x, y)); x = new byte[] { 1, 2, 3, 4, 5 }; y = x; - comparer.Compare(x, y).Should().Be(0); - comparer.Compare(x, x).Should().Be(0); + Assert.AreEqual(0, comparer.Compare(x, y)); + Assert.AreEqual(0, comparer.Compare(x, x)); y = null; - comparer.Compare(x, y).Should().BeGreaterThan(0); + Assert.IsTrue(comparer.Compare(x, y) > 0); y = x; x = null; - comparer.Compare(x, y).Should().BeLessThan(0); + Assert.IsTrue(comparer.Compare(x, y) < 0); x = new byte[] { 1 }; y = Array.Empty(); - comparer.Compare(x, y).Should().BeGreaterThan(0); + Assert.IsTrue(comparer.Compare(x, y) > 0); y = x; - comparer.Compare(x, y).Should().Be(0); + Assert.AreEqual(0, comparer.Compare(x, y)); x = new byte[] { 1 }; y = new byte[] { 2 }; - comparer.Compare(x, y).Should().BeLessThan(0); + Assert.IsTrue(comparer.Compare(x, y) < 0); - comparer.Compare(null, Array.Empty()).Should().Be(0); - comparer.Compare(Array.Empty(), null).Should().Be(0); + Assert.AreEqual(0, comparer.Compare(null, Array.Empty())); + Assert.AreEqual(0, comparer.Compare(Array.Empty(), null)); x = new byte[] { 1, 2, 3, 4, 5 }; y = new byte[] { 1, 2, 3 }; - comparer.Compare(x, y).Should().BeGreaterThan(0); + Assert.IsTrue(comparer.Compare(x, y) > 0); x = new byte[] { 1, 2, 3, 4, 5 }; y = new byte[] { 1, 2, 3, 4, 5, 6 }; - comparer.Compare(x, y).Should().BeLessThan(0); + Assert.IsTrue(comparer.Compare(x, y) < 0); // cases for reverse comparer comparer = ByteArrayComparer.Reverse; x = new byte[] { 3 }; - comparer.Compare(x, y).Should().BeLessThan(0); + Assert.IsTrue(comparer.Compare(x, y) < 0); y = x; - comparer.Compare(x, y).Should().Be(0); + Assert.AreEqual(0, comparer.Compare(x, y)); x = new byte[] { 1 }; y = new byte[] { 2 }; - comparer.Compare(x, y).Should().BeGreaterThan(0); + Assert.IsTrue(comparer.Compare(x, y) > 0); - comparer.Compare(null, Array.Empty()).Should().Be(0); - comparer.Compare(Array.Empty(), null).Should().Be(0); + Assert.AreEqual(0, comparer.Compare(null, Array.Empty())); + Assert.AreEqual(0, comparer.Compare(Array.Empty(), null)); x = new byte[] { 1, 2, 3, 4, 5 }; y = new byte[] { 1, 2, 3 }; - comparer.Compare(x, y).Should().BeLessThan(0); + Assert.IsTrue(comparer.Compare(x, y) < 0); x = new byte[] { 1, 2, 3, 4, 5 }; y = new byte[] { 1, 2, 3, 4, 5, 6 }; - comparer.Compare(x, y).Should().BeGreaterThan(0); + Assert.IsTrue(comparer.Compare(x, y) > 0); } } } diff --git a/tests/Neo.Extensions.Tests/UT_ByteExtensions.cs b/tests/Neo.Extensions.Tests/UT_ByteExtensions.cs index 7fc8a7973e..00c4c8a35c 100644 --- a/tests/Neo.Extensions.Tests/UT_ByteExtensions.cs +++ b/tests/Neo.Extensions.Tests/UT_ByteExtensions.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using System; using System.IO.Hashing; using System.Linq; @@ -29,21 +28,21 @@ public void TestToHexString() Assert.ThrowsException(() => nullStr.ToHexString(true)); byte[] empty = Array.Empty(); - empty.ToHexString().Should().Be(""); - empty.ToHexString(false).Should().Be(""); - empty.ToHexString(true).Should().Be(""); + Assert.AreEqual("", empty.ToHexString()); + Assert.AreEqual("", empty.ToHexString(false)); + Assert.AreEqual("", empty.ToHexString(true)); byte[] str1 = new byte[] { (byte)'n', (byte)'e', (byte)'o' }; - str1.ToHexString().Should().Be("6e656f"); - str1.ToHexString(false).Should().Be("6e656f"); - str1.ToHexString(true).Should().Be("6f656e"); + Assert.AreEqual("6e656f", str1.ToHexString()); + Assert.AreEqual("6e656f", str1.ToHexString(false)); + Assert.AreEqual("6f656e", str1.ToHexString(true)); } [TestMethod] public void TestXxHash3() { byte[] data = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat("Hello, World!^_^", 16 * 1024))); - data.XxHash3_32().Should().Be(HashCode.Combine(XxHash3.HashToUInt64(data, 40343))); + Assert.AreEqual(HashCode.Combine(XxHash3.HashToUInt64(data, 40343)), data.XxHash3_32()); } [TestMethod] @@ -52,22 +51,22 @@ public void TestReadOnlySpanToHexString() byte[] input = { 0x0F, 0xA4, 0x3B }; var span = new ReadOnlySpan(input); string result = span.ToHexString(); - result.Should().Be("0fa43b"); + Assert.AreEqual("0fa43b", result); input = Array.Empty(); span = new ReadOnlySpan(input); result = span.ToHexString(); - result.Should().BeEmpty(); + Assert.IsTrue(result.Length == 0); input = new byte[] { 0x5A }; span = new ReadOnlySpan(input); result = span.ToHexString(); - result.Should().Be("5a"); + Assert.AreEqual("5a", result); input = new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }; span = new ReadOnlySpan(input); result = span.ToHexString(); - result.Should().Be("0123456789abcdef"); + Assert.AreEqual("0123456789abcdef", result); } } } diff --git a/tests/Neo.Extensions.Tests/UT_DateTimeExtensions.cs b/tests/Neo.Extensions.Tests/UT_DateTimeExtensions.cs index 29b3fa2ec5..faee5233d8 100644 --- a/tests/Neo.Extensions.Tests/UT_DateTimeExtensions.cs +++ b/tests/Neo.Extensions.Tests/UT_DateTimeExtensions.cs @@ -9,7 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; namespace Neo.Extensions.Tests @@ -26,7 +26,7 @@ public void TestToTimestamp() var expected = (uint)(time.ToUniversalTime() - unixEpoch).TotalSeconds; var actual = time.ToTimestamp(); - actual.Should().Be(expected); + Assert.AreEqual(expected, actual); } [TestMethod] @@ -36,7 +36,7 @@ public void TestToTimestampMS() var expected = (ulong)(time.ToUniversalTime() - unixEpoch).TotalMilliseconds; var actual = time.ToTimestampMS(); - actual.Should().Be(expected); + Assert.AreEqual(expected, actual); } } } diff --git a/tests/Neo.Extensions.Tests/UT_RandomExtensions.cs b/tests/Neo.Extensions.Tests/UT_RandomExtensions.cs index 0dc4d021c0..0bf9f334cf 100644 --- a/tests/Neo.Extensions.Tests/UT_RandomExtensions.cs +++ b/tests/Neo.Extensions.Tests/UT_RandomExtensions.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using System; namespace Neo.Extensions.Tests @@ -22,11 +21,11 @@ public void TestNextBigIntegerForRandom() { Random ran = new(); Action action1 = () => ran.NextBigInteger(-1); - action1.Should().Throw(); + Assert.ThrowsException(action1); - ran.NextBigInteger(0).Should().Be(0); - ran.NextBigInteger(8).Should().NotBeNull(); - ran.NextBigInteger(9).Should().NotBeNull(); + Assert.AreEqual(0, ran.NextBigInteger(0)); + Assert.IsNotNull(ran.NextBigInteger(8)); + Assert.IsNotNull(ran.NextBigInteger(9)); } } } diff --git a/tests/Neo.Extensions.Tests/UT_StringExtensions.cs b/tests/Neo.Extensions.Tests/UT_StringExtensions.cs index 0575ee9a12..976f2f51f4 100644 --- a/tests/Neo.Extensions.Tests/UT_StringExtensions.cs +++ b/tests/Neo.Extensions.Tests/UT_StringExtensions.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using System; using System.Collections.Generic; @@ -22,22 +21,22 @@ public class UT_StringExtensions public void TestHexToBytes() { string? nullStr = null; - _ = nullStr.HexToBytes().ToHexString().Should().Be(Array.Empty().ToHexString()); + Assert.AreEqual(Array.Empty().ToHexString(), nullStr.HexToBytes().ToHexString()); string emptyStr = ""; - emptyStr.HexToBytes().ToHexString().Should().Be(Array.Empty().ToHexString()); + Assert.AreEqual(Array.Empty().ToHexString(), emptyStr.HexToBytes().ToHexString()); string str1 = "hab"; Action action = () => str1.HexToBytes(); - action.Should().Throw(); + Assert.ThrowsException(action); string str2 = "0102"; byte[] bytes = str2.HexToBytes(); - bytes.ToHexString().Should().Be(new byte[] { 0x01, 0x02 }.ToHexString()); + Assert.AreEqual(new byte[] { 0x01, 0x02 }.ToHexString(), bytes.ToHexString()); string str3 = "0A0b0C"; bytes = str3.AsSpan().HexToBytes(); - bytes.ToHexString().Should().Be(new byte[] { 0x0A, 0x0B, 0x0C }.ToHexString()); + Assert.AreEqual(new byte[] { 0x0A, 0x0B, 0x0C }.ToHexString(), bytes.ToHexString()); bytes = str3.AsSpan().HexToBytesReversed(); - bytes.ToHexString().Should().Be(new byte[] { 0x0C, 0x0B, 0x0A }.ToHexString()); + Assert.AreEqual(new byte[] { 0x0C, 0x0B, 0x0A }.ToHexString(), bytes.ToHexString()); } [TestMethod] diff --git a/tests/Neo.Json.UnitTests/UT_JArray.cs b/tests/Neo.Json.UnitTests/UT_JArray.cs index 177ca0f2fe..f34a73ae25 100644 --- a/tests/Neo.Json.UnitTests/UT_JArray.cs +++ b/tests/Neo.Json.UnitTests/UT_JArray.cs @@ -9,6 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections; namespace Neo.Json.UnitTests @@ -61,18 +62,18 @@ public void TestAdd() }; var jAlice = jArray[0]; var jBob = jArray[1]; - jAlice["name"].ToString().Should().Be(alice["name"].ToString()); - jAlice["age"].ToString().Should().Be(alice["age"].ToString()); - jAlice["score"].ToString().Should().Be(alice["score"].ToString()); - jAlice["gender"].ToString().Should().Be(alice["gender"].ToString()); - jAlice["isMarried"].ToString().Should().Be(alice["isMarried"].ToString()); - jAlice["pet"].ToString().Should().Be(alice["pet"].ToString()); - jBob["name"].ToString().Should().Be(bob["name"].ToString()); - jBob["age"].ToString().Should().Be(bob["age"].ToString()); - jBob["score"].ToString().Should().Be(bob["score"].ToString()); - jBob["gender"].ToString().Should().Be(bob["gender"].ToString()); - jBob["isMarried"].ToString().Should().Be(bob["isMarried"].ToString()); - jBob["pet"].ToString().Should().Be(bob["pet"].ToString()); + Assert.AreEqual(alice["name"].ToString(), jAlice["name"].ToString()); + Assert.AreEqual(alice["age"].ToString(), jAlice["age"].ToString()); + Assert.AreEqual(alice["score"].ToString(), jAlice["score"].ToString()); + Assert.AreEqual(alice["gender"].ToString(), jAlice["gender"].ToString()); + Assert.AreEqual(alice["isMarried"].ToString(), jAlice["isMarried"].ToString()); + Assert.AreEqual(alice["pet"].ToString(), jAlice["pet"].ToString()); + Assert.AreEqual(bob["name"].ToString(), jBob["name"].ToString()); + Assert.AreEqual(bob["age"].ToString(), jBob["age"].ToString()); + Assert.AreEqual(bob["score"].ToString(), jBob["score"].ToString()); + Assert.AreEqual(bob["gender"].ToString(), jBob["gender"].ToString()); + Assert.AreEqual(bob["isMarried"].ToString(), jBob["isMarried"].ToString()); + Assert.AreEqual(bob["pet"].ToString(), jBob["pet"].ToString()); } [TestMethod] @@ -86,7 +87,7 @@ public void TestSetItem() Assert.AreEqual(jArray[0], bob); Action action = () => jArray[1] = alice; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -97,16 +98,16 @@ public void TestClear() alice }; var jAlice = jArray[0]; - jAlice["name"].ToString().Should().Be(alice["name"].ToString()); - jAlice["age"].ToString().Should().Be(alice["age"].ToString()); - jAlice["score"].ToString().Should().Be(alice["score"].ToString()); - jAlice["gender"].ToString().Should().Be(alice["gender"].ToString()); - jAlice["isMarried"].ToString().Should().Be(alice["isMarried"].ToString()); - jAlice["pet"].ToString().Should().Be(alice["pet"].ToString()); + Assert.AreEqual(alice["name"].ToString(), jAlice["name"].ToString()); + Assert.AreEqual(alice["age"].ToString(), jAlice["age"].ToString()); + Assert.AreEqual(alice["score"].ToString(), jAlice["score"].ToString()); + Assert.AreEqual(alice["gender"].ToString(), jAlice["gender"].ToString()); + Assert.AreEqual(alice["isMarried"].ToString(), jAlice["isMarried"].ToString()); + Assert.AreEqual(alice["pet"].ToString(), jAlice["pet"].ToString()); jArray.Clear(); Action action = () => jArray[0].ToString(); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -116,8 +117,8 @@ public void TestContains() { alice }; - jArray.Contains(alice).Should().BeTrue(); - jArray.Contains(bob).Should().BeFalse(); + Assert.IsTrue(jArray.Contains(alice)); + Assert.IsFalse(jArray.Contains(bob)); } [TestMethod] @@ -140,8 +141,8 @@ public void TestCopyTo() jArray.CopyTo(jObjects2, 2); var jAlice2 = jObjects2[2]; var jBob2 = jObjects2[3]; - jObjects2[0].Should().BeNull(); - jObjects2[1].Should().BeNull(); + Assert.IsNull(jObjects2[0]); + Assert.IsNull(jObjects2[1]); Assert.AreEqual(alice, jAlice2); Assert.AreEqual(bob, jBob2); } @@ -158,37 +159,37 @@ public void TestInsert() }; jArray.Insert(1, bob); - jArray.Count().Should().Be(5); - jArray[0].Should().Be(alice); - jArray[1].Should().Be(bob); - jArray[2].Should().Be(alice); + Assert.AreEqual(5, jArray.Count()); + Assert.AreEqual(alice, jArray[0]); + Assert.AreEqual(bob, jArray[1]); + Assert.AreEqual(alice, jArray[2]); jArray.Insert(5, bob); - jArray.Count().Should().Be(6); - jArray[5].Should().Be(bob); + Assert.AreEqual(6, jArray.Count()); + Assert.AreEqual(bob, jArray[5]); } [TestMethod] public void TestIndexOf() { var jArray = new JArray(); - jArray.IndexOf(alice).Should().Be(-1); + Assert.AreEqual(-1, jArray.IndexOf(alice)); jArray.Add(alice); jArray.Add(alice); jArray.Add(alice); jArray.Add(alice); - jArray.IndexOf(alice).Should().Be(0); + Assert.AreEqual(0, jArray.IndexOf(alice)); jArray.Insert(1, bob); - jArray.IndexOf(bob).Should().Be(1); + Assert.AreEqual(1, jArray.IndexOf(bob)); } [TestMethod] public void TestIsReadOnly() { var jArray = new JArray(); - jArray.IsReadOnly.Should().BeFalse(); + Assert.IsFalse(jArray.IsReadOnly); } [TestMethod] @@ -198,15 +199,15 @@ public void TestRemove() { alice }; - jArray.Count().Should().Be(1); + Assert.AreEqual(1, jArray.Count()); jArray.Remove(alice); - jArray.Count().Should().Be(0); + Assert.AreEqual(0, jArray.Count()); jArray.Add(alice); jArray.Add(alice); - jArray.Count().Should().Be(2); + Assert.AreEqual(2, jArray.Count()); jArray.Remove(alice); - jArray.Count().Should().Be(1); + Assert.AreEqual(1, jArray.Count()); } [TestMethod] @@ -219,8 +220,8 @@ public void TestRemoveAt() alice }; jArray.RemoveAt(1); - jArray.Count().Should().Be(2); - jArray.Contains(bob).Should().BeFalse(); + Assert.AreEqual(2, jArray.Count()); + Assert.IsFalse(jArray.Contains(bob)); } [TestMethod] @@ -236,8 +237,8 @@ public void TestGetEnumerator() int i = 0; foreach (var item in jArray) { - if (i % 2 == 0) item.Should().Be(alice); - if (i % 2 != 0) item.Should().Be(bob); + if (i % 2 == 0) Assert.AreEqual(alice, item); + if (i % 2 != 0) Assert.AreEqual(bob, item); i++; } Assert.IsNotNull(((IEnumerable)jArray).GetEnumerator()); @@ -259,7 +260,7 @@ public void TestAsString() public void TestCount() { var jArray = new JArray { alice, bob }; - jArray.Count.Should().Be(2); + Assert.AreEqual(2, jArray.Count); } [TestMethod] @@ -267,7 +268,7 @@ public void TestInvalidIndexAccess() { var jArray = new JArray { alice }; Action action = () => { var item = jArray[1]; }; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -286,9 +287,9 @@ public void TestImplicitConversionFromJTokenArray() JToken[] jTokens = { alice, bob }; JArray jArray = jTokens; - jArray.Count.Should().Be(2); - jArray[0].Should().Be(alice); - jArray[1].Should().Be(bob); + Assert.AreEqual(2, jArray.Count); + Assert.AreEqual(alice, jArray[0]); + Assert.AreEqual(bob, jArray[1]); } [TestMethod] @@ -298,8 +299,8 @@ public void TestAddNullValues() { null }; - jArray.Count.Should().Be(1); - jArray[0].Should().BeNull(); + Assert.AreEqual(1, jArray.Count); + Assert.IsNull(jArray[0]); } [TestMethod] @@ -308,24 +309,24 @@ public void TestClone() var jArray = new JArray { alice, bob }; var clone = (JArray)jArray.Clone(); - clone.Should().NotBeSameAs(jArray); - clone.Count.Should().Be(jArray.Count); + Assert.AreNotSame(jArray, clone); + Assert.AreEqual(jArray.Count, clone.Count); for (int i = 0; i < jArray.Count; i++) { - clone[i]?.AsString().Should().Be(jArray[i]?.AsString()); + Assert.AreEqual(jArray[i]?.AsString(), clone[i]?.AsString()); } var a = jArray.AsString(); var b = jArray.Clone().AsString(); - a.Should().Be(b); + Assert.AreEqual(a, b); } [TestMethod] public void TestReadOnlyBehavior() { var jArray = new JArray(); - jArray.IsReadOnly.Should().BeFalse(); + Assert.IsFalse(jArray.IsReadOnly); } [TestMethod] @@ -333,8 +334,8 @@ public void TestAddNull() { var jArray = new JArray { null }; - jArray.Count.Should().Be(1); - jArray[0].Should().BeNull(); + Assert.AreEqual(1, jArray.Count); + Assert.IsNull(jArray[0]); } [TestMethod] @@ -343,8 +344,8 @@ public void TestSetNull() var jArray = new JArray { alice }; jArray[0] = null; - jArray.Count.Should().Be(1); - jArray[0].Should().BeNull(); + Assert.AreEqual(1, jArray.Count); + Assert.IsNull(jArray[0]); } [TestMethod] @@ -353,9 +354,9 @@ public void TestInsertNull() var jArray = new JArray { alice }; jArray.Insert(0, null); - jArray.Count.Should().Be(2); - jArray[0].Should().BeNull(); - jArray[1].Should().Be(alice); + Assert.AreEqual(2, jArray.Count); + Assert.IsNull(jArray[0]); + Assert.AreEqual(alice, jArray[1]); } [TestMethod] @@ -364,24 +365,24 @@ public void TestRemoveNull() var jArray = new JArray { null, alice }; jArray.Remove(null); - jArray.Count.Should().Be(1); - jArray[0].Should().Be(alice); + Assert.AreEqual(1, jArray.Count); + Assert.AreEqual(alice, jArray[0]); } [TestMethod] public void TestContainsNull() { var jArray = new JArray { null, alice }; - jArray.Contains(null).Should().BeTrue(); - jArray.Contains(bob).Should().BeFalse(); + Assert.IsTrue(jArray.Contains(null)); + Assert.IsFalse(jArray.Contains(bob)); } [TestMethod] public void TestIndexOfNull() { var jArray = new JArray { null, alice }; - jArray.IndexOf(null).Should().Be(0); - jArray.IndexOf(alice).Should().Be(1); + Assert.AreEqual(0, jArray.IndexOf(null)); + Assert.AreEqual(1, jArray.IndexOf(alice)); } [TestMethod] @@ -391,8 +392,8 @@ public void TestCopyToWithNull() JObject[] jObjects = new JObject[2]; jArray.CopyTo(jObjects, 0); - jObjects[0].Should().BeNull(); - jObjects[1].Should().Be(alice); + Assert.IsNull(jObjects[0]); + Assert.AreEqual(alice, jObjects[1]); } [TestMethod] @@ -402,8 +403,8 @@ public void TestToStringWithNull() var jsonString = jArray.ToString(); var asString = jArray.AsString(); // JSON string should properly represent the null value - jsonString.Should().Be("[null,{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}]"); - asString.Should().Be("[null,{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}]"); + Assert.AreEqual("[null,{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}]", jsonString); + Assert.AreEqual("[null,{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}]", asString); } [TestMethod] @@ -412,12 +413,12 @@ public void TestFromStringWithNull() var jsonString = "[null,{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}]"; var jArray = (JArray)JArray.Parse(jsonString); - jArray.Count.Should().Be(3); - jArray[0].Should().BeNull(); + Assert.AreEqual(3, jArray.Count); + Assert.IsNull(jArray[0]); // Checking the second and third elements - jArray[1]["name"].AsString().Should().Be("alice"); - jArray[2]["name"].AsString().Should().Be("bob"); + Assert.AreEqual("alice", jArray[1]["name"].AsString()); + Assert.AreEqual("bob", jArray[2]["name"].AsString()); } } } diff --git a/tests/Neo.Json.UnitTests/UT_JBoolean.cs b/tests/Neo.Json.UnitTests/UT_JBoolean.cs index 464b0316bf..7dd26eab30 100644 --- a/tests/Neo.Json.UnitTests/UT_JBoolean.cs +++ b/tests/Neo.Json.UnitTests/UT_JBoolean.cs @@ -29,22 +29,22 @@ public void SetUp() [TestMethod] public void TestAsNumber() { - jFalse.AsNumber().Should().Be(0); - jTrue.AsNumber().Should().Be(1); + Assert.AreEqual(0, jFalse.AsNumber()); + Assert.AreEqual(1, jTrue.AsNumber()); } [TestMethod] public void TestDefaultConstructor() { var defaultJBoolean = new JBoolean(); - defaultJBoolean.AsNumber().Should().Be(0); + Assert.AreEqual(0, defaultJBoolean.AsNumber()); } [TestMethod] public void TestExplicitFalse() { var explicitFalse = new JBoolean(false); - explicitFalse.AsNumber().Should().Be(0); + Assert.AreEqual(0, explicitFalse.AsNumber()); } [TestMethod] diff --git a/tests/Neo.Json.UnitTests/UT_JNumber.cs b/tests/Neo.Json.UnitTests/UT_JNumber.cs index d405a9c830..496a25c521 100644 --- a/tests/Neo.Json.UnitTests/UT_JNumber.cs +++ b/tests/Neo.Json.UnitTests/UT_JNumber.cs @@ -9,6 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Numerics; namespace Neo.Json.UnitTests @@ -38,32 +39,32 @@ public void SetUp() [TestMethod] public void TestAsBoolean() { - maxInt.AsBoolean().Should().BeTrue(); - zero.AsBoolean().Should().BeFalse(); + Assert.IsTrue(maxInt.AsBoolean()); + Assert.IsFalse(zero.AsBoolean()); } [TestMethod] public void TestAsString() { Action action1 = () => new JNumber(double.PositiveInfinity).AsString(); - action1.Should().Throw(); + Assert.ThrowsException(action1); Action action2 = () => new JNumber(double.NegativeInfinity).AsString(); - action2.Should().Throw(); + Assert.ThrowsException(action2); Action action3 = () => new JNumber(double.NaN).AsString(); - action3.Should().Throw(); + Assert.ThrowsException(action3); } [TestMethod] public void TestGetEnum() { - zero.GetEnum().Should().Be(Woo.Tom); - new JNumber(1).GetEnum().Should().Be(Woo.Jerry); - new JNumber(2).GetEnum().Should().Be(Woo.James); - new JNumber(3).AsEnum().Should().Be(Woo.Tom); + Assert.AreEqual(Woo.Tom, zero.GetEnum()); + Assert.AreEqual(Woo.Jerry, new JNumber(1).GetEnum()); + Assert.AreEqual(Woo.James, new JNumber(2).GetEnum()); + Assert.AreEqual(Woo.Tom, new JNumber(3).AsEnum()); Action action = () => new JNumber(3).GetEnum(); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -79,21 +80,21 @@ public void TestEqual() Assert.IsFalse(zero == null); var jnum = new JNumber(1); - jnum.Equals(new JNumber(1)).Should().BeTrue(); - jnum.Equals((uint)1).Should().BeTrue(); - jnum.Equals((int)1).Should().BeTrue(); - jnum.Equals((ulong)1).Should().BeTrue(); - jnum.Equals((long)1).Should().BeTrue(); - jnum.Equals((byte)1).Should().BeTrue(); - jnum.Equals((sbyte)1).Should().BeTrue(); - jnum.Equals((short)1).Should().BeTrue(); - jnum.Equals((ushort)1).Should().BeTrue(); - jnum.Equals((decimal)1).Should().BeTrue(); - jnum.Equals((float)1).Should().BeTrue(); - jnum.Equals((double)1).Should().BeTrue(); - jnum.Equals(null).Should().BeFalse(); + Assert.IsTrue(jnum.Equals(new JNumber(1))); + Assert.IsTrue(jnum.Equals((uint)1)); + Assert.IsTrue(jnum.Equals((int)1)); + Assert.IsTrue(jnum.Equals((ulong)1)); + Assert.IsTrue(jnum.Equals((long)1)); + Assert.IsTrue(jnum.Equals((byte)1)); + Assert.IsTrue(jnum.Equals((sbyte)1)); + Assert.IsTrue(jnum.Equals((short)1)); + Assert.IsTrue(jnum.Equals((ushort)1)); + Assert.IsTrue(jnum.Equals((decimal)1)); + Assert.IsTrue(jnum.Equals((float)1)); + Assert.IsTrue(jnum.Equals((double)1)); + Assert.IsFalse(jnum.Equals(null)); var x = jnum; - jnum.Equals(x).Should().BeTrue(); + Assert.IsTrue(jnum.Equals(x)); Assert.ThrowsException(() => jnum.Equals(new BigInteger(1))); } } diff --git a/tests/Neo.Json.UnitTests/UT_JObject.cs b/tests/Neo.Json.UnitTests/UT_JObject.cs index c4a687b4c6..bbce69894b 100644 --- a/tests/Neo.Json.UnitTests/UT_JObject.cs +++ b/tests/Neo.Json.UnitTests/UT_JObject.cs @@ -46,13 +46,13 @@ public void SetUp() [TestMethod] public void TestAsBoolean() { - alice.AsBoolean().Should().BeTrue(); + Assert.IsTrue(alice.AsBoolean()); } [TestMethod] public void TestAsNumber() { - alice.AsNumber().Should().Be(double.NaN); + Assert.AreEqual(double.NaN, alice.AsNumber()); } [TestMethod] @@ -73,64 +73,66 @@ public void TestParse() Assert.ThrowsException(() => JObject.Parse("{\"color\":\"\\uDBFF\\u0DFFF\"}")); Assert.ThrowsException(() => JObject.Parse("\"\\uDBFF\\u0DFFF\"")); - JObject.Parse("null").Should().BeNull(); - JObject.Parse("true").AsBoolean().Should().BeTrue(); - JObject.Parse("false").AsBoolean().Should().BeFalse(); - JObject.Parse("\"hello world\"").AsString().Should().Be("hello world"); - JObject.Parse("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\"").AsString().Should().Be("\"\\/\b\f\n\r\t"); - JObject.Parse("\"\\u0030\"").AsString().Should().Be("0"); - JObject.Parse("{\"k1\":\"v1\"}", 100).ToString().Should().Be("{\"k1\":\"v1\"}"); + Assert.IsNull(JObject.Parse("null")); + Assert.IsTrue(JObject.Parse("true").AsBoolean()); + Assert.IsFalse(JObject.Parse("false").AsBoolean()); + Assert.AreEqual("hello world", JObject.Parse("\"hello world\"").AsString()); + Assert.AreEqual("\"\\/\b\f\n\r\t", JObject.Parse("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\"").AsString()); + Assert.AreEqual("0", JObject.Parse("\"\\u0030\"").AsString()); + Assert.AreEqual("{\"k1\":\"v1\"}", JObject.Parse("{\"k1\":\"v1\"}", 100).ToString()); } [TestMethod] public void TestGetEnum() { - alice.AsEnum().Should().Be(Woo.Tom); + Assert.AreEqual(Woo.Tom, alice.AsEnum()); Action action = () => alice.GetEnum(); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] public void TestOpImplicitEnum() { JToken obj = Woo.Tom; - obj.AsString().Should().Be("Tom"); + Assert.AreEqual("Tom", obj.AsString()); } [TestMethod] public void TestOpImplicitString() { JToken obj = null; - obj.Should().BeNull(); + Assert.IsNull(obj); obj = "{\"aaa\":\"111\"}"; - obj.AsString().Should().Be("{\"aaa\":\"111\"}"); + Assert.AreEqual("{\"aaa\":\"111\"}", obj.AsString()); } [TestMethod] public void TestGetNull() { - JToken.Null.Should().BeNull(); + Assert.IsNull(JToken.Null); } [TestMethod] public void TestClone() { var bobClone = (JObject)bob.Clone(); - bobClone.Should().NotBeSameAs(bob); + Assert.AreNotSame(bob, bobClone); foreach (var key in bobClone.Properties.Keys) { switch (bob[key]) { case JToken.Null: - bobClone[key].Should().BeNull(); + Assert.IsNull(bobClone[key]); break; case JObject obj: - ((JObject)bobClone[key]).Properties.Should().BeEquivalentTo(obj.Properties); + CollectionAssert.AreEqual( + ((JObject)bob[key]).Properties.ToList(), + ((JObject)bobClone[key]).Properties.ToList()); break; default: - bobClone[key].Should().BeEquivalentTo(bob[key]); + Assert.AreEqual(bob[key], bobClone[key]); break; } } diff --git a/tests/Neo.Json.UnitTests/UT_JPath.cs b/tests/Neo.Json.UnitTests/UT_JPath.cs index 832917cb29..df698693e4 100644 --- a/tests/Neo.Json.UnitTests/UT_JPath.cs +++ b/tests/Neo.Json.UnitTests/UT_JPath.cs @@ -9,6 +9,8 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Neo.Json.UnitTests { [TestClass] diff --git a/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs b/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs index 514417959a..457ff65155 100644 --- a/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs +++ b/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs @@ -28,71 +28,70 @@ public void SetUp() { "c", 3 } }; } - [TestMethod] public void TestClear() { od.Clear(); - od.Count.Should().Be(0); - od.TryGetValue("a", out uint i).Should().BeFalse(); + Assert.AreEqual(0, od.Count); + Assert.IsFalse(od.TryGetValue("a", out uint i)); } [TestMethod] public void TestCount() { - od.Count.Should().Be(3); + Assert.AreEqual(3, od.Count); od.Add("d", 4); - od.Count.Should().Be(4); + Assert.AreEqual(4, od.Count); } [TestMethod] public void TestIsReadOnly() { - od.IsReadOnly.Should().BeFalse(); + Assert.IsFalse(od.IsReadOnly); } [TestMethod] public void TestSetAndGetItem() { var val = od["a"]; - val.Should().Be(1); + Assert.AreEqual(1u, val); od["d"] = 10; - od["d"].Should().Be(10); + Assert.AreEqual(10u, od["d"]); od["d"] = 15; - od["d"].Should().Be(15); + Assert.AreEqual(15u, od["d"]); } [TestMethod] public void TestGetKeys() { var keys = od.Keys; - keys.Should().Contain("a"); - keys.Count.Should().Be(3); + Assert.IsTrue(keys.Contains("a")); + Assert.AreEqual(3, keys.Count); } [TestMethod] public void TestGetValues() { var values = od.Values; - values.Should().Contain(1); - values.Count.Should().Be(3); + Assert.IsTrue(values.Contains(1u)); + Assert.AreEqual(3, values.Count); } [TestMethod] public void TestRemove() { od.Remove("a"); - od.Count.Should().Be(2); - od.ContainsKey("a").Should().BeFalse(); + Assert.AreEqual(2, od.Count); + Assert.IsFalse(od.ContainsKey("a")); } [TestMethod] public void TestTryGetValue() { - od.TryGetValue("a", out uint i).Should().BeTrue(); - i.Should().Be(1); - od.TryGetValue("d", out uint j).Should().BeFalse(); - j.Should().Be(0); + Assert.IsTrue(od.TryGetValue("a", out uint i)); + Assert.AreEqual(1u, i); + Assert.IsFalse(od.TryGetValue("d", out uint j)); + Assert.AreEqual(0u, j); } [TestMethod] @@ -101,7 +100,7 @@ public void TestCollectionAddAndContains() var pair = new KeyValuePair("d", 4); ICollection> collection = od; collection.Add(pair); - collection.Contains(pair).Should().BeTrue(); + Assert.IsTrue(collection.Contains(pair)); } [TestMethod] @@ -110,12 +109,12 @@ public void TestCollectionCopyTo() var arr = new KeyValuePair[3]; ICollection> collection = od; collection.CopyTo(arr, 0); - arr[0].Key.Should().Be("a"); - arr[0].Value.Should().Be(1); - arr[1].Key.Should().Be("b"); - arr[1].Value.Should().Be(2); - arr[2].Key.Should().Be("c"); - arr[2].Value.Should().Be(3); + Assert.AreEqual("a", arr[0].Key); + Assert.AreEqual(1u, arr[0].Value); + Assert.AreEqual("b", arr[1].Key); + Assert.AreEqual(2u, arr[1].Value); + Assert.AreEqual("c", arr[2].Key); + Assert.AreEqual(3u, arr[2].Value); } [TestMethod] @@ -124,15 +123,15 @@ public void TestCollectionRemove() ICollection> collection = od; var pair = new KeyValuePair("a", 1); collection.Remove(pair); - collection.Contains(pair).Should().BeFalse(); - collection.Count.Should().Be(2); + Assert.IsFalse(collection.Contains(pair)); + Assert.AreEqual(2, collection.Count); } [TestMethod] public void TestGetEnumerator() { IEnumerable collection = od; - collection.GetEnumerator().MoveNext().Should().BeTrue(); + Assert.IsTrue(collection.GetEnumerator().MoveNext()); } } } diff --git a/tests/Neo.Json.UnitTests/Usings.cs b/tests/Neo.Json.UnitTests/Usings.cs index d7c3d100b0..14b61dab70 100644 --- a/tests/Neo.Json.UnitTests/Usings.cs +++ b/tests/Neo.Json.UnitTests/Usings.cs @@ -9,5 +9,4 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -global using FluentAssertions; global using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index 69f2286df0..7c8fcca031 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -9,7 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; +using Akka.Dispatch.SysMsg; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Moq.Protected; @@ -116,7 +116,14 @@ public void TestConstructorByUrlAndDispose() //dummy url for test var client = new RpcClient(new Uri("http://www.xxx.yyy")); Action action = () => client.Dispose(); - action.Should().NotThrow(); + try + { + action(); + } + catch + { + Assert.Fail("Dispose should not throw exception"); + } } [TestMethod] diff --git a/tests/Neo.Network.RPC.Tests/UT_Utility.cs b/tests/Neo.Network.RPC.Tests/UT_Utility.cs index b54dc0199d..7b9b5cebae 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Utility.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Utility.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.Network.P2P.Payloads; @@ -43,8 +42,8 @@ public void TestAsScriptHash() var scriptHash1 = Utility.AsScriptHash(NativeContract.NEO.Id.ToString()); var scriptHash2 = Utility.AsScriptHash(NativeContract.NEO.Hash.ToString()); var scriptHash3 = Utility.AsScriptHash(NativeContract.NEO.Name); - scriptHash2.Should().Be(scriptHash1); - scriptHash3.Should().Be(scriptHash1); + Assert.AreEqual(scriptHash1, scriptHash2); + Assert.AreEqual(scriptHash1, scriptHash3); } [TestMethod] @@ -66,7 +65,7 @@ public void TestGetKeyPair() Assert.AreEqual(keyPair, result); var action = () => { Utility.GetKeyPair("00"); }; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -88,7 +87,7 @@ public void TestGetScriptHash() Assert.AreEqual(scriptHash, result); var action = () => { Utility.GetScriptHash("00", protocolSettings); }; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -100,7 +99,7 @@ public void TestTransactionAttribute() }; var json = attribute.ToJson(); var result = Utility.TransactionAttributeFromJson(json).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); var attribute2 = new OracleResponse { @@ -110,7 +109,7 @@ public void TestTransactionAttribute() }; json = attribute2.ToJson(); result = Utility.TransactionAttributeFromJson(json).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); var attribute3 = new NotValidBefore { @@ -118,12 +117,12 @@ public void TestTransactionAttribute() }; json = attribute3.ToJson(); result = Utility.TransactionAttributeFromJson(json).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); var attribute4 = new HighPriorityAttribute(); json = attribute4.ToJson(); result = Utility.TransactionAttributeFromJson(json).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); } [TestMethod] @@ -136,7 +135,7 @@ public void TestWitnessRule() }; var json = rule.ToJson(); var result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.OrCondition() { @@ -154,7 +153,7 @@ public void TestWitnessRule() }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.AndCondition() { @@ -172,12 +171,12 @@ public void TestWitnessRule() }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.BooleanCondition() { Expression = true }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.NotCondition() { @@ -188,30 +187,30 @@ public void TestWitnessRule() }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); var kp = Utility.GetKeyPair("KyXwTh1hB76RRMquSvnxZrJzQx7h9nQP2PCRL38v6VDb5ip3nf1p"); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.GroupCondition() { Group = kp.PublicKey }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.CalledByContractCondition() { Hash = UInt160.Zero }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.ScriptHashCondition() { Hash = UInt160.Zero }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); rule.Condition = new Neo.Network.P2P.Payloads.Conditions.CalledByGroupCondition() { Group = kp.PublicKey }; json = rule.ToJson(); result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); - result.ToString().Should().Be(json.ToString()); - result.ToString().Should().Be(json.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); + Assert.AreEqual(json.ToString(), result.ToString()); } [TestMethod] diff --git a/tests/Neo.Plugins.OracleService.Tests/TestUtils.cs b/tests/Neo.Plugins.OracleService.Tests/TestUtils.cs index f6b2d394ca..3aeb997e1a 100644 --- a/tests/Neo.Plugins.OracleService.Tests/TestUtils.cs +++ b/tests/Neo.Plugins.OracleService.Tests/TestUtils.cs @@ -9,7 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; using Neo.Json; using Neo.SmartContract; @@ -50,7 +50,7 @@ public static NEP6Wallet GenerateTestWallet(string password) wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = null; - wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"1.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}"); + Assert.AreEqual("{\"name\":\"noname\",\"version\":\"1.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}", wallet.ToString()); return new NEP6Wallet(null, password, settings, wallet); } } diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs index 4ed93e4023..405d1ed312 100644 --- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs +++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs @@ -11,7 +11,6 @@ using Akka.Actor; using Akka.Util.Internal; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -70,7 +69,7 @@ public void TestGetBlockByHash() result = _rpcServer.GetBlock(new BlockHashOrIndex(block.Hash), true); var block3 = block.ToJson(UnitTests.TestProtocolSettings.Default); block3["confirmations"] = NativeContract.Ledger.CurrentIndex(snapshot) - block.Index + 1; - result.ToString().Should().Be(block3.ToString()); + Assert.AreEqual(block3.ToString(), result.ToString()); } [TestMethod] @@ -92,7 +91,7 @@ public void TestGetBlockByIndex() result = _rpcServer.GetBlock(new BlockHashOrIndex(block.Index), true); var block3 = block.ToJson(UnitTests.TestProtocolSettings.Default); block3["confirmations"] = NativeContract.Ledger.CurrentIndex(snapshot) - block.Index + 1; - result.ToString().Should().Be(block3.ToString()); + Assert.AreEqual(block3.ToString(), result.ToString()); } [TestMethod] @@ -139,7 +138,7 @@ public void TestGetBlockHeader() result = _rpcServer.GetBlockHeader(new BlockHashOrIndex(block.Hash), false); var headerArr = Convert.FromBase64String(result.AsString()); var header2 = headerArr.AsSerializable
(); - header2.ToJson(_neoSystem.Settings).ToString().Should().Be(block.Header.ToJson(_neoSystem.Settings).ToString()); + Assert.AreEqual(block.Header.ToJson(_neoSystem.Settings).ToString(), header2.ToJson(_neoSystem.Settings).ToString()); } [TestMethod] @@ -158,14 +157,29 @@ public void TestGetContractState() var byId = _rpcServer.GetContractState(new ContractNameOrHashOrId(-1)); var byName = _rpcServer.GetContractState(new ContractNameOrHashOrId("ContractManagement")); - byId.ToString().Should().Be(byName.ToString()); + Assert.AreEqual(byId.ToString(), byName.ToString()); snapshot.DeleteContract(contractState.Hash); snapshot.Commit(); - Action act = () => _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Hash)); - act.Should().Throw().WithMessage(RpcError.UnknownContract.Message); - act = () => _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Id)); - act.Should().Throw().WithMessage(RpcError.UnknownContract.Message); + try + { + _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Hash)); + Assert.Fail("Expected RpcException was not thrown."); + } + catch (RpcException ex) + { + Assert.AreEqual(RpcError.UnknownContract.Message, ex.Message); + } + + try + { + _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Id)); + Assert.Fail("Expected RpcException was not thrown."); + } + catch (RpcException ex) + { + Assert.AreEqual(RpcError.UnknownContract.Message, ex.Message); + } } [TestMethod] @@ -197,7 +211,7 @@ public void TestGetRawTransaction() result = _rpcServer.GetRawTransaction(tx.Hash, false); var tx2 = Convert.FromBase64String(result.AsString()).AsSerializable(); - tx2.ToJson(_neoSystem.Settings).ToString().Should().Be(tx.ToJson(_neoSystem.Settings).ToString()); + Assert.AreEqual(tx.ToJson(_neoSystem.Settings).ToString(), tx2.ToJson(_neoSystem.Settings).ToString()); } [TestMethod] @@ -239,13 +253,13 @@ public void TestFindStorage() Assert.AreEqual(json.ToString(), result.ToString()); var result2 = _rpcServer.FindStorage(new ContractNameOrHashOrId(contractState.Hash), Convert.ToBase64String(key)); - result2.ToString().Should().Be(result.ToString()); + Assert.AreEqual(result.ToString(), result2.ToString()); Enumerable.Range(0, 51).ToList().ForEach(i => TestUtils.StorageItemAdd(snapshot, contractState.Id, new byte[] { 0x01, (byte)i }, new byte[] { 0x02 })); snapshot.Commit(); var result4 = _rpcServer.FindStorage(new ContractNameOrHashOrId(contractState.Hash), Convert.ToBase64String(new byte[] { 0x01 }), 0); - result4["next"].Should().Be(RpcServerSettings.Default.FindStoragePageSize); - (result4["truncated"]).AsBoolean().Should().Be(true); + Assert.AreEqual(RpcServerSettings.Default.FindStoragePageSize, result4["next"].AsNumber()); + Assert.IsTrue(result4["truncated"].AsBoolean()); } [TestMethod] @@ -403,8 +417,7 @@ public void TestGetBlockHashInvalidIndex() var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); - Action act = () => _rpcServer.GetBlockHash(block.Index + 1); - act.Should().Throw(); + Assert.ThrowsException(() => _rpcServer.GetBlockHash(block.Index + 1)); } [TestMethod] diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs index c40ba1b263..6b3c624540 100644 --- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs +++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs @@ -10,7 +10,6 @@ // modifications are permitted. using Akka.Actor; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -31,7 +30,7 @@ partial class UT_RpcServer public void TestGetConnectionCount() { var result = _rpcServer.GetConnectionCount(); - result.GetType().Should().Be(typeof(JNumber)); + Assert.IsInstanceOfType(result, typeof(JNumber)); } [TestMethod] @@ -48,10 +47,10 @@ public void TestGetPeers() var result = rpcServer.GetPeers(); Assert.IsInstanceOfType(result, typeof(JObject)); var json = (JObject)result; - json.ContainsProperty("unconnected").Should().BeTrue(); - (json["unconnected"] as JArray).Count.Should().Be(3); - json.ContainsProperty("bad").Should().BeTrue(); - json.ContainsProperty("connected").Should().BeTrue(); + Assert.IsTrue(json.ContainsProperty("unconnected")); + Assert.AreEqual(3, (json["unconnected"] as JArray).Count); + Assert.IsTrue(json.ContainsProperty("bad")); + Assert.IsTrue(json.ContainsProperty("connected")); } [TestMethod] diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Utilities.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Utilities.cs index 4492419b67..f66e0c77c8 100644 --- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Utilities.cs +++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Utilities.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.AspNetCore.Http; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; diff --git a/tests/Neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs b/tests/Neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs index 4cbd6ba77a..80a33aad2d 100644 --- a/tests/Neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs +++ b/tests/Neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -27,15 +26,22 @@ public class UT_ECFieldElement public void TestECFieldElementConstructor() { BigInteger input = new(100); - Action action = () => new ECFieldElement(input, ECCurve.Secp256k1); - action.Should().NotThrow(); + + try + { + _ = new ECFieldElement(input, ECCurve.Secp256k1); + } + catch + { + Assert.Fail(); + } input = ECCurve.Secp256k1.Q; - action = () => new ECFieldElement(input, ECCurve.Secp256k1); - action.Should().Throw(); + var action = () => new ECFieldElement(input, ECCurve.Secp256k1); + Assert.ThrowsException(() => action()); action = () => new ECFieldElement(input, null); - action.Should().Throw(); + Assert.ThrowsException(() => action()); } [TestMethod] @@ -52,13 +58,14 @@ public void TestCompareTo() ECPoint point3 = new(X1, Y2, ECCurve.Secp256k1); ECPoint point4 = new(X3, Y3, ECCurve.Secp256r1); - point1.CompareTo(point1).Should().Be(0); - point1.CompareTo(point2).Should().Be(-1); - point2.CompareTo(point1).Should().Be(1); - point1.CompareTo(point3).Should().Be(-1); - point3.CompareTo(point1).Should().Be(1); - Action action = () => point3.CompareTo(point4); - action.Should().Throw(); + Assert.AreEqual(0, point1.CompareTo(point1)); + Assert.AreEqual(-1, point1.CompareTo(point2)); + Assert.AreEqual(1, point2.CompareTo(point1)); + Assert.AreEqual(-1, point1.CompareTo(point3)); + Assert.AreEqual(1, point3.CompareTo(point1)); + + var action = new Action(() => point3.CompareTo(point4)); + Assert.ThrowsException(() => action()); } [TestMethod] @@ -66,19 +73,19 @@ public void TestEquals() { BigInteger input = new(100); object element = new ECFieldElement(input, ECCurve.Secp256k1); - element.Equals(element).Should().BeTrue(); - element.Equals(1).Should().BeFalse(); - element.Equals(new ECFieldElement(input, ECCurve.Secp256r1)).Should().BeFalse(); + Assert.IsTrue(element.Equals(element)); + Assert.IsFalse(element.Equals(1)); + Assert.IsFalse(element.Equals(new ECFieldElement(input, ECCurve.Secp256r1))); input = new BigInteger(200); - element.Equals(new ECFieldElement(input, ECCurve.Secp256k1)).Should().BeFalse(); + Assert.IsFalse(element.Equals(new ECFieldElement(input, ECCurve.Secp256k1))); } [TestMethod] public void TestSqrt() { ECFieldElement element = new(new BigInteger(100), ECCurve.Secp256k1); - element.Sqrt().Should().Be(new ECFieldElement(BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007908834671653"), ECCurve.Secp256k1)); + Assert.AreEqual(new ECFieldElement(BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007908834671653"), ECCurve.Secp256k1), element.Sqrt()); ConstructorInfo constructor = typeof(ECCurve).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(BigInteger), typeof(BigInteger), typeof(BigInteger), typeof(BigInteger), typeof(byte[]) }, null); ECCurve testCruve = constructor.Invoke(new object[] { @@ -88,7 +95,7 @@ public void TestSqrt() BigInteger.Parse("00FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", NumberStyles.AllowHexSpecifier), ("04" + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296" + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5").HexToBytes() }) as ECCurve; element = new ECFieldElement(new BigInteger(200), testCruve); - element.Sqrt().Should().Be(null); + Assert.IsNull(element.Sqrt()); } [TestMethod] @@ -96,13 +103,13 @@ public void TestToByteArray() { byte[] result = new byte[32]; result[31] = 100; - new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1).ToByteArray().Should().BeEquivalentTo(result); + CollectionAssert.AreEqual(result, new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1).ToByteArray()); byte[] result2 = { 2, 53, 250, 221, 129, 194, 130, 43, 179, 240, 120, 119, 151, 61, 80, 242, 139, 242, 42, 49, 190, 142, 232, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - new ECFieldElement(BigInteger.Pow(new BigInteger(10), 75), ECCurve.Secp256k1).ToByteArray().Should().BeEquivalentTo(result2); + CollectionAssert.AreEqual(result2, new ECFieldElement(BigInteger.Pow(new BigInteger(10), 75), ECCurve.Secp256k1).ToByteArray()); byte[] result3 = { 221, 21, 254, 134, 175, 250, 217, 18, 73, 239, 14, 183, 19, 243, 158, 190, 170, 152, 123, 110, 111, 210, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - new ECFieldElement(BigInteger.Pow(new BigInteger(10), 77), ECCurve.Secp256k1).ToByteArray().Should().BeEquivalentTo(result3); + CollectionAssert.AreEqual(result3, new ECFieldElement(BigInteger.Pow(new BigInteger(10), 77), ECCurve.Secp256k1).ToByteArray()); } } } diff --git a/tests/Neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs b/tests/Neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs index a31dde7238..ac02ce6048 100644 --- a/tests/Neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs +++ b/tests/Neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -43,31 +42,31 @@ public void TestCompareTo() ECFieldElement X2 = new ECFieldElement(new BigInteger(200), ECCurve.Secp256k1); ECFieldElement X3 = new ECFieldElement(new BigInteger(100), ECCurve.Secp256r1); - X1.CompareTo(X2).Should().Be(-1); + Assert.AreEqual(-1, X1.CompareTo(X2)); Action action = () => X1.CompareTo(X3); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] public void TestECPointConstructor() { ECPoint point = new ECPoint(); - point.X.Should().BeNull(); - point.Y.Should().BeNull(); - point.Curve.Should().Be(ECCurve.Secp256r1); + Assert.IsNull(point.X); + Assert.IsNull(point.Y); + Assert.AreEqual(ECCurve.Secp256r1, point.Curve); ECFieldElement X = new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1); ECFieldElement Y = new ECFieldElement(new BigInteger(200), ECCurve.Secp256k1); point = new ECPoint(X, Y, ECCurve.Secp256k1); - point.X.Should().Be(X); - point.Y.Should().Be(Y); - point.Curve.Should().Be(ECCurve.Secp256k1); + Assert.AreEqual(X, point.X); + Assert.AreEqual(Y, point.Y); + Assert.AreEqual(ECCurve.Secp256k1, point.Curve); Action action = () => new ECPoint(X, null, ECCurve.Secp256k1); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => new ECPoint(null, Y, ECCurve.Secp256k1); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => new ECPoint(null, Y, null); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -75,21 +74,21 @@ public void TestDecodePoint() { byte[] input1 = { 0 }; Action action = () => ECPoint.DecodePoint(input1, ECCurve.Secp256k1); - action.Should().Throw(); + Assert.ThrowsException(action); 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); + Assert.AreEqual(ECCurve.Secp256k1.G, ECPoint.DecodePoint(input2, ECCurve.Secp256k1)); action = () => ECPoint.DecodePoint(input2.Take(32).ToArray(), ECCurve.Secp256k1); - action.Should().Throw(); + Assert.ThrowsException(action); 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 }; - ECPoint.DecodePoint(input3, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); - ECPoint.DecodePoint(input4, ECCurve.Secp256r1).Should().Be(ECCurve.Secp256r1.G); + Assert.AreEqual(ECCurve.Secp256k1.G, ECPoint.DecodePoint(input3, ECCurve.Secp256k1)); + Assert.AreEqual(ECCurve.Secp256r1.G, ECPoint.DecodePoint(input4, ECCurve.Secp256r1)); action = () => ECPoint.DecodePoint(input3.Take(input3.Length - 1).ToArray(), ECCurve.Secp256k1); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -100,14 +99,14 @@ public void TestDeserializeFrom() try { ECPoint.DeserializeFrom(ref reader1, ECCurve.Secp256k1); - Assert.Fail(); + Assert.Fail("Expected FormatException was not thrown"); } catch (FormatException) { } 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 }; MemoryReader reader2 = new(input2); - ECPoint.DeserializeFrom(ref reader2, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); + Assert.AreEqual(ECPoint.DeserializeFrom(ref reader2, ECCurve.Secp256k1), ECCurve.Secp256k1.G); reader2 = new(input2.Take(32).ToArray()); try { @@ -118,16 +117,17 @@ public void TestDeserializeFrom() 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 }; MemoryReader reader3 = new(input3); - ECPoint.DeserializeFrom(ref reader3, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); + Assert.AreEqual(ECCurve.Secp256k1.G, ECPoint.DeserializeFrom(ref reader3, ECCurve.Secp256k1)); + 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 }; MemoryReader reader4 = new(input4); - ECPoint.DeserializeFrom(ref reader4, ECCurve.Secp256r1).Should().Be(ECCurve.Secp256r1.G); + Assert.AreEqual(ECCurve.Secp256r1.G, ECPoint.DeserializeFrom(ref reader4, ECCurve.Secp256r1)); reader3 = new(input3.Take(input3.Length - 1).ToArray()); try { ECPoint.DeserializeFrom(ref reader3, ECCurve.Secp256k1); - Assert.Fail(); + Assert.Fail("Expected FormatException was not thrown"); } catch (FormatException) { } } @@ -137,48 +137,48 @@ public void TestEncodePoint() { ECPoint point = new ECPoint(null, null, ECCurve.Secp256k1); byte[] result1 = { 0 }; - point.EncodePoint(true).Should().BeEquivalentTo(result1); + CollectionAssert.AreEqual(result1, point.EncodePoint(true)); point = ECCurve.Secp256k1.G; byte[] result2 = { 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 }; - point.EncodePoint(false).Should().BeEquivalentTo(result2); - point.EncodePoint(false).Should().BeEquivalentTo(result2); + CollectionAssert.AreEqual(result2, point.EncodePoint(false)); + CollectionAssert.AreEqual(result2, point.EncodePoint(false)); byte[] result3 = { 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 }; - point.EncodePoint(true).Should().BeEquivalentTo(result3); - point.EncodePoint(true).Should().BeEquivalentTo(result3); + CollectionAssert.AreEqual(result3, point.EncodePoint(true)); + CollectionAssert.AreEqual(result3, point.EncodePoint(true)); point = ECCurve.Secp256r1.G; byte[] result4 = { 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 }; - point.EncodePoint(true).Should().BeEquivalentTo(result4); - point.EncodePoint(true).Should().BeEquivalentTo(result4); + CollectionAssert.AreEqual(result4, point.EncodePoint(true)); + CollectionAssert.AreEqual(result4, point.EncodePoint(true)); // Test cache point = ECPoint.DecodePoint(ECCurve.Secp256r1.G.EncodePoint(true), ECCurve.Secp256r1); - point.EncodePoint(true).Should().BeEquivalentTo(result4); - point.EncodePoint(true).Should().BeEquivalentTo(result4); + CollectionAssert.AreEqual(result4, point.EncodePoint(true)); + CollectionAssert.AreEqual(result4, point.EncodePoint(true)); byte[] result5 = "046b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c2964fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5".HexToBytes(); point = ECPoint.DecodePoint(ECCurve.Secp256r1.G.EncodePoint(false), ECCurve.Secp256r1); - point.EncodePoint(true).Should().BeEquivalentTo(result4); - point.EncodePoint(true).Should().BeEquivalentTo(result4); - point.EncodePoint(false).Should().BeEquivalentTo(result5); - point.EncodePoint(false).Should().BeEquivalentTo(result5); + CollectionAssert.AreEqual(result4, point.EncodePoint(true)); + CollectionAssert.AreEqual(result4, point.EncodePoint(true)); + CollectionAssert.AreEqual(result5, point.EncodePoint(false)); + CollectionAssert.AreEqual(result5, point.EncodePoint(false)); } [TestMethod] public void TestEquals() { ECPoint point = ECCurve.Secp256k1.G; - point.Equals(point).Should().BeTrue(); - point.Equals(null).Should().BeFalse(); + Assert.IsTrue(point.Equals(point)); + Assert.IsFalse(point.Equals(null)); point = new ECPoint(null, null, ECCurve.Secp256k1); - point.Equals(new ECPoint(null, null, ECCurve.Secp256r1)).Should().BeFalse(); - point.Equals(ECCurve.Secp256r1.G).Should().BeFalse(); - ECCurve.Secp256r1.G.Equals(point).Should().BeFalse(); + Assert.IsFalse(point.Equals(new ECPoint(null, null, ECCurve.Secp256r1))); + Assert.IsFalse(point.Equals(ECCurve.Secp256r1.G)); + Assert.IsFalse(ECCurve.Secp256r1.G.Equals(point)); ECFieldElement X1 = new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1); ECFieldElement Y1 = new ECFieldElement(new BigInteger(200), ECCurve.Secp256k1); @@ -187,22 +187,22 @@ public void TestEquals() ECPoint point1 = new ECPoint(X1, Y1, ECCurve.Secp256k1); ECPoint point2 = new ECPoint(X2, Y1, ECCurve.Secp256k1); ECPoint point3 = new ECPoint(X1, Y2, ECCurve.Secp256k1); - point1.Equals(point2).Should().BeFalse(); - point1.Equals(point3).Should().BeFalse(); + Assert.IsFalse(point1.Equals(point2)); + Assert.IsFalse(point1.Equals(point3)); } [TestMethod] public void TestEqualsObject() { object point = ECCurve.Secp256k1.G; - point.Equals(point).Should().BeTrue(); - point.Equals(null).Should().BeFalse(); - point.Equals(1u).Should().BeFalse(); + Assert.IsTrue(point.Equals(point)); + Assert.IsFalse(point.Equals(null)); + Assert.IsFalse(point.Equals(1u)); point = new ECPoint(null, null, ECCurve.Secp256k1); - point.Equals(new ECPoint(null, null, ECCurve.Secp256r1)).Should().BeFalse(); - point.Equals(ECCurve.Secp256r1.G).Should().BeFalse(); - ECCurve.Secp256r1.G.Equals(point).Should().BeFalse(); + Assert.IsFalse(point.Equals(new ECPoint(null, null, ECCurve.Secp256r1))); + Assert.IsFalse(point.Equals(ECCurve.Secp256r1.G)); + Assert.IsFalse(ECCurve.Secp256r1.G.Equals(point)); ECFieldElement X1 = new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1); ECFieldElement Y1 = new ECFieldElement(new BigInteger(200), ECCurve.Secp256k1); @@ -211,8 +211,8 @@ public void TestEqualsObject() object point1 = new ECPoint(X1, Y1, ECCurve.Secp256k1); object point2 = new ECPoint(X2, Y1, ECCurve.Secp256k1); object point3 = new ECPoint(X1, Y2, ECCurve.Secp256k1); - point1.Equals(point2).Should().BeFalse(); - point1.Equals(point3).Should().BeFalse(); + Assert.IsFalse(point1.Equals(point2)); + Assert.IsFalse(point1.Equals(point3)); } [TestMethod] @@ -220,37 +220,37 @@ public void TestFromBytes() { byte[] input1 = { 0 }; Action action = () => ECPoint.FromBytes(input1, ECCurve.Secp256k1); - action.Should().Throw(); + Assert.ThrowsException(action); 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.FromBytes(input2, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); + Assert.AreEqual(ECCurve.Secp256k1.G, ECPoint.FromBytes(input2, ECCurve.Secp256k1)); 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.FromBytes(input3, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); - ECPoint.FromBytes(input2.Skip(1).ToArray(), ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G); + Assert.AreEqual(ECCurve.Secp256k1.G, ECPoint.FromBytes(input3, ECCurve.Secp256k1)); + Assert.AreEqual(ECCurve.Secp256k1.G, ECPoint.FromBytes(input2.Skip(1).ToArray(), ECCurve.Secp256k1)); byte[] input4 = GeneratePrivateKey(72); - ECPoint.FromBytes(input4, ECCurve.Secp256k1).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("3634473727541135791764834762056624681715094789735830699031648" + + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("3634473727541135791764834762056624681715094789735830699031648" + "273128038409767"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("18165245710263168158644330920009617039772504630129940696140050972160274286151"), - ECCurve.Secp256k1), ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECCurve.Secp256k1), ECPoint.FromBytes(input4, ECCurve.Secp256k1)); byte[] input5 = GeneratePrivateKey(96); - ECPoint.FromBytes(input5, ECCurve.Secp256k1).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("1780731860627700044960722568376592200742329637303199754547598" + + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("1780731860627700044960722568376592200742329637303199754547598" + "369979440671"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("14532552714582660066924456880521368950258152170031413196862950297402215317055"), - ECCurve.Secp256k1), ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECCurve.Secp256k1), ECPoint.FromBytes(input5, ECCurve.Secp256k1)); byte[] input6 = GeneratePrivateKey(104); - ECPoint.FromBytes(input6, ECCurve.Secp256k1).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("3634473727541135791764834762056624681715094789735830699031648" + + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("3634473727541135791764834762056624681715094789735830699031648" + "273128038409767"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("18165245710263168158644330920009617039772504630129940696140050972160274286151"), - ECCurve.Secp256k1), ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECCurve.Secp256k1), ECPoint.FromBytes(input6, ECCurve.Secp256k1)); } [TestMethod] public void TestGetSize() { - ECCurve.Secp256k1.G.Size.Should().Be(33); - ECCurve.Secp256k1.Infinity.Size.Should().Be(1); + Assert.AreEqual(33, ECCurve.Secp256k1.G.Size); + Assert.AreEqual(1, ECCurve.Secp256k1.Infinity.Size); } [TestMethod] @@ -258,39 +258,39 @@ public void TestMultiply() { ECPoint p = ECCurve.Secp256k1.G; BigInteger k = BigInteger.Parse("100"); - ECPoint.Multiply(p, k).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("107303582290733097924842193972465022053148211775194373671539518313500194639752"), + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("107303582290733097924842193972465022053148211775194373671539518313500194639752"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("103795966108782717446806684023742168462365449272639790795591544606836007446638"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECPoint.Multiply(p, k)); k = BigInteger.Parse("10000"); - ECPoint.Multiply(p, k).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("55279067612272658004429375184716238028207484982037227804583126224321918234542"), + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("55279067612272658004429375184716238028207484982037227804583126224321918234542"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("93139664895507357192565643142424306097487832058389223752321585898830257071353"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECPoint.Multiply(p, k)); k = BigInteger.Parse("10000000000000"); - ECPoint.Multiply(p, k).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("115045167963494515061513744671884131783397561769819471159495798754884242293003"), + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("115045167963494515061513744671884131783397561769819471159495798754884242293003"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("93759167105263077270762304290738437383691912799231615884447658154878797241853"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECPoint.Multiply(p, k)); k = BigInteger.Parse("1000000000000000000000000000000000000000"); - ECPoint.Multiply(p, k).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("114831276968810911840931876895388845736099852671055832194631099067239418074350"), + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("114831276968810911840931876895388845736099852671055832194631099067239418074350"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("16721517996619732311261078486295444964227498319433363271180755596201863690708"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECPoint.Multiply(p, k)); k = new BigInteger(GeneratePrivateKey(100)); - ECPoint.Multiply(p, k).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("19222995016448259376216431079553428738726180595337971417371897285865264889977"), + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("19222995016448259376216431079553428738726180595337971417371897285865264889977"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("6637081904924493791520919212064582313497884724460823966446023080706723904419"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECPoint.Multiply(p, k)); k = new BigInteger(GeneratePrivateKey(120)); - ECPoint.Multiply(p, k).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("79652345192111851576650978679091010173409410384772942769927955775006682639778"), + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("79652345192111851576650978679091010173409410384772942769927955775006682639778"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("6460429961979335115790346961011058418773289452368186110818621539624566803831"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECPoint.Multiply(p, k)); k = new BigInteger(GeneratePrivateKey(300)); - ECPoint.Multiply(p, k).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("105331914562708556186724786757483927866790351460145374033180496740107603569412"), + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("105331914562708556186724786757483927866790351460145374033180496740107603569412"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("60523670886755698512704385951571322569877668383890769288780681319304421873758"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + ECCurve.Secp256k1), ECPoint.Multiply(p, k)); } [TestMethod] @@ -302,8 +302,8 @@ public void TestDeserialize() 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 }; MemoryReader reader = new(input); serializable.Deserialize(ref reader); - point.X.Should().Be(ECCurve.Secp256k1.G.X); - point.Y.Should().Be(ECCurve.Secp256k1.G.Y); + Assert.AreEqual(ECCurve.Secp256k1.G.X, point.X); + Assert.AreEqual(ECCurve.Secp256k1.G.Y, point.Y); } [TestMethod] @@ -313,19 +313,17 @@ public void TestSerialize() ECPoint point = new ECPoint(null, null, ECCurve.Secp256k1); ISerializable serializable = point; serializable.Serialize(new BinaryWriter(stream)); - stream.ToArray().Should().BeEquivalentTo(new byte[] { 0 }); + CollectionAssert.AreEqual(new byte[] { 0 }, stream.ToArray()); } [TestMethod] public void TestOpAddition() { - (ECCurve.Secp256k1.Infinity + ECCurve.Secp256k1.G).Should().Be(ECCurve.Secp256k1.G); - (ECCurve.Secp256k1.G + ECCurve.Secp256k1.Infinity).Should().Be(ECCurve.Secp256k1.G); - (ECCurve.Secp256k1.G + ECCurve.Secp256k1.G).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("8956589192654700423125292042593569236064414582962220983368432" + - "9913297188986597"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("12158399299693830322967808612713398636155367887041628176798871954788371653930"), - ECCurve.Secp256k1), ECCurve.Secp256k1)); - (ECCurve.Secp256k1.G + new ECPoint(ECCurve.Secp256k1.G.X, new ECFieldElement(BigInteger.One, ECCurve.Secp256k1), ECCurve.Secp256k1)).Should().Be(ECCurve.Secp256k1.Infinity); - (ECCurve.Secp256k1.G + ECCurve.Secp256k1.G + ECCurve.Secp256k1.G).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("112711660439710606056748659173929673102" + + Assert.AreEqual(ECCurve.Secp256k1.Infinity + ECCurve.Secp256k1.G, ECCurve.Secp256k1.G); + Assert.AreEqual(ECCurve.Secp256k1.G + ECCurve.Secp256k1.Infinity, ECCurve.Secp256k1.G); + Assert.AreEqual(ECCurve.Secp256k1.G + ECCurve.Secp256k1.G, new ECPoint(new ECFieldElement(BigInteger.Parse("89565891926547004231252920425935692360644145829622209833684329913297188986597"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("12158399299693830322967808612713398636155367887041628176798871954788371653930"), ECCurve.Secp256k1), ECCurve.Secp256k1)); + Assert.AreEqual(ECCurve.Secp256k1.G + new ECPoint(ECCurve.Secp256k1.G.X, new ECFieldElement(BigInteger.One, ECCurve.Secp256k1), ECCurve.Secp256k1), ECCurve.Secp256k1.Infinity); + Assert.AreEqual(ECCurve.Secp256k1.G + ECCurve.Secp256k1.G + ECCurve.Secp256k1.G, new ECPoint(new ECFieldElement(BigInteger.Parse("112711660439710606056748659173929673102" + "114977341539408544630613555209775888121"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("2558302798057088369165690587740197640644886825481629506991988" + "8960541586679410"), ECCurve.Secp256k1), ECCurve.Secp256k1)); } @@ -336,60 +334,57 @@ public void TestOpMultiply() ECPoint p = null; byte[] n = new byte[] { 1 }; Action action = () => p = p * n; - action.Should().Throw(); + Assert.ThrowsException(action); p = ECCurve.Secp256k1.G; n = null; - action.Should().Throw(); + action = () => p = p * n; + Assert.ThrowsException(action); n = new byte[] { 1 }; - action.Should().Throw(); + action = () => p = p * n; + Assert.ThrowsException(action); p = ECCurve.Secp256k1.Infinity; n = new byte[32]; - (p * n).Should().Be(p); + Assert.AreEqual(p, p * n); p = ECCurve.Secp256k1.G; - (p * n).Should().Be(ECCurve.Secp256k1.Infinity); + Assert.AreEqual(ECCurve.Secp256k1.Infinity, p * n); n[0] = 1; - (p * n).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("63395642421589016740518975608504846303065672135176650115036476193363423546538"), ECCurve.Secp256k1), - new ECFieldElement(BigInteger.Parse("29236048674093813394523910922582374630829081423043497254162533033164154049666"), ECCurve.Secp256k1), ECCurve.Secp256k1)); + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("63395642421589016740518975608504846303065672135176650115036476193363423546538"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("29236048674093813394523910922582374630829081423043497254162533033164154049666"), ECCurve.Secp256k1), ECCurve.Secp256k1), p * n); } [TestMethod] public void TestOpSubtraction() { - (ECCurve.Secp256k1.G - ECCurve.Secp256k1.Infinity).Should().Be(ECCurve.Secp256k1.G); - (ECCurve.Secp256k1.G - ECCurve.Secp256k1.G).Should().Be(ECCurve.Secp256k1.Infinity); + Assert.AreEqual(ECCurve.Secp256k1.G, ECCurve.Secp256k1.G - ECCurve.Secp256k1.Infinity); + Assert.AreEqual(ECCurve.Secp256k1.Infinity, ECCurve.Secp256k1.G - ECCurve.Secp256k1.G); } [TestMethod] public void TestOpUnaryNegation() { - (-ECCurve.Secp256k1.G).Should().Be(new ECPoint(ECCurve.Secp256k1.G.X, -ECCurve.Secp256k1.G.Y, ECCurve.Secp256k1)); + Assert.AreEqual(new ECPoint(ECCurve.Secp256k1.G.X, -ECCurve.Secp256k1.G.Y, ECCurve.Secp256k1), -ECCurve.Secp256k1.G); } [TestMethod] public void TestTryParse() { - ECPoint.TryParse("00", ECCurve.Secp256k1, out ECPoint result).Should().BeFalse(); - result.Should().BeNull(); + Assert.IsFalse(ECPoint.TryParse("00", ECCurve.Secp256k1, out ECPoint result)); + Assert.IsNull(result); - ECPoint.TryParse("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", ECCurve.Secp256k1, - out result).Should().BeTrue(); - result.Should().Be(ECCurve.Secp256k1.G); + Assert.IsTrue(ECPoint.TryParse("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", ECCurve.Secp256k1, out result)); + Assert.AreEqual(ECCurve.Secp256k1.G, result); } [TestMethod] public void TestTwice() { - ECCurve.Secp256k1.Infinity.Twice().Should().Be(ECCurve.Secp256k1.Infinity); - new ECPoint(new ECFieldElement(BigInteger.Zero, ECCurve.Secp256k1), new ECFieldElement(BigInteger.Zero, ECCurve.Secp256k1), - ECCurve.Secp256k1).Twice().Should().Be(ECCurve.Secp256k1.Infinity); - ECCurve.Secp256k1.G.Twice().Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("89565891926547004231252920425935692360644145829622209833684329913297188986597"), - ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("12158399299693830322967808612713398636155367887041628176798871954788371653930"), ECCurve.Secp256k1), - ECCurve.Secp256k1)); + Assert.AreEqual(ECCurve.Secp256k1.Infinity, ECCurve.Secp256k1.Infinity.Twice()); + Assert.AreEqual(ECCurve.Secp256k1.Infinity, new ECPoint(new ECFieldElement(BigInteger.Zero, ECCurve.Secp256k1), new ECFieldElement(BigInteger.Zero, ECCurve.Secp256k1), ECCurve.Secp256k1).Twice()); + Assert.AreEqual(new ECPoint(new ECFieldElement(BigInteger.Parse("89565891926547004231252920425935692360644145829622209833684329913297188986597"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("12158399299693830322967808612713398636155367887041628176798871954788371653930"), ECCurve.Secp256k1), ECCurve.Secp256k1), ECCurve.Secp256k1.G.Twice()); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_Base58.cs b/tests/Neo.UnitTests/Cryptography/UT_Base58.cs index 8a414bf721..a37fa8e22d 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_Base58.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_Base58.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -42,20 +41,22 @@ public void TestEncodeDecode() {"00000000000000000000", "1111111111"}, {"000111d38e5fc9071ffcd20b4a763cc9ae4f252bb4e48fd66a835e252ada93ff480d6dd43dc62a641155a5", "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}, {"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", "1cWB5HCBdLjAuqGGReWE3R3CguuwSjw6RHn39s2yuDRTS5NsBgNiFpWgAnEx6VQi8csexkgYw3mdYrMHr8x9i7aEwP8kZ7vccXWqKDvGv3u1GxFKPuAkn8JCPPGDMf3vMMnbzm6Nh9zh1gcNsMvH3ZNLmP5fSG6DGbbi2tuwMWPthr4boWwCxf7ewSgNQeacyozhKDDQQ1qL5fQFUW52QKUZDZ5fw3KXNQJMcNTcaB723LchjeKun7MuGW5qyCBZYzA1KjofN1gYBV3NqyhQJ3Ns746GNuf9N2pQPmHz4xpnSrrfCvy6TVVz5d4PdrjeshsWQwpZsZGzvbdAdN8MKV5QsBDY"}, - // Extra tests - {"00", "1"}, {"00010203040506070809", "1kA3B2yGe2z4"}, }; foreach (var entry in bitcoinTest) { - Base58.Encode(entry.Key.HexToBytes()).Should().Be(entry.Value); - Base58.Decode(entry.Value).Should().BeEquivalentTo(entry.Key.HexToBytes()); + Assert.AreEqual(entry.Value, Base58.Encode(entry.Key.HexToBytes())); + CollectionAssert.AreEqual(entry.Key.HexToBytes(), Base58.Decode(entry.Value)); + } - Action action = () => Base58.Decode(entry.Value + "l"); - action.Should().Throw(); + var invalidBase58 = new string[] { "0", "O", "I", "l", "+", "/" }; + foreach (var s in invalidBase58) + { + var action = new Action(() => Base58.Decode(s)); + Assert.ThrowsException(action); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_BloomFilter.cs b/tests/Neo.UnitTests/Cryptography/UT_BloomFilter.cs index c87aaa733c..9fb45522a5 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_BloomFilter.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_BloomFilter.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using System; @@ -27,9 +26,9 @@ public void TestAddCheck() byte[] elements = { 0, 1, 2, 3, 4 }; BloomFilter filter = new BloomFilter(m, n, nTweak); filter.Add(elements); - filter.Check(elements).Should().BeTrue(); + Assert.IsTrue(filter.Check(elements)); byte[] anotherElements = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - filter.Check(anotherElements).Should().BeFalse(); + Assert.IsFalse(filter.Check(anotherElements)); } [TestMethod] @@ -38,32 +37,32 @@ public void TestBloomFIlterConstructorGetKMTweak() int m = -7, n = 10; uint nTweak = 123456; Action action = () => new BloomFilter(m, n, nTweak); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => new BloomFilter(m, n, nTweak, new byte[] { 0, 1, 2, 3, 4 }); - action.Should().Throw(); + Assert.ThrowsException(action); m = 7; n = -10; action = () => new BloomFilter(m, n, nTweak); - action.Should().Throw(); + Assert.ThrowsException(action); n = 10; BloomFilter filter = new BloomFilter(m, n, nTweak); - filter.M.Should().Be(m); - filter.K.Should().Be(n); - filter.Tweak.Should().Be(nTweak); + Assert.AreEqual(m, filter.M); + Assert.AreEqual(n, filter.K); + Assert.AreEqual(nTweak, filter.Tweak); byte[] shorterElements = { 0, 1, 2, 3, 4 }; filter = new BloomFilter(m, n, nTweak, shorterElements); - filter.M.Should().Be(m); - filter.K.Should().Be(n); - filter.Tweak.Should().Be(nTweak); + Assert.AreEqual(m, filter.M); + Assert.AreEqual(n, filter.K); + Assert.AreEqual(nTweak, filter.Tweak); byte[] longerElements = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; filter = new BloomFilter(m, n, nTweak, longerElements); - filter.M.Should().Be(m); - filter.K.Should().Be(n); - filter.Tweak.Should().Be(nTweak); + Assert.AreEqual(m, filter.M); + Assert.AreEqual(n, filter.K); + Assert.AreEqual(nTweak, filter.Tweak); } [TestMethod] @@ -76,7 +75,7 @@ public void TestGetBits() byte[] result = new byte[m]; filter.GetBits(result); foreach (byte value in result) - value.Should().Be(0); + Assert.AreEqual(0, value); } [TestMethod] @@ -84,10 +83,10 @@ public void TestInvalidArguments() { uint nTweak = 123456; Action action = () => new BloomFilter(0, 3, nTweak); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => new BloomFilter(3, 0, nTweak); - action.Should().Throw(); + Assert.ThrowsException(action); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_Crypto.cs b/tests/Neo.UnitTests/Cryptography/UT_Crypto.cs index 4c97c52856..fd14e9f39a 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_Crypto.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_Crypto.cs @@ -9,10 +9,11 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; +using Neo.Cryptography.ECC; using Neo.Extensions; +using Neo.IO; using Neo.Wallets; using System; using System.Security.Cryptography; @@ -23,6 +24,9 @@ namespace Neo.UnitTests.Cryptography public class UT_Crypto { private KeyPair key = null; + private readonly byte[] message = System.Text.Encoding.Default.GetBytes("HelloWorld"); + private readonly byte[] wrongKey = new byte[33]; + private readonly byte[] wrongKey2 = new byte[36]; public static KeyPair GenerateKey(int privateKeyLength) { @@ -53,22 +57,17 @@ public void TestSetup() [TestMethod] public void TestVerifySignature() { - byte[] message = System.Text.Encoding.Default.GetBytes("HelloWorld"); byte[] signature = Crypto.Sign(message, key.PrivateKey); - Crypto.VerifySignature(message, signature, key.PublicKey).Should().BeTrue(); + Assert.IsTrue(Crypto.VerifySignature(message, signature, key.PublicKey)); - byte[] wrongKey = new byte[33]; wrongKey[0] = 0x02; - Crypto.VerifySignature(message, signature, wrongKey, Neo.Cryptography.ECC.ECCurve.Secp256r1).Should().BeFalse(); + Assert.IsFalse(Crypto.VerifySignature(message, signature, wrongKey, Neo.Cryptography.ECC.ECCurve.Secp256r1)); wrongKey[0] = 0x03; for (int i = 1; i < 33; i++) wrongKey[i] = byte.MaxValue; - Action action = () => Crypto.VerifySignature(message, signature, wrongKey, Neo.Cryptography.ECC.ECCurve.Secp256r1); - action.Should().Throw(); + Assert.ThrowsException(() => Crypto.VerifySignature(message, signature, wrongKey, Neo.Cryptography.ECC.ECCurve.Secp256r1)); - wrongKey = new byte[36]; - action = () => Crypto.VerifySignature(message, signature, wrongKey, Neo.Cryptography.ECC.ECCurve.Secp256r1); - action.Should().Throw(); + Assert.ThrowsException(() => Crypto.VerifySignature(message, signature, wrongKey2, Neo.Cryptography.ECC.ECCurve.Secp256r1)); } [TestMethod] @@ -79,21 +78,18 @@ public void TestSecp256k1() var signature = Crypto.Sign(message, privkey, Neo.Cryptography.ECC.ECCurve.Secp256k1); byte[] pubKey = "04fd0a8c1ce5ae5570fdd46e7599c16b175bf0ebdfe9c178f1ab848fb16dac74a5d301b0534c7bcf1b3760881f0c420d17084907edd771e1c9c8e941bbf6ff9108".HexToBytes(); - Crypto.VerifySignature(message, signature, pubKey, Neo.Cryptography.ECC.ECCurve.Secp256k1) - .Should().BeTrue(); + Assert.IsTrue(Crypto.VerifySignature(message, signature, pubKey, Neo.Cryptography.ECC.ECCurve.Secp256k1)); message = System.Text.Encoding.Default.GetBytes("world"); signature = Crypto.Sign(message, privkey, Neo.Cryptography.ECC.ECCurve.Secp256k1); - Crypto.VerifySignature(message, signature, pubKey, Neo.Cryptography.ECC.ECCurve.Secp256k1) - .Should().BeTrue(); + Assert.IsTrue(Crypto.VerifySignature(message, signature, pubKey, Neo.Cryptography.ECC.ECCurve.Secp256k1)); message = System.Text.Encoding.Default.GetBytes("中文"); signature = "b8cba1ff42304d74d083e87706058f59cdd4f755b995926d2cd80a734c5a3c37e4583bfd4339ac762c1c91eee3782660a6baf62cd29e407eccd3da3e9de55a02".HexToBytes(); pubKey = "03661b86d54eb3a8e7ea2399e0db36ab65753f95fff661da53ae0121278b881ad0".HexToBytes(); - Crypto.VerifySignature(message, signature, pubKey, Neo.Cryptography.ECC.ECCurve.Secp256k1) - .Should().BeTrue(); + Assert.IsTrue(Crypto.VerifySignature(message, signature, pubKey, Neo.Cryptography.ECC.ECCurve.Secp256k1)); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs b/tests/Neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs index 815f308d5a..3e49730938 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -35,15 +34,15 @@ public void TestBase58CheckDecode() string input = "3vQB7B6MrGQZaxCuFg4oh"; byte[] result = input.Base58CheckDecode(); byte[] helloWorld = { 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 }; - result.Should().Equal(helloWorld); + CollectionAssert.AreEqual(helloWorld, result); input = "3v"; Action action = () => input.Base58CheckDecode(); - action.Should().Throw(); + Assert.ThrowsException(action); input = "3vQB7B6MrGQZaxCuFg4og"; action = () => input.Base58CheckDecode(); - action.Should().Throw(); + Assert.ThrowsException(action); Assert.ThrowsException(() => string.Empty.Base58CheckDecode()); } @@ -53,8 +52,8 @@ public void TestMurmurReadOnlySpan() { ReadOnlySpan input = "Hello, world!"u8; byte[] input2 = input.ToArray(); - input.Murmur32(0).Should().Be(input2.Murmur32(0)); - input.Murmur128(0).Should().Equal(input2.Murmur128(0)); + Assert.AreEqual(input2.Murmur32(0), input.Murmur32(0)); + CollectionAssert.AreEqual(input2.Murmur128(0), input.Murmur128(0)); } [TestMethod] @@ -62,10 +61,10 @@ public void TestSha256() { byte[] value = Encoding.ASCII.GetBytes("hello world"); byte[] result = value.Sha256(0, value.Length); - result.ToHexString().Should().Be("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"); - value.Sha256().Should().Equal(result); - ((Span)value).Sha256().Should().Equal(result); - ((ReadOnlySpan)value).Sha256().Should().Equal(result); + Assert.AreEqual("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", result.ToHexString()); + CollectionAssert.AreEqual(result, value.Sha256()); + CollectionAssert.AreEqual(result, ((Span)value).Sha256()); + CollectionAssert.AreEqual(result, ((ReadOnlySpan)value).Sha256()); } [TestMethod] @@ -73,9 +72,9 @@ public void TestKeccak256() { var input = "Hello, world!"u8.ToArray(); var result = input.Keccak256(); - result.ToHexString().Should().Be("b6e16d27ac5ab427a7f68900ac5559ce272dc6c37c82b3e052246c82244c50e4"); - ((Span)input).Keccak256().Should().Equal(result); - ((ReadOnlySpan)input).Keccak256().Should().Equal(result); + Assert.AreEqual("b6e16d27ac5ab427a7f68900ac5559ce272dc6c37c82b3e052246c82244c50e4", result.ToHexString()); + CollectionAssert.AreEqual(result, ((Span)input).Keccak256()); + CollectionAssert.AreEqual(result, ((ReadOnlySpan)input).Keccak256()); } [TestMethod] @@ -83,7 +82,7 @@ public void TestRIPEMD160() { ReadOnlySpan value = Encoding.ASCII.GetBytes("hello world"); byte[] result = value.RIPEMD160(); - result.ToHexString().Should().Be("98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"); + Assert.AreEqual("98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f", result.ToHexString()); } [TestMethod] @@ -148,11 +147,11 @@ public void TestTest() } } }; - filter.Test(tx).Should().BeFalse(); + Assert.IsFalse(filter.Test(tx)); filter.Add(tx.Witnesses[0].ScriptHash.ToArray()); - filter.Test(tx).Should().BeTrue(); + Assert.IsTrue(filter.Test(tx)); filter.Add(tx.Hash.ToArray()); - filter.Test(tx).Should().BeTrue(); + Assert.IsTrue(filter.Test(tx)); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_Ed25519.cs b/tests/Neo.UnitTests/Cryptography/UT_Ed25519.cs index f4754651a9..3505bc3224 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_Ed25519.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_Ed25519.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -25,8 +24,8 @@ public class UT_Ed25519 public void TestGenerateKeyPair() { byte[] keyPair = Ed25519.GenerateKeyPair(); - keyPair.Should().NotBeNull(); - keyPair.Length.Should().Be(32); + Assert.IsNotNull(keyPair); + Assert.AreEqual(32, keyPair.Length); } [TestMethod] @@ -34,8 +33,8 @@ public void TestGetPublicKey() { byte[] privateKey = Ed25519.GenerateKeyPair(); byte[] publicKey = Ed25519.GetPublicKey(privateKey); - publicKey.Should().NotBeNull(); - publicKey.Length.Should().Be(Ed25519.PublicKeySize); + Assert.IsNotNull(publicKey); + Assert.AreEqual(Ed25519.PublicKeySize, publicKey.Length); } [TestMethod] @@ -46,11 +45,11 @@ public void TestSignAndVerify() byte[] message = Encoding.UTF8.GetBytes("Hello, Neo!"); byte[] signature = Ed25519.Sign(privateKey, message); - signature.Should().NotBeNull(); - signature.Length.Should().Be(Ed25519.SignatureSize); + Assert.IsNotNull(signature); + Assert.AreEqual(Ed25519.SignatureSize, signature.Length); bool isValid = Ed25519.Verify(publicKey, message, signature); - isValid.Should().BeTrue(); + Assert.IsTrue(isValid); } [TestMethod] @@ -66,7 +65,7 @@ public void TestFailedVerify() byte[] tamperedMessage = Encoding.UTF8.GetBytes("Hello, Neo?"); bool isValid = Ed25519.Verify(publicKey, tamperedMessage, signature); - isValid.Should().BeFalse(); + Assert.IsFalse(isValid); // Tamper with the signature byte[] tamperedSignature = new byte[signature.Length]; @@ -74,14 +73,14 @@ public void TestFailedVerify() tamperedSignature[0] ^= 0x01; // Flip one bit isValid = Ed25519.Verify(publicKey, message, tamperedSignature); - isValid.Should().BeFalse(); + Assert.IsFalse(isValid); // Use wrong public key byte[] wrongPrivateKey = Ed25519.GenerateKeyPair(); byte[] wrongPublicKey = Ed25519.GetPublicKey(wrongPrivateKey); isValid = Ed25519.Verify(wrongPublicKey, message, signature); - isValid.Should().BeFalse(); + Assert.IsFalse(isValid); } [TestMethod] @@ -89,7 +88,7 @@ public void TestInvalidPrivateKeySize() { byte[] invalidPrivateKey = new byte[31]; // Invalid size Action act = () => Ed25519.GetPublicKey(invalidPrivateKey); - act.Should().Throw().WithMessage("Invalid private key size*"); + Assert.ThrowsException(act, "Invalid private key size*"); } [TestMethod] @@ -99,7 +98,7 @@ public void TestInvalidSignatureSize() byte[] invalidSignature = new byte[63]; // Invalid size byte[] publicKey = new byte[Ed25519.PublicKeySize]; Action act = () => Ed25519.Verify(publicKey, message, invalidSignature); - act.Should().Throw().WithMessage("Invalid signature size*"); + Assert.ThrowsException(act, "Invalid signature size*"); } [TestMethod] @@ -109,7 +108,7 @@ public void TestInvalidPublicKeySize() byte[] signature = new byte[Ed25519.SignatureSize]; byte[] invalidPublicKey = new byte[31]; // Invalid size Action act = () => Ed25519.Verify(invalidPublicKey, message, signature); - act.Should().Throw().WithMessage("Invalid public key size*"); + Assert.ThrowsException(act, "Invalid public key size*"); } // Test vectors from RFC 8032 (https://datatracker.ietf.org/doc/html/rfc8032) @@ -124,8 +123,8 @@ public void TestVectorCase1() byte[] signature = ("e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e06522490155" + "5fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b").HexToBytes(); - Ed25519.GetPublicKey(privateKey).Should().Equal(publicKey); - Ed25519.Sign(privateKey, message).Should().Equal(signature); + CollectionAssert.AreEqual(publicKey, Ed25519.GetPublicKey(privateKey)); + CollectionAssert.AreEqual(signature, Ed25519.Sign(privateKey, message)); } [TestMethod] @@ -137,8 +136,8 @@ public void TestVectorCase2() byte[] signature = ("92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da" + "085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00").HexToBytes(); - Ed25519.GetPublicKey(privateKey).Should().Equal(publicKey); - Ed25519.Sign(privateKey, message).Should().Equal(signature); + CollectionAssert.AreEqual(publicKey, Ed25519.GetPublicKey(privateKey)); + CollectionAssert.AreEqual(signature, Ed25519.Sign(privateKey, message)); } [TestMethod] @@ -149,8 +148,8 @@ public void TestVectorCase3() byte[] signature = ("6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac" + "18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40a").HexToBytes(); byte[] message = "af82".HexToBytes(); - Ed25519.GetPublicKey(privateKey).Should().Equal(publicKey); - Ed25519.Sign(privateKey, message).Should().Equal(signature); + CollectionAssert.AreEqual(publicKey, Ed25519.GetPublicKey(privateKey)); + CollectionAssert.AreEqual(signature, Ed25519.Sign(privateKey, message)); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_MerkleTree.cs b/tests/Neo.UnitTests/Cryptography/UT_MerkleTree.cs index 16e14f6960..823e70303f 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_MerkleTree.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_MerkleTree.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -45,16 +44,16 @@ public void TestBuildAndDepthFirstSearch() UInt256[] hashes = { hash1, hash2, hash3 }; MerkleTree tree = new MerkleTree(hashes); var hashArray = tree.ToHashArray(); - hashArray[0].Should().Be(hash1); - hashArray[1].Should().Be(hash2); - hashArray[2].Should().Be(hash3); - hashArray[3].Should().Be(hash3); + Assert.AreEqual(hash1, hashArray[0]); + Assert.AreEqual(hash2, hashArray[1]); + Assert.AreEqual(hash3, hashArray[2]); + Assert.AreEqual(hash3, hashArray[3]); var rootHash = MerkleTree.ComputeRoot(hashes); var hash4 = Crypto.Hash256(hash1.ToArray().Concat(hash2.ToArray()).ToArray()); var hash5 = Crypto.Hash256(hash3.ToArray().Concat(hash3.ToArray()).ToArray()); var result = new UInt256(Crypto.Hash256(hash4.ToArray().Concat(hash5.ToArray()).ToArray())); - rootHash.Should().Be(result); + Assert.AreEqual(result, rootHash); } [TestMethod] @@ -77,12 +76,12 @@ public void TestTrim() tree.Trim(bitArray); var hashArray = tree.ToHashArray(); - hashArray.Length.Should().Be(1); + Assert.AreEqual(1, hashArray.Length); var rootHash = MerkleTree.ComputeRoot(hashes); var hash4 = Crypto.Hash256(hash1.ToArray().Concat(hash2.ToArray()).ToArray()); var hash5 = Crypto.Hash256(hash3.ToArray().Concat(hash3.ToArray()).ToArray()); var result = new UInt256(Crypto.Hash256(hash4.ToArray().Concat(hash5.ToArray()).ToArray())); - hashArray[0].Should().Be(result); + Assert.AreEqual(result, hashArray[0]); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs b/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs index 61b466f08a..e69de29bb2 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs @@ -1,62 +0,0 @@ -// Copyright (C) 2015-2025 The Neo Project. -// -// UT_MerkleTreeNode.cs file belongs to the neo project and is free -// software distributed under the MIT software license, see the -// accompanying file LICENSE in the main directory of the -// repository or http://www.opensource.org/licenses/mit-license.php -// for more details. -// -// Redistribution and use in source and binary forms with or without -// modifications are permitted. - -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Neo.Cryptography; -using System.Text; - -namespace Neo.UnitTests.Cryptography -{ - [TestClass] - public class UT_MerkleTreeNode - { - private readonly MerkleTreeNode node = new MerkleTreeNode(); - - [TestInitialize] - public void TestSetup() - { - node.Hash = null; - node.Parent = null; - node.LeftChild = null; - node.RightChild = null; - } - - [TestMethod] - public void TestConstructor() - { - byte[] byteArray = Encoding.ASCII.GetBytes("hello world"); - var hash = new UInt256(Crypto.Hash256(byteArray)); - node.Hash = hash; - - node.Hash.Should().Be(hash); - node.Parent.Should().BeNull(); - node.LeftChild.Should().BeNull(); - node.RightChild.Should().BeNull(); - } - - [TestMethod] - public void TestGetIsLeaf() - { - node.IsLeaf.Should().BeTrue(); - - MerkleTreeNode child = new MerkleTreeNode(); - node.LeftChild = child; - node.IsLeaf.Should().BeFalse(); - } - - [TestMethod] - public void TestGetIsRoot() - { - node.IsRoot.Should().BeTrue(); - } - } -} diff --git a/tests/Neo.UnitTests/Cryptography/UT_Murmur128.cs b/tests/Neo.UnitTests/Cryptography/UT_Murmur128.cs index 1aef3ca05a..20a426e909 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_Murmur128.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_Murmur128.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -24,23 +23,23 @@ public class UT_Murmur128 public void TestGetHashSize() { Murmur128 murmur128 = new Murmur128(1); - murmur128.HashSize.Should().Be(128); + Assert.AreEqual(128, murmur128.HashSize); } [TestMethod] public void TestHashCore() { byte[] array = Encoding.ASCII.GetBytes("hello"); - array.Murmur128(123u).ToHexString().ToString().Should().Be("0bc59d0ad25fde2982ed65af61227a0e"); + Assert.AreEqual("0bc59d0ad25fde2982ed65af61227a0e", array.Murmur128(123u).ToHexString()); array = Encoding.ASCII.GetBytes("world"); - array.Murmur128(123u).ToHexString().ToString().Should().Be("3d3810fed480472bd214a14023bb407f"); + Assert.AreEqual("3d3810fed480472bd214a14023bb407f", array.Murmur128(123u).ToHexString()); array = Encoding.ASCII.GetBytes("hello world"); - array.Murmur128(123u).ToHexString().ToString().Should().Be("e0a0632d4f51302c55e3b3e48d28795d"); + Assert.AreEqual("e0a0632d4f51302c55e3b3e48d28795d", array.Murmur128(123u).ToHexString()); array = "718f952132679baa9c5c2aa0d329fd2a".HexToBytes(); - array.Murmur128(123u).ToHexString().ToString().Should().Be("9b4aa747ff0cf4e41b3d96251551c8ae"); + Assert.AreEqual("9b4aa747ff0cf4e41b3d96251551c8ae", array.Murmur128(123u).ToHexString()); } [TestMethod] @@ -49,8 +48,8 @@ public void TestTryComputeHash() var murmur128 = new Murmur128(123u); var buffer = new byte[murmur128.HashSize / 8]; var ok = murmur128.TryComputeHash("hello world"u8.ToArray(), buffer, out _); - ok.Should().BeTrue(); - buffer.ToHexString().Should().Be("e0a0632d4f51302c55e3b3e48d28795d"); + Assert.IsTrue(ok); + Assert.AreEqual("e0a0632d4f51302c55e3b3e48d28795d", buffer.ToHexString()); } } } diff --git a/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs b/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs index 16adceba0d..e69de29bb2 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs @@ -1,53 +0,0 @@ -// Copyright (C) 2015-2025 The Neo Project. -// -// UT_Murmur32.cs file belongs to the neo project and is free -// software distributed under the MIT software license, see the -// accompanying file LICENSE in the main directory of the -// repository or http://www.opensource.org/licenses/mit-license.php -// for more details. -// -// Redistribution and use in source and binary forms with or without -// modifications are permitted. - -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Neo.Cryptography; -using System.Buffers.Binary; - -namespace Neo.UnitTests.Cryptography -{ - [TestClass] - public class UT_Murmur32 - { - [TestMethod] - public void TestGetHashSize() - { - Murmur32.HashSizeInBits.Should().Be(32); - } - - [TestMethod] - public void TestHashToUInt32() - { - byte[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }; - array.Murmur32(10u).Should().Be(378574820u); - } - - [TestMethod] - public void TestComputeHash() - { - var murmur3 = new Murmur32(10u); - var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }; - var buffer = murmur3.ComputeHash(data); - var hash = BinaryPrimitives.ReadUInt32LittleEndian(buffer); - hash.Should().Be(378574820u); - } - - [TestMethod] - public void TestComputeHashUInt32() - { - var murmur3 = new Murmur32(10u); - var hash = murmur3.ComputeHashUInt32("hello worldhello world"u8.ToArray()); - hash.Should().Be(60539726u); - } - } -} diff --git a/tests/Neo.UnitTests/Cryptography/UT_RIPEMD160Managed.cs b/tests/Neo.UnitTests/Cryptography/UT_RIPEMD160Managed.cs index 7f0ecd404c..bdd410e701 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_RIPEMD160Managed.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_RIPEMD160Managed.cs @@ -9,10 +9,10 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; +using System.Text; namespace Neo.UnitTests.Cryptography { @@ -24,7 +24,7 @@ public void TestHashCore() { using var ripemd160 = new RIPEMD160Managed(); var hash = ripemd160.ComputeHash("hello world"u8.ToArray()); - hash.ToHexString().Should().Be("98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"); + Assert.AreEqual("98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f", hash.ToHexString()); } [TestMethod] @@ -33,8 +33,8 @@ public void TestTryComputeHash() using var ripemd160 = new RIPEMD160Managed(); var buffer = new byte[ripemd160.HashSize / 8]; var ok = ripemd160.TryComputeHash("hello world"u8.ToArray(), buffer, out _); - ok.Should().BeTrue(); - buffer.ToHexString().Should().Be("98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"); + Assert.IsTrue(ok); + Assert.AreEqual("98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f", buffer.ToHexString()); } } } diff --git a/tests/Neo.UnitTests/Extensions/NativeContractExtensions.cs b/tests/Neo.UnitTests/Extensions/NativeContractExtensions.cs index 8bf3b2ea21..0c530b3848 100644 --- a/tests/Neo.UnitTests/Extensions/NativeContractExtensions.cs +++ b/tests/Neo.UnitTests/Extensions/NativeContractExtensions.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Neo.Extensions; using Neo.IO; using Neo.Network.P2P.Payloads; diff --git a/tests/Neo.UnitTests/Extensions/Nep17NativeContractExtensions.cs b/tests/Neo.UnitTests/Extensions/Nep17NativeContractExtensions.cs index d14fab0e75..ee81b70667 100644 --- a/tests/Neo.UnitTests/Extensions/Nep17NativeContractExtensions.cs +++ b/tests/Neo.UnitTests/Extensions/Nep17NativeContractExtensions.cs @@ -9,7 +9,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; using Neo.Network.P2P.Payloads; @@ -63,7 +63,7 @@ public static bool Transfer(this NativeContract contract, DataCache snapshot, by } var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Boolean)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Boolean)); return result.GetBoolean(); } @@ -76,10 +76,10 @@ public static BigInteger TotalSupply(this NativeContract contract, DataCache sna script.EmitDynamicCall(contract.Hash, "totalSupply"); engine.LoadScript(script.ToArray()); - engine.Execute().Should().Be(VMState.HALT); + Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Integer)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Integer)); return result.GetInteger(); } @@ -92,10 +92,10 @@ public static BigInteger BalanceOf(this NativeContract contract, DataCache snaps script.EmitDynamicCall(contract.Hash, "balanceOf", account); engine.LoadScript(script.ToArray()); - engine.Execute().Should().Be(VMState.HALT); + Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Integer)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Integer)); return result.GetInteger(); } @@ -108,10 +108,10 @@ public static BigInteger Decimals(this NativeContract contract, DataCache snapsh script.EmitDynamicCall(contract.Hash, "decimals"); engine.LoadScript(script.ToArray()); - engine.Execute().Should().Be(VMState.HALT); + Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Integer)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Integer)); return result.GetInteger(); } @@ -124,10 +124,10 @@ public static string Symbol(this NativeContract contract, DataCache snapshot) script.EmitDynamicCall(contract.Hash, "symbol"); engine.LoadScript(script.ToArray()); - engine.Execute().Should().Be(VMState.HALT); + Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.ByteString)); + Assert.IsInstanceOfType(result, typeof(VM.Types.ByteString)); return result.GetString(); } diff --git a/tests/Neo.UnitTests/IO/Caching/UT_Cache.cs b/tests/Neo.UnitTests/IO/Caching/UT_Cache.cs index df2dcfd57d..b6352d3910 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_Cache.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_Cache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO.Caching; using System; @@ -80,30 +79,30 @@ public void Init() [TestMethod] public void TestCount() { - cache.Count.Should().Be(0); + Assert.AreEqual(0, cache.Count); cache.Add("hello"); cache.Add("world"); - cache.Count.Should().Be(2); + Assert.AreEqual(2, cache.Count); cache.Remove("hello"); - cache.Count.Should().Be(1); + Assert.AreEqual(1, cache.Count); } [TestMethod] public void TestIsReadOnly() { - cache.IsReadOnly.Should().BeFalse(); + Assert.IsFalse(cache.IsReadOnly); } [TestMethod] public void TestAddAndAddInternal() { cache.Add("hello"); - cache.Contains("hello").Should().BeTrue(); - cache.Contains("world").Should().BeFalse(); + Assert.IsTrue(cache.Contains("hello")); + Assert.IsFalse(cache.Contains("world")); cache.Add("hello"); - cache.Count.Should().Be(1); + Assert.AreEqual(1, cache.Count); } [TestMethod] @@ -111,10 +110,10 @@ public void TestAddRange() { string[] range = { "hello", "world" }; cache.AddRange(range); - cache.Count.Should().Be(2); - cache.Contains("hello").Should().BeTrue(); - cache.Contains("world").Should().BeTrue(); - cache.Contains("non exist string").Should().BeFalse(); + Assert.AreEqual(2, cache.Count); + Assert.IsTrue(cache.Contains("hello")); + Assert.IsTrue(cache.Contains("world")); + Assert.IsFalse(cache.Contains("non exist string")); } [TestMethod] @@ -122,25 +121,25 @@ public void TestClear() { cache.Add("hello"); cache.Add("world"); - cache.Count.Should().Be(2); + Assert.AreEqual(2, cache.Count); cache.Clear(); - cache.Count.Should().Be(0); + Assert.AreEqual(0, cache.Count); } [TestMethod] public void TestContainsKey() { cache.Add("hello"); - cache.Contains("hello").Should().BeTrue(); - cache.Contains("world").Should().BeFalse(); + Assert.IsTrue(cache.Contains("hello")); + Assert.IsFalse(cache.Contains("world")); } [TestMethod] public void TestContainsValue() { cache.Add("hello"); - cache.Contains("hello".GetHashCode()).Should().BeTrue(); - cache.Contains("world".GetHashCode()).Should().BeFalse(); + Assert.IsTrue(cache.Contains("hello".GetHashCode())); + Assert.IsFalse(cache.Contains("world".GetHashCode())); } [TestMethod] @@ -151,26 +150,26 @@ public void TestCopyTo() string[] temp = new string[2]; Action action = () => cache.CopyTo(null, 1); - action.Should().Throw(); + Assert.ThrowsException(() => action()); action = () => cache.CopyTo(temp, -1); - action.Should().Throw(); + Assert.ThrowsException(() => action()); action = () => cache.CopyTo(temp, 1); - action.Should().Throw(); + Assert.ThrowsException(() => action()); cache.CopyTo(temp, 0); - temp[0].Should().Be("hello"); - temp[1].Should().Be("world"); + Assert.AreEqual("hello", temp[0]); + Assert.AreEqual("world", temp[1]); } [TestMethod] public void TestRemoveKey() { cache.Add("hello"); - cache.Remove("hello".GetHashCode()).Should().BeTrue(); - cache.Remove("world".GetHashCode()).Should().BeFalse(); - cache.Contains("hello").Should().BeFalse(); + Assert.IsTrue(cache.Remove("hello".GetHashCode())); + Assert.IsFalse(cache.Remove("world".GetHashCode())); + Assert.IsFalse(cache.Contains("hello")); } [TestMethod] @@ -182,30 +181,29 @@ public void TestRemoveDisposableKey() entry }; - entry.IsDisposed.Should().BeFalse(); - dcache.Remove(entry.Key).Should().BeTrue(); - dcache.Remove(entry.Key).Should().BeFalse(); - entry.IsDisposed.Should().BeTrue(); + Assert.IsFalse(entry.IsDisposed); + Assert.IsTrue(dcache.Remove(entry.Key)); + Assert.IsFalse(dcache.Remove(entry.Key)); + Assert.IsTrue(entry.IsDisposed); } [TestMethod] public void TestRemoveValue() { cache.Add("hello"); - cache.Remove("hello").Should().BeTrue(); - cache.Remove("world").Should().BeFalse(); - cache.Contains("hello").Should().BeFalse(); + Assert.IsTrue(cache.Remove("hello")); + Assert.IsFalse(cache.Remove("world")); + Assert.IsFalse(cache.Contains("hello")); } [TestMethod] public void TestTryGet() { cache.Add("hello"); - cache.TryGet("hello".GetHashCode(), out string output).Should().BeTrue(); - output.Should().Be("hello"); - cache.TryGet("world".GetHashCode(), out string output2).Should().BeFalse(); - output2.Should().NotBe("world"); - output2.Should().BeNull(); + Assert.IsTrue(cache.TryGet("hello".GetHashCode(), out string output)); + Assert.AreEqual("hello", output); + Assert.IsFalse(cache.TryGet("world".GetHashCode(), out string output2)); + Assert.IsNull(output2); } [TestMethod] @@ -213,14 +211,14 @@ public void TestArrayIndexAccess() { cache.Add("hello"); cache.Add("world"); - cache["hello".GetHashCode()].Should().Be("hello"); - cache["world".GetHashCode()].Should().Be("world"); + Assert.AreEqual("hello", cache["hello".GetHashCode()]); + Assert.AreEqual("world", cache["world".GetHashCode()]); Action action = () => { string temp = cache["non exist string".GetHashCode()]; }; - action.Should().Throw(); + Assert.ThrowsException(() => action()); } [TestMethod] @@ -231,12 +229,12 @@ public void TestGetEnumerator() int i = 0; foreach (string item in cache) { - if (i == 0) item.Should().Be("hello"); - if (i == 1) item.Should().Be("world"); + if (i == 0) Assert.AreEqual("hello", item); + if (i == 1) Assert.AreEqual("world", item); i++; } - i.Should().Be(2); - cache.MyGetEnumerator().Should().NotBeNull(); + Assert.AreEqual(2, i); + Assert.IsNotNull(cache.MyGetEnumerator()); } [TestMethod] @@ -247,9 +245,9 @@ public void TestOverMaxCapacity() { cache.Add(i.ToString()); } - cache.Add(i.ToString()); // The first one will be deleted - cache.Count.Should().Be(max_capacity); - cache.Contains((max_capacity + 1).ToString()).Should().BeTrue(); + cache.Add(i.ToString()); // The first one will be deleted + Assert.AreEqual(max_capacity, cache.Count); + Assert.IsTrue(cache.Contains((max_capacity + 1).ToString())); } [TestMethod] @@ -263,7 +261,7 @@ public void TestDispose() { int count = cache.Count; }; - action.Should().Throw(); + Assert.ThrowsException(() => action()); } } } diff --git a/tests/Neo.UnitTests/IO/Caching/UT_ECPointCache.cs b/tests/Neo.UnitTests/IO/Caching/UT_ECPointCache.cs index 6db39b4626..f4e8341726 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_ECPointCache.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_ECPointCache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.IO.Caching; @@ -31,9 +30,9 @@ public void SetUp() public void TestGetKeyForItem() { relayCache.Add(ECCurve.Secp256r1.G); - relayCache.Contains(ECCurve.Secp256r1.G).Should().BeTrue(); - relayCache.TryGet(ECCurve.Secp256r1.G.EncodePoint(true), out ECPoint tmp).Should().BeTrue(); - (tmp is ECPoint).Should().BeTrue(); + Assert.IsTrue(relayCache.Contains(ECCurve.Secp256r1.G)); + Assert.IsTrue(relayCache.TryGet(ECCurve.Secp256r1.G.EncodePoint(true), out ECPoint tmp)); + Assert.IsTrue(tmp is ECPoint); } } } diff --git a/tests/Neo.UnitTests/IO/Caching/UT_HashSetCache.cs b/tests/Neo.UnitTests/IO/Caching/UT_HashSetCache.cs index 55fb7049b7..aad197ac65 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_HashSetCache.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_HashSetCache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO.Caching; using System; @@ -30,17 +29,17 @@ public void TestHashSetCache() Assert.IsTrue(bucket.Add(i)); Assert.IsFalse(bucket.Add(i)); } - bucket.Count.Should().Be(100); + Assert.AreEqual(100, bucket.Count); int sum = 0; foreach (var ele in bucket) { sum += ele; } - sum.Should().Be(5050); + Assert.AreEqual(5050, sum); bucket.Add(101); - bucket.Count.Should().Be(91); + Assert.AreEqual(91, bucket.Count); var items = new int[10]; var value = 11; @@ -50,20 +49,20 @@ public void TestHashSetCache() value += 2; } bucket.ExceptWith(items); - bucket.Count.Should().Be(81); + Assert.AreEqual(81, bucket.Count); - bucket.Contains(13).Should().BeFalse(); - bucket.Contains(50).Should().BeTrue(); + Assert.IsFalse(bucket.Contains(13)); + Assert.IsTrue(bucket.Contains(50)); } [TestMethod] public void TestConstructor() { Action action1 = () => new HashSetCache(-1); - action1.Should().Throw(); + Assert.ThrowsException(() => action1()); Action action2 = () => new HashSetCache(1, -1); - action2.Should().Throw(); + Assert.ThrowsException(() => action2()); } [TestMethod] @@ -110,7 +109,7 @@ public void TestGetEnumerator() b }; IEnumerable ie = set; - ie.GetEnumerator().Should().NotBeNull(); + Assert.IsNotNull(ie.GetEnumerator()); } [TestMethod] diff --git a/tests/Neo.UnitTests/IO/Caching/UT_IndexedQueue.cs b/tests/Neo.UnitTests/IO/Caching/UT_IndexedQueue.cs index c559cb8d7b..216b95a56d 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_IndexedQueue.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_IndexedQueue.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO.Caching; using System; @@ -24,19 +23,19 @@ public class UT_IndexedQueue public void TestDefault() { var queue = new IndexedQueue(10); - queue.Count.Should().Be(0); + Assert.AreEqual(0, queue.Count); queue = new IndexedQueue(); - queue.Count.Should().Be(0); + Assert.AreEqual(0, queue.Count); queue.TrimExcess(); - queue.Count.Should().Be(0); + Assert.AreEqual(0, queue.Count); queue = new IndexedQueue(Array.Empty()); - queue.Count.Should().Be(0); - queue.TryPeek(out var a).Should().BeFalse(); - a.Should().Be(0); - queue.TryDequeue(out a).Should().BeFalse(); - a.Should().Be(0); + Assert.AreEqual(0, queue.Count); + Assert.IsFalse(queue.TryPeek(out var a)); + Assert.AreEqual(0, a); + Assert.IsFalse(queue.TryDequeue(out a)); + Assert.AreEqual(0, a); Assert.ThrowsException(() => queue.Peek()); Assert.ThrowsException(() => queue.Dequeue()); @@ -51,27 +50,27 @@ public void TestDefault() public void TestQueue() { var queue = new IndexedQueue(new int[] { 1, 2, 3 }); - queue.Count.Should().Be(3); + Assert.AreEqual(3, queue.Count); queue.Enqueue(4); - queue.Count.Should().Be(4); - queue.Peek().Should().Be(1); - queue.TryPeek(out var a).Should().BeTrue(); - a.Should().Be(1); - - queue[0].Should().Be(1); - queue[1].Should().Be(2); - queue[2].Should().Be(3); - queue.Dequeue().Should().Be(1); - queue.Dequeue().Should().Be(2); - queue.Dequeue().Should().Be(3); + Assert.AreEqual(4, queue.Count); + Assert.AreEqual(1, queue.Peek()); + Assert.IsTrue(queue.TryPeek(out var a)); + Assert.AreEqual(1, a); + + Assert.AreEqual(1, queue[0]); + Assert.AreEqual(2, queue[1]); + Assert.AreEqual(3, queue[2]); + Assert.AreEqual(1, queue.Dequeue()); + Assert.AreEqual(2, queue.Dequeue()); + Assert.AreEqual(3, queue.Dequeue()); queue[0] = 5; - queue.TryDequeue(out a).Should().BeTrue(); - a.Should().Be(5); + Assert.IsTrue(queue.TryDequeue(out a)); + Assert.AreEqual(5, a); queue.Enqueue(4); queue.Clear(); - queue.Count.Should().Be(0); + Assert.AreEqual(0, queue.Count); } [TestMethod] @@ -80,7 +79,7 @@ public void TestEnumerator() int[] arr = new int[3] { 1, 2, 3 }; var queue = new IndexedQueue(arr); - arr.SequenceEqual(queue).Should().BeTrue(); + Assert.IsTrue(arr.SequenceEqual(queue)); } [TestMethod] @@ -95,15 +94,15 @@ public void TestCopyTo() queue.CopyTo(arr, 0); - arr[0].Should().Be(1); - arr[1].Should().Be(2); - arr[2].Should().Be(3); + Assert.AreEqual(1, arr[0]); + Assert.AreEqual(2, arr[1]); + Assert.AreEqual(3, arr[2]); arr = queue.ToArray(); - arr[0].Should().Be(1); - arr[1].Should().Be(2); - arr[2].Should().Be(3); + Assert.AreEqual(1, arr[0]); + Assert.AreEqual(2, arr[1]); + Assert.AreEqual(3, arr[2]); } } } diff --git a/tests/Neo.UnitTests/IO/Caching/UT_KeyedCollectionSlim.cs b/tests/Neo.UnitTests/IO/Caching/UT_KeyedCollectionSlim.cs index 0f7b39afe3..dcf87ab923 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_KeyedCollectionSlim.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_KeyedCollectionSlim.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO.Caching; using System; @@ -31,9 +30,9 @@ public void Add_ShouldAddItem() collection.Add(item); // Assert - collection.Count.Should().Be(1); - collection.Contains(1).Should().BeTrue(); - collection.First.Should().Be(item); + Assert.AreEqual(1, collection.Count); + Assert.IsTrue(collection.Contains(1)); + Assert.AreEqual(item, collection.First); } [TestMethod] @@ -48,8 +47,7 @@ public void Add_ShouldThrowException_WhenKeyAlreadyExists() collection.Add(item1); // Assert - var act = (() => collection.Add(item2)); - act.Should().Throw(); + Assert.ThrowsException(() => collection.Add(item2)); } [TestMethod] @@ -64,8 +62,8 @@ public void Remove_ShouldRemoveItem() collection.Remove(1); // Assert - collection.Count.Should().Be(0); - collection.Contains(1).Should().BeFalse(); + Assert.AreEqual(0, collection.Count); + Assert.IsFalse(collection.Contains(1)); } [TestMethod] @@ -82,9 +80,9 @@ public void RemoveFirst_ShouldRemoveFirstItem() collection.RemoveFirst(); // Assert - collection.Count.Should().Be(1); - collection.Contains(1).Should().BeFalse(); - collection.Contains(2).Should().BeTrue(); + Assert.AreEqual(1, collection.Count); + Assert.IsFalse(collection.Contains(1)); + Assert.IsTrue(collection.Contains(2)); } public class TestItem : IStructuralEquatable, IStructuralComparable, IComparable diff --git a/tests/Neo.UnitTests/IO/Caching/UT_ReflectionCache.cs b/tests/Neo.UnitTests/IO/Caching/UT_ReflectionCache.cs index 8d325b66ab..aaac74f66e 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_ReflectionCache.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_ReflectionCache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; using Neo.IO.Caching; @@ -45,33 +44,33 @@ public class UT_ReflectionCache [TestMethod] public void TestCreateFromEmptyEnum() { - ReflectionCache.Count.Should().Be(0); + Assert.AreEqual(0, ReflectionCache.Count); } [TestMethod] public void TestCreateInstance() { object item1 = ReflectionCache.CreateInstance(MyTestEnum.Item1, null); - (item1 is TestItem1).Should().BeTrue(); + Assert.IsTrue(item1 is TestItem1); object item2 = ReflectionCache.CreateInstance(MyTestEnum.Item2, null); - (item2 is TestItem2).Should().BeTrue(); + Assert.IsTrue(item2 is TestItem2); object item3 = ReflectionCache.CreateInstance((MyTestEnum)0x02, null); - item3.Should().BeNull(); + Assert.IsNull(item3); } [TestMethod] public void TestCreateSerializable() { object item1 = ReflectionCache.CreateSerializable(MyTestEnum.Item1, new byte[0]); - (item1 is TestItem1).Should().BeTrue(); + Assert.IsTrue(item1 is TestItem1); object item2 = ReflectionCache.CreateSerializable(MyTestEnum.Item2, new byte[0]); - (item2 is TestItem2).Should().BeTrue(); + Assert.IsTrue(item2 is TestItem2); object item3 = ReflectionCache.CreateSerializable((MyTestEnum)0x02, new byte[0]); - item3.Should().BeNull(); + Assert.IsNull(item3); } [TestMethod] @@ -79,10 +78,10 @@ public void TestCreateInstance2() { TestItem defaultItem = new TestItem1(); object item2 = ReflectionCache.CreateInstance(MyTestEnum.Item2, defaultItem); - (item2 is TestItem2).Should().BeTrue(); + Assert.IsTrue(item2 is TestItem2); object item1 = ReflectionCache.CreateInstance((MyTestEnum)0x02, new TestItem1()); - (item1 is TestItem1).Should().BeTrue(); + Assert.IsTrue(item1 is TestItem1); } } } diff --git a/tests/Neo.UnitTests/IO/Caching/UT_RelayCache.cs b/tests/Neo.UnitTests/IO/Caching/UT_RelayCache.cs index d96b9a5702..4d3d50c211 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_RelayCache.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_RelayCache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO.Caching; using Neo.Network.P2P.Payloads; @@ -44,9 +43,9 @@ public void TestGetKeyForItem() Witnesses = Array.Empty() }; relayCache.Add(tx); - relayCache.Contains(tx).Should().BeTrue(); - relayCache.TryGet(tx.Hash, out IInventory tmp).Should().BeTrue(); - (tmp is Transaction).Should().BeTrue(); + Assert.IsTrue(relayCache.Contains(tx)); + Assert.IsTrue(relayCache.TryGet(tx.Hash, out IInventory tmp)); + Assert.IsTrue(tmp is Transaction); } } } diff --git a/tests/Neo.UnitTests/IO/UT_IOHelper.cs b/tests/Neo.UnitTests/IO/UT_IOHelper.cs index 425d47a91b..c7175a9087 100644 --- a/tests/Neo.UnitTests/IO/UT_IOHelper.cs +++ b/tests/Neo.UnitTests/IO/UT_IOHelper.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -243,7 +242,7 @@ public void TestReadVarInt() stream.Seek(0, SeekOrigin.Begin); BinaryReader reader = new(stream); Action action = () => reader.ReadVarInt(0xFFFFFFFF); - action.Should().Throw(); + Assert.ThrowsException(action); } } } @@ -308,21 +307,21 @@ public void TestWriteFixedString() MemoryStream stream = new(); BinaryWriter writer = new(stream); Action action = () => writer.WriteFixedString(null, 0); - action.Should().Throw(); + Assert.ThrowsException(action); } else if (i == 1) { MemoryStream stream = new(); BinaryWriter writer = new(stream); Action action = () => writer.WriteFixedString("AA", Encoding.UTF8.GetBytes("AA").Length - 1); - action.Should().Throw(); + Assert.ThrowsException(action); } else if (i == 2) { MemoryStream stream = new(); BinaryWriter writer = new(stream); Action action = () => writer.WriteFixedString("拉拉", Encoding.UTF8.GetBytes("拉拉").Length - 1); - action.Should().Throw(); + Assert.ThrowsException(action); } else if (i == 3) { @@ -361,7 +360,7 @@ public void TestWriteVarInt() MemoryStream stream = new(); BinaryWriter writer = new(stream); Action action = () => writer.WriteVarInt(-1); - action.Should().Throw(); + Assert.ThrowsException(action); } else if (i == 1) { diff --git a/tests/Neo.UnitTests/IO/UT_MemoryReader.cs b/tests/Neo.UnitTests/IO/UT_MemoryReader.cs index c6ef73caa6..e4e2c769a7 100644 --- a/tests/Neo.UnitTests/IO/UT_MemoryReader.cs +++ b/tests/Neo.UnitTests/IO/UT_MemoryReader.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -64,7 +63,7 @@ public void TestReadSByte() byteArray[0] = (byte)v; MemoryReader reader = new(byteArray); var n = reader.ReadSByte(); - n.Should().Be(v); + Assert.AreEqual(v, n); } var values2 = new long[] { (long)int.MaxValue + 1, (long)int.MinValue - 1 }; @@ -74,7 +73,7 @@ public void TestReadSByte() byteArray[0] = (byte)v; MemoryReader reader = new(byteArray); var n = reader.ReadSByte(); - n.Should().Be((sbyte)v); + Assert.AreEqual((sbyte)v, n); } } @@ -87,7 +86,7 @@ public void TestReadInt32() byte[] bytes = BitConverter.GetBytes(v); MemoryReader reader = new(bytes); var n = reader.ReadInt32(); - n.Should().Be(v); + Assert.AreEqual(v, n); } var values2 = new long[] { (long)int.MaxValue + 1, (long)int.MinValue - 1 }; @@ -96,7 +95,7 @@ public void TestReadInt32() byte[] bytes = BitConverter.GetBytes(v); MemoryReader reader = new(bytes); var n = reader.ReadInt32(); - n.Should().Be((int)v); + Assert.AreEqual((int)v, n); } } @@ -109,7 +108,7 @@ public void TestReadUInt64() byte[] bytes = BitConverter.GetBytes(v); MemoryReader reader = new(bytes); var n = reader.ReadUInt64(); - n.Should().Be(v); + Assert.AreEqual(v, n); } var values2 = new long[] { long.MinValue, -1, long.MaxValue }; @@ -118,7 +117,7 @@ public void TestReadUInt64() byte[] bytes = BitConverter.GetBytes(v); MemoryReader reader = new(bytes); var n = reader.ReadUInt64(); - n.Should().Be((ulong)v); + Assert.AreEqual((ulong)v, n); } } @@ -135,7 +134,7 @@ public void TestReadInt16BigEndian() } MemoryReader reader = new(bytes); var n = reader.ReadInt16BigEndian(); - n.Should().Be(v); + Assert.AreEqual(v, n); } } @@ -152,7 +151,7 @@ public void TestReadUInt16BigEndian() } MemoryReader reader = new(bytes); var n = reader.ReadUInt16BigEndian(); - n.Should().Be(v); + Assert.AreEqual(v, n); } } @@ -169,7 +168,7 @@ public void TestReadInt32BigEndian() } MemoryReader reader = new(bytes); var n = reader.ReadInt32BigEndian(); - n.Should().Be(v); + Assert.AreEqual(v, n); } } @@ -186,7 +185,7 @@ public void TestReadUInt32BigEndian() } MemoryReader reader = new(bytes); var n = reader.ReadUInt32BigEndian(); - n.Should().Be(v); + Assert.AreEqual(v, n); } } @@ -203,7 +202,7 @@ public void TestReadInt64BigEndian() } MemoryReader reader = new(bytes); var n = reader.ReadInt64BigEndian(); - n.Should().Be(v); + Assert.AreEqual(v, n); } } @@ -220,7 +219,7 @@ public void TestReadUInt64BigEndian() } MemoryReader reader = new(bytes); var n = reader.ReadUInt64BigEndian(); - n.Should().Be(v); + Assert.AreEqual(v, n); } } } diff --git a/tests/Neo.UnitTests/Ledger/UT_HashIndexState.cs b/tests/Neo.UnitTests/Ledger/UT_HashIndexState.cs index 3d8fd2814e..95ef3e82d4 100644 --- a/tests/Neo.UnitTests/Ledger/UT_HashIndexState.cs +++ b/tests/Neo.UnitTests/Ledger/UT_HashIndexState.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; using Neo.SmartContract; @@ -42,8 +41,8 @@ public void TestDeserialize() HashIndexState dest = new(); ((IInteroperable)dest).FromStackItem(BinarySerializer.Deserialize(ref reader, ExecutionEngineLimits.Default, null)); - dest.Hash.Should().Be(origin.Hash); - dest.Index.Should().Be(origin.Index); + Assert.AreEqual(origin.Hash, dest.Hash); + Assert.AreEqual(origin.Index, dest.Index); } } } diff --git a/tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs b/tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs index c108cd628d..abc156a527 100644 --- a/tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs +++ b/tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Ledger; using Neo.Network.P2P.Payloads; @@ -31,42 +30,42 @@ public void TestHeaderCache() cache.Add(header); var got = cache[1]; - got.Should().NotBeNull(); - got.Index.Should().Be(1); + Assert.IsNotNull(got); + Assert.AreEqual((uint)1, got.Index); var count = cache.Count; - count.Should().Be(1); + Assert.AreEqual(1, count); var full = cache.Full; - full.Should().BeFalse(); + Assert.IsFalse(full); var last = cache.Last; - last.Should().NotBeNull(); - last.Index.Should().Be(1); + Assert.IsNotNull(last); + Assert.AreEqual((uint)1, last.Index); got = cache[2]; - got.Should().BeNull(); + Assert.IsNull(got); // enumerate var enumerator = cache.GetEnumerator(); - enumerator.MoveNext().Should().BeTrue(); - enumerator.Current.Index.Should().Be(1); - enumerator.MoveNext().Should().BeFalse(); + Assert.IsTrue(enumerator.MoveNext()); + Assert.AreEqual((uint)1, enumerator.Current.Index); + Assert.IsFalse(enumerator.MoveNext()); var removed = cache.TryRemoveFirst(out header); - removed.Should().BeTrue(); + Assert.IsTrue(removed); count = cache.Count; - count.Should().Be(0); + Assert.AreEqual(0, count); full = cache.Full; - full.Should().BeFalse(); + Assert.IsFalse(full); last = cache.Last; - last.Should().BeNull(); + Assert.IsNull(last); got = cache[1]; - got.Should().BeNull(); + Assert.IsNull(got); } } } diff --git a/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs b/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs index fb49045db7..ba03618650 100644 --- a/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs +++ b/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs @@ -10,7 +10,6 @@ // modifications are permitted. using Akka.TestKit.Xunit2; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Neo.Cryptography; @@ -61,11 +60,11 @@ public void TestSetup() _unit = new MemoryPool(new NeoSystem(TestProtocolSettings.Default with { MemoryPoolMaxTransactions = 100 }, storageProvider: (string)null)); // Verify capacity equals the amount specified - _unit.Capacity.Should().Be(100); + Assert.AreEqual(100, _unit.Capacity); - _unit.VerifiedCount.Should().Be(0); - _unit.UnVerifiedCount.Should().Be(0); - _unit.Count.Should().Be(0); + Assert.AreEqual(0, _unit.VerifiedCount); + Assert.AreEqual(0, _unit.UnVerifiedCount); + Assert.AreEqual(0, _unit.Count); } private static long LongRandom(long min, long max, Random rand) @@ -166,10 +165,10 @@ public void CapacityTest() Console.WriteLine($"VerifiedCount: {_unit.VerifiedCount} Count {_unit.SortedTxCount}"); - _unit.SortedTxCount.Should().Be(100); - _unit.VerifiedCount.Should().Be(100); - _unit.UnVerifiedCount.Should().Be(0); - _unit.Count.Should().Be(100); + Assert.AreEqual(100, _unit.SortedTxCount); + Assert.AreEqual(100, _unit.VerifiedCount); + Assert.AreEqual(0, _unit.UnVerifiedCount); + Assert.AreEqual(100, _unit.Count); } [TestMethod] @@ -177,7 +176,7 @@ public void BlockPersistMovesTxToUnverifiedAndReverification() { AddTransactions(70); - _unit.SortedTxCount.Should().Be(70); + Assert.AreEqual(70, _unit.SortedTxCount); var block = new Block { @@ -187,32 +186,32 @@ public void BlockPersistMovesTxToUnverifiedAndReverification() }; _unit.UpdatePoolForBlockPersisted(block, GetSnapshot()); _unit.InvalidateVerifiedTransactions(); - _unit.SortedTxCount.Should().Be(0); - _unit.UnverifiedSortedTxCount.Should().Be(60); + Assert.AreEqual(0, _unit.SortedTxCount); + Assert.AreEqual(60, _unit.UnverifiedSortedTxCount); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot()); - _unit.SortedTxCount.Should().Be(10); - _unit.UnverifiedSortedTxCount.Should().Be(50); + Assert.AreEqual(10, _unit.SortedTxCount); + Assert.AreEqual(50, _unit.UnverifiedSortedTxCount); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot()); - _unit.SortedTxCount.Should().Be(20); - _unit.UnverifiedSortedTxCount.Should().Be(40); + Assert.AreEqual(20, _unit.SortedTxCount); + Assert.AreEqual(40, _unit.UnverifiedSortedTxCount); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot()); - _unit.SortedTxCount.Should().Be(30); - _unit.UnverifiedSortedTxCount.Should().Be(30); + Assert.AreEqual(30, _unit.SortedTxCount); + Assert.AreEqual(30, _unit.UnverifiedSortedTxCount); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot()); - _unit.SortedTxCount.Should().Be(40); - _unit.UnverifiedSortedTxCount.Should().Be(20); + Assert.AreEqual(40, _unit.SortedTxCount); + Assert.AreEqual(20, _unit.UnverifiedSortedTxCount); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot()); - _unit.SortedTxCount.Should().Be(50); - _unit.UnverifiedSortedTxCount.Should().Be(10); + Assert.AreEqual(50, _unit.SortedTxCount); + Assert.AreEqual(10, _unit.UnverifiedSortedTxCount); _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot()); - _unit.SortedTxCount.Should().Be(60); - _unit.UnverifiedSortedTxCount.Should().Be(0); + Assert.AreEqual(60, _unit.SortedTxCount); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); } [TestMethod] @@ -228,7 +227,7 @@ public async Task BlockPersistAndReverificationWillAbandonTxAsBalanceTransfered( long txFee = 1; AddTransactionsWithBalanceVerify(70, txFee, engine.SnapshotCache); - _unit.SortedTxCount.Should().Be(70); + Assert.AreEqual(70, _unit.SortedTxCount); var block = new Block { @@ -246,8 +245,8 @@ public async Task BlockPersistAndReverificationWillAbandonTxAsBalanceTransfered( // Persist block and reverify all the txs in mempool, but half of the txs will be discarded _unit.UpdatePoolForBlockPersisted(block, applicationEngine.SnapshotCache); - _unit.SortedTxCount.Should().Be(30); - _unit.UnverifiedSortedTxCount.Should().Be(0); + Assert.AreEqual(30, _unit.SortedTxCount); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); // Revert the balance await NativeContract.GAS.Burn(applicationEngine, sender, txFee * 30); @@ -267,7 +266,7 @@ public async Task UpdatePoolForBlockPersisted_RemoveBlockConflicts() _ = NativeContract.GAS.Mint(engine, UInt160.Zero, 7, true); // balance enough for 7 mempooled txs var mp1 = CreateTransactionWithFeeAndBalanceVerify(txFee); // mp1 doesn't conflict with anyone - _unit.TryAdd(mp1, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp1, engine.SnapshotCache)); var tx1 = CreateTransactionWithFeeAndBalanceVerify(txFee); // but in-block tx1 conflicts with mempooled mp1 => mp1 should be removed from pool after persist tx1.Attributes = new TransactionAttribute[] { new Conflicts() { Hash = mp1.Hash } }; @@ -292,13 +291,13 @@ public async Task UpdatePoolForBlockPersisted_RemoveBlockConflicts() var mp6 = CreateTransactionWithFeeAndBalanceVerify(txFee); // mp6 doesn't conflict with anyone and noone conflicts with mp6 => mp6 should be left in the pool after persist _unit.TryAdd(mp6, engine.SnapshotCache); - _unit.SortedTxCount.Should().Be(6); - _unit.UnverifiedSortedTxCount.Should().Be(0); + Assert.AreEqual(6, _unit.SortedTxCount); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); var mp7 = CreateTransactionWithFeeAndBalanceVerify(txFee); // mp7 doesn't conflict with anyone var tx6 = CreateTransactionWithFeeAndBalanceVerify(txFee); // in-block tx6 conflicts with mp7, but doesn't include sender of mp7 into signers list => even if tx6 is included into block, mp7 shouldn't be removed from the pool - tx6.Signers = new Signer[] { new Signer() { Account = new UInt160(Crypto.Hash160(new byte[] { 1, 2, 3 })) }, new Signer() { Account = new UInt160(Crypto.Hash160(new byte[] { 4, 5, 6 })) } }; tx6.Attributes = new TransactionAttribute[] { new Conflicts() { Hash = mp7.Hash } }; + tx6.Signers = new Signer[] { new Signer() { Account = new UInt160(Crypto.Hash160(new byte[] { 1, 2, 3 })) }, new Signer() { Account = new UInt160(Crypto.Hash160(new byte[] { 4, 5, 6 })) } }; _unit.TryAdd(mp7, engine.SnapshotCache); // Act: persist block and reverify all mempooled txs. @@ -310,10 +309,10 @@ public async Task UpdatePoolForBlockPersisted_RemoveBlockConflicts() _unit.UpdatePoolForBlockPersisted(block, engine.SnapshotCache); // Assert: conflicting txs should be removed from the pool; the only mp6 that doesn't conflict with anyone should be left. - _unit.SortedTxCount.Should().Be(2); - _unit.GetSortedVerifiedTransactions().Select(tx => tx.Hash).Should().Contain(mp6.Hash); - _unit.GetSortedVerifiedTransactions().Select(tx => tx.Hash).Should().Contain(mp7.Hash); - _unit.UnverifiedSortedTxCount.Should().Be(0); + Assert.AreEqual(2, _unit.SortedTxCount); + Assert.IsTrue(_unit.GetSortedVerifiedTransactions().Select(tx => tx.Hash).Contains(mp6.Hash)); + Assert.IsTrue(_unit.GetSortedVerifiedTransactions().Select(tx => tx.Hash).Contains(mp7.Hash)); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); // Cleanup: revert the balance. await NativeContract.GAS.Burn(engine, UInt160.Zero, txFee * 7); @@ -369,50 +368,50 @@ public async Task TryAdd_AddRangeOfConflictingTransactions() mp10malicious.Attributes = new TransactionAttribute[] { new Conflicts() { Hash = mp7.Hash } }; mp10malicious.Signers = new Signer[] { new Signer() { Account = maliciousSender, Scopes = WitnessScope.None } }; - _unit.SortedTxCount.Should().Be(3); - _unit.UnverifiedSortedTxCount.Should().Be(0); + Assert.AreEqual(3, _unit.SortedTxCount); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); // Act & Assert: try to add conlflicting transactions to the pool. - _unit.TryAdd(mp1, engine.SnapshotCache).Should().Be(VerifyResult.HasConflicts); // mp1 conflicts with mp2_1, mp2_2 and mp3 but has lower network fee than mp3 => mp1 fails to be added - _unit.SortedTxCount.Should().Be(3); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp2_1, mp2_2, mp3 }); - - _unit.TryAdd(malicious, engine.SnapshotCache).Should().Be(VerifyResult.HasConflicts); // malicious conflicts with mp3, has larger network fee but malicious (different) sender => mp3 shoould be left in pool - _unit.SortedTxCount.Should().Be(3); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp2_1, mp2_2, mp3 }); - - _unit.TryAdd(mp4, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); // mp4 conflicts with mp3 and has larger network fee => mp3 shoould be removed from pool - _unit.SortedTxCount.Should().Be(3); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp2_1, mp2_2, mp4 }); - - _unit.TryAdd(mp1, engine.SnapshotCache).Should().Be(VerifyResult.HasConflicts); // mp1 conflicts with mp2_1 and mp2_2 and has same network fee => mp2_1 and mp2_2 should be left in pool. - _unit.SortedTxCount.Should().Be(3); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp2_1, mp2_2, mp4 }); - - _unit.TryAdd(mp6, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); // mp6 conflicts with mp2_1 and mp2_2 and has larger network fee than the sum of mp2_1 and mp2_2 fees => mp6 should be added. - _unit.SortedTxCount.Should().Be(2); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp6, mp4 }); - - _unit.TryAdd(mp1, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); // mp1 conflicts with mp2_1 and mp2_2, but they are not in the pool now => mp1 should be added. - _unit.SortedTxCount.Should().Be(3); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp1, mp6, mp4 }); - - _unit.TryAdd(mp2_1, engine.SnapshotCache).Should().Be(VerifyResult.HasConflicts); // mp2_1 conflicts with mp1 and has same network fee => mp2_1 shouldn't be added to the pool. - _unit.SortedTxCount.Should().Be(3); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp1, mp6, mp4 }); - - _unit.TryAdd(mp5, engine.SnapshotCache).Should().Be(VerifyResult.HasConflicts); // mp5 conflicts with mp4 and has smaller network fee => mp5 fails to be added. - _unit.SortedTxCount.Should().Be(3); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp1, mp6, mp4 }); - - _unit.TryAdd(mp8, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); // mp8, mp9 and mp10malicious conflict with mp7, but mo7 is not in the pool yet. - _unit.TryAdd(mp9, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); - _unit.TryAdd(mp10malicious, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); - _unit.SortedTxCount.Should().Be(6); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp1, mp6, mp4, mp8, mp9, mp10malicious }); - _unit.TryAdd(mp7, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); // mp7 has larger network fee than the sum of mp8 and mp9 fees => should be added to the pool. - _unit.SortedTxCount.Should().Be(4); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp1, mp6, mp4, mp7 }); + Assert.AreEqual(VerifyResult.HasConflicts, _unit.TryAdd(mp1, engine.SnapshotCache)); // mp1 conflicts with mp2_1, mp2_2 and mp3 but has lower network fee than mp3 => mp1 fails to be added + Assert.AreEqual(3, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp2_1, mp2_2, mp3 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.HasConflicts, _unit.TryAdd(malicious, engine.SnapshotCache)); // malicious conflicts with mp3, has larger network fee but malicious (different) sender => mp3 shoould be left in pool + Assert.AreEqual(3, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp2_1, mp2_2, mp3 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp4, engine.SnapshotCache)); // mp4 conflicts with mp3 and has larger network fee => mp3 shoould be removed from pool + Assert.AreEqual(3, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp2_1, mp2_2, mp4 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.HasConflicts, _unit.TryAdd(mp1, engine.SnapshotCache)); // mp1 conflicts with mp2_1 and mp2_2 and has same network fee => mp2_1 and mp2_2 should be left in pool. + Assert.AreEqual(3, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp2_1, mp2_2, mp4 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp6, engine.SnapshotCache)); // mp6 conflicts with mp2_1 and mp2_2 and has larger network fee than the sum of mp2_1 and mp2_2 fees => mp6 should be added. + Assert.AreEqual(2, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp6, mp4 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp1, engine.SnapshotCache)); // mp1 conflicts with mp2_1 and mp2_2, but they are not in the pool now => mp1 should be added. + Assert.AreEqual(3, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp1, mp6, mp4 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.HasConflicts, _unit.TryAdd(mp2_1, engine.SnapshotCache)); // mp2_1 conflicts with mp1 and has same network fee => mp2_1 shouldn't be added to the pool. + Assert.AreEqual(3, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp1, mp6, mp4 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.HasConflicts, _unit.TryAdd(mp5, engine.SnapshotCache)); // mp5 conflicts with mp4 and has smaller network fee => mp5 fails to be added. + Assert.AreEqual(3, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp1, mp6, mp4 }, _unit.GetVerifiedTransactions().ToList()); + + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp8, engine.SnapshotCache)); // mp8, mp9 and mp10malicious conflict with mp7, but mo7 is not in the pool yet. + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp9, engine.SnapshotCache)); + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp10malicious, engine.SnapshotCache)); + Assert.AreEqual(6, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp1, mp6, mp4, mp8, mp9, mp10malicious }, _unit.GetVerifiedTransactions().ToList()); + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp7, engine.SnapshotCache)); // mp7 has larger network fee than the sum of mp8 and mp9 fees => should be added to the pool. + Assert.AreEqual(4, _unit.SortedTxCount); + CollectionAssert.IsSubsetOf(new List() { mp1, mp6, mp4, mp7 }, _unit.GetVerifiedTransactions().ToList()); // Cleanup: revert the balance. await NativeContract.GAS.Burn(engine, UInt160.Zero, 100); @@ -439,18 +438,18 @@ public async Task TryRemoveVerified_RemoveVerifiedTxWithConflicts() mp2.Attributes = new TransactionAttribute[] { new Conflicts() { Hash = mp1.Hash } }; _unit.TryAdd(mp2, engine.SnapshotCache); - _unit.SortedTxCount.Should().Be(1); - _unit.UnverifiedSortedTxCount.Should().Be(0); + Assert.AreEqual(1, _unit.SortedTxCount); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); - _unit.TryAdd(mp1, engine.SnapshotCache).Should().Be(VerifyResult.HasConflicts); // mp1 conflicts with mp2 but has lower network fee - _unit.SortedTxCount.Should().Be(1); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp2 }); + Assert.AreEqual(_unit.TryAdd(mp1, engine.SnapshotCache), VerifyResult.HasConflicts); // mp1 conflicts with mp2 but has lower network fee + Assert.AreEqual(_unit.SortedTxCount, 1); + CollectionAssert.Contains(_unit.GetVerifiedTransactions().ToList(), mp2); // Act & Assert: try to invalidate verified transactions and push conflicting one. _unit.InvalidateVerifiedTransactions(); - _unit.TryAdd(mp1, engine.SnapshotCache).Should().Be(VerifyResult.Succeed); // mp1 conflicts with mp2 but mp2 is not verified anymore - _unit.SortedTxCount.Should().Be(1); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp1 }); + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(mp1, engine.SnapshotCache)); // mp1 conflicts with mp2 but mp2 is not verified anymore + Assert.AreEqual(1, _unit.SortedTxCount); + CollectionAssert.Contains(_unit.GetVerifiedTransactions().ToList(), mp1); var tx1 = CreateTransactionWithFeeAndBalanceVerify(txFee); // in-block tx1 doesn't conflict with anyone and is aimed to trigger reverification var block = new Block @@ -459,8 +458,8 @@ public async Task TryRemoveVerified_RemoveVerifiedTxWithConflicts() Transactions = new Transaction[] { tx1 }, }; _unit.UpdatePoolForBlockPersisted(block, engine.SnapshotCache); - _unit.SortedTxCount.Should().Be(1); - _unit.GetVerifiedTransactions().Should().Contain(new List() { mp2 }); // after reverificaion mp2 should be back at verified list; mp1 should be completely kicked off + Assert.AreEqual(1, _unit.SortedTxCount); + CollectionAssert.Contains(_unit.GetVerifiedTransactions().ToList(), mp2); // after reverificaion mp2 should be back at verified list; mp1 should be completely kicked off } private static void VerifyTransactionsSortedDescending(IEnumerable transactions) @@ -473,13 +472,13 @@ private static void VerifyTransactionsSortedDescending(IEnumerable if (lastTransaction.FeePerByte == tx.FeePerByte) { if (lastTransaction.NetworkFee == tx.NetworkFee) - lastTransaction.Hash.Should().BeLessThan(tx.Hash); + Assert.IsTrue(lastTransaction.Hash < tx.Hash); else - lastTransaction.NetworkFee.Should().BeGreaterThan(tx.NetworkFee); + Assert.IsTrue(lastTransaction.NetworkFee > tx.NetworkFee); } else { - lastTransaction.FeePerByte.Should().BeGreaterThan(tx.FeePerByte); + Assert.IsTrue(lastTransaction.FeePerByte > tx.FeePerByte); } } lastTransaction = tx; @@ -493,7 +492,7 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() var sortedVerifiedTxs = _unit.GetSortedVerifiedTransactions().ToList(); // verify all 100 transactions are returned in sorted order - sortedVerifiedTxs.Count.Should().Be(100); + Assert.AreEqual(100, sortedVerifiedTxs.Count); VerifyTransactionsSortedDescending(sortedVerifiedTxs); // move all to unverified @@ -504,14 +503,14 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() }; _unit.UpdatePoolForBlockPersisted(block, GetSnapshot()); _unit.InvalidateVerifiedTransactions(); - _unit.SortedTxCount.Should().Be(0); - _unit.UnverifiedSortedTxCount.Should().Be(100); + Assert.AreEqual(0, _unit.SortedTxCount); + Assert.AreEqual(100, _unit.UnverifiedSortedTxCount); // 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().Should().Be(0); + Assert.AreEqual(0, sortedVerifiedTransactions.Count()); var sortedUnverifiedArray = sortedUnverifiedTransactions.ToArray(); VerifyTransactionsSortedDescending(sortedUnverifiedArray); var maxTransaction = sortedUnverifiedArray.First(); @@ -520,8 +519,8 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() // reverify 1 high priority and 1 low priority transaction _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, GetSnapshot()); var verifiedTxs = _unit.GetSortedVerifiedTransactions().ToArray(); - verifiedTxs.Length.Should().Be(1); - verifiedTxs[0].Should().BeEquivalentTo(maxTransaction); + Assert.AreEqual(1, verifiedTxs.Length); + Assert.AreEqual(maxTransaction, verifiedTxs[0]); var blockWith2Tx = new Block { Header = new Header(), @@ -530,9 +529,9 @@ public void VerifySortOrderAndThatHighetFeeTransactionsAreReverifiedFirst() // verify and remove the 2 transactions from the verified pool _unit.UpdatePoolForBlockPersisted(blockWith2Tx, GetSnapshot()); _unit.InvalidateVerifiedTransactions(); - _unit.SortedTxCount.Should().Be(0); + Assert.AreEqual(0, _unit.SortedTxCount); } - _unit.UnverifiedSortedTxCount.Should().Be(0); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); } void VerifyCapacityThresholdForAttemptingToAddATransaction() @@ -540,9 +539,9 @@ void VerifyCapacityThresholdForAttemptingToAddATransaction() var sortedVerified = _unit.GetSortedVerifiedTransactions().ToArray(); var txBarelyWontFit = CreateTransactionWithFee(sortedVerified.Last().NetworkFee - 1); - _unit.CanTransactionFitInPool(txBarelyWontFit).Should().Be(false); + Assert.IsFalse(_unit.CanTransactionFitInPool(txBarelyWontFit)); var txBarelyFits = CreateTransactionWithFee(sortedVerified.Last().NetworkFee + 1); - _unit.CanTransactionFitInPool(txBarelyFits).Should().Be(true); + Assert.IsTrue(_unit.CanTransactionFitInPool(txBarelyFits)); } [TestMethod] @@ -573,9 +572,9 @@ public void CapacityTestWithUnverifiedHighProirtyTransactions() }; _unit.UpdatePoolForBlockPersisted(block, GetSnapshot()); - _unit.CanTransactionFitInPool(CreateTransaction()).Should().Be(true); + Assert.IsTrue(_unit.CanTransactionFitInPool(CreateTransaction())); AddTransactions(1); - _unit.CanTransactionFitInPool(CreateTransactionWithFee(0)).Should().Be(false); + Assert.IsFalse(_unit.CanTransactionFitInPool(CreateTransactionWithFee(0))); } [TestMethod] @@ -583,11 +582,11 @@ public void TestInvalidateAll() { AddTransactions(30); - _unit.UnverifiedSortedTxCount.Should().Be(0); - _unit.SortedTxCount.Should().Be(30); + Assert.AreEqual(0, _unit.UnverifiedSortedTxCount); + Assert.AreEqual(30, _unit.SortedTxCount); _unit.InvalidateAllTransactions(); - _unit.UnverifiedSortedTxCount.Should().Be(30); - _unit.SortedTxCount.Should().Be(0); + Assert.AreEqual(30, _unit.UnverifiedSortedTxCount); + Assert.AreEqual(0, _unit.SortedTxCount); } [TestMethod] @@ -598,9 +597,9 @@ public void TestContainsKey() var txToAdd = CreateTransaction(); _unit.TryAdd(txToAdd, snapshot); - _unit.ContainsKey(txToAdd.Hash).Should().BeTrue(); + Assert.IsTrue(_unit.ContainsKey(txToAdd.Hash)); _unit.InvalidateVerifiedTransactions(); - _unit.ContainsKey(txToAdd.Hash).Should().BeTrue(); + Assert.IsTrue(_unit.ContainsKey(txToAdd.Hash)); } [TestMethod] @@ -612,7 +611,7 @@ public void TestGetEnumerator() foreach (Transaction tx in _unit) { enumerator.MoveNext(); - enumerator.Current.Should().BeSameAs(tx); + Assert.IsTrue(ReferenceEquals(tx, enumerator.Current)); } } @@ -626,7 +625,7 @@ public void TestIEnumerableGetEnumerator() foreach (Transaction tx in _unit) { enumerator.MoveNext(); - enumerator.Current.Should().BeSameAs(tx); + Assert.IsTrue(ReferenceEquals(tx, enumerator.Current)); } } @@ -640,10 +639,10 @@ public void TestGetVerifiedTransactions() _unit.InvalidateVerifiedTransactions(); _unit.TryAdd(tx2, snapshot); IEnumerable enumerable = _unit.GetVerifiedTransactions(); - enumerable.Count().Should().Be(1); + Assert.AreEqual(1, enumerable.Count()); var enumerator = enumerable.GetEnumerator(); enumerator.MoveNext(); - enumerator.Current.Should().BeSameAs(tx2); + Assert.AreEqual(tx2, enumerator.Current); } [TestMethod] @@ -655,31 +654,31 @@ public void TestReVerifyTopUnverifiedTransactionsIfNeeded() AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(100000001)); AddTransaction(CreateTransaction(1)); - _unit.VerifiedCount.Should().Be(4); - _unit.UnVerifiedCount.Should().Be(0); + Assert.AreEqual(4, _unit.VerifiedCount); + Assert.AreEqual(0, _unit.UnVerifiedCount); _unit.InvalidateVerifiedTransactions(); - _unit.VerifiedCount.Should().Be(0); - _unit.UnVerifiedCount.Should().Be(4); + Assert.AreEqual(0, _unit.VerifiedCount); + Assert.AreEqual(4, _unit.UnVerifiedCount); AddTransactions(511); // Max per block currently is 512 - _unit.VerifiedCount.Should().Be(511); - _unit.UnVerifiedCount.Should().Be(4); + Assert.AreEqual(511, _unit.VerifiedCount); + Assert.AreEqual(4, _unit.UnVerifiedCount); var result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, GetSnapshot()); - result.Should().BeTrue(); - _unit.VerifiedCount.Should().Be(512); - _unit.UnVerifiedCount.Should().Be(3); + Assert.IsTrue(result); + Assert.AreEqual(512, _unit.VerifiedCount); + Assert.AreEqual(3, _unit.UnVerifiedCount); result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(2, GetSnapshot()); - result.Should().BeTrue(); - _unit.VerifiedCount.Should().Be(514); - _unit.UnVerifiedCount.Should().Be(1); + Assert.IsTrue(result); + Assert.AreEqual(514, _unit.VerifiedCount); + Assert.AreEqual(1, _unit.UnVerifiedCount); result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(3, GetSnapshot()); - result.Should().BeFalse(); - _unit.VerifiedCount.Should().Be(515); - _unit.UnVerifiedCount.Should().Be(0); + Assert.IsFalse(result); + Assert.AreEqual(515, _unit.VerifiedCount); + Assert.AreEqual(0, _unit.UnVerifiedCount); } [TestMethod] @@ -687,8 +686,8 @@ public void TestTryAdd() { var snapshot = GetSnapshot(); var tx1 = CreateTransaction(); - _unit.TryAdd(tx1, snapshot).Should().Be(VerifyResult.Succeed); - _unit.TryAdd(tx1, snapshot).Should().NotBe(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, _unit.TryAdd(tx1, snapshot)); + Assert.AreNotEqual(VerifyResult.Succeed, _unit.TryAdd(tx1, snapshot)); } [TestMethod] @@ -697,15 +696,15 @@ public void TestTryGetValue() var snapshot = GetSnapshot(); var tx1 = CreateTransaction(); _unit.TryAdd(tx1, snapshot); - _unit.TryGetValue(tx1.Hash, out Transaction tx).Should().BeTrue(); - tx.Should().BeEquivalentTo(tx1); + Assert.IsTrue(_unit.TryGetValue(tx1.Hash, out Transaction tx)); + Assert.AreEqual(tx1, tx); _unit.InvalidateVerifiedTransactions(); - _unit.TryGetValue(tx1.Hash, out tx).Should().BeTrue(); - tx.Should().BeEquivalentTo(tx1); + Assert.IsTrue(_unit.TryGetValue(tx1.Hash, out tx)); + Assert.AreEqual(tx1, tx); var tx2 = CreateTransaction(); - _unit.TryGetValue(tx2.Hash, out _).Should().BeFalse(); + Assert.IsFalse(_unit.TryGetValue(tx2.Hash, out _)); } [TestMethod] @@ -738,32 +737,32 @@ public void TestUpdatePoolForBlockPersisted() Transactions = transactions }; - _unit.UnVerifiedCount.Should().Be(0); - _unit.VerifiedCount.Should().Be(1); + Assert.AreEqual(0, _unit.UnVerifiedCount); + Assert.AreEqual(1, _unit.VerifiedCount); _unit.UpdatePoolForBlockPersisted(block, snapshot); - _unit.UnVerifiedCount.Should().Be(0); - _unit.VerifiedCount.Should().Be(0); + Assert.AreEqual(0, _unit.UnVerifiedCount); + Assert.AreEqual(0, _unit.VerifiedCount); } [TestMethod] public void TestTryRemoveUnVerified() { AddTransactions(32); - _unit.SortedTxCount.Should().Be(32); + Assert.AreEqual(32, _unit.SortedTxCount); var txs = _unit.GetSortedVerifiedTransactions().ToArray(); _unit.InvalidateVerifiedTransactions(); - _unit.SortedTxCount.Should().Be(0); + Assert.AreEqual(0, _unit.SortedTxCount); foreach (var tx in txs) { _unit.TryRemoveUnVerified(tx.Hash, out _); } - _unit.UnVerifiedCount.Should().Be(0); + Assert.AreEqual(0, _unit.UnVerifiedCount); } public static StorageKey CreateStorageKey(int id, byte prefix, byte[] key = null) diff --git a/tests/Neo.UnitTests/Ledger/UT_PoolItem.cs b/tests/Neo.UnitTests/Ledger/UT_PoolItem.cs index 728de4a0fd..d40526c589 100644 --- a/tests/Neo.UnitTests/Ledger/UT_PoolItem.cs +++ b/tests/Neo.UnitTests/Ledger/UT_PoolItem.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Neo.Ledger; @@ -58,9 +57,9 @@ public void PoolItem_CompareTo_Fee() Console.WriteLine($"item1 time {pitem1.Timestamp} item2 time {pitem2.Timestamp}"); // pitem1 < pitem2 (fee) => -1 - pitem1.CompareTo(pitem2).Should().Be(-1); + Assert.AreEqual(-1, pitem1.CompareTo(pitem2)); // pitem2 > pitem1 (fee) => 1 - pitem2.CompareTo(pitem1).Should().Be(1); + Assert.AreEqual(1, pitem2.CompareTo(pitem1)); } [TestMethod] @@ -78,7 +77,7 @@ public void PoolItem_CompareTo_Hash() PoolItem pitem2 = new PoolItem(tx2); // Different priority - pitem2.CompareTo(pitem1).Should().Be(-1); + Assert.AreEqual(-1, pitem2.CompareTo(pitem1)); // Bulk test for (int testRuns = 0; testRuns < 30; testRuns++) @@ -89,13 +88,13 @@ public void PoolItem_CompareTo_Hash() pitem1 = new PoolItem(tx1); pitem2 = new PoolItem(tx2); - pitem2.CompareTo((Transaction)null).Should().Be(1); + Assert.AreEqual(1, pitem2.CompareTo((Transaction)null)); // pitem2.tx.Hash < pitem1.tx.Hash => 1 descending order - pitem2.CompareTo(pitem1).Should().Be(1); + Assert.AreEqual(1, pitem2.CompareTo(pitem1)); // pitem2.tx.Hash > pitem1.tx.Hash => -1 descending order - pitem1.CompareTo(pitem2).Should().Be(-1); + Assert.AreEqual(-1, pitem1.CompareTo(pitem2)); } } @@ -110,9 +109,9 @@ public void PoolItem_CompareTo_Equals() PoolItem pitem2 = new PoolItem(tx); // pitem1 == pitem2 (fee) => 0 - pitem1.CompareTo(pitem2).Should().Be(0); - pitem2.CompareTo(pitem1).Should().Be(0); - pitem2.CompareTo((PoolItem)null).Should().Be(1); + Assert.AreEqual(0, pitem1.CompareTo(pitem2)); + Assert.AreEqual(0, pitem2.CompareTo(pitem1)); + Assert.AreEqual(1, pitem2.CompareTo((PoolItem)null)); } public Transaction GenerateTxWithFirstByteOfHashGreaterThanOrEqualTo(byte firstHashByte, long networkFee, int size) @@ -157,8 +156,8 @@ public static Transaction GenerateTx(long networkFee, int size, byte[] overrideS } }; - tx.Attributes.Length.Should().Be(0); - tx.Signers.Length.Should().Be(0); + Assert.AreEqual(0, tx.Attributes.Length); + Assert.AreEqual(0, tx.Signers.Length); int diff = size - tx.Size; if (diff < 0) throw new ArgumentException(); diff --git a/tests/Neo.UnitTests/Ledger/UT_StorageItem.cs b/tests/Neo.UnitTests/Ledger/UT_StorageItem.cs index a6afe975bf..83727b7496 100644 --- a/tests/Neo.UnitTests/Ledger/UT_StorageItem.cs +++ b/tests/Neo.UnitTests/Ledger/UT_StorageItem.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; using Neo.SmartContract; @@ -32,7 +31,7 @@ public void TestSetup() [TestMethod] public void Value_Get() { - uut.Value.IsEmpty.Should().BeTrue(); + Assert.IsTrue(uut.Value.IsEmpty); } [TestMethod] @@ -40,23 +39,23 @@ public void Value_Set() { byte[] val = new byte[] { 0x42, 0x32 }; uut.Value = val; - uut.Value.Length.Should().Be(2); - uut.Value.Span[0].Should().Be(val[0]); - uut.Value.Span[1].Should().Be(val[1]); + Assert.AreEqual(2, uut.Value.Length); + Assert.AreEqual(val[0], uut.Value.Span[0]); + Assert.AreEqual(val[1], uut.Value.Span[1]); } [TestMethod] public void Size_Get() { uut.Value = TestUtils.GetByteArray(10, 0x42); - uut.Size.Should().Be(11); // 1 + 10 + Assert.AreEqual(11, uut.Size); // 1 + 10 } [TestMethod] public void Size_Get_Larger() { uut.Value = TestUtils.GetByteArray(88, 0x42); - uut.Size.Should().Be(89); // 1 + 88 + Assert.AreEqual(89, uut.Size); // 1 + 88 } [TestMethod] @@ -66,11 +65,11 @@ public void Clone() StorageItem newSi = uut.Clone(); var span = newSi.Value.Span; - span.Length.Should().Be(10); - span[0].Should().Be(0x42); + Assert.AreEqual(10, span.Length); + Assert.AreEqual(0x42, span[0]); for (int i = 1; i < 10; i++) { - span[i].Should().Be(0x20); + Assert.AreEqual(0x20, span[i]); } } @@ -81,11 +80,11 @@ public void Deserialize() MemoryReader reader = new(data); uut.Deserialize(ref reader); var span = uut.Value.Span; - span.Length.Should().Be(10); - span[0].Should().Be(0x42); + Assert.AreEqual(10, span.Length); + Assert.AreEqual(0x42, span[0]); for (int i = 1; i < 10; i++) { - span[i].Should().Be(0x20); + Assert.AreEqual(0x20, span[i]); } } @@ -106,10 +105,10 @@ public void Serialize() byte[] requiredData = new byte[] { 66, 32, 32, 32, 32, 32, 32, 32, 32, 32 }; - data.Length.Should().Be(requiredData.Length); + Assert.AreEqual(requiredData.Length, data.Length); for (int i = 0; i < requiredData.Length; i++) { - data[i].Should().Be(requiredData[i]); + Assert.AreEqual(requiredData[i], data[i]); } } @@ -119,7 +118,7 @@ public void TestFromReplica() uut.Value = TestUtils.GetByteArray(10, 0x42); StorageItem dest = new StorageItem(); dest.FromReplica(uut); - dest.Value.Should().BeEquivalentTo(uut.Value); + CollectionAssert.AreEqual(uut.Value.ToArray(), dest.Value.ToArray()); } } } diff --git a/tests/Neo.UnitTests/Ledger/UT_StorageKey.cs b/tests/Neo.UnitTests/Ledger/UT_StorageKey.cs index 814bbcec7c..57a56d6c9c 100644 --- a/tests/Neo.UnitTests/Ledger/UT_StorageKey.cs +++ b/tests/Neo.UnitTests/Ledger/UT_StorageKey.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -25,7 +24,7 @@ public class UT_StorageKey public void Id_Get() { var uut = new StorageKey { Id = 1, Key = new byte[] { 0x01 } }; - uut.Id.Should().Be(1); + Assert.AreEqual(1, uut.Id); } [TestMethod] @@ -33,7 +32,7 @@ public void Id_Set() { int val = 1; StorageKey uut = new() { Id = val }; - uut.Id.Should().Be(val); + Assert.AreEqual(val, uut.Id); } [TestMethod] @@ -41,23 +40,23 @@ public void Key_Set() { byte[] val = new byte[] { 0x42, 0x32 }; StorageKey uut = new() { Key = val }; - uut.Key.Length.Should().Be(2); - uut.Key.Span[0].Should().Be(val[0]); - uut.Key.Span[1].Should().Be(val[1]); + Assert.AreEqual(2, uut.Key.Length); + Assert.AreEqual(val[0], uut.Key.Span[0]); + Assert.AreEqual(val[1], uut.Key.Span[1]); } [TestMethod] public void Equals_SameObj() { StorageKey uut = new(); - uut.Equals(uut).Should().BeTrue(); + Assert.IsTrue(uut.Equals(uut)); } [TestMethod] public void Equals_Null() { StorageKey uut = new(); - uut.Equals(null).Should().BeFalse(); + Assert.IsFalse(uut.Equals(null)); } [TestMethod] @@ -71,7 +70,7 @@ public void Equals_SameHash_SameKey() Key = keyVal }; StorageKey uut = new() { Id = val, Key = keyVal }; - uut.Equals(newSk).Should().BeTrue(); + Assert.IsTrue(uut.Equals(newSk)); } [TestMethod] @@ -85,7 +84,7 @@ public void Equals_DiffHash_SameKey() Key = keyVal }; StorageKey uut = new() { Id = 0x78000000, Key = keyVal }; - uut.Equals(newSk).Should().BeFalse(); + Assert.IsFalse(uut.Equals(newSk)); } [TestMethod] @@ -99,7 +98,7 @@ public void Equals_SameHash_DiffKey() Key = keyVal }; StorageKey uut = new() { Id = val, Key = TestUtils.GetByteArray(10, 0x88) }; - uut.Equals(newSk).Should().BeFalse(); + Assert.IsFalse(uut.Equals(newSk)); } [TestMethod] @@ -107,15 +106,15 @@ public void GetHashCode_Get() { var data = TestUtils.GetByteArray(10, 0x42); StorageKey uut = new() { Id = 0x42000000, Key = data }; - uut.GetHashCode().Should().Be(HashCode.Combine(0x42000000, data.XxHash3_32())); + Assert.AreEqual(HashCode.Combine(0x42000000, data.XxHash3_32()), uut.GetHashCode()); } [TestMethod] public void Equals_Obj() { StorageKey uut = new(); - uut.Equals(1u).Should().BeFalse(); - uut.Equals((object)uut).Should().BeTrue(); + Assert.IsFalse(uut.Equals(1u)); + Assert.IsTrue(uut.Equals((object)uut)); } } } diff --git a/tests/Neo.UnitTests/Ledger/UT_TransactionState.cs b/tests/Neo.UnitTests/Ledger/UT_TransactionState.cs index 4500b74793..ec1bfff0b8 100644 --- a/tests/Neo.UnitTests/Ledger/UT_TransactionState.cs +++ b/tests/Neo.UnitTests/Ledger/UT_TransactionState.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; using Neo.Network.P2P.Payloads; @@ -59,9 +58,9 @@ public void TestDeserialize() TransactionState dest = new(); ((IInteroperable)dest).FromStackItem(BinarySerializer.Deserialize(ref reader, ExecutionEngineLimits.Default, null)); - dest.BlockIndex.Should().Be(origin.BlockIndex); - dest.Transaction.Hash.Should().Be(origin.Transaction.Hash); - dest.Transaction.Should().NotBeNull(); + Assert.AreEqual(origin.BlockIndex, dest.BlockIndex); + Assert.AreEqual(origin.Transaction.Hash, dest.Transaction.Hash); + Assert.IsNotNull(dest.Transaction); } [TestMethod] @@ -73,9 +72,8 @@ public void TestDeserializeTrimmed() TransactionState dest = new(); ((IInteroperable)dest).FromStackItem(BinarySerializer.Deserialize(ref reader, ExecutionEngineLimits.Default, null)); - dest.BlockIndex.Should().Be(originTrimmed.BlockIndex); - dest.Transaction.Should().Be(null); - dest.Transaction.Should().BeNull(); + Assert.AreEqual(originTrimmed.BlockIndex, dest.BlockIndex); + Assert.IsNull(dest.Transaction); } } } diff --git a/tests/Neo.UnitTests/Ledger/UT_TransactionVerificationContext.cs b/tests/Neo.UnitTests/Ledger/UT_TransactionVerificationContext.cs index 5b77358169..9b00bef734 100644 --- a/tests/Neo.UnitTests/Ledger/UT_TransactionVerificationContext.cs +++ b/tests/Neo.UnitTests/Ledger/UT_TransactionVerificationContext.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Neo.Ledger; @@ -73,12 +72,12 @@ public async Task TestDuplicateOracle() var tx = CreateTransactionWithFee(1, 2); tx.Attributes = new TransactionAttribute[] { new OracleResponse() { Code = OracleResponseCode.ConsensusUnreachable, Id = 1, Result = Array.Empty() } }; var conflicts = new List(); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeTrue(); + Assert.IsTrue(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); verificationContext.AddTransaction(tx); tx = CreateTransactionWithFee(2, 1); tx.Attributes = new TransactionAttribute[] { new OracleResponse() { Code = OracleResponseCode.ConsensusUnreachable, Id = 1, Result = Array.Empty() } }; - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeFalse(); + Assert.IsFalse(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); } [TestMethod] @@ -93,15 +92,15 @@ public async Task TestTransactionSenderFee() TransactionVerificationContext verificationContext = new(); var tx = CreateTransactionWithFee(1, 2); var conflicts = new List(); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeTrue(); + Assert.IsTrue(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); verificationContext.AddTransaction(tx); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeTrue(); + Assert.IsTrue(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); verificationContext.AddTransaction(tx); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeFalse(); + Assert.IsFalse(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); verificationContext.RemoveTransaction(tx); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeTrue(); + Assert.IsTrue(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); verificationContext.AddTransaction(tx); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeFalse(); + Assert.IsFalse(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); } [TestMethod] @@ -118,14 +117,14 @@ public async Task TestTransactionSenderFeeWithConflicts() var conflictingTx = CreateTransactionWithFee(1, 1); // costs 2 GAS var conflicts = new List(); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeTrue(); + Assert.IsTrue(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); verificationContext.AddTransaction(tx); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeTrue(); + Assert.IsTrue(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); verificationContext.AddTransaction(tx); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeFalse(); + Assert.IsFalse(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); conflicts.Add(conflictingTx); - verificationContext.CheckTransaction(tx, conflicts, snapshotCache).Should().BeTrue(); // 1 GAS is left on the balance + 2 GAS is free after conflicts removal => enough for one more trasnaction. + Assert.IsTrue(verificationContext.CheckTransaction(tx, conflicts, snapshotCache)); // 1 GAS is left on the balance + 2 GAS is free after conflicts removal => enough for one more trasnaction. } } } diff --git a/tests/Neo.UnitTests/Ledger/UT_TrimmedBlock.cs b/tests/Neo.UnitTests/Ledger/UT_TrimmedBlock.cs index 424ec7aae0..b3f4d1e65f 100644 --- a/tests/Neo.UnitTests/Ledger/UT_TrimmedBlock.cs +++ b/tests/Neo.UnitTests/Ledger/UT_TrimmedBlock.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -78,12 +77,12 @@ public void TestGetBlock() Block block = NativeContract.Ledger.GetBlock(snapshotCache, tblock.Hash); - block.Index.Should().Be(1); - block.MerkleRoot.Should().Be(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff02")); - block.Transactions.Length.Should().Be(2); - block.Transactions[0].Hash.Should().Be(tx1.Hash); - block.Witness.InvocationScript.Span.ToHexString().Should().Be(tblock.Header.Witness.InvocationScript.Span.ToHexString()); - block.Witness.VerificationScript.Span.ToHexString().Should().Be(tblock.Header.Witness.VerificationScript.Span.ToHexString()); + Assert.AreEqual((uint)1, block.Index); + Assert.AreEqual(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff02"), block.MerkleRoot); + Assert.AreEqual(2, block.Transactions.Length); + Assert.AreEqual(tx1.Hash, block.Transactions[0].Hash); + Assert.AreEqual(tblock.Header.Witness.InvocationScript.Span.ToHexString(), block.Witness.InvocationScript.Span.ToHexString()); + Assert.AreEqual(tblock.Header.Witness.VerificationScript.Span.ToHexString(), block.Witness.VerificationScript.Span.ToHexString()); } [TestMethod] @@ -91,8 +90,8 @@ public void TestGetHeader() { TrimmedBlock tblock = GetTrimmedBlockWithNoTransaction(); Header header = tblock.Header; - header.PrevHash.Should().Be(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff01")); - header.MerkleRoot.Should().Be(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff02")); + Assert.AreEqual(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff01"), header.PrevHash); + Assert.AreEqual(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff02"), header.MerkleRoot); } [TestMethod] @@ -100,7 +99,7 @@ public void TestGetSize() { TrimmedBlock tblock = GetTrimmedBlockWithNoTransaction(); tblock.Hashes = new UInt256[] { TestUtils.GetTransaction(UInt160.Zero).Hash }; - tblock.Size.Should().Be(146); // 138 + 8 + Assert.AreEqual(146, tblock.Size); // 138 + 8 } [TestMethod] @@ -116,8 +115,8 @@ public void TestDeserialize() MemoryReader reader = new(ms.ToArray()); newBlock.Deserialize(ref reader); } - tblock.Hashes.Length.Should().Be(newBlock.Hashes.Length); - tblock.Header.ToJson(TestProtocolSettings.Default).ToString().Should().Be(newBlock.Header.ToJson(ProtocolSettings.Default).ToString()); + Assert.AreEqual(newBlock.Hashes.Length, tblock.Hashes.Length); + Assert.AreEqual(newBlock.Header.ToJson(ProtocolSettings.Default).ToString(), tblock.Header.ToJson(TestProtocolSettings.Default).ToString()); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ArchivalNodeCapability.cs b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ArchivalNodeCapability.cs index c7c3b4a9f4..13c63be31a 100644 --- a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ArchivalNodeCapability.cs +++ b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ArchivalNodeCapability.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -25,7 +24,7 @@ public class UT_ArchivalNodeCapability public void Size_Get() { var test = new ArchivalNodeCapability(); - test.Size.Should().Be(2); + Assert.AreEqual(2, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_FullNodeCapability.cs b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_FullNodeCapability.cs index 2a5cfabf1c..a96d651072 100644 --- a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_FullNodeCapability.cs +++ b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_FullNodeCapability.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -24,10 +23,10 @@ public class UT_FullNodeCapability public void Size_Get() { var test = new FullNodeCapability() { StartHeight = 1 }; - test.Size.Should().Be(5); + Assert.AreEqual(5, test.Size); test = new FullNodeCapability(2); - test.Size.Should().Be(5); + Assert.AreEqual(5, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs index f0ebadae71..0931d832ba 100644 --- a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs +++ b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ServerCapability.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -25,12 +24,12 @@ public class UT_ServerCapability public void Size_Get() { var test = new ServerCapability(NodeCapabilityType.TcpServer) { Port = 1 }; - test.Size.Should().Be(3); + Assert.AreEqual(3, test.Size); #pragma warning disable CS0612 // Type or member is obsolete test = new ServerCapability(NodeCapabilityType.WsServer) { Port = 2 }; #pragma warning restore CS0612 // Type or member is obsolete - test.Size.Should().Be(3); + Assert.AreEqual(3, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_UnknownCapability.cs b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_UnknownCapability.cs index ea5659a3af..a2e85c7c4c 100644 --- a/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_UnknownCapability.cs +++ b/tests/Neo.UnitTests/Network/P2P/Capabilities/UT_UnknownCapability.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_AddrPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_AddrPayload.cs index de36dd6ff5..36086dcbf0 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_AddrPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_AddrPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -27,10 +26,10 @@ public class UT_AddrPayload public void Size_Get() { var test = new AddrPayload() { AddressList = new NetworkAddressWithTime[0] }; - test.Size.Should().Be(1); + Assert.AreEqual(1, test.Size); test = AddrPayload.Create(new NetworkAddressWithTime[] { new NetworkAddressWithTime() { Address = IPAddress.Any, Capabilities = new Neo.Network.P2P.Capabilities.NodeCapability[0], Timestamp = 1 } }); - test.Size.Should().Be(22); + Assert.AreEqual(22, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Block.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Block.cs index bd8f5b19d6..ebdf281a86 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Block.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Block.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -44,7 +43,7 @@ public void TestSetup() [TestMethod] public void Transactions_Get() { - uut.Transactions.Should().BeNull(); + Assert.IsNull(uut.Transactions); } [TestMethod] @@ -53,13 +52,13 @@ public void Header_Get() UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(null, uut, val256, out var merkRootVal, out _, out var timestampVal, out var nonceVal, out var indexVal, out var scriptVal, out _, 0); - uut.Header.Should().NotBeNull(); - uut.Header.PrevHash.Should().Be(val256); - uut.Header.MerkleRoot.Should().Be(merkRootVal); - uut.Header.Timestamp.Should().Be(timestampVal); - uut.Header.Index.Should().Be(indexVal); - uut.Header.Nonce.Should().Be(nonceVal); - uut.Header.Witness.Should().Be(scriptVal); + Assert.IsNotNull(uut.Header); + Assert.AreEqual(val256, uut.Header.PrevHash); + Assert.AreEqual(merkRootVal, uut.Header.MerkleRoot); + Assert.AreEqual(timestampVal, uut.Header.Timestamp); + Assert.AreEqual(indexVal, uut.Header.Index); + Assert.AreEqual(nonceVal, uut.Header.Nonce); + Assert.AreEqual(scriptVal, uut.Header.Witness); } [TestMethod] @@ -69,7 +68,7 @@ public void Size_Get() TestUtils.SetupBlockWithValues(null, uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, out var _, 0); // header 4 + 32 + 32 + 8 + 4 + 1 + 20 + 4 // tx 1 - uut.Size.Should().Be(114); // 106 + nonce + Assert.AreEqual(114, uut.Size); // 106 + nonce } [TestMethod] @@ -83,7 +82,7 @@ public void Size_Get_1_Transaction() TestUtils.GetTransaction(UInt160.Zero) }; - uut.Size.Should().Be(167); // 159 + nonce + Assert.AreEqual(167, uut.Size); // 159 + nonce } [TestMethod] @@ -99,7 +98,7 @@ public void Size_Get_3_Transaction() TestUtils.GetTransaction(UInt160.Zero) }; - uut.Size.Should().Be(273); // 265 + nonce + Assert.AreEqual(273, uut.Size); // 265 + nonce } [TestMethod] @@ -109,7 +108,7 @@ public void Serialize() TestUtils.SetupBlockWithValues(null, uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, out var _, 1); var hex = "0000000000000000000000000000000000000000000000000000000000000000000000006c23be5d32679baa9c5c2aa0d329fd2a2441d7875d0f34d42f58f70428fbbbb9493ed0e58f01000000000000000000000000000000000000000000000000000000000000000000000001000111010000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000001000112010000"; - uut.ToArray().ToHexString().Should().Be(hex); + Assert.AreEqual(hex, uut.ToArray().ToHexString()); } [TestMethod] @@ -129,35 +128,35 @@ public void Deserialize() private void AssertStandardBlockTestVals(UInt256 val256, UInt256 merkRoot, UInt160 val160, ulong timestampVal, ulong nonceVal, uint indexVal, Witness scriptVal, Transaction[] transactionsVal, bool testTransactions = true) { - uut.PrevHash.Should().Be(val256); - uut.MerkleRoot.Should().Be(merkRoot); - uut.Timestamp.Should().Be(timestampVal); - uut.Index.Should().Be(indexVal); - uut.Nonce.Should().Be(nonceVal); - uut.NextConsensus.Should().Be(val160); - uut.Witness.InvocationScript.Length.Should().Be(0); - uut.Witness.Size.Should().Be(scriptVal.Size); - uut.Witness.VerificationScript.Span[0].Should().Be(scriptVal.VerificationScript.Span[0]); + Assert.AreEqual(val256, uut.PrevHash); + Assert.AreEqual(merkRoot, uut.MerkleRoot); + Assert.AreEqual(timestampVal, uut.Timestamp); + Assert.AreEqual(indexVal, uut.Index); + Assert.AreEqual(nonceVal, uut.Nonce); + Assert.AreEqual(val160, uut.NextConsensus); + Assert.AreEqual(0, uut.Witness.InvocationScript.Length); + Assert.AreEqual(scriptVal.Size, uut.Witness.Size); + Assert.AreEqual(scriptVal.VerificationScript.Span[0], uut.Witness.VerificationScript.Span[0]); if (testTransactions) { - uut.Transactions.Length.Should().Be(1); - uut.Transactions[0].Should().Be(transactionsVal[0]); + Assert.AreEqual(1, uut.Transactions.Length); + Assert.AreEqual(transactionsVal[0], uut.Transactions[0]); } } [TestMethod] public void Equals_SameObj() { - uut.Equals(uut).Should().BeTrue(); + Assert.IsTrue(uut.Equals(uut)); var obj = uut as object; - uut.Equals(obj).Should().BeTrue(); + Assert.IsTrue(uut.Equals(obj)); } [TestMethod] public void TestGetHashCode() { var snapshot = GetEngine(true, true).SnapshotCache; - NativeContract.Ledger.GetBlock(snapshot, 0).GetHashCode().Should().Be(-626492395); + Assert.AreEqual(-626492395, NativeContract.Ledger.GetBlock(snapshot, 0).GetHashCode()); } [TestMethod] @@ -169,13 +168,13 @@ public void Equals_DiffObj() TestUtils.SetupBlockWithValues(null, newBlock, val256, out _, out _, out _, out ulong _, out uint _, out _, out _, 1); TestUtils.SetupBlockWithValues(null, uut, prevHash, out _, out _, out _, out _, out _, out _, out _, 0); - uut.Equals(newBlock).Should().BeFalse(); + Assert.IsFalse(uut.Equals(newBlock)); } [TestMethod] public void Equals_Null() { - uut.Equals(null).Should().BeFalse(); + Assert.IsFalse(uut.Equals(null)); } [TestMethod] @@ -186,7 +185,7 @@ public void Equals_SameHash() TestUtils.SetupBlockWithValues(null, newBlock, prevHash, out _, out _, out _, out _, out _, out _, out _, 1); TestUtils.SetupBlockWithValues(null, uut, prevHash, out _, out _, out _, out _, out _, out _, out _, 1); - uut.Equals(newBlock).Should().BeTrue(); + Assert.IsTrue(uut.Equals(newBlock)); } [TestMethod] @@ -196,28 +195,28 @@ public void ToJson() TestUtils.SetupBlockWithValues(null, uut, val256, out _, out _, out var timeVal, out var indexVal, out var nonceVal, out _, out _, 1); JObject jObj = uut.ToJson(TestProtocolSettings.Default); - jObj.Should().NotBeNull(); - jObj["hash"].AsString().Should().Be("0x942065e93848732c2e7844061fa92d20c5d9dc0bc71d420a1ea71b3431fc21b4"); - jObj["size"].AsNumber().Should().Be(167); // 159 + nonce - jObj["version"].AsNumber().Should().Be(0); - jObj["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000"); - jObj["merkleroot"].AsString().Should().Be("0xb9bbfb2804f7582fd4340f5d87d741242afd29d3a02a5c9caa9b67325dbe236c"); - jObj["time"].AsNumber().Should().Be(timeVal); - jObj["nonce"].AsString().Should().Be(nonceVal.ToString("X16")); - jObj["index"].AsNumber().Should().Be(indexVal); - jObj["nextconsensus"].AsString().Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf"); + Assert.IsNotNull(jObj); + Assert.AreEqual("0x942065e93848732c2e7844061fa92d20c5d9dc0bc71d420a1ea71b3431fc21b4", jObj["hash"].AsString()); + Assert.AreEqual(167, jObj["size"].AsNumber()); // 159 + nonce + Assert.AreEqual(0, jObj["version"].AsNumber()); + Assert.AreEqual("0x0000000000000000000000000000000000000000000000000000000000000000", jObj["previousblockhash"].AsString()); + Assert.AreEqual("0xb9bbfb2804f7582fd4340f5d87d741242afd29d3a02a5c9caa9b67325dbe236c", jObj["merkleroot"].AsString()); + Assert.AreEqual(timeVal, jObj["time"].AsNumber()); + Assert.AreEqual(nonceVal.ToString("X16"), jObj["nonce"].AsString()); + Assert.AreEqual(indexVal, jObj["index"].AsNumber()); + Assert.AreEqual("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf", jObj["nextconsensus"].AsString()); JObject scObj = (JObject)jObj["witnesses"][0]; - scObj["invocation"].AsString().Should().Be(""); - scObj["verification"].AsString().Should().Be("EQ=="); + Assert.AreEqual("", scObj["invocation"].AsString()); + Assert.AreEqual("EQ==", scObj["verification"].AsString()); - jObj["tx"].Should().NotBeNull(); + Assert.IsNotNull(jObj["tx"]); JObject txObj = (JObject)jObj["tx"][0]; - txObj["hash"].AsString().Should().Be("0xb9bbfb2804f7582fd4340f5d87d741242afd29d3a02a5c9caa9b67325dbe236c"); - txObj["size"].AsNumber().Should().Be(53); - txObj["version"].AsNumber().Should().Be(0); - ((JArray)txObj["attributes"]).Count.Should().Be(0); - txObj["netfee"].AsString().Should().Be("0"); + Assert.AreEqual("0xb9bbfb2804f7582fd4340f5d87d741242afd29d3a02a5c9caa9b67325dbe236c", txObj["hash"].AsString()); + Assert.AreEqual(53, txObj["size"].AsNumber()); + Assert.AreEqual(0, txObj["version"].AsNumber()); + Assert.AreEqual(0, ((JArray)txObj["attributes"]).Count); + Assert.AreEqual("0", txObj["netfee"].AsString()); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Conflicts.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Conflicts.cs index 8e71336a1f..fe783bd32e 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Conflicts.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Conflicts.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -32,17 +31,22 @@ public class UT_Conflicts 0x01, 0x01 }); + private Conflicts CreateConflictsPayload() + { + return new Conflicts() { Hash = _u }; + } + [TestMethod] public void Size_Get() { - var test = new Conflicts() { Hash = _u }; - test.Size.Should().Be(1 + 32); + var test = CreateConflictsPayload(); + Assert.AreEqual(1 + 32, test.Size); } [TestMethod] public void ToJson() { - var test = new Conflicts() { Hash = _u }; + var test = CreateConflictsPayload(); var json = test.ToJson().ToString(); Assert.AreEqual(@"{""type"":""Conflicts"",""hash"":""0x0101010101010101010101010101010101010101010101010101010101010101""}", json); } @@ -50,7 +54,7 @@ public void ToJson() [TestMethod] public void DeserializeAndSerialize() { - var test = new Conflicts() { Hash = _u }; + var test = CreateConflictsPayload(); var clone = test.ToArray().AsSerializable(); Assert.AreEqual(clone.Type, test.Type); @@ -73,7 +77,7 @@ public void DeserializeAndSerialize() [TestMethod] public void Verify() { - var test = new Conflicts() { Hash = _u }; + var test = CreateConflictsPayload(); var snapshotCache = TestBlockchain.GetTestSnapshotCache(); var key = Ledger.UT_MemoryPool.CreateStorageKey(NativeContract.Ledger.Id, Prefix_Transaction, _u.ToArray()); diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_ExtensiblePayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_ExtensiblePayload.cs index 0f7baa0b28..d841f33f9e 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_ExtensiblePayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_ExtensiblePayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -33,7 +32,7 @@ public void Size_Get() Data = new byte[] { 1, 2, 3 }, Witness = new Witness() { InvocationScript = new byte[] { 3, 5, 6 }, VerificationScript = Array.Empty() } }; - test.Size.Should().Be(42); + Assert.AreEqual(42, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterAddPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterAddPayload.cs index 6f8d398ceb..d371b3fe6b 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterAddPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterAddPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -25,10 +24,10 @@ public class UT_FilterAddPayload public void Size_Get() { var test = new FilterAddPayload() { Data = new byte[0] }; - test.Size.Should().Be(1); + Assert.AreEqual(1, test.Size); test = new FilterAddPayload() { Data = new byte[] { 1, 2, 3 } }; - test.Size.Should().Be(4); + Assert.AreEqual(4, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterLoadPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterLoadPayload.cs index 5ef91447a2..6b9ceec306 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterLoadPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_FilterLoadPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -25,10 +24,10 @@ public class UT_FilterLoadPayload public void Size_Get() { var test = new FilterLoadPayload() { Filter = Array.Empty(), K = 1, Tweak = uint.MaxValue }; - test.Size.Should().Be(6); + Assert.AreEqual(6, test.Size); test = FilterLoadPayload.Create(new Neo.Cryptography.BloomFilter(8, 10, 123456)); - test.Size.Should().Be(7); + Assert.AreEqual(7, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlockByIndexPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlockByIndexPayload.cs index 564ed73f5b..6c0819fe02 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlockByIndexPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlockByIndexPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -25,10 +24,10 @@ public class UT_GetBlockByIndexPayload public void Size_Get() { var test = new GetBlockByIndexPayload() { Count = 5, IndexStart = 5 }; - test.Size.Should().Be(6); + Assert.AreEqual(6, test.Size); test = GetBlockByIndexPayload.Create(1, short.MaxValue); - test.Size.Should().Be(6); + Assert.AreEqual(6, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlocksPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlocksPayload.cs index 93ae662b72..23b01fec13 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlocksPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_GetBlocksPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -25,10 +24,10 @@ public class UT_GetBlocksPayload public void Size_Get() { var test = new GetBlocksPayload() { Count = 5, HashStart = UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff01") }; - test.Size.Should().Be(34); + Assert.AreEqual(34, test.Size); test = new GetBlocksPayload() { Count = 1, HashStart = UInt256.Zero }; - test.Size.Should().Be(34); + Assert.AreEqual(34, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs index 1316695c64..88d8ce9eda 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -37,7 +36,7 @@ public void Size_Get() TestUtils.SetupHeaderWithValues(null, uut, val256, out _, out _, out _, out _, out _, out _); // blockbase 4 + 64 + 1 + 32 + 4 + 4 + 20 + 4 // header 1 - uut.Size.Should().Be(113); // 105 + nonce + Assert.AreEqual(113, uut.Size); // 105 + nonce } [TestMethod] @@ -45,7 +44,7 @@ public void GetHashCodeTest() { UInt256 val256 = UInt256.Zero; TestUtils.SetupHeaderWithValues(null, uut, val256, out _, out _, out _, out _, out _, out _); - uut.GetHashCode().Should().Be(uut.Hash.GetHashCode()); + Assert.AreEqual(uut.Hash.GetHashCode(), uut.GetHashCode()); } [TestMethod] @@ -72,15 +71,15 @@ public void TrimTest() var trim = NativeContract.Ledger.GetTrimmedBlock(snapshotCache, uut.Hash); var header = trim.Header; - header.Version.Should().Be(uut.Version); - header.PrevHash.Should().Be(uut.PrevHash); - header.MerkleRoot.Should().Be(uut.MerkleRoot); - header.Timestamp.Should().Be(uut.Timestamp); - header.Index.Should().Be(uut.Index); - header.NextConsensus.Should().Be(uut.NextConsensus); - header.Witness.InvocationScript.Span.SequenceEqual(uut.Witness.InvocationScript.Span).Should().BeTrue(); - header.Witness.VerificationScript.Span.SequenceEqual(uut.Witness.VerificationScript.Span).Should().BeTrue(); - trim.Hashes.Length.Should().Be(0); + Assert.AreEqual(uut.Version, header.Version); + Assert.AreEqual(uut.PrevHash, header.PrevHash); + Assert.AreEqual(uut.MerkleRoot, header.MerkleRoot); + Assert.AreEqual(uut.Timestamp, header.Timestamp); + Assert.AreEqual(uut.Index, header.Index); + Assert.AreEqual(uut.NextConsensus, header.NextConsensus); + CollectionAssert.AreEqual(uut.Witness.InvocationScript.ToArray(), header.Witness.InvocationScript.ToArray()); + CollectionAssert.AreEqual(uut.Witness.VerificationScript.ToArray(), header.Witness.VerificationScript.ToArray()); + Assert.AreEqual(0, trim.Hashes.Length); } [TestMethod] @@ -101,28 +100,28 @@ public void Deserialize() private void AssertStandardHeaderTestVals(UInt256 val256, UInt256 merkRoot, UInt160 val160, ulong timestampVal, ulong nonceVal, uint indexVal, Witness scriptVal) { - uut.PrevHash.Should().Be(val256); - uut.MerkleRoot.Should().Be(merkRoot); - uut.Timestamp.Should().Be(timestampVal); - uut.Index.Should().Be(indexVal); - uut.Nonce.Should().Be(nonceVal); - uut.NextConsensus.Should().Be(val160); - uut.Witness.InvocationScript.Length.Should().Be(0); - uut.Witness.Size.Should().Be(scriptVal.Size); - uut.Witness.VerificationScript.Span[0].Should().Be(scriptVal.VerificationScript.Span[0]); + Assert.AreEqual(val256, uut.PrevHash); + Assert.AreEqual(merkRoot, uut.MerkleRoot); + Assert.AreEqual(timestampVal, uut.Timestamp); + Assert.AreEqual(indexVal, uut.Index); + Assert.AreEqual(nonceVal, uut.Nonce); + Assert.AreEqual(val160, uut.NextConsensus); + Assert.AreEqual(0, uut.Witness.InvocationScript.Length); + Assert.AreEqual(scriptVal.Size, uut.Witness.Size); + Assert.AreEqual(scriptVal.VerificationScript.Span[0], uut.Witness.VerificationScript.Span[0]); } [TestMethod] public void Equals_Null() { - uut.Equals(null).Should().BeFalse(); + Assert.IsFalse(uut.Equals(null)); } [TestMethod] public void Equals_SameHeader() { - uut.Equals(uut).Should().BeTrue(); + Assert.IsTrue(uut.Equals(uut)); } [TestMethod] @@ -133,13 +132,13 @@ public void Equals_SameHash() TestUtils.SetupHeaderWithValues(null, newHeader, prevHash, out _, out _, out _, out _, out _, out _); TestUtils.SetupHeaderWithValues(null, uut, prevHash, out _, out _, out _, out _, out _, out _); - uut.Equals(newHeader).Should().BeTrue(); + Assert.IsTrue(uut.Equals(newHeader)); } [TestMethod] public void Equals_SameObject() { - uut.Equals((object)uut).Should().BeTrue(); + Assert.IsTrue(uut.Equals((object)uut)); } [TestMethod] @@ -149,7 +148,7 @@ public void Serialize() TestUtils.SetupHeaderWithValues(null, uut, val256, out _, out _, out _, out _, out _, out _); var hex = "0000000000000000000000000000000000000000000000000000000000000000000000007227ba7b747f1a98f68679d4a98b68927646ab195a6f56b542ca5a0e6a412662493ed0e58f01000000000000000000000000000000000000000000000000000000000000000000000001000111"; - uut.ToArray().ToHexString().Should().Be(hex); + Assert.AreEqual(hex, uut.ToArray().ToHexString()); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HeadersPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HeadersPayload.cs index f41ea02497..96eef35688 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HeadersPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HeadersPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -27,9 +26,9 @@ public void Size_Get() TestUtils.SetupHeaderWithValues(null, header, UInt256.Zero, out _, out _, out _, out _, out _, out _); var test = HeadersPayload.Create(); - test.Size.Should().Be(1); + Assert.AreEqual(1, test.Size); test = HeadersPayload.Create(header); - test.Size.Should().Be(1 + header.Size); + Assert.AreEqual(1 + header.Size, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs index 5d40715fe8..a8b96996c8 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -26,7 +25,7 @@ public class UT_HighPriorityAttribute public void Size_Get() { var test = new HighPriorityAttribute(); - test.Size.Should().Be(1); + Assert.AreEqual(1, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_InvPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_InvPayload.cs index 2ae6841109..a6baf2c4e6 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_InvPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_InvPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -26,10 +25,10 @@ public class UT_InvPayload public void Size_Get() { var test = InvPayload.Create(InventoryType.TX, UInt256.Zero); - test.Size.Should().Be(34); + Assert.AreEqual(34, test.Size); test = InvPayload.Create(InventoryType.TX, UInt256.Zero, UInt256.Parse("01ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00a4")); - test.Size.Should().Be(66); + Assert.AreEqual(66, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_MerkleBlockPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_MerkleBlockPayload.cs index b38758bd84..73629f68d2 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_MerkleBlockPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_MerkleBlockPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -26,10 +25,10 @@ public class UT_MerkleBlockPayload public void Size_Get() { var test = MerkleBlockPayload.Create(TestBlockchain.TheNeoSystem.GenesisBlock, new BitArray(1024, false)); - test.Size.Should().Be(247); // 239 + nonce + Assert.AreEqual(247, test.Size); // 239 + nonce test = MerkleBlockPayload.Create(TestBlockchain.TheNeoSystem.GenesisBlock, new BitArray(0, false)); - test.Size.Should().Be(119); // 111 + nonce + Assert.AreEqual(119, test.Size); // 111 + nonce } [TestMethod] @@ -39,7 +38,8 @@ public void DeserializeAndSerialize() var clone = test.ToArray().AsSerializable(); Assert.AreEqual(test.TxCount, clone.TxCount); - Assert.AreEqual(test.Hashes.Length, clone.TxCount); + Assert.AreEqual(test.Hashes.Length, clone.Hashes.Length); + Assert.AreEqual(test.Flags.Length, clone.Flags.Length); CollectionAssert.AreEqual(test.Hashes, clone.Hashes); Assert.IsTrue(test.Flags.Span.SequenceEqual(clone.Flags.Span)); } diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs index ba0cf5327a..b8f3810f42 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs @@ -9,14 +9,13 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; -using FluentAssertions.Equivalency; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; using Neo.Network.P2P.Capabilities; using Neo.Network.P2P.Payloads; using System; +using System.Collections; using System.Net; namespace Neo.UnitTests.Network.P2P.Payloads @@ -28,12 +27,12 @@ public class UT_NetworkAddressWithTime public void SizeAndEndPoint_Get() { var test = new NetworkAddressWithTime() { Capabilities = new NodeCapability[0], Address = IPAddress.Any, Timestamp = 1 }; - test.Size.Should().Be(21); + Assert.AreEqual(21, test.Size); Assert.AreEqual(test.EndPoint.Port, 0); test = NetworkAddressWithTime.Create(IPAddress.Any, 1, new NodeCapability[] { new ServerCapability(NodeCapabilityType.TcpServer, 22) }); - test.Size.Should().Be(24); + Assert.AreEqual(24, test.Size); Assert.AreEqual(test.EndPoint.Port, 22); } @@ -44,10 +43,10 @@ public void DeserializeAndSerialize() var test = NetworkAddressWithTime.Create(IPAddress.Any, 1, new NodeCapability[] { new ServerCapability(NodeCapabilityType.TcpServer, 22), new UnknownCapability(NodeCapabilityType.Extension0), new UnknownCapability(NodeCapabilityType.Extension0) }); var clone = test.ToArray().AsSerializable(); - CollectionAssert.AreEqual(test.Capabilities.ToByteArray(), clone.Capabilities.ToByteArray()); + Assert.AreEqual(test.Address, clone.Address); Assert.AreEqual(test.EndPoint.ToString(), clone.EndPoint.ToString()); Assert.AreEqual(test.Timestamp, clone.Timestamp); - Assert.AreEqual(test.Address, clone.Address); + CollectionAssert.AreEqual(test.Capabilities.ToByteArray(), clone.Capabilities.ToByteArray()); Assert.ThrowsException(() => NetworkAddressWithTime.Create(IPAddress.Any, 1, new NodeCapability[] { diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs index 407e3d9337..458b2078ea 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -26,7 +25,7 @@ public class UT_NotValidBefore public void Size_Get() { var test = new NotValidBefore(); - test.Size.Should().Be(5); + Assert.AreEqual(5, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Signers.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Signers.cs index e6d5e705ab..db4b753da3 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Signers.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Signers.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -112,7 +111,7 @@ public void Serialize_Deserialize_Global() }; var hex = "000000000000000000000000000000000000000080"; - attr.ToArray().ToHexString().Should().Be(hex); + CollectionAssert.AreEqual(attr.ToArray(), hex.HexToBytes()); var copy = hex.HexToBytes().AsSerializable(); @@ -130,7 +129,7 @@ public void Serialize_Deserialize_CalledByEntry() }; var hex = "000000000000000000000000000000000000000001"; - attr.ToArray().ToHexString().Should().Be(hex); + CollectionAssert.AreEqual(attr.ToArray(), hex.HexToBytes()); var copy = hex.HexToBytes().AsSerializable(); @@ -171,7 +170,7 @@ public void Serialize_Deserialize_MaxNested_And() }; var hex = "00000000000000000000000000000000000000004001010201020102010001"; - attr.ToArray().ToHexString().Should().Be(hex); + CollectionAssert.AreEqual(attr.ToArray(), hex.HexToBytes()); Assert.ThrowsException(() => hex.HexToBytes().AsSerializable()); } @@ -209,7 +208,7 @@ public void Serialize_Deserialize_MaxNested_Or() }; var hex = "00000000000000000000000000000000000000004001010301030103010001"; - attr.ToArray().ToHexString().Should().Be(hex); + CollectionAssert.AreEqual(attr.ToArray(), hex.HexToBytes()); Assert.ThrowsException(() => hex.HexToBytes().AsSerializable()); } @@ -225,7 +224,7 @@ public void Serialize_Deserialize_CustomContracts() }; var hex = "000000000000000000000000000000000000000010010000000000000000000000000000000000000000"; - attr.ToArray().ToHexString().Should().Be(hex); + CollectionAssert.AreEqual(attr.ToArray(), hex.HexToBytes()); var copy = hex.HexToBytes().AsSerializable(); @@ -245,7 +244,7 @@ public void Serialize_Deserialize_CustomGroups() }; var hex = "0000000000000000000000000000000000000000200103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"; - attr.ToArray().ToHexString().Should().Be(hex); + CollectionAssert.AreEqual(attr.ToArray(), hex.HexToBytes()); var copy = hex.HexToBytes().AsSerializable(); @@ -264,7 +263,7 @@ public void Json_Global() }; var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"Global\"}"; - attr.ToJson().ToString().Should().Be(json); + Assert.AreEqual(json, attr.ToJson().ToString()); } [TestMethod] @@ -277,7 +276,7 @@ public void Json_CalledByEntry() }; var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CalledByEntry\"}"; - attr.ToJson().ToString().Should().Be(json); + Assert.AreEqual(json, attr.ToJson().ToString()); } [TestMethod] @@ -291,7 +290,7 @@ public void Json_CustomContracts() }; var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CustomContracts\",\"allowedcontracts\":[\"0x0000000000000000000000000000000000000000\"]}"; - attr.ToJson().ToString().Should().Be(json); + Assert.AreEqual(json, attr.ToJson().ToString()); } [TestMethod] @@ -305,7 +304,7 @@ public void Json_CustomGroups() }; var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CustomGroups\",\"allowedgroups\":[\"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c\"]}"; - attr.ToJson().ToString().Should().Be(json); + Assert.AreEqual(json, attr.ToJson().ToString()); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index aea71f2442..9dfc2e06be 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -48,7 +47,7 @@ public void Clean() [TestMethod] public void Script_Get() { - uut.Script.IsEmpty.Should().BeTrue(); + Assert.IsTrue(uut.Script.IsEmpty); } [TestMethod] @@ -67,7 +66,7 @@ public void TestEquals() [TestMethod] public void InventoryType_Get() { - ((IInventory)uut).InventoryType.Should().Be(InventoryType.TX); + Assert.AreEqual(InventoryType.TX, ((IInventory)uut).InventoryType); } [TestMethod] @@ -76,17 +75,17 @@ public void Script_Set() byte[] val = TestUtils.GetByteArray(32, 0x42); uut.Script = val; var span = uut.Script.Span; - span.Length.Should().Be(32); + Assert.AreEqual(32, span.Length); for (int i = 0; i < val.Length; i++) { - span[i].Should().Be(val[i]); + Assert.AreEqual(val[i], span[i]); } } [TestMethod] public void Gas_Get() { - uut.SystemFee.Should().Be(0); + Assert.AreEqual(0, uut.SystemFee); } [TestMethod] @@ -94,28 +93,28 @@ public void Gas_Set() { long val = 4200000000; uut.SystemFee = val; - uut.SystemFee.Should().Be(val); + Assert.AreEqual(val, uut.SystemFee); } [TestMethod] public void Size_Get() { uut.Script = TestUtils.GetByteArray(32, 0x42); - uut.Signers = []; - uut.Attributes = []; - uut.Witnesses = - [ + uut.Signers = new Signer[0]; + uut.Attributes = new TransactionAttribute[0]; + uut.Witnesses = new Witness[] + { new Witness { InvocationScript = Array.Empty(), VerificationScript = Array.Empty() } - ]; + }; - uut.Version.Should().Be(0); - uut.Script.Length.Should().Be(32); - uut.Script.GetVarSize().Should().Be(33); - uut.Size.Should().Be(63); + Assert.AreEqual(0, uut.Version); + Assert.AreEqual(32, uut.Script.Length); + Assert.AreEqual(33, uut.Script.GetVarSize()); + Assert.AreEqual(63, uut.Size); } [TestMethod] @@ -228,7 +227,7 @@ public void FeeIsSignatureContractDetailed() Assert.IsNull(tx.Witnesses); // check pre-computed network fee (already guessing signature sizes) - tx.NetworkFee.Should().Be(1228520L); + Assert.AreEqual(1228520L, tx.NetworkFee); // ---- // Sign @@ -237,14 +236,14 @@ public void FeeIsSignatureContractDetailed() var data = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); // '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].Should().BeEquivalentTo(acc.ScriptHash); + Assert.AreEqual(1, data.ScriptHashes.Count); + Assert.AreEqual(acc.ScriptHash, data.ScriptHashes[0]); // will sign tx bool signed = wallet.Sign(data); Assert.IsTrue(signed); // get witnesses from signed 'data' tx.Witnesses = data.GetWitnesses(); - tx.Witnesses.Length.Should().Be(1); + Assert.AreEqual(1, tx.Witnesses.Length); // Fast check @@ -351,7 +350,7 @@ public void FeeIsSignatureContract_TestScope_Global() // get witnesses from signed 'data' tx.Witnesses = data.GetWitnesses(); - tx.Witnesses.Length.Should().Be(1); + Assert.AreEqual(1, tx.Witnesses.Length); // Fast check Assert.IsTrue(tx.VerifyWitnesses(TestProtocolSettings.Default, snapshotCache, tx.NetworkFee)); @@ -431,7 +430,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_GAS() // get witnesses from signed 'data' tx.Witnesses = data.GetWitnesses(); - tx.Witnesses.Length.Should().Be(1); + Assert.AreEqual(1, tx.Witnesses.Length); // Fast check Assert.IsTrue(tx.VerifyWitnesses(TestProtocolSettings.Default, snapshotCache, tx.NetworkFee)); @@ -514,7 +513,7 @@ public void FeeIsSignatureContract_TestScope_CalledByEntry_Plus_GAS() // get witnesses from signed 'data' tx.Witnesses = data.GetWitnesses(); - tx.Witnesses.Length.Should().Be(1); + Assert.AreEqual(1, tx.Witnesses.Length); // Fast check Assert.IsTrue(tx.VerifyWitnesses(TestProtocolSettings.Default, snapshotCache, tx.NetworkFee)); @@ -577,9 +576,9 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_FAULT() // using this... + Transaction tx = null; // expects FAULT on execution of 'transfer' Application script // due to lack of a valid witness validation - Transaction tx = null; Assert.ThrowsException(() => tx = wallet.MakeTransaction(snapshotCache, script, acc.ScriptHash, signers)); Assert.IsNull(tx); } @@ -640,11 +639,11 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_GAS() // get witnesses from signed 'data' tx.Witnesses = data.GetWitnesses(); // only a single witness should exist - tx.Witnesses.Length.Should().Be(1); + Assert.AreEqual(1, tx.Witnesses.Length); // no attributes must exist - tx.Attributes.Length.Should().Be(0); + Assert.AreEqual(0, tx.Attributes.Length); // one cosigner must exist - tx.Signers.Length.Should().Be(1); + Assert.AreEqual(1, tx.Signers.Length); // Fast check Assert.IsTrue(tx.VerifyWitnesses(TestProtocolSettings.Default, snapshotCache, tx.NetworkFee)); @@ -813,8 +812,7 @@ public void Transaction_Serialize_Deserialize_Simple() byte[] sTx = txSimple.ToArray(); // detailed hexstring info (basic checking) - sTx.ToHexString().Should().Be( - "00" + // version + Assert.AreEqual("00" + // version "04030201" + // nonce "00e1f50500000000" + // system fee (1 GAS) "0100000000000000" + // network fee (1 datoshi) @@ -822,30 +820,31 @@ public void Transaction_Serialize_Deserialize_Simple() "01000000000000000000000000000000000000000000" + // empty signer "00" + // no attributes "0111" + // push1 script - "010000"); // empty witnesses + "010000", sTx.ToHexString()); // empty witnesses // try to deserialize Transaction tx2 = sTx.AsSerializable(); - tx2.Version.Should().Be(0x00); - tx2.Nonce.Should().Be(0x01020304); - tx2.Sender.Should().Be(UInt160.Zero); - tx2.SystemFee.Should().Be(0x0000000005f5e100); // 1 GAS (long)BigInteger.Pow(10, 8) - tx2.NetworkFee.Should().Be(0x0000000000000001); - tx2.ValidUntilBlock.Should().Be(0x01020304); - tx2.Attributes.Should().BeEquivalentTo(Array.Empty()); - tx2.Signers.Should().BeEquivalentTo([ + Assert.AreEqual(0x00, tx2.Version); + Assert.AreEqual(0x01020304u, tx2.Nonce); + Assert.AreEqual(UInt160.Zero, tx2.Sender); + Assert.AreEqual(0x0000000005f5e100, tx2.SystemFee); // 1 GAS (long)BigInteger.Pow(10, 8) + Assert.AreEqual(0x0000000000000001, tx2.NetworkFee); + Assert.AreEqual(0x01020304u, tx2.ValidUntilBlock); + CollectionAssert.AreEqual(Array.Empty(), tx2.Attributes); + CollectionAssert.AreEqual(new[] + { new Signer { Account = UInt160.Zero, - AllowedContracts = [], - AllowedGroups = [], - Rules = [] + AllowedContracts = Array.Empty(), + AllowedGroups = Array.Empty(), + Rules = Array.Empty() } - ]); - tx2.Script.Span.SequenceEqual([(byte)OpCode.PUSH1]).Should().BeTrue(); - tx2.Witnesses[0].InvocationScript.Span.IsEmpty.Should().BeTrue(); - tx2.Witnesses[0].VerificationScript.Span.IsEmpty.Should().BeTrue(); + }, tx2.Signers); + Assert.IsTrue(tx2.Script.Span.SequenceEqual(new byte[] { (byte)OpCode.PUSH1 })); + Assert.IsTrue(tx2.Witnesses[0].InvocationScript.Span.IsEmpty); + Assert.IsTrue(tx2.Witnesses[0].VerificationScript.Span.IsEmpty); } [TestMethod] @@ -882,7 +881,7 @@ public void Transaction_Serialize_Deserialize_DistinctCosigners() var sTx = txDoubleCosigners.ToArray(); // no need for detailed hexstring here (see basic tests for it) - sTx.ToHexString().Should().Be("000403020100e1f5050000000001000000000000000403020102090807060504030201000908070605040302010080090807060504030201000908070605040302010001000111010000"); + Assert.AreEqual("000403020100e1f5050000000001000000000000000403020102090807060504030201000908070605040302010080090807060504030201000908070605040302010001000111010000", sTx.ToHexString()); // back to transaction (should fail, due to non-distinct cosigners) Transaction tx2 = null; @@ -980,7 +979,7 @@ public void FeeIsSignatureContract_TestScope_FeeOnly_Default() // Global is supposed to be default Signer cosigner = new(); - cosigner.Scopes.Should().Be(WitnessScope.None); + Assert.AreEqual(WitnessScope.None, cosigner.Scopes); var wallet = TestUtils.GenerateTestWallet(""); var snapshotCache = TestBlockchain.GetTestSnapshotCache(); @@ -1036,7 +1035,7 @@ public void FeeIsSignatureContract_TestScope_FeeOnly_Default() // get witnesses from signed 'data' tx.Witnesses = data.GetWitnesses(); - tx.Witnesses.Length.Should().Be(1); + Assert.AreEqual(1, tx.Witnesses.Length); // Fast check Assert.IsTrue(tx.VerifyWitnesses(TestProtocolSettings.Default, snapshotCache, tx.NetworkFee)); @@ -1078,14 +1077,14 @@ public void ToJson() ]; JObject jObj = uut.ToJson(ProtocolSettings.Default); - jObj.Should().NotBeNull(); - jObj["hash"].AsString().Should().Be("0x0ab073429086d9e48fc87386122917989705d1c81fe4a60bf90e2fc228de3146"); - jObj["size"].AsNumber().Should().Be(84); - jObj["version"].AsNumber().Should().Be(0); - ((JArray)jObj["attributes"]).Count.Should().Be(0); - jObj["netfee"].AsString().Should().Be("0"); - jObj["script"].AsString().Should().Be("QiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA="); - jObj["sysfee"].AsString().Should().Be("4200000000"); + Assert.IsNotNull(jObj); + Assert.AreEqual("0x0ab073429086d9e48fc87386122917989705d1c81fe4a60bf90e2fc228de3146", jObj["hash"].AsString()); + Assert.AreEqual(84, jObj["size"].AsNumber()); + Assert.AreEqual(0, jObj["version"].AsNumber()); + Assert.AreEqual(0, ((JArray)jObj["attributes"]).Count); + Assert.AreEqual("0", jObj["netfee"].AsString()); + Assert.AreEqual("QiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA=", jObj["script"].AsString()); + Assert.AreEqual("4200000000", jObj["sysfee"].AsString()); } [TestMethod] @@ -1135,9 +1134,9 @@ public void Test_VerifyStateIndependent() } ] }; - tx.VerifyStateIndependent(TestProtocolSettings.Default).Should().Be(VerifyResult.OverSize); + Assert.AreEqual(VerifyResult.OverSize, tx.VerifyStateIndependent(TestProtocolSettings.Default)); tx.Script = Array.Empty(); - tx.VerifyStateIndependent(TestProtocolSettings.Default).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, tx.VerifyStateIndependent(TestProtocolSettings.Default)); var walletA = TestUtils.GenerateTestWallet("123"); var walletB = TestUtils.GenerateTestWallet("123"); @@ -1183,7 +1182,7 @@ public void Test_VerifyStateIndependent() Assert.IsTrue(data.Completed); tx.Witnesses = data.GetWitnesses(); - tx.VerifyStateIndependent(TestProtocolSettings.Default).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, tx.VerifyStateIndependent(TestProtocolSettings.Default)); // Different hash @@ -1192,7 +1191,7 @@ public void Test_VerifyStateIndependent() VerificationScript = walletB.GetAccounts().First().Contract.Script, InvocationScript = tx.Witnesses[0].InvocationScript.ToArray() }; - tx.VerifyStateIndependent(TestProtocolSettings.Default).Should().Be(VerifyResult.Invalid); + Assert.AreEqual(VerifyResult.Invalid, tx.VerifyStateIndependent(TestProtocolSettings.Default)); } [TestMethod] @@ -1224,10 +1223,10 @@ public void Test_VerifyStateDependent() balance.GetInteroperable().Balance = tx.NetworkFee; var conflicts = new List(); - tx.VerifyStateDependent(ProtocolSettings.Default, snapshotCache, new TransactionVerificationContext(), conflicts).Should().Be(VerifyResult.Invalid); + Assert.AreEqual(VerifyResult.Invalid, tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, new TransactionVerificationContext(), conflicts)); balance.GetInteroperable().Balance = 0; tx.SystemFee = 10; - tx.VerifyStateDependent(ProtocolSettings.Default, snapshotCache, new TransactionVerificationContext(), conflicts).Should().Be(VerifyResult.InsufficientFunds); + Assert.AreEqual(VerifyResult.InsufficientFunds, tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, new TransactionVerificationContext(), conflicts)); var walletA = TestUtils.GenerateTestWallet("123"); var walletB = TestUtils.GenerateTestWallet("123"); @@ -1272,7 +1271,7 @@ public void Test_VerifyStateDependent() Assert.IsTrue(data.Completed); tx.Witnesses = data.GetWitnesses(); - tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, new TransactionVerificationContext(), new List()).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, new TransactionVerificationContext(), new List())); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs index c4182a8b64..29bdc4f6dc 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -27,10 +26,10 @@ public class UT_VersionPayload public void SizeAndEndPoint_Get() { var test = new VersionPayload() { Capabilities = Array.Empty(), UserAgent = "neo3" }; - test.Size.Should().Be(22); + Assert.AreEqual(22, test.Size); test = VersionPayload.Create(123, 456, "neo3", new NodeCapability[] { new ServerCapability(NodeCapabilityType.TcpServer, 22) }); - test.Size.Should().Be(25); + Assert.AreEqual(25, test.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index 48de01e9c9..a02e4076db 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -37,7 +36,7 @@ public void TestSetup() [TestMethod] public void InvocationScript_Get() { - uut.InvocationScript.IsEmpty.Should().BeTrue(); + Assert.IsTrue(uut.InvocationScript.IsEmpty); } private static Witness PrepareDummyWitness(int pubKeys, int m) @@ -96,9 +95,9 @@ public void MaxSize_OK() // Check max size - witness.Size.Should().Be(1023); - witness.InvocationScript.GetVarSize().Should().Be(663); - witness.VerificationScript.GetVarSize().Should().Be(360); + Assert.AreEqual(1023, witness.Size); + Assert.AreEqual(663, witness.InvocationScript.GetVarSize()); + Assert.AreEqual(360, witness.VerificationScript.GetVarSize()); var copy = witness.ToArray().AsSerializable(); @@ -131,8 +130,8 @@ public void InvocationScript_Set() { byte[] dataArray = new byte[] { 0, 32, 32, 20, 32, 32 }; uut.InvocationScript = dataArray; - uut.InvocationScript.Length.Should().Be(6); - Assert.AreEqual(uut.InvocationScript.Span.ToHexString(), "002020142020"); + Assert.AreEqual(6, uut.InvocationScript.Length); + Assert.AreEqual("002020142020", uut.InvocationScript.Span.ToHexString()); } private static void SetupWitnessWithValues(Witness uut, int lenghtInvocation, int lengthVerification, out byte[] invocationScript, out byte[] verificationScript) @@ -148,7 +147,7 @@ public void SizeWitness_Small_Arrary() { SetupWitnessWithValues(uut, 252, 253, out _, out _); - uut.Size.Should().Be(509); // (1 + 252*1) + (1 + 2 + 253*1) + Assert.AreEqual(509, uut.Size); // (1 + 252*1) + (1 + 2 + 253*1) } [TestMethod] @@ -156,7 +155,7 @@ public void SizeWitness_Large_Arrary() { SetupWitnessWithValues(uut, 65535, 65536, out _, out _); - uut.Size.Should().Be(131079); // (1 + 2 + 65535*1) + (1 + 4 + 65536*1) + Assert.AreEqual(131079, uut.Size); // (1 + 2 + 65535*1) + (1 + 4 + 65536*1) } [TestMethod] @@ -167,8 +166,8 @@ public void ToJson() JObject json = uut.ToJson(); Assert.IsTrue(json.ContainsProperty("invocation")); Assert.IsTrue(json.ContainsProperty("verification")); - Assert.AreEqual(json["invocation"].AsString(), "ICA="); - Assert.AreEqual(json["verification"].AsString(), "ICAg"); + Assert.AreEqual("ICA=", json["invocation"].AsString()); + Assert.AreEqual("ICAg", json["verification"].AsString()); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/UT_ChannelsConfig.cs b/tests/Neo.UnitTests/Network/P2P/UT_ChannelsConfig.cs index 12c6244e08..9d4d8d83b0 100644 --- a/tests/Neo.UnitTests/Network/P2P/UT_ChannelsConfig.cs +++ b/tests/Neo.UnitTests/Network/P2P/UT_ChannelsConfig.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Network.P2P; using System.Net; @@ -24,22 +23,22 @@ public void CreateTest() { var config = new ChannelsConfig(); - config.Tcp.Should().BeNull(); - config.MinDesiredConnections.Should().Be(10); - config.MaxConnections.Should().Be(40); - config.MaxConnectionsPerAddress.Should().Be(3); + Assert.IsNull(config.Tcp); + Assert.AreEqual(10, config.MinDesiredConnections); + Assert.AreEqual(40, config.MaxConnections); + Assert.AreEqual(3, config.MaxConnectionsPerAddress); - config.Tcp = config.Tcp = new IPEndPoint(IPAddress.Any, 21); + config.Tcp = new IPEndPoint(IPAddress.Any, 21); config.MaxConnectionsPerAddress++; config.MaxConnections++; config.MinDesiredConnections++; - config.Tcp.Should().BeSameAs(config.Tcp); - config.Tcp.Address.Should().BeEquivalentTo(IPAddress.Any); - config.Tcp.Port.Should().Be(21); - config.MinDesiredConnections.Should().Be(11); - config.MaxConnections.Should().Be(41); - config.MaxConnectionsPerAddress.Should().Be(4); + Assert.AreSame(config.Tcp, config.Tcp); + CollectionAssert.AreEqual(IPAddress.Any.GetAddressBytes(), config.Tcp.Address.GetAddressBytes()); + Assert.AreEqual(21, config.Tcp.Port); + Assert.AreEqual(11, config.MinDesiredConnections); + Assert.AreEqual(41, config.MaxConnections); + Assert.AreEqual(4, config.MaxConnectionsPerAddress); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/UT_Message.cs b/tests/Neo.UnitTests/Network/P2P/UT_Message.cs index 838da40989..690f1bae85 100644 --- a/tests/Neo.UnitTests/Network/P2P/UT_Message.cs +++ b/tests/Neo.UnitTests/Network/P2P/UT_Message.cs @@ -10,7 +10,6 @@ // modifications are permitted. using Akka.IO; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -34,13 +33,13 @@ public void Serialize_Deserialize() var copy = buffer.AsSerializable(); var payloadCopy = (PingPayload)copy.Payload; - copy.Command.Should().Be(msg.Command); - copy.Flags.Should().Be(msg.Flags); - msg.Size.Should().Be(payload.Size + 3); + Assert.AreEqual(msg.Command, copy.Command); + Assert.AreEqual(msg.Flags, copy.Flags); + Assert.AreEqual(payload.Size + 3, msg.Size); - payloadCopy.LastBlockIndex.Should().Be(payload.LastBlockIndex); - payloadCopy.Nonce.Should().Be(payload.Nonce); - payloadCopy.Timestamp.Should().Be(payload.Timestamp); + Assert.AreEqual(payload.LastBlockIndex, payloadCopy.LastBlockIndex); + Assert.AreEqual(payload.Nonce, payloadCopy.Nonce); + Assert.AreEqual(payload.Timestamp, payloadCopy.Timestamp); } [TestMethod] @@ -50,9 +49,9 @@ public void Serialize_Deserialize_WithoutPayload() var buffer = msg.ToArray(); var copy = buffer.AsSerializable(); - copy.Command.Should().Be(msg.Command); - copy.Flags.Should().Be(msg.Flags); - copy.Payload.Should().Be(null); + Assert.AreEqual(msg.Command, copy.Command); + Assert.AreEqual(msg.Flags, copy.Flags); + Assert.IsNull(copy.Payload); } [TestMethod] @@ -62,7 +61,7 @@ public void ToArray() var msg = Message.Create(MessageCommand.Ping, payload); _ = msg.ToArray(); - msg.Size.Should().Be(payload.Size + 3); + Assert.AreEqual(payload.Size + 3, msg.Size); } [TestMethod] @@ -75,14 +74,14 @@ public void Serialize_Deserialize_ByteString() var payloadCopy = (PingPayload)copy.Payload; - copy.Command.Should().Be(msg.Command); - copy.Flags.Should().Be(msg.Flags); + Assert.AreEqual(msg.Command, copy.Command); + Assert.AreEqual(msg.Flags, copy.Flags); - payloadCopy.LastBlockIndex.Should().Be(payload.LastBlockIndex); - payloadCopy.Nonce.Should().Be(payload.Nonce); - payloadCopy.Timestamp.Should().Be(payload.Timestamp); + Assert.AreEqual(payload.LastBlockIndex, payloadCopy.LastBlockIndex); + Assert.AreEqual(payload.Nonce, payloadCopy.Nonce); + Assert.AreEqual(payload.Timestamp, payloadCopy.Timestamp); - buffer.Count.Should().Be(length); + Assert.AreEqual(length, buffer.Count); } [TestMethod] @@ -99,11 +98,11 @@ public void Serialize_Deserialize_WithoutPayload_ByteString() var buffer = ByteString.CopyFrom(msg.ToArray()); var length = Message.TryDeserialize(buffer, out var copy); - copy.Command.Should().Be(msg.Command); - copy.Flags.Should().Be(msg.Flags); - copy.Payload.Should().Be(null); + Assert.AreEqual(msg.Command, copy.Command); + Assert.AreEqual(msg.Flags, copy.Flags); + Assert.IsNull(copy.Payload); - buffer.Count.Should().Be(length); + Assert.AreEqual(length, buffer.Count); } [TestMethod] @@ -169,7 +168,7 @@ public void Compression() var msg = Message.Create(MessageCommand.Transaction, payload); var buffer = msg.ToArray(); - buffer.Length.Should().Be(56); + Assert.AreEqual(56, buffer.Length); byte[] script = new byte[100]; Array.Fill(script, (byte)OpCode.PUSH2); @@ -177,13 +176,13 @@ public void Compression() msg = Message.Create(MessageCommand.Transaction, payload); buffer = msg.ToArray(); - buffer.Length.Should().Be(30); - msg.Flags.HasFlag(MessageFlags.Compressed).Should().BeTrue(); + Assert.AreEqual(30, buffer.Length); + Assert.IsTrue(msg.Flags.HasFlag(MessageFlags.Compressed)); _ = Message.TryDeserialize(ByteString.CopyFrom(msg.ToArray()), out var copy); Assert.IsNotNull(copy); - copy.Flags.HasFlag(MessageFlags.Compressed).Should().BeTrue(); + Assert.IsTrue(copy.Flags.HasFlag(MessageFlags.Compressed)); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/UT_RemoteNode.cs b/tests/Neo.UnitTests/Network/P2P/UT_RemoteNode.cs index 0cd60e0917..4b55e0610f 100644 --- a/tests/Neo.UnitTests/Network/P2P/UT_RemoteNode.cs +++ b/tests/Neo.UnitTests/Network/P2P/UT_RemoteNode.cs @@ -11,7 +11,6 @@ using Akka.IO; using Akka.TestKit.Xunit2; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -88,7 +87,7 @@ public void RemoteNode_Test_Accept_IfSameNetwork() var verackMessage = connectionTestProbe.ExpectMsg(); //Verack - verackMessage.Data.Count.Should().Be(3); + Assert.AreEqual(3, verackMessage.Data.Count); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/UT_RemoteNodeMailbox.cs b/tests/Neo.UnitTests/Network/P2P/UT_RemoteNodeMailbox.cs index 8f11331381..7f5e76ae52 100644 --- a/tests/Neo.UnitTests/Network/P2P/UT_RemoteNodeMailbox.cs +++ b/tests/Neo.UnitTests/Network/P2P/UT_RemoteNodeMailbox.cs @@ -11,7 +11,6 @@ using Akka.IO; using Akka.TestKit.Xunit2; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO; using Neo.Network.P2P; @@ -49,45 +48,45 @@ public void RemoteNode_Test_IsHighPriority() ISerializable s = null; //handshaking - uut.IsHighPriority(Message.Create(MessageCommand.Version, s)).Should().Be(true); - uut.IsHighPriority(Message.Create(MessageCommand.Verack, s)).Should().Be(true); + Assert.IsTrue(uut.IsHighPriority(Message.Create(MessageCommand.Version, s))); + Assert.IsTrue(uut.IsHighPriority(Message.Create(MessageCommand.Verack, s))); //connectivity - uut.IsHighPriority(Message.Create(MessageCommand.GetAddr, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Addr, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Ping, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Pong, s)).Should().Be(false); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.GetAddr, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Addr, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Ping, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Pong, s))); //synchronization - uut.IsHighPriority(Message.Create(MessageCommand.GetHeaders, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Headers, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.GetBlocks, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Mempool, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Inv, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.GetData, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.NotFound, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Transaction, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Block, s)).Should().Be(false); - uut.IsHighPriority(Message.Create(MessageCommand.Extensible, s)).Should().Be(true); - uut.IsHighPriority(Message.Create(MessageCommand.Reject, s)).Should().Be(false); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.GetHeaders, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Headers, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.GetBlocks, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Mempool, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Inv, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.GetData, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.NotFound, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Transaction, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Block, s))); + Assert.IsTrue(uut.IsHighPriority(Message.Create(MessageCommand.Extensible, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.Reject, s))); //SPV protocol - uut.IsHighPriority(Message.Create(MessageCommand.FilterLoad, s)).Should().Be(true); - uut.IsHighPriority(Message.Create(MessageCommand.FilterAdd, s)).Should().Be(true); - uut.IsHighPriority(Message.Create(MessageCommand.FilterClear, s)).Should().Be(true); - uut.IsHighPriority(Message.Create(MessageCommand.MerkleBlock, s)).Should().Be(false); + Assert.IsTrue(uut.IsHighPriority(Message.Create(MessageCommand.FilterLoad, s))); + Assert.IsTrue(uut.IsHighPriority(Message.Create(MessageCommand.FilterAdd, s))); + Assert.IsTrue(uut.IsHighPriority(Message.Create(MessageCommand.FilterClear, s))); + Assert.IsFalse(uut.IsHighPriority(Message.Create(MessageCommand.MerkleBlock, s))); //others - uut.IsHighPriority(Message.Create(MessageCommand.Alert, s)).Should().Be(true); + Assert.IsTrue(uut.IsHighPriority(Message.Create(MessageCommand.Alert, s))); // high priority commands - uut.IsHighPriority(new Tcp.ConnectionClosed()).Should().Be(true); - uut.IsHighPriority(new Connection.Close()).Should().Be(true); - uut.IsHighPriority(new Connection.Ack()).Should().Be(true); + Assert.IsTrue(uut.IsHighPriority(new Tcp.ConnectionClosed())); + Assert.IsTrue(uut.IsHighPriority(new Connection.Close())); + Assert.IsTrue(uut.IsHighPriority(new Connection.Ack())); // any random object should not have priority object obj = null; - uut.IsHighPriority(obj).Should().Be(false); + Assert.IsFalse(uut.IsHighPriority(obj)); } public void ProtocolHandlerMailbox_Test_ShallDrop() @@ -100,101 +99,101 @@ public void ProtocolHandlerMailbox_Test_ShallDrop() // any random object (non Message) should be dropped object obj = null; - uut.ShallDrop(obj, emptyQueue).Should().Be(true); + Assert.IsTrue(uut.ShallDrop(obj, emptyQueue)); //handshaking // Version (no drop) msg = Message.Create(MessageCommand.Version, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // Verack (no drop) msg = Message.Create(MessageCommand.Verack, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); //connectivity // GetAddr (drop) msg = Message.Create(MessageCommand.GetAddr, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsTrue(uut.ShallDrop(msg, new object[] { msg })); // Addr (no drop) msg = Message.Create(MessageCommand.Addr, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // Ping (no drop) msg = Message.Create(MessageCommand.Ping, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // Pong (no drop) msg = Message.Create(MessageCommand.Pong, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); //synchronization // GetHeaders (drop) msg = Message.Create(MessageCommand.GetHeaders, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsTrue(uut.ShallDrop(msg, new object[] { msg })); // Headers (no drop) msg = Message.Create(MessageCommand.Headers, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // GetBlocks (drop) msg = Message.Create(MessageCommand.GetBlocks, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsTrue(uut.ShallDrop(msg, new object[] { msg })); // Mempool (drop) msg = Message.Create(MessageCommand.Mempool, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(true); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsTrue(uut.ShallDrop(msg, new object[] { msg })); // Inv (no drop) msg = Message.Create(MessageCommand.Inv, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // NotFound (no drop) msg = Message.Create(MessageCommand.NotFound, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // Transaction (no drop) msg = Message.Create(MessageCommand.Transaction, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // Block (no drop) msg = Message.Create(MessageCommand.Block, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // Consensus (no drop) msg = Message.Create(MessageCommand.Extensible, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // Reject (no drop) msg = Message.Create(MessageCommand.Reject, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); //SPV protocol // FilterLoad (no drop) msg = Message.Create(MessageCommand.FilterLoad, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // FilterAdd (no drop) msg = Message.Create(MessageCommand.FilterAdd, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // FilterClear (no drop) msg = Message.Create(MessageCommand.FilterClear, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); // MerkleBlock (no drop) msg = Message.Create(MessageCommand.MerkleBlock, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); //others // Alert (no drop) msg = Message.Create(MessageCommand.Alert, s); - uut.ShallDrop(msg, emptyQueue).Should().Be(false); - uut.ShallDrop(msg, new object[] { msg }).Should().Be(false); + Assert.IsFalse(uut.ShallDrop(msg, emptyQueue)); + Assert.IsFalse(uut.ShallDrop(msg, new object[] { msg })); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs b/tests/Neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs index 626c3df2ab..085b4572d5 100644 --- a/tests/Neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs +++ b/tests/Neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs @@ -10,7 +10,6 @@ // modifications are permitted. using Akka.TestKit.Xunit2; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Network.P2P; using Neo.Network.P2P.Payloads; @@ -44,21 +43,21 @@ public void TestSetup() public void TaskManager_Test_IsHighPriority() { // high priority - uut.IsHighPriority(new TaskManager.Register()).Should().Be(true); - uut.IsHighPriority(new TaskManager.RestartTasks()).Should().Be(true); + Assert.IsTrue(uut.IsHighPriority(new TaskManager.Register())); + Assert.IsTrue(uut.IsHighPriority(new TaskManager.RestartTasks())); // low priority // -> NewTasks: generic InvPayload - uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload() }).Should().Be(false); + Assert.IsFalse(uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload() })); // high priority // -> NewTasks: payload Block or Consensus - uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Block } }).Should().Be(true); - uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Extensible } }).Should().Be(true); + Assert.IsTrue(uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Block } })); + Assert.IsTrue(uut.IsHighPriority(new TaskManager.NewTasks { Payload = new InvPayload { Type = InventoryType.Extensible } })); // any random object should not have priority object obj = null; - uut.IsHighPriority(obj).Should().Be(false); + Assert.IsFalse(uut.IsHighPriority(obj)); } } } diff --git a/tests/Neo.UnitTests/Network/P2P/UT_TaskSession.cs b/tests/Neo.UnitTests/Network/P2P/UT_TaskSession.cs index 0aabd51ea3..d8b90ceac6 100644 --- a/tests/Neo.UnitTests/Network/P2P/UT_TaskSession.cs +++ b/tests/Neo.UnitTests/Network/P2P/UT_TaskSession.cs @@ -14,7 +14,6 @@ using Neo.Network.P2P.Capabilities; using Neo.Network.P2P.Payloads; using System; -using Xunit.Sdk; namespace Neo.UnitTests.Network.P2P { diff --git a/tests/Neo.UnitTests/Persistence/UT_CloneCache.cs b/tests/Neo.UnitTests/Persistence/UT_CloneCache.cs index c6ae3d6ba5..1e56a6b425 100644 --- a/tests/Neo.UnitTests/Persistence/UT_CloneCache.cs +++ b/tests/Neo.UnitTests/Persistence/UT_CloneCache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.Persistence; @@ -48,14 +47,14 @@ public void Init() [TestMethod] public void TestCloneCache() { - clonedCache.Should().NotBeNull(); + Assert.IsNotNull(clonedCache); } [TestMethod] public void TestAddInternal() { clonedCache.Add(key1, value1); - clonedCache[key1].Should().Be(value1); + Assert.AreEqual(value1, clonedCache[key1]); clonedCache.Commit(); Assert.IsTrue(myDataCache[key1].Value.Span.SequenceEqual(value1.Value.Span)); @@ -68,8 +67,8 @@ public void TestDeleteInternal() clonedCache.Delete(key1); // trackable.State = TrackState.Deleted clonedCache.Commit(); - clonedCache.TryGet(key1).Should().BeNull(); - myDataCache.TryGet(key1).Should().BeNull(); + Assert.IsNull(clonedCache.TryGet(key1)); + Assert.IsNull(myDataCache.TryGet(key1)); } [TestMethod] @@ -80,22 +79,22 @@ public void TestFindInternal() store.Put(key3.ToArray(), value3.ToArray()); var items = clonedCache.Find(key1.ToArray()); - items.ElementAt(0).Key.Should().Be(key1); - items.ElementAt(0).Value.Should().Be(value1); - items.Count().Should().Be(1); + Assert.AreEqual(key1, items.ElementAt(0).Key); + Assert.AreEqual(value1, items.ElementAt(0).Value); + Assert.AreEqual(1, items.Count()); items = clonedCache.Find(key2.ToArray()); - items.ElementAt(0).Key.Should().Be(key2); - value2.EqualsTo(items.ElementAt(0).Value).Should().BeTrue(); - items.Count().Should().Be(1); + Assert.AreEqual(key2, items.ElementAt(0).Key); + Assert.IsTrue(value2.EqualsTo(items.ElementAt(0).Value)); + Assert.AreEqual(1, items.Count()); items = clonedCache.Find(key3.ToArray()); - items.ElementAt(0).Key.Should().Be(key3); - value3.EqualsTo(items.ElementAt(0).Value).Should().BeTrue(); - items.Count().Should().Be(1); + Assert.AreEqual(key3, items.ElementAt(0).Key); + Assert.IsTrue(value3.EqualsTo(items.ElementAt(0).Value)); + Assert.AreEqual(1, items.Count()); items = clonedCache.Find(key4.ToArray()); - items.Count().Should().Be(0); + Assert.AreEqual(0, items.Count()); } [TestMethod] @@ -105,15 +104,15 @@ public void TestGetInternal() myDataCache.Add(key2, value2); store.Put(key3.ToArray(), value3.ToArray()); - value1.EqualsTo(clonedCache[key1]).Should().BeTrue(); - value2.EqualsTo(clonedCache[key2]).Should().BeTrue(); - value3.EqualsTo(clonedCache[key3]).Should().BeTrue(); + Assert.IsTrue(value1.EqualsTo(clonedCache[key1])); + Assert.IsTrue(value2.EqualsTo(clonedCache[key2])); + Assert.IsTrue(value3.EqualsTo(clonedCache[key3])); Action action = () => { var item = clonedCache[key4]; }; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -123,10 +122,10 @@ public void TestTryGetInternal() myDataCache.Add(key2, value2); store.Put(key3.ToArray(), value3.ToArray()); - value1.EqualsTo(clonedCache.TryGet(key1)).Should().BeTrue(); - value2.EqualsTo(clonedCache.TryGet(key2)).Should().BeTrue(); - value3.EqualsTo(clonedCache.TryGet(key3)).Should().BeTrue(); - clonedCache.TryGet(key4).Should().BeNull(); + Assert.IsTrue(value1.EqualsTo(clonedCache.TryGet(key1))); + Assert.IsTrue(value2.EqualsTo(clonedCache.TryGet(key2))); + Assert.IsTrue(value3.EqualsTo(clonedCache.TryGet(key3))); + Assert.IsNull(clonedCache.TryGet(key4)); } [TestMethod] @@ -146,10 +145,10 @@ public void TestUpdateInternal() StorageItem value_new_2 = new(Encoding.UTF8.GetBytes("value_new_2")); StorageItem value_new_3 = new(Encoding.UTF8.GetBytes("value_new_3")); - value_new_1.EqualsTo(clonedCache[key1]).Should().BeTrue(); - value_new_2.EqualsTo(clonedCache[key2]).Should().BeTrue(); - value_new_3.EqualsTo(clonedCache[key3]).Should().BeTrue(); - value_new_2.EqualsTo(clonedCache[key2]).Should().BeTrue(); + Assert.IsTrue(value_new_1.EqualsTo(clonedCache[key1])); + Assert.IsTrue(value_new_2.EqualsTo(clonedCache[key2])); + Assert.IsTrue(value_new_3.EqualsTo(clonedCache[key3])); + Assert.IsTrue(value_new_2.EqualsTo(clonedCache[key2])); } [TestMethod] diff --git a/tests/Neo.UnitTests/Persistence/UT_DataCache.cs b/tests/Neo.UnitTests/Persistence/UT_DataCache.cs index aaf4c731d0..0c39ca4311 100644 --- a/tests/Neo.UnitTests/Persistence/UT_DataCache.cs +++ b/tests/Neo.UnitTests/Persistence/UT_DataCache.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -52,11 +51,11 @@ public void TestAccessByKey() myDataCache.Add(key1, value1); myDataCache.Add(key2, value2); - myDataCache[key1].EqualsTo(value1).Should().BeTrue(); + Assert.IsTrue(myDataCache[key1].EqualsTo(value1)); // case 2 read from inner store.Put(key3.ToArray(), value3.ToArray()); - myDataCache[key3].EqualsTo(value3).Should().BeTrue(); + Assert.IsTrue(myDataCache[key3].EqualsTo(value3)); } [TestMethod] @@ -66,7 +65,7 @@ public void TestAccessByNotFoundKey() { var item = myDataCache[key1]; }; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -79,17 +78,17 @@ public void TestAccessByDeletedKey() { var item = myDataCache[key1]; }; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] public void TestAdd() { myDataCache.Add(key1, value1); - myDataCache[key1].Should().Be(value1); + Assert.AreEqual(value1, myDataCache[key1]); Action action = () => myDataCache.Add(key1, value1); - action.Should().Throw(); + Assert.ThrowsException(action); store.Put(key2.ToArray(), value2.ToArray()); myDataCache.Delete(key2); @@ -98,7 +97,7 @@ public void TestAdd() Assert.AreEqual(TrackState.Changed, myDataCache.GetChangeSet().Where(u => u.Key.Equals(key2)).Select(u => u.State).FirstOrDefault()); action = () => myDataCache.Add(key2, value2); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -127,20 +126,20 @@ public void TestCommit() myDataCache.Commit(); Assert.AreEqual(0, myDataCache.GetChangeSet().Count()); - store.TryGet(key1.ToArray()).SequenceEqual(value1.ToArray()).Should().BeTrue(); - store.TryGet(key2.ToArray()).Should().BeNull(); - store.TryGet(key3.ToArray()).SequenceEqual(value4.ToArray()).Should().BeTrue(); + Assert.IsTrue(store.TryGet(key1.ToArray()).SequenceEqual(value1.ToArray())); + Assert.IsNull(store.TryGet(key2.ToArray())); + Assert.IsTrue(store.TryGet(key3.ToArray()).SequenceEqual(value4.ToArray())); - myDataCache.TryGet(key1).Value.ToArray().SequenceEqual(value1.ToArray()).Should().BeTrue(); + Assert.IsTrue(myDataCache.TryGet(key1).Value.ToArray().SequenceEqual(value1.ToArray())); // Though value is deleted from the store, the value can still be gotten from the snapshot cache. - myDataCache.TryGet(key2).Value.ToArray().SequenceEqual(value2.ToArray()).Should().BeTrue(); - myDataCache.TryGet(key3).Value.ToArray().SequenceEqual(value4.ToArray()).Should().BeTrue(); + Assert.IsTrue(myDataCache.TryGet(key2).Value.ToArray().SequenceEqual(value2.ToArray())); + Assert.IsTrue(myDataCache.TryGet(key3).Value.ToArray().SequenceEqual(value4.ToArray())); } [TestMethod] public void TestCreateSnapshot() { - myDataCache.CloneCache().Should().NotBeNull(); + Assert.IsNotNull(myDataCache.CloneCache()); } [TestMethod] @@ -154,11 +153,11 @@ public void TestDelete() myDataCache.Add(key1, value1); myDataCache.Delete(key1); - store.TryGet(key1.ToArray()).Should().BeNull(); + Assert.IsNull(store.TryGet(key1.ToArray())); myDataCache.Delete(key2); myDataCache.Commit(); - store.TryGet(key2.ToArray()).Should().BeNull(); + Assert.IsNull(store.TryGet(key2.ToArray())); } [TestMethod] @@ -172,52 +171,52 @@ public void TestFind() var k1 = key1.ToArray(); var items = myDataCache.Find(k1); - key1.Should().Be(items.ElementAt(0).Key); - value1.Should().Be(items.ElementAt(0).Value); - items.Count().Should().Be(1); + Assert.AreEqual(key1, items.ElementAt(0).Key); + Assert.AreEqual(value1, items.ElementAt(0).Value); + Assert.AreEqual(1, items.Count()); // null and empty with the forward direction -> finds everything. items = myDataCache.Find(null); - items.Count().Should().Be(4); + Assert.AreEqual(4, items.Count()); items = myDataCache.Find(new byte[] { }); - items.Count().Should().Be(4); + Assert.AreEqual(4, items.Count()); // null and empty with the backwards direction -> miserably fails. Action action = () => myDataCache.Find(null, SeekDirection.Backward); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => myDataCache.Find(new byte[] { }, SeekDirection.Backward); - action.Should().Throw(); + Assert.ThrowsException(action); items = myDataCache.Find(k1, SeekDirection.Backward); - key1.Should().Be(items.ElementAt(0).Key); - value1.Should().Be(items.ElementAt(0).Value); - items.Count().Should().Be(1); + Assert.AreEqual(key1, items.ElementAt(0).Key); + Assert.AreEqual(value1, items.ElementAt(0).Value); + Assert.AreEqual(1, items.Count()); var prefix = k1.Take(k1.Count() - 1).ToArray(); // Just the "key" part to match everything. items = myDataCache.Find(prefix); - items.Count().Should().Be(4); - key1.Should().Be(items.ElementAt(0).Key); - value1.Should().Be(items.ElementAt(0).Value); - key2.Should().Be(items.ElementAt(1).Key); - value2.Should().Be(items.ElementAt(1).Value); - key3.Should().Be(items.ElementAt(2).Key); - value3.EqualsTo(items.ElementAt(2).Value).Should().BeTrue(); - key4.Should().Be(items.ElementAt(3).Key); - value4.EqualsTo(items.ElementAt(3).Value).Should().BeTrue(); + Assert.AreEqual(4, items.Count()); + Assert.AreEqual(key1, items.ElementAt(0).Key); + Assert.AreEqual(value1, items.ElementAt(0).Value); + Assert.AreEqual(key2, items.ElementAt(1).Key); + Assert.AreEqual(value2, items.ElementAt(1).Value); + Assert.AreEqual(key3, items.ElementAt(2).Key); + Assert.IsTrue(items.ElementAt(2).Value.EqualsTo(value3)); + Assert.AreEqual(key4, items.ElementAt(3).Key); + Assert.IsTrue(items.ElementAt(3).Value.EqualsTo(value4)); items = myDataCache.Find(prefix, SeekDirection.Backward); - items.Count().Should().Be(4); - key4.Should().Be(items.ElementAt(0).Key); - value4.EqualsTo(items.ElementAt(0).Value).Should().BeTrue(); - key3.Should().Be(items.ElementAt(1).Key); - value3.EqualsTo(items.ElementAt(1).Value).Should().BeTrue(); - key2.Should().Be(items.ElementAt(2).Key); - value2.Should().Be(items.ElementAt(2).Value); - key1.Should().Be(items.ElementAt(3).Key); - value1.Should().Be(items.ElementAt(3).Value); + Assert.AreEqual(4, items.Count()); + Assert.AreEqual(key4, items.ElementAt(0).Key); + Assert.IsTrue(items.ElementAt(0).Value.EqualsTo(value4)); + Assert.AreEqual(key3, items.ElementAt(1).Key); + Assert.IsTrue(items.ElementAt(1).Value.EqualsTo(value3)); + Assert.AreEqual(key2, items.ElementAt(2).Key); + Assert.AreEqual(value2, items.ElementAt(2).Value); + Assert.AreEqual(key1, items.ElementAt(3).Key); + Assert.AreEqual(value1, items.ElementAt(3).Value); items = myDataCache.Find(key5.ToArray()); - items.Count().Should().Be(0); + Assert.AreEqual(0, items.Count()); } [TestMethod] @@ -230,14 +229,14 @@ public void TestSeek() store.Put(key4.ToArray(), value4.ToArray()); var items = myDataCache.Seek(key3.ToArray(), SeekDirection.Backward).ToArray(); - key3.Should().Be(items[0].Key); - value3.EqualsTo(items[0].Value).Should().BeTrue(); - key2.Should().Be(items[1].Key); - value2.EqualsTo(items[1].Value).Should().BeTrue(); - items.Length.Should().Be(3); + Assert.AreEqual(key3, items[0].Key); + Assert.IsTrue(items[0].Value.EqualsTo(value3)); + Assert.AreEqual(key2, items[1].Key); + Assert.IsTrue(items[1].Value.EqualsTo(value2)); + Assert.AreEqual(3, items.Length); items = myDataCache.Seek(key5.ToArray(), SeekDirection.Forward).ToArray(); - items.Length.Should().Be(0); + Assert.AreEqual(0, items.Length); } [TestMethod] @@ -252,11 +251,11 @@ public void TestFindRange() myDataCache.Add(key2, value2); var items = myDataCache.FindRange(key3.ToArray(), key5.ToArray()).ToArray(); - key3.Should().Be(items[0].Key); - value3.EqualsTo(items[0].Value).Should().BeTrue(); - key4.Should().Be(items[1].Key); - value4.EqualsTo(items[1].Value).Should().BeTrue(); - items.Length.Should().Be(2); + Assert.AreEqual(key3, items[0].Key); + Assert.IsTrue(items[0].Value.EqualsTo(value3)); + Assert.AreEqual(key4, items[1].Key); + Assert.IsTrue(items[1].Value.EqualsTo(value4)); + Assert.AreEqual(2, items.Length); // case 2 Need to sort the cache of myDataCache @@ -269,11 +268,11 @@ public void TestFindRange() myDataCache.Add(key2, value2); items = myDataCache.FindRange(key3.ToArray(), key5.ToArray()).ToArray(); - key3.Should().Be(items[0].Key); - value3.EqualsTo(items[0].Value).Should().BeTrue(); - key4.Should().Be(items[1].Key); - value4.EqualsTo(items[1].Value).Should().BeTrue(); - items.Length.Should().Be(2); + Assert.AreEqual(key3, items[0].Key); + Assert.IsTrue(items[0].Value.EqualsTo(value3)); + Assert.AreEqual(key4, items[1].Key); + Assert.IsTrue(items[1].Value.EqualsTo(value4)); + Assert.AreEqual(2, items.Length); // case 3 FindRange by Backward @@ -287,11 +286,11 @@ public void TestFindRange() myDataCache.Add(key2, value2); items = myDataCache.FindRange(key5.ToArray(), key3.ToArray(), SeekDirection.Backward).ToArray(); - key5.Should().Be(items[0].Key); - value5.EqualsTo(items[0].Value).Should().BeTrue(); - key4.Should().Be(items[1].Key); - value4.EqualsTo(items[1].Value).Should().BeTrue(); - items.Length.Should().Be(2); + Assert.AreEqual(key5, items[0].Key); + Assert.IsTrue(items[0].Value.EqualsTo(value5)); + Assert.AreEqual(key4, items[1].Key); + Assert.IsTrue(items[1].Value.EqualsTo(value4)); + Assert.AreEqual(2, items.Length); } [TestMethod] @@ -316,10 +315,10 @@ public void TestGetChangeSet() i++; StorageKey key = new() { Id = 0, Key = Encoding.UTF8.GetBytes("key" + i) }; StorageItem value = new(Encoding.UTF8.GetBytes("value" + i)); - key.Should().Be(item.Key); - value.EqualsTo(item.Item).Should().BeTrue(); + Assert.AreEqual(key, item.Key); + Assert.IsTrue(value.EqualsTo(item.Item)); } - i.Should().Be(4); + Assert.AreEqual(4, i); } [TestMethod] @@ -337,10 +336,10 @@ public void TestGetAndChange() StorageItem value_bk_3 = new(Encoding.UTF8.GetBytes("value_bk_3")); StorageItem value_bk_4 = new(Encoding.UTF8.GetBytes("value_bk_4")); - myDataCache.GetAndChange(key1, () => value_bk_1).EqualsTo(value1).Should().BeTrue(); - myDataCache.GetAndChange(key2, () => value_bk_2).EqualsTo(value2).Should().BeTrue(); - myDataCache.GetAndChange(key3, () => value_bk_3).EqualsTo(value_bk_3).Should().BeTrue(); - myDataCache.GetAndChange(key4, () => value_bk_4).EqualsTo(value_bk_4).Should().BeTrue(); + Assert.IsTrue(myDataCache.GetAndChange(key1, () => value_bk_1).EqualsTo(value1)); + Assert.IsTrue(myDataCache.GetAndChange(key2, () => value_bk_2).EqualsTo(value2)); + Assert.IsTrue(myDataCache.GetAndChange(key3, () => value_bk_3).EqualsTo(value_bk_3)); + Assert.IsTrue(myDataCache.GetAndChange(key4, () => value_bk_4).EqualsTo(value_bk_4)); } [TestMethod] @@ -358,10 +357,10 @@ public void TestGetOrAdd() StorageItem value_bk_3 = new(Encoding.UTF8.GetBytes("value_bk_3")); StorageItem value_bk_4 = new(Encoding.UTF8.GetBytes("value_bk_4")); - myDataCache.GetOrAdd(key1, () => value_bk_1).EqualsTo(value1).Should().BeTrue(); - myDataCache.GetOrAdd(key2, () => value_bk_2).EqualsTo(value2).Should().BeTrue(); - myDataCache.GetOrAdd(key3, () => value_bk_3).EqualsTo(value_bk_3).Should().BeTrue(); - myDataCache.GetOrAdd(key4, () => value_bk_4).EqualsTo(value_bk_4).Should().BeTrue(); + Assert.IsTrue(myDataCache.GetOrAdd(key1, () => value_bk_1).EqualsTo(value1)); + Assert.IsTrue(myDataCache.GetOrAdd(key2, () => value_bk_2).EqualsTo(value2)); + Assert.IsTrue(myDataCache.GetOrAdd(key3, () => value_bk_3).EqualsTo(value_bk_3)); + Assert.IsTrue(myDataCache.GetOrAdd(key4, () => value_bk_4).EqualsTo(value_bk_4)); } [TestMethod] @@ -374,9 +373,9 @@ public void TestTryGet() myDataCache.Delete(key3); Assert.AreEqual(TrackState.Deleted, myDataCache.GetChangeSet().Where(u => u.Key.Equals(key3)).Select(u => u.State).FirstOrDefault()); - myDataCache.TryGet(key1).EqualsTo(value1).Should().BeTrue(); - myDataCache.TryGet(key2).EqualsTo(value2).Should().BeTrue(); - myDataCache.TryGet(key3).Should().BeNull(); + Assert.IsTrue(myDataCache.TryGet(key1).EqualsTo(value1)); + Assert.IsTrue(myDataCache.TryGet(key2).EqualsTo(value2)); + Assert.IsNull(myDataCache.TryGet(key3)); } [TestMethod] @@ -391,18 +390,18 @@ public void TestFindInvalid() store.Put(key4.ToArray(), value3.ToArray()); var items = myDataCache.Find().GetEnumerator(); - items.MoveNext().Should().Be(true); - items.Current.Key.Should().Be(key1); + items.MoveNext(); + Assert.AreEqual(key1, items.Current.Key); myDataCache.TryGet(key3); // GETLINE - items.MoveNext().Should().Be(true); - items.Current.Key.Should().Be(key2); - items.MoveNext().Should().Be(true); - items.Current.Key.Should().Be(key3); - items.MoveNext().Should().Be(true); - items.Current.Key.Should().Be(key4); - items.MoveNext().Should().Be(false); + items.MoveNext(); + Assert.AreEqual(key2, items.Current.Key); + items.MoveNext(); + Assert.AreEqual(key3, items.Current.Key); + items.MoveNext(); + Assert.AreEqual(key4, items.Current.Key); + Assert.IsFalse(items.MoveNext()); } } } diff --git a/tests/Neo.UnitTests/Plugins/UT_Plugin.cs b/tests/Neo.UnitTests/Plugins/UT_Plugin.cs index 73167e13ed..fcbb5afd0b 100644 --- a/tests/Neo.UnitTests/Plugins/UT_Plugin.cs +++ b/tests/Neo.UnitTests/Plugins/UT_Plugin.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Ledger; using Neo.Plugins; @@ -72,22 +71,28 @@ public void TestGetConfigFile() { var pp = new TestPlugin(); var file = pp.ConfigFile; - file.EndsWith("config.json").Should().BeTrue(); + Assert.IsTrue(file.EndsWith("config.json")); } [TestMethod] public void TestGetName() { var pp = new TestPlugin(); - pp.Name.Should().Be("TestPlugin"); + Assert.AreEqual("TestPlugin", pp.Name); } [TestMethod] public void TestGetVersion() { var pp = new TestPlugin(); - Action action = () => pp.Version.ToString(); - action.Should().NotThrow(); + try + { + _ = pp.Version.ToString(); + } + catch (Exception ex) + { + Assert.Fail($"Should not throw but threw {ex}"); + } } [TestMethod] @@ -96,10 +101,10 @@ public void TestSendMessage() lock (s_locker) { Plugin.Plugins.Clear(); - Plugin.SendMessage("hey1").Should().BeFalse(); + Assert.IsFalse(Plugin.SendMessage("hey1")); var lp = new TestPlugin(); - Plugin.SendMessage("hey2").Should().BeTrue(); + Assert.IsTrue(Plugin.SendMessage("hey2")); } } @@ -107,7 +112,7 @@ public void TestSendMessage() public void TestGetConfiguration() { var pp = new TestPlugin(); - pp.TestGetConfiguration().Key.Should().Be("PluginConfiguration"); + Assert.AreEqual("PluginConfiguration", pp.TestGetConfiguration().Key); } [TestMethod] diff --git a/tests/Neo.UnitTests/SmartContract/Iterators/UT_StorageIterator.cs b/tests/Neo.UnitTests/SmartContract/Iterators/UT_StorageIterator.cs index f2e4b6ad1c..d15a3f8ef8 100644 --- a/tests/Neo.UnitTests/SmartContract/Iterators/UT_StorageIterator.cs +++ b/tests/Neo.UnitTests/SmartContract/Iterators/UT_StorageIterator.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.SmartContract; using Neo.SmartContract.Iterators; @@ -27,8 +26,15 @@ public void TestGeneratorAndDispose() { StorageIterator storageIterator = new(new List<(StorageKey, StorageItem)>().GetEnumerator(), 0, FindOptions.None); Assert.IsNotNull(storageIterator); - Action action = () => storageIterator.Dispose(); - action.Should().NotThrow(); + try + { + storageIterator.Dispose(); + } + catch + { + Assert.Fail(); + } + } [TestMethod] diff --git a/tests/Neo.UnitTests/SmartContract/Manifest/UT_ContractPermissionDescriptor.cs b/tests/Neo.UnitTests/SmartContract/Manifest/UT_ContractPermissionDescriptor.cs index 862c5d2ee2..f3d4a8423e 100644 --- a/tests/Neo.UnitTests/SmartContract/Manifest/UT_ContractPermissionDescriptor.cs +++ b/tests/Neo.UnitTests/SmartContract/Manifest/UT_ContractPermissionDescriptor.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Json; using Neo.SmartContract.Manifest; @@ -59,7 +58,7 @@ public void TestContractManifestFromJson() { var json = JObject.Parse(System.IO.File.ReadAllText(item)) as JObject; var manifest = ContractManifest.FromJson(json); - manifest.ToJson().ToString().Should().Be(json.ToString()); + Assert.AreEqual(manifest.ToJson().ToString(), json.ToString()); } } diff --git a/tests/Neo.UnitTests/SmartContract/Manifest/UT_WildCardContainer.cs b/tests/Neo.UnitTests/SmartContract/Manifest/UT_WildCardContainer.cs index 6856f5323b..3ba2c41525 100644 --- a/tests/Neo.UnitTests/SmartContract/Manifest/UT_WildCardContainer.cs +++ b/tests/Neo.UnitTests/SmartContract/Manifest/UT_WildCardContainer.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Json; using Neo.SmartContract.Manifest; @@ -26,23 +25,22 @@ public class UT_WildCardContainer public void TestFromJson() { JString jstring = new JString("*"); - WildcardContainer s = WildcardContainer.FromJson(jstring, u => u.AsString()); - s.Should().BeEmpty(); + var s = WildcardContainer.FromJson(jstring, u => u.AsString()); + Assert.IsTrue(s.IsWildcard); + Assert.AreEqual(0, s.Count); jstring = new JString("hello world"); - Action action = () => WildcardContainer.FromJson(jstring, u => u.AsString()); - action.Should().Throw(); + Assert.ThrowsException(() => WildcardContainer.FromJson(jstring, u => u.AsString())); JObject alice = new JObject(); alice["name"] = "alice"; alice["age"] = 30; JArray jarray = new JArray { alice }; WildcardContainer r = WildcardContainer.FromJson(jarray, u => u.AsString()); - r[0].Should().Be("{\"name\":\"alice\",\"age\":30}"); + Assert.AreEqual("{\"name\":\"alice\",\"age\":30}", r[0]); JBoolean jbool = new JBoolean(); - action = () => WildcardContainer.FromJson(jbool, u => u.AsString()); - action.Should().Throw(); + Assert.ThrowsException(() => WildcardContainer.FromJson(jbool, u => u.AsString())); } [TestMethod] @@ -50,11 +48,11 @@ public void TestGetCount() { string[] s = new string[] { "hello", "world" }; WildcardContainer container = WildcardContainer.Create(s); - container.Count.Should().Be(2); + Assert.AreEqual(2, container.Count); s = null; container = WildcardContainer.Create(s); - container.Count.Should().Be(0); + Assert.AreEqual(0, container.Count); } [TestMethod] @@ -62,8 +60,8 @@ public void TestGetItem() { string[] s = new string[] { "hello", "world" }; WildcardContainer container = WildcardContainer.Create(s); - container[0].Should().Be("hello"); - container[1].Should().Be("world"); + Assert.AreEqual("hello", container[0]); + Assert.AreEqual("world", container[1]); } [TestMethod] @@ -73,7 +71,7 @@ public void TestGetEnumerator() IReadOnlyList rs = new string[0]; WildcardContainer container = WildcardContainer.Create(s); IEnumerator enumerator = container.GetEnumerator(); - enumerator.Should().Be(rs.GetEnumerator()); + Assert.AreEqual(rs.GetEnumerator(), enumerator); s = new string[] { "hello", "world" }; container = WildcardContainer.Create(s); @@ -81,7 +79,7 @@ public void TestGetEnumerator() foreach (string _ in s) { enumerator.MoveNext(); - enumerator.Current.Should().Be(_); + Assert.AreEqual(_, enumerator.Current); } } @@ -95,7 +93,7 @@ public void TestIEnumerableGetEnumerator() foreach (string _ in s) { enumerator.MoveNext(); - enumerator.Current.Should().Be(_); + Assert.AreEqual(_, enumerator.Current); } } } diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs index 15836c45d1..bc449d5c35 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Cryptography.BLS12_381; @@ -35,14 +34,13 @@ public class UT_CryptoLib { private readonly byte[] g1 = "97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb".ToLower().HexToBytes(); private readonly byte[] g2 = "93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8".ToLower().HexToBytes(); - private readonly byte[] gt = "0f41e58663bf08cf068672cbd01a7ec73baca4d72ca93544deff686bfd6df543d48eaa24afe47e1efde449383b67663104c581234d086a9902249b64728ffd21a189e87935a954051c7cdba7b3872629a4fafc05066245cb9108f0242d0fe3ef03350f55a7aefcd3c31b4fcb6ce5771cc6a0e9786ab5973320c806ad360829107ba810c5a09ffdd9be2291a0c25a99a211b8b424cd48bf38fcef68083b0b0ec5c81a93b330ee1a677d0d15ff7b984e8978ef48881e32fac91b93b47333e2ba5706fba23eb7c5af0d9f80940ca771b6ffd5857baaf222eb95a7d2809d61bfe02e1bfd1b68ff02f0b8102ae1c2d5d5ab1a19f26337d205fb469cd6bd15c3d5a04dc88784fbb3d0b2dbdea54d43b2b73f2cbb12d58386a8703e0f948226e47ee89d018107154f25a764bd3c79937a45b84546da634b8f6be14a8061e55cceba478b23f7dacaa35c8ca78beae9624045b4b601b2f522473d171391125ba84dc4007cfbf2f8da752f7c74185203fcca589ac719c34dffbbaad8431dad1c1fb597aaa5193502b86edb8857c273fa075a50512937e0794e1e65a7617c90d8bd66065b1fffe51d7a579973b1315021ec3c19934f1368bb445c7c2d209703f239689ce34c0378a68e72a6b3b216da0e22a5031b54ddff57309396b38c881c4c849ec23e87089a1c5b46e5110b86750ec6a532348868a84045483c92b7af5af689452eafabf1a8943e50439f1d59882a98eaa0170f1250ebd871fc0a92a7b2d83168d0d727272d441befa15c503dd8e90ce98db3e7b6d194f60839c508a84305aaca1789b6".ToLower().HexToBytes(); + private readonly byte[] gt = "0f41e58663bf08cf068672cbd01a7ec73baca4d72ca93544deff686bfd6df543d48eaa24afe47e1efde449383b67663104c581234d086a9902249b64728ffd21a189e87935a954051c7cdba7b3872629a4fafc05066245cb9108f0242d0fe3ef03350f55a7aefcd3c31b4fcB6ce5771cc6a0e9786ab5973320c806ad360829107ba810c5a09ffdd9be2291a0c25a99a211b8b424cd48bf38fcef68083b0b0ec5c81a93b330ee1a677d0d15ff7b984e8978ef48881e32fac91b93b47333e2ba5706fba23eb7c5af0d9f80940ca771b6ffd5857baaf222eb95a7d2809d61bfe02e1bfd1b68ff02f0b8102ae1c2d5d5ab1a19f26337d205fb469cd6bd15c3d5a04dc88784fbb3d0b2dbdea54d43b2b73f2cbb12d58386a8703e0f948226e47ee89d018107154f25a764bd3c79937a45b84546da634b8f6be14a8061e55cceba478b23f7dacaa35c8ca78beae9624045b4b601b2f522473d171391125ba84dc4007cfbf2f8da752f7c74185203fcca589ac719c34dffbbaad8431dad1c1fb597aaa5193502b86edb8857c273fa075a50512937e0794e1e65a7617c90d8bd66065b1fffe51d7a579973b1315021ec3c19934f1368bb445c7c2d209703f239689ce34c0378a68e72a6b3b216da0e22a5031b54ddff57309396b38c881c4c849ec23e87089a1c5b46e5110b86750ec6a532348868a84045483c92b7af5af689452eafabf1a8943e50439f1d59882a98eaa0170f1250ebd871fc0a92a7b2d83168d0d727272d441befa15c503dd8e90ce98db3e7b6d194f60839c508a84305aaca1789b6".ToLower().HexToBytes(); private readonly byte[] not_g1 = "8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".ToLower().HexToBytes(); private readonly byte[] not_g2 = - "8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - .ToLower().HexToBytes(); + "8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".ToLower().HexToBytes(); [TestMethod] public void TestG1() @@ -55,7 +53,7 @@ public void TestG1() engine.LoadScript(script.ToArray()); Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.GetInterface().ToCompressed().ToHexString().Should().Be("97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"); + Assert.AreEqual("97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", result.GetInterface().ToCompressed().ToHexString()); } [TestMethod] @@ -69,7 +67,7 @@ public void TestG2() engine.LoadScript(script.ToArray()); Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.GetInterface().ToCompressed().ToHexString().Should().Be("93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"); + Assert.AreEqual("93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8", result.GetInterface().ToCompressed().ToHexString()); } [TestMethod] @@ -113,7 +111,7 @@ public void TestBls12381Add() engine.LoadScript(script.ToArray()); Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.GetInterface().ToArray().ToHexString().Should().Be("079AB7B345EB23C944C957A36A6B74C37537163D4CBF73BAD9751DE1DD9C68EF72CB21447E259880F72A871C3EDA1B0C017F1C95CF79B22B459599EA57E613E00CB75E35DE1F837814A93B443C54241015AC9761F8FB20A44512FF5CFC04AC7F0F6B8B52B2B5D0661CBF232820A257B8C5594309C01C2A45E64C6A7142301E4FB36E6E16B5A85BD2E437599D103C3ACE06D8046C6B3424C4CD2D72CE98D279F2290A28A87E8664CB0040580D0C485F34DF45267F8C215DCBCD862787AB555C7E113286DEE21C9C63A458898BEB35914DC8DAAAC453441E7114B21AF7B5F47D559879D477CF2A9CBD5B40C86BECD071280900410BB2751D0A6AF0FE175DCF9D864ECAAC463C6218745B543F9E06289922434EE446030923A3E4C4473B4E3B1914081ABD33A78D31EB8D4C1BB3BAAB0529BB7BAF1103D848B4CEAD1A8E0AA7A7B260FBE79C67DBE41CA4D65BA8A54A72B61692A61CE5F4D7A093B2C46AA4BCA6C4A66CF873D405EBC9C35D8AA639763720177B23BEFFAF522D5E41D3C5310EA3331409CEBEF9EF393AA00F2AC64673675521E8FC8FDDAF90976E607E62A740AC59C3DDDF95A6DE4FBA15BEB30C43D4E3F803A3734DBEB064BF4BC4A03F945A4921E49D04AB8D45FD753A28B8FA082616B4B17BBCB685E455FF3BF8F60C3BD32A0C185EF728CF41A1B7B700B7E445F0B372BC29E370BC227D443C70AE9DBCF73FEE8ACEDBD317A286A53266562D817269C004FB0F149DD925D2C590A960936763E519C2B62E14C7759F96672CD852194325904197B0B19C6B528AB33566946AF39B".ToLower()); + Assert.AreEqual("079AB7B345EB23C944C957A36A6B74C37537163D4CBF73BAD9751DE1DD9C68EF72CB21447E259880F72A871C3EDA1B0C017F1C95CF79B22B459599EA57E613E00CB75E35DE1F837814A93B443C54241015AC9761F8FB20A44512FF5CFC04AC7F0F6B8B52B2B5D0661CBF232820A257B8C5594309C01C2A45E64C6A7142301E4FB36E6E16B5A85BD2E437599D103C3ACE06D8046C6B3424C4CD2D72CE98D279F2290A28A87E8664CB0040580D0C485F34DF45267F8C215DCBCD862787AB555C7E113286DEE21C9C63A458898BEB35914DC8DAAAC453441E7114B21AF7B5F47D559879D477CF2A9CBD5B40C86BECD071280900410BB2751D0A6AF0FE175DCF9D864ECAAC463C6218745B543F9E06289922434EE446030923A3E4C4473B4E3B1914081ABD33A78D31EB8D4C1BB3BAAB0529BB7BAF1103D848B4CEAD1A8E0AA7A7B260FBE79C67DBE41CA4D65BA8A54A72B61692A61CE5F4D7A093B2C46AA4BCA6C4A66CF873D405EBC9C35D8AA639763720177B23BEFFAF522D5E41D3C5310EA3331409CEBEF9EF393AA00F2AC64673675521E8FC8FDDAF90976E607E62A740AC59C3DDDF95A6DE4FBA15BEB30C43D4E3F803A3734DBEB064BF4BC4A03F945A4921E49D04AB8D45FD753A28B8FA082616B4B17BBCB685E455FF3BF8F60C3BD32A0C185EF728CF41A1B7B700B7E445F0B372BC29E370BC227D443C70AE9DBCF73FEE8ACEDBD317A286A53266562D817269C004FB0F149DD925D2C590A960936763E519C2B62E14C7759F96672CD852194325904197B0B19C6B528AB33566946AF39B".ToLower(), result.GetInterface().ToArray().ToHexString()); } [TestMethod] @@ -138,7 +136,7 @@ public void TestBls12381Mul() engine.LoadScript(script.ToArray()); Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.GetInterface().ToArray().ToHexString().Should().Be("18B2DB6B3286BAEA116CCAD8F5554D170A69B329A6DE5B24C50B8834965242001A1C58089FD872B211ACD3263897FA660B117248D69D8AC745283A3E6A4CCEC607F6CF7CEDEE919575D4B7C8AE14C36001F76BE5FCA50ADC296EF8DF4926FA7F0B55A75F255FE61FC2DA7CFFE56ADC8775AAAB54C50D0C4952AD919D90FB0EB221C41ABB9F2352A11BE2D7F176ABE41E0E30AFB34FC2CE16136DE66900D92068F30011E9882C0A56E7E7B30F08442BE9E58D093E1888151136259D059FB539210D635BC491D5244A16CA28FDCF10546EC0F7104D3A419DDC081BA30ECB0CD2289010C2D385946229B7A9735ADC82736914FE61AD26C6C38B787775DE3B939105DE055F8D7004358272A0823F6F1787A7ABB6C3C59C8C9CBD1674AC900512632818CDD273F0D38833C07467EAF77743B70C924D43975D3821D47110A358757F926FCF970660FBDD74EF15D93B81E3AA290C78F59CBC6ED0C1E0DCBADFD11A73EB7137850D29EFEB6FA321330D0CF70F5C7F6B004BCF86AC99125F8FECF83157930BEC2AF89F8B378C6D7F63B0A07B3651F5207A84F62CEE929D574DA154EBE795D519B661086F069C9F061BA3B53DC4910EA1614C87B114E2F9EF328AC94E93D00440B412D5AE5A3C396D52D26C0CDF2156EBD3D3F60EA500C42120A7CE1F7EF80F15323118956B17C09E80E96ED4E1572461D604CDE2533330C684F86680406B1D3EE830CBAFE6D29C9A0A2F41E03E26095B713EB7E782144DB1EC6B53047FCB606B7B665B3DD1F52E95FCF2AE59C4AB159C3F98468C0A43C36C022B548189B6".ToLower()); + Assert.AreEqual("18B2DB6B3286BAEA116CCAD8F5554D170A69B329A6DE5B24C50B8834965242001A1C58089FD872B211ACD3263897FA660B117248D69D8AC745283A3E6A4CCEC607F6CF7CEDEE919575D4B7C8AE14C36001F76BE5FCA50ADC296EF8DF4926FA7F0B55A75F255FE61FC2DA7CFFE56ADC8775AAAB54C50D0C4952AD919D90FB0EB221C41ABB9F2352A11BE2D7F176ABE41E0E30AFB34FC2CE16136DE66900D92068F30011E9882C0A56E7E7B30F08442BE9E58D093E1888151136259D059FB539210D635BC491D5244A16CA28FDCF10546EC0F7104D3A419DDC081BA30ECB0CD2289010C2D385946229B7A9735ADC82736914FE61AD26C6C38B787775DE3B939105DE055F8D7004358272A0823F6F1787A7ABB6C3C59C8C9CBD1674AC900512632818CDD273F0D38833C07467EAF77743B70C924D43975D3821D47110A358757F926FCF970660FBDD74EF15D93B81E3AA290C78F59CBC6ED0C1E0DCBADFD11A73EB7137850D29EFEB6FA321330D0CF70F5C7F6B004BCF86AC99125F8FECF83157930BEC2AF89F8B378C6D7F63B0A07B3651F5207A84F62CEE929D574DA154EBE795D519B661086F069C9F061BA3B53DC4910EA1614C87B114E2F9EF328AC94E93D00440B412D5AE5A3C396D52D26C0CDF2156EBD3D3F60EA500C42120A7CE1F7EF80F15323118956B17C09E80E96ED4E1572461D604CDE2533330C684F86680406B1D3EE830CBAFE6D29C9A0A2F41E03E26095B713EB7E782144DB1EC6B53047FCB606B7B665B3DD1F52E95FCF2AE59C4AB159C3F98468C0A43C36C022B548189B6".ToLower(), result.GetInterface().ToArray().ToHexString()); } using (ScriptBuilder script = new()) { @@ -156,7 +154,7 @@ public void TestBls12381Mul() engine.LoadScript(script.ToArray()); Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.GetInterface().ToArray().ToHexString().Should().Be("014E367F06F92BB039AEDCDD4DF65FC05A0D985B4CA6B79AA2254A6C605EB424048FA7F6117B8D4DA8522CD9C767B0450EEF9FA162E25BD305F36D77D8FEDE115C807C0805968129F15C1AD8489C32C41CB49418B4AEF52390900720B6D8B02C0EAB6A8B1420007A88412AB65DE0D04FEECCA0302E7806761483410365B5E771FCE7E5431230AD5E9E1C280E8953C68D0BD06236E9BD188437ADC14D42728C6E7177399B6B5908687F491F91EE6CCA3A391EF6C098CBEAEE83D962FA604A718A0C9DB625A7AAC25034517EB8743B5868A3803B37B94374E35F152F922BA423FB8E9B3D2B2BBF9DD602558CA5237D37420502B03D12B9230ED2A431D807B81BD18671EBF78380DD3CF490506187996E7C72F53C3914C76342A38A536FFAED478318CDD273F0D38833C07467EAF77743B70C924D43975D3821D47110A358757F926FCF970660FBDD74EF15D93B81E3AA290C78F59CBC6ED0C1E0DCBADFD11A73EB7137850D29EFEB6FA321330D0CF70F5C7F6B004BCF86AC99125F8FECF83157930BEC2AF89F8B378C6D7F63B0A07B3651F5207A84F62CEE929D574DA154EBE795D519B661086F069C9F061BA3B53DC4910EA1614C87B114E2F9EF328AC94E93D00440B412D5AE5A3C396D52D26C0CDF2156EBD3D3F60EA500C42120A7CE1F7EF80F15323118956B17C09E80E96ED4E1572461D604CDE2533330C684F86680406B1D3EE830CBAFE6D29C9A0A2F41E03E26095B713EB7E782144DB1EC6B53047FCB606B7B665B3DD1F52E95FCF2AE59C4AB159C3F98468C0A43C36C022B548189B6".ToLower()); + Assert.AreEqual("014E367F06F92BB039AEDCDD4DF65FC05A0D985B4CA6B79AA2254A6C605EB424048FA7F6117B8D4DA8522CD9C767B0450EEF9FA162E25BD305F36D77D8FEDE115C807C0805968129F15C1AD8489C32C41CB49418B4AEF52390900720B6D8B02C0EAB6A8B1420007A88412AB65DE0D04FEECCA0302E7806761483410365B5E771FCE7E5431230AD5E9E1C280E8953C68D0BD06236E9BD188437ADC14D42728C6E7177399B6B5908687F491F91EE6CCA3A391EF6C098CBEAEE83D962FA604A718A0C9DB625A7AAC25034517EB8743B5868A3803B37B94374E35F152F922BA423FB8E9B3D2B2BBF9DD602558CA5237D37420502B03D12B9230ED2A431D807B81BD18671EBF78380DD3CF490506187996E7C72F53C3914C76342A38A536FFAED478318CDD273F0D38833C07467EAF77743B70C924D43975D3821D47110A358757F926FCF970660FBDD74EF15D93B81E3AA290C78F59CBC6ED0C1E0DCBADFD11A73EB7137850D29EFEB6FA321330D0CF70F5C7F6B004BCF86AC99125F8FECF83157930BEC2AF89F8B378C6D7F63B0A07B3651F5207A84F62CEE929D574DA154EBE795D519B661086F069C9F061BA3B53DC4910EA1614C87B114E2F9EF328AC94E93D00440B412D5AE5A3C396D52D26C0CDF2156EBD3D3F60EA500C42120A7CE1F7EF80F15323118956B17C09E80E96ED4E1572461D604CDE2533330C684F86680406B1D3EE830CBAFE6D29C9A0A2F41E03E26095B713EB7E782144DB1EC6B53047FCB606B7B665B3DD1F52E95FCF2AE59C4AB159C3F98468C0A43C36C022B548189B6".ToLower(), result.GetInterface().ToArray().ToHexString()); } } @@ -178,7 +176,7 @@ public void TestBls12381Pairing() engine.LoadScript(script.ToArray()); Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.GetInterface().ToArray().ToHexString().Should().Be("0F41E58663BF08CF068672CBD01A7EC73BACA4D72CA93544DEFF686BFD6DF543D48EAA24AFE47E1EFDE449383B67663104C581234D086A9902249B64728FFD21A189E87935A954051C7CDBA7B3872629A4FAFC05066245CB9108F0242D0FE3EF03350F55A7AEFCD3C31B4FCB6CE5771CC6A0E9786AB5973320C806AD360829107BA810C5A09FFDD9BE2291A0C25A99A211B8B424CD48BF38FCEF68083B0B0EC5C81A93B330EE1A677D0D15FF7B984E8978EF48881E32FAC91B93B47333E2BA5706FBA23EB7C5AF0D9F80940CA771B6FFD5857BAAF222EB95A7D2809D61BFE02E1BFD1B68FF02F0B8102AE1C2D5D5AB1A19F26337D205FB469CD6BD15C3D5A04DC88784FBB3D0B2DBDEA54D43B2B73F2CBB12D58386A8703E0F948226E47EE89D018107154F25A764BD3C79937A45B84546DA634B8F6BE14A8061E55CCEBA478B23F7DACAA35C8CA78BEAE9624045B4B601B2F522473D171391125BA84DC4007CFBF2F8DA752F7C74185203FCCA589AC719C34DFFBBAAD8431DAD1C1FB597AAA5193502B86EDB8857C273FA075A50512937E0794E1E65A7617C90D8BD66065B1FFFE51D7A579973B1315021EC3C19934F1368BB445C7C2D209703F239689CE34C0378A68E72A6B3B216DA0E22A5031B54DDFF57309396B38C881C4C849EC23E87089A1C5B46E5110B86750EC6A532348868A84045483C92B7AF5AF689452EAFABF1A8943E50439F1D59882A98EAA0170F1250EBD871FC0A92A7B2D83168D0D727272D441BEFA15C503DD8E90CE98DB3E7B6D194F60839C508A84305AACA1789B6".ToLower()); + Assert.AreEqual("0F41E58663BF08CF068672CBD01A7EC73BACA4D72CA93544DEFF686BFD6DF543D48EAA24AFE47E1EFDE449383B67663104C581234D086A9902249B64728FFD21A189E87935A954051C7CDBA7B3872629A4FAFC05066245CB9108F0242D0FE3EF03350F55A7AEFCD3C31B4FCB6CE5771CC6A0E9786AB5973320C806AD360829107BA810C5A09FFDD9BE2291A0C25A99A211B8B424CD48BF38FCEF68083B0B0EC5C81A93B330EE1A677D0D15FF7B984E8978EF48881E32FAC91B93B47333E2BA5706FBA23EB7C5AF0D9F80940CA771B6FFD5857BAAF222EB95A7D2809D61BFE02E1BFD1B68FF02F0B8102AE1C2D5D5AB1A19F26337D205FB469CD6BD15C3D5A04DC88784FBB3D0B2DBDEA54D43B2B73F2CBB12D58386A8703E0F948226E47EE89D018107154F25A764BD3C79937A45B84546DA634B8F6BE14A8061E55CCEBA478B23F7DACAA35C8CA78BEAE9624045B4B601B2F522473D171391125BA84DC4007CFBF2F8DA752F7C74185203FCCA589AC719C34DFFBBAAD8431DAD1C1FB597AAA5193502B86EDB8857C273FA075A50512937E0794E1E65A7617C90D8BD66065B1FFFE51D7A579973B1315021EC3C19934F1368BB445C7C2D209703F239689CE34C0378A68E72A6B3B216DA0E22A5031B54DDFF57309396B38C881C4C849EC23E87089A1C5B46E5110B86750EC6A532348868A84045483C92B7AF5AF689452EAFABF1A8943E50439F1D59882A98EAA0170F1250EBD871FC0A92A7B2D83168D0D727272D441BEFA15C503DD8E90CE98DB3E7B6D194F60839C508A84305AACA1789B6".ToLower(), result.GetInterface().ToArray().ToHexString()); } [TestMethod] @@ -199,7 +197,7 @@ public void Bls12381Equal() engine.LoadScript(script.ToArray()); Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.GetBoolean().Should().BeTrue(); + Assert.IsTrue(result.GetBoolean()); } private enum BLS12381PointType : byte @@ -234,17 +232,17 @@ private void CheckBls12381ScalarMul_Compat(string point, string mul, bool negati { case BLS12381PointType.G1Proj: { - new G1Affine(result.GetInterface()).ToCompressed().ToHexString().Should().Be(expected); + Assert.AreEqual(expected, new G1Affine(result.GetInterface()).ToCompressed().ToHexString()); break; } case BLS12381PointType.G2Proj: { - new G2Affine(result.GetInterface()).ToCompressed().ToHexString().Should().Be(expected); + Assert.AreEqual(expected, new G2Affine(result.GetInterface()).ToCompressed().ToHexString()); break; } case BLS12381PointType.GT: { - result.GetInterface().ToArray().ToHexString().Should().Be(expected); + Assert.AreEqual(expected, result.GetInterface().ToArray().ToHexString()); break; } default: @@ -506,7 +504,7 @@ public void TestVerifyWithECDsa_CustomTxWitness_SingleSig() new Witness { InvocationScript = inv.ToArray(), VerificationScript = vrfScript } ]; - tx.VerifyStateIndependent(TestProtocolSettings.Default).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, tx.VerifyStateIndependent(TestProtocolSettings.Default)); var snapshotCache = TestBlockchain.GetTestSnapshotCache(); @@ -517,7 +515,7 @@ public void TestVerifyWithECDsa_CustomTxWitness_SingleSig() var txVrfContext = new TransactionVerificationContext(); var conflicts = new List(); - tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, txVrfContext, conflicts).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, txVrfContext, conflicts)); // The resulting witness verification cost is 2154270 * 10e-8GAS. // The resulting witness Invocation script (66 bytes length): @@ -588,9 +586,9 @@ public void TestVerifyWithECDsa_CustomTxWitness_MultiSig() var n = keys.Count; // Must ensure the following conditions are met before verification script construction: - n.Should().BeGreaterThan(0); - m.Should().BeLessThanOrEqualTo(n); - keys.Select(k => k.Item2).Distinct().Count().Should().Be(n); + Assert.IsTrue(n > 0); + Assert.IsTrue(m <= n); + Assert.AreEqual(n, keys.Select(k => k.Item2).Distinct().Count()); // In fact, the following algorithm is implemented via NeoVM instructions: // @@ -747,7 +745,7 @@ public void TestVerifyWithECDsa_CustomTxWitness_MultiSig() new Witness { InvocationScript = inv.ToArray(), VerificationScript = vrfScript } ]; - tx.VerifyStateIndependent(TestProtocolSettings.Default).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, tx.VerifyStateIndependent(TestProtocolSettings.Default)); var snapshotCache = TestBlockchain.GetTestSnapshotCache(); @@ -763,7 +761,7 @@ public void TestVerifyWithECDsa_CustomTxWitness_MultiSig() // Check that witness verification passes. var txVrfContext = new TransactionVerificationContext(); var conflicts = new List(); - tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, txVrfContext, conflicts).Should().Be(VerifyResult.Succeed); + Assert.AreEqual(VerifyResult.Succeed, tx.VerifyStateDependent(TestProtocolSettings.Default, snapshotCache, txVrfContext, conflicts)); // The resulting witness verification cost for 3/4 multisig is 8389470 * 10e-8GAS. Cost depends on M/N. // The resulting witness Invocation script (198 bytes for 3 signatures): @@ -870,23 +868,23 @@ public void TestVerifyWithECDsa() // secp256r1 + SHA256 byte[] signature = Crypto.Sign(message, privR1, ECCurve.Secp256r1, HashAlgorithm.SHA256); - Crypto.VerifySignature(message, signature, pubR1).Should().BeTrue(); // SHA256 hash is used by default. - CallVerifyWithECDsa(message, pubR1, signature, NamedCurveHash.secp256r1SHA256).Should().Be(true); + Assert.IsTrue(Crypto.VerifySignature(message, signature, pubR1)); // SHA256 hash is used by default. + Assert.IsTrue(CallVerifyWithECDsa(message, pubR1, signature, NamedCurveHash.secp256r1SHA256)); // secp256r1 + Keccak256 signature = Crypto.Sign(message, privR1, ECCurve.Secp256r1, HashAlgorithm.Keccak256); - Crypto.VerifySignature(message, signature, pubR1, HashAlgorithm.Keccak256).Should().BeTrue(); - CallVerifyWithECDsa(message, pubR1, signature, NamedCurveHash.secp256r1Keccak256).Should().Be(true); + Assert.IsTrue(Crypto.VerifySignature(message, signature, pubR1, HashAlgorithm.Keccak256)); + Assert.IsTrue(CallVerifyWithECDsa(message, pubR1, signature, NamedCurveHash.secp256r1Keccak256)); // secp256k1 + SHA256 signature = Crypto.Sign(message, privK1, ECCurve.Secp256k1, HashAlgorithm.SHA256); - Crypto.VerifySignature(message, signature, pubK1).Should().BeTrue(); // SHA256 hash is used by default. - CallVerifyWithECDsa(message, pubK1, signature, NamedCurveHash.secp256k1SHA256).Should().Be(true); + Assert.IsTrue(Crypto.VerifySignature(message, signature, pubK1)); // SHA256 hash is used by default. + Assert.IsTrue(CallVerifyWithECDsa(message, pubK1, signature, NamedCurveHash.secp256k1SHA256)); // secp256k1 + Keccak256 signature = Crypto.Sign(message, privK1, ECCurve.Secp256k1, HashAlgorithm.Keccak256); - Crypto.VerifySignature(message, signature, pubK1, HashAlgorithm.Keccak256).Should().BeTrue(); - CallVerifyWithECDsa(message, pubK1, signature, NamedCurveHash.secp256k1Keccak256).Should().Be(true); + Assert.IsTrue(Crypto.VerifySignature(message, signature, pubK1, HashAlgorithm.Keccak256)); + Assert.IsTrue(CallVerifyWithECDsa(message, pubK1, signature, NamedCurveHash.secp256k1Keccak256)); } private bool CallVerifyWithECDsa(byte[] message, ECPoint pub, byte[] signature, NamedCurveHash curveHash) @@ -922,26 +920,26 @@ public void TestVerifyWithEd25519() "5fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b").HexToBytes(); // Verify using Ed25519 directly - Ed25519.Verify(publicKey, message, signature).Should().BeTrue(); + Assert.IsTrue(Ed25519.Verify(publicKey, message, signature)); // Verify using CryptoLib.VerifyWithEd25519 - CallVerifyWithEd25519(message, publicKey, signature).Should().BeTrue(); + Assert.IsTrue(CallVerifyWithEd25519(message, publicKey, signature)); // Test with a different message byte[] differentMessage = Encoding.UTF8.GetBytes("Different message"); - CallVerifyWithEd25519(differentMessage, publicKey, signature).Should().BeFalse(); + Assert.IsFalse(CallVerifyWithEd25519(differentMessage, publicKey, signature)); // Test with an invalid signature byte[] invalidSignature = new byte[signature.Length]; Array.Copy(signature, invalidSignature, signature.Length); invalidSignature[0] ^= 0x01; // Flip one bit - CallVerifyWithEd25519(message, publicKey, invalidSignature).Should().BeFalse(); + Assert.IsFalse(CallVerifyWithEd25519(message, publicKey, invalidSignature)); // Test with an invalid public key byte[] invalidPublicKey = new byte[publicKey.Length]; Array.Copy(publicKey, invalidPublicKey, publicKey.Length); invalidPublicKey[0] ^= 0x01; // Flip one bit - CallVerifyWithEd25519(message, invalidPublicKey, signature).Should().BeFalse(); + Assert.IsFalse(CallVerifyWithEd25519(message, invalidPublicKey, signature)); } private bool CallVerifyWithEd25519(byte[] message, byte[] publicKey, byte[] signature) diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_FungibleToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_FungibleToken.cs index 8416147a9d..c612b8ad39 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_FungibleToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_FungibleToken.cs @@ -10,7 +10,6 @@ // modifications are permitted. using Akka.TestKit.Xunit2; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.SmartContract.Native; @@ -23,7 +22,7 @@ public class UT_FungibleToken : TestKit public void TestTotalSupply() { var snapshotCache = TestBlockchain.GetTestSnapshotCache(); - NativeContract.GAS.TotalSupply(snapshotCache).Should().Be(5200000050000000); + Assert.AreEqual(5200000050000000, NativeContract.GAS.TotalSupply(snapshotCache)); } } } diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs index e2b63b68f1..36a8d05cba 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs @@ -9,10 +9,8 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; -using Neo.IO; using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.SmartContract; @@ -39,13 +37,13 @@ public void TestSetup() } [TestMethod] - public void Check_Name() => NativeContract.GAS.Name.Should().Be(nameof(GasToken)); + public void Check_Name() => Assert.AreEqual(nameof(GasToken), NativeContract.GAS.Name); [TestMethod] - public void Check_Symbol() => NativeContract.GAS.Symbol(_snapshotCache).Should().Be("GAS"); + public void Check_Symbol() => Assert.AreEqual("GAS", NativeContract.GAS.Symbol(_snapshotCache)); [TestMethod] - public void Check_Decimals() => NativeContract.GAS.Decimals(_snapshotCache).Should().Be(8); + public void Check_Decimals() => Assert.AreEqual(8, NativeContract.GAS.Decimals(_snapshotCache)); [TestMethod] public async Task Check_BalanceOfTransferAndBurn() @@ -55,7 +53,7 @@ public async Task Check_BalanceOfTransferAndBurn() byte[] from = Contract.GetBFTAddress(TestProtocolSettings.Default.StandbyValidators).ToArray(); byte[] to = new byte[20]; var supply = NativeContract.GAS.TotalSupply(snapshot); - supply.Should().Be(5200000050000000); // 3000000000000000 + 50000000 (neo holder reward) + Assert.AreEqual(5200000050000000, supply); // 3000000000000000 + 50000000 (neo holder reward) var storageKey = new KeyBuilder(NativeContract.Ledger.Id, 12); snapshot.Add(storageKey, new StorageItem(new HashIndexState { Hash = UInt256.Zero, Index = persistingBlock.Index - 1 })); @@ -63,45 +61,45 @@ public async Task Check_BalanceOfTransferAndBurn() // Check unclaim var unclaim = UT_NeoToken.Check_UnclaimedGas(snapshot, from, persistingBlock); - unclaim.Value.Should().Be(new BigInteger(0.5 * 1000 * 100000000L)); - unclaim.State.Should().BeTrue(); + Assert.AreEqual(new BigInteger(0.5 * 1000 * 100000000L), unclaim.Value); + Assert.IsTrue(unclaim.State); // Transfer - NativeContract.NEO.Transfer(snapshot, from, to, BigInteger.Zero, true, persistingBlock).Should().BeTrue(); + Assert.IsTrue(NativeContract.NEO.Transfer(snapshot, from, to, BigInteger.Zero, true, persistingBlock)); Assert.ThrowsException(() => NativeContract.NEO.Transfer(snapshot, from, null, BigInteger.Zero, true, persistingBlock)); Assert.ThrowsException(() => NativeContract.NEO.Transfer(snapshot, null, to, BigInteger.Zero, false, persistingBlock)); - NativeContract.NEO.BalanceOf(snapshot, from).Should().Be(100000000); - NativeContract.NEO.BalanceOf(snapshot, to).Should().Be(0); + Assert.AreEqual(100000000, NativeContract.NEO.BalanceOf(snapshot, from)); + Assert.AreEqual(0, NativeContract.NEO.BalanceOf(snapshot, to)); - NativeContract.GAS.BalanceOf(snapshot, from).Should().Be(52000500_00000000); - NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(0); + Assert.AreEqual(52000500_00000000, NativeContract.GAS.BalanceOf(snapshot, from)); + Assert.AreEqual(0, NativeContract.GAS.BalanceOf(snapshot, to)); // Check unclaim unclaim = UT_NeoToken.Check_UnclaimedGas(snapshot, from, persistingBlock); - unclaim.Value.Should().Be(new BigInteger(0)); - unclaim.State.Should().BeTrue(); + Assert.AreEqual(new BigInteger(0), unclaim.Value); + Assert.IsTrue(unclaim.State); supply = NativeContract.GAS.TotalSupply(snapshot); - supply.Should().Be(5200050050000000); + Assert.AreEqual(5200050050000000, supply); - snapshot.GetChangeSet().Count().Should().Be(keyCount + 3); // Gas + Assert.AreEqual(keyCount + 3, snapshot.GetChangeSet().Count()); // Gas // Transfer keyCount = snapshot.GetChangeSet().Count(); - NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000000, false, persistingBlock).Should().BeFalse(); // Not signed - NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000001, true, persistingBlock).Should().BeFalse(); // More than balance - NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000000, true, persistingBlock).Should().BeTrue(); // All balance + Assert.IsFalse(NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000000, false, persistingBlock)); // Not signed + Assert.IsFalse(NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000001, true, persistingBlock)); // More than balance + Assert.IsTrue(NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000000, true, persistingBlock)); // All balance // Balance of - NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(52000500_00000000); - NativeContract.GAS.BalanceOf(snapshot, from).Should().Be(0); + Assert.AreEqual(52000500_00000000, NativeContract.GAS.BalanceOf(snapshot, to)); + Assert.AreEqual(0, NativeContract.GAS.BalanceOf(snapshot, from)); - snapshot.GetChangeSet().Count().Should().Be(keyCount + 1); // All + Assert.AreEqual(keyCount + 1, snapshot.GetChangeSet().Count()); // All // Burn @@ -120,14 +118,14 @@ await Assert.ThrowsExceptionAsync(async () => await NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(1)); - NativeContract.GAS.BalanceOf(engine.SnapshotCache, to).Should().Be(5200049999999999); + Assert.AreEqual(5200049999999999, NativeContract.GAS.BalanceOf(engine.SnapshotCache, to)); - engine.SnapshotCache.GetChangeSet().Count().Should().Be(2); + Assert.AreEqual(2, engine.SnapshotCache.GetChangeSet().Count()); // Burn all await NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(5200049999999999)); - (keyCount - 2).Should().Be(engine.SnapshotCache.GetChangeSet().Count()); + Assert.AreEqual(keyCount - 2, engine.SnapshotCache.GetChangeSet().Count()); // Bad inputs diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs index 872db2fb8d..3096c5a1b1 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.Network.P2P.Payloads; @@ -207,7 +206,7 @@ public void TestContractMethodWithSpecialParameter() { // should be failed var action = () => CheckSpecialParameter(method); - action.Should().Throw(); + Assert.ThrowsException(() => action()); } } } @@ -272,10 +271,9 @@ internal static ContractState Call_GetContract(DataCache snapshot, UInt160 addre script.EmitDynamicCall(NativeContract.ContractManagement.Hash, "getContract", address); engine.LoadScript(script.ToArray()); - engine.Execute().Should().Be(VMState.HALT); - + Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Array)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Array)); var cs = new ContractState(); ((IInteroperable)cs).FromStackItem(result); diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs index ef3481836d..118747340c 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -49,13 +48,13 @@ public void TestSetup() } [TestMethod] - public void Check_Name() => NativeContract.NEO.Name.Should().Be(nameof(NeoToken)); + public void Check_Name() => Assert.AreEqual(nameof(NeoToken), NativeContract.NEO.Name); [TestMethod] - public void Check_Symbol() => NativeContract.NEO.Symbol(_snapshotCache).Should().Be("NEO"); + public void Check_Symbol() => Assert.AreEqual("NEO", NativeContract.NEO.Symbol(_snapshotCache)); [TestMethod] - public void Check_Decimals() => NativeContract.NEO.Decimals(_snapshotCache).Should().Be(0); + public void Check_Decimals() => Assert.AreEqual(0, NativeContract.NEO.Decimals(_snapshotCache)); [TestMethod] public void Test_HF_EchidnaStates() @@ -113,20 +112,20 @@ public void Check_Vote() // No signature var ret = Check_Vote(clonedCache, from, null, false, persistingBlock); - ret.Result.Should().BeFalse(); - ret.State.Should().BeTrue(); + Assert.IsFalse(ret.Result); + Assert.IsTrue(ret.State); // Wrong address ret = Check_Vote(clonedCache, new byte[19], null, false, persistingBlock); - ret.Result.Should().BeFalse(); - ret.State.Should().BeFalse(); + Assert.IsFalse(ret.Result); + Assert.IsFalse(ret.State); // Wrong ec ret = Check_Vote(clonedCache, from, new byte[19], true, persistingBlock); - ret.Result.Should().BeFalse(); - ret.State.Should().BeFalse(); + Assert.IsFalse(ret.Result); + Assert.IsFalse(ret.State); // no registered @@ -135,26 +134,26 @@ public void Check_Vote() fakeAddr[5] = 0xFF; ret = Check_Vote(clonedCache, fakeAddr, null, true, persistingBlock); - ret.Result.Should().BeFalse(); - ret.State.Should().BeTrue(); + Assert.IsFalse(ret.Result); + Assert.IsTrue(ret.State); // no registered var accountState = clonedCache.TryGet(CreateStorageKey(20, from)).GetInteroperable(); accountState.VoteTo = null; ret = Check_Vote(clonedCache, from, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); - ret.Result.Should().BeFalse(); - ret.State.Should().BeTrue(); - accountState.VoteTo.Should().BeNull(); + Assert.IsFalse(ret.Result); + Assert.IsTrue(ret.State); + Assert.IsNull(accountState.VoteTo); // normal case clonedCache.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true })); ret = Check_Vote(clonedCache, from, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); accountState = clonedCache.TryGet(CreateStorageKey(20, from)).GetInteroperable(); - accountState.VoteTo.Should().Be(ECCurve.Secp256r1.G); + Assert.AreEqual(ECCurve.Secp256r1.G, accountState.VoteTo); } [TestMethod] @@ -171,23 +170,23 @@ public void Check_Vote_Sameaccounts() accountState.Balance = 100; clonedCache.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true })); var ret = Check_Vote(clonedCache, from, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); accountState = clonedCache.TryGet(CreateStorageKey(20, from)).GetInteroperable(); - accountState.VoteTo.Should().Be(ECCurve.Secp256r1.G); + Assert.AreEqual(ECCurve.Secp256r1.G, accountState.VoteTo); //two account vote for the same account var stateValidator = clonedCache.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable(); - stateValidator.Votes.Should().Be(100); + Assert.AreEqual(100, stateValidator.Votes); var G_Account = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash.ToArray(); clonedCache.Add(CreateStorageKey(20, G_Account), new StorageItem(new NeoAccountState { Balance = 200 })); var secondAccount = clonedCache.TryGet(CreateStorageKey(20, G_Account)).GetInteroperable(); - secondAccount.Balance.Should().Be(200); + Assert.AreEqual(200, secondAccount.Balance); ret = Check_Vote(clonedCache, G_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); stateValidator = clonedCache.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable(); - stateValidator.Votes.Should().Be(300); + Assert.AreEqual(300, stateValidator.Votes); } [TestMethod] @@ -205,24 +204,24 @@ public void Check_Vote_ChangeVote() accountState.Balance = 100; clonedCache.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true })); var ret = Check_Vote(clonedCache, from_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); accountState = clonedCache.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable(); - accountState.VoteTo.Should().Be(ECCurve.Secp256r1.G); + Assert.AreEqual(ECCurve.Secp256r1.G, accountState.VoteTo); //from change vote to itself var G_stateValidator = clonedCache.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable(); - G_stateValidator.Votes.Should().Be(100); + Assert.AreEqual(100, G_stateValidator.Votes); var G_Account = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash.ToArray(); clonedCache.Add(CreateStorageKey(20, G_Account), new StorageItem(new NeoAccountState { Balance = 200 })); clonedCache.Add(CreateStorageKey(33, from), new StorageItem(new CandidateState() { Registered = true })); ret = Check_Vote(clonedCache, from_Account, from, true, persistingBlock); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); G_stateValidator = clonedCache.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable(); - G_stateValidator.Votes.Should().Be(0); + Assert.AreEqual(0, G_stateValidator.Votes); var from_stateValidator = clonedCache.GetAndChange(CreateStorageKey(33, from)).GetInteroperable(); - from_stateValidator.Votes.Should().Be(100); + Assert.AreEqual(100, from_stateValidator.Votes); } [TestMethod] @@ -240,26 +239,26 @@ public void Check_Vote_VoteToNull() clonedCache.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true })); clonedCache.Add(CreateStorageKey(23, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new BigInteger(100500))); var ret = Check_Vote(clonedCache, from_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); accountState = clonedCache.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable(); - accountState.VoteTo.Should().Be(ECCurve.Secp256r1.G); - accountState.LastGasPerVote.Should().Be(100500); + Assert.AreEqual(ECCurve.Secp256r1.G, accountState.VoteTo); + Assert.AreEqual(100500, accountState.LastGasPerVote); //from vote to null account G votes becomes 0 var G_stateValidator = clonedCache.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable(); - G_stateValidator.Votes.Should().Be(100); + Assert.AreEqual(100, G_stateValidator.Votes); var G_Account = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash.ToArray(); clonedCache.Add(CreateStorageKey(20, G_Account), new StorageItem(new NeoAccountState { Balance = 200 })); clonedCache.Add(CreateStorageKey(33, from), new StorageItem(new CandidateState() { Registered = true })); ret = Check_Vote(clonedCache, from_Account, null, true, persistingBlock); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); G_stateValidator = clonedCache.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable(); - G_stateValidator.Votes.Should().Be(0); + Assert.AreEqual(0, G_stateValidator.Votes); accountState = clonedCache.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable(); - accountState.VoteTo.Should().Be(null); - accountState.LastGasPerVote.Should().Be(0); + Assert.IsNull(accountState.VoteTo); + Assert.AreEqual(0, accountState.LastGasPerVote); } [TestMethod] @@ -274,12 +273,12 @@ public void Check_UnclaimedGas() byte[] from = Contract.GetBFTAddress(TestProtocolSettings.Default.StandbyValidators).ToArray(); var unclaim = Check_UnclaimedGas(clonedCache, from, persistingBlock); - unclaim.Value.Should().Be(new BigInteger(0.5 * 1000 * 100000000L)); - unclaim.State.Should().BeTrue(); + Assert.AreEqual(new BigInteger(0.5 * 1000 * 100000000L), unclaim.Value); + Assert.IsTrue(unclaim.State); unclaim = Check_UnclaimedGas(clonedCache, new byte[19], persistingBlock); - unclaim.Value.Should().Be(BigInteger.Zero); - unclaim.State.Should().BeFalse(); + Assert.AreEqual(BigInteger.Zero, unclaim.Value); + Assert.IsFalse(unclaim.State); } [TestMethod] @@ -291,18 +290,18 @@ public void Check_RegisterValidator() var point = TestProtocolSettings.Default.StandbyValidators[0].EncodePoint(true).Clone() as byte[]; var ret = Check_RegisterValidator(clonedCache, point, _persistingBlock); // Exists - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); - clonedCache.GetChangeSet().Count().Should().Be(++keyCount); // No changes + Assert.AreEqual(++keyCount, clonedCache.GetChangeSet().Count()); // No changes point[20]++; // fake point ret = Check_RegisterValidator(clonedCache, point, _persistingBlock); // New - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); - clonedCache.GetChangeSet().Count().Should().Be(keyCount + 1); // New validator + Assert.AreEqual(keyCount + 1, clonedCache.GetChangeSet().Count()); // New validator // Check GetRegisteredValidators @@ -319,21 +318,21 @@ public void Check_RegisterValidatorViaNEP27() // Send some NEO, shouldn't be accepted var ret = Check_RegisterValidatorViaNEP27(clonedCache, point, _persistingBlock, true, pointData, 1000_0000_0000); - ret.State.Should().BeFalse(); + Assert.IsFalse(ret.State); // Send improper amount of GAS, shouldn't be accepted. ret = Check_RegisterValidatorViaNEP27(clonedCache, point, _persistingBlock, false, pointData, 1000_0000_0001); - ret.State.Should().BeFalse(); + Assert.IsFalse(ret.State); // Broken witness. var badPoint = ECPoint.Parse("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", ECCurve.Secp256r1); ret = Check_RegisterValidatorViaNEP27(clonedCache, point, _persistingBlock, false, badPoint.EncodePoint(true), 1000_0000_0000); - ret.State.Should().BeFalse(); + Assert.IsFalse(ret.State); // Successful case. ret = Check_RegisterValidatorViaNEP27(clonedCache, point, _persistingBlock, false, pointData, 1000_0000_0000); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); // Check GetRegisteredValidators var members = NativeContract.NEO.GetCandidatesInternal(clonedCache); @@ -354,55 +353,57 @@ public void Check_UnregisterCandidate() //without register var ret = Check_UnregisterCandidate(clonedCache, point, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); - clonedCache.GetChangeSet().Count().Should().Be(keyCount); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); + + Assert.AreEqual(keyCount, clonedCache.GetChangeSet().Count()); //register and then unregister ret = Check_RegisterValidator(clonedCache, point, _persistingBlock); StorageItem item = clonedCache.GetAndChange(CreateStorageKey(33, point)); - item.Size.Should().Be(7); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.AreEqual(7, item.Size); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); var members = NativeContract.NEO.GetCandidatesInternal(clonedCache); Assert.AreEqual(1, members.Count()); - clonedCache.GetChangeSet().Count().Should().Be(keyCount + 1); + Assert.AreEqual(keyCount + 1, clonedCache.GetChangeSet().Count()); StorageKey key = CreateStorageKey(33, point); - clonedCache.TryGet(key).Should().NotBeNull(); + Assert.IsNotNull(clonedCache.TryGet(key)); ret = Check_UnregisterCandidate(clonedCache, point, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); - clonedCache.GetChangeSet().Count().Should().Be(keyCount); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); + + Assert.AreEqual(keyCount, clonedCache.GetChangeSet().Count()); members = NativeContract.NEO.GetCandidatesInternal(clonedCache); Assert.AreEqual(0, members.Count()); - clonedCache.TryGet(key).Should().BeNull(); + Assert.IsNull(clonedCache.TryGet(key)); //register with votes, then unregister ret = Check_RegisterValidator(clonedCache, point, _persistingBlock); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.State); var G_Account = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash.ToArray(); clonedCache.Add(CreateStorageKey(20, G_Account), new StorageItem(new NeoAccountState())); var accountState = clonedCache.TryGet(CreateStorageKey(20, G_Account)).GetInteroperable(); accountState.Balance = 100; Check_Vote(clonedCache, G_Account, TestProtocolSettings.Default.StandbyValidators[0].ToArray(), true, _persistingBlock); ret = Check_UnregisterCandidate(clonedCache, point, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); - clonedCache.TryGet(key).Should().NotBeNull(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); + Assert.IsNotNull(clonedCache.TryGet(key)); StorageItem pointItem = clonedCache.TryGet(key); CandidateState pointState = pointItem.GetInteroperable(); - pointState.Registered.Should().BeFalse(); - pointState.Votes.Should().Be(100); + Assert.IsFalse(pointState.Registered); + Assert.AreEqual(100, pointState.Votes); //vote fail ret = Check_Vote(clonedCache, G_Account, TestProtocolSettings.Default.StandbyValidators[0].ToArray(), true, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeFalse(); + Assert.IsTrue(ret.State); + Assert.IsFalse(ret.Result); accountState = clonedCache.TryGet(CreateStorageKey(20, G_Account)).GetInteroperable(); - accountState.VoteTo.Should().Be(TestProtocolSettings.Default.StandbyValidators[0]); + Assert.AreEqual(TestProtocolSettings.Default.StandbyValidators[0], accountState.VoteTo); } [TestMethod] @@ -419,18 +420,19 @@ public void Check_GetCommittee() var accountState = clonedCache.TryGet(CreateStorageKey(20, G_Account)).GetInteroperable(); accountState.Balance = 20000000; var ret = Check_RegisterValidator(clonedCache, ECCurve.Secp256r1.G.ToArray(), persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); ret = Check_Vote(clonedCache, G_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); + var committeemembers = NativeContract.NEO.GetCommittee(clonedCache); var defaultCommittee = TestProtocolSettings.Default.StandbyCommittee.OrderBy(p => p).ToArray(); - committeemembers.GetType().Should().Be(typeof(ECPoint[])); + Assert.AreEqual(committeemembers.GetType(), typeof(ECPoint[])); for (int i = 0; i < TestProtocolSettings.Default.CommitteeMembersCount; i++) { - committeemembers[i].Should().Be(defaultCommittee[i]); + Assert.AreEqual(committeemembers[i], defaultCommittee[i]); } //register more candidates, committee member change @@ -449,20 +451,20 @@ public void Check_GetCommittee() for (int i = 0; i < TestProtocolSettings.Default.CommitteeMembersCount - 1; i++) { ret = Check_RegisterValidator(clonedCache, TestProtocolSettings.Default.StandbyCommittee[i].ToArray(), persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); } - Check_OnPersist(clonedCache, persistingBlock).Should().BeTrue(); + Assert.IsTrue(Check_OnPersist(clonedCache, persistingBlock)); committeemembers = NativeContract.NEO.GetCommittee(clonedCache); - committeemembers.Length.Should().Be(TestProtocolSettings.Default.CommitteeMembersCount); - committeemembers.Contains(ECCurve.Secp256r1.G).Should().BeTrue(); + Assert.AreEqual(committeemembers.Length, TestProtocolSettings.Default.CommitteeMembersCount); + Assert.IsTrue(committeemembers.Contains(ECCurve.Secp256r1.G)); for (int i = 0; i < TestProtocolSettings.Default.CommitteeMembersCount - 1; i++) { - committeemembers.Contains(TestProtocolSettings.Default.StandbyCommittee[i]).Should().BeTrue(); + Assert.IsTrue(committeemembers.Contains(TestProtocolSettings.Default.StandbyCommittee[i])); } - committeemembers.Contains(TestProtocolSettings.Default.StandbyCommittee[TestProtocolSettings.Default.CommitteeMembersCount - 1]).Should().BeFalse(); + Assert.IsFalse(committeemembers.Contains(TestProtocolSettings.Default.StandbyCommittee[TestProtocolSettings.Default.CommitteeMembersCount - 1])); } [TestMethod] @@ -481,37 +483,37 @@ public void Check_Transfer() // Check unclaim var unclaim = Check_UnclaimedGas(clonedCache, from, persistingBlock); - unclaim.Value.Should().Be(new BigInteger(0.5 * 1000 * 100000000L)); - unclaim.State.Should().BeTrue(); + Assert.AreEqual(new BigInteger(0.5 * 1000 * 100000000L), unclaim.Value); + Assert.IsTrue(unclaim.State); // Transfer - NativeContract.NEO.Transfer(clonedCache, from, to, BigInteger.One, false, persistingBlock).Should().BeFalse(); // Not signed - NativeContract.NEO.Transfer(clonedCache, from, to, BigInteger.One, true, persistingBlock).Should().BeTrue(); - NativeContract.NEO.BalanceOf(clonedCache, from).Should().Be(99999999); - NativeContract.NEO.BalanceOf(clonedCache, to).Should().Be(1); + Assert.IsFalse(NativeContract.NEO.Transfer(clonedCache, from, to, BigInteger.One, false, persistingBlock)); // Not signed + Assert.IsTrue(NativeContract.NEO.Transfer(clonedCache, from, to, BigInteger.One, true, persistingBlock)); + Assert.AreEqual(99999999, NativeContract.NEO.BalanceOf(clonedCache, from)); + Assert.AreEqual(1, NativeContract.NEO.BalanceOf(clonedCache, to)); var (from_balance, _, _) = GetAccountState(clonedCache, new UInt160(from)); var (to_balance, _, _) = GetAccountState(clonedCache, new UInt160(to)); - from_balance.Should().Be(99999999); - to_balance.Should().Be(1); + Assert.AreEqual(99999999, from_balance); + Assert.AreEqual(1, to_balance); // Check unclaim unclaim = Check_UnclaimedGas(clonedCache, from, persistingBlock); - unclaim.Value.Should().Be(new BigInteger(0)); - unclaim.State.Should().BeTrue(); + Assert.AreEqual(BigInteger.Zero, unclaim.Value); + Assert.IsTrue(unclaim.State); - clonedCache.GetChangeSet().Count().Should().Be(keyCount + 4); // Gas + new balance + Assert.AreEqual(keyCount + 4, clonedCache.GetChangeSet().Count()); // Gas + new balance // Return balance keyCount = clonedCache.GetChangeSet().Count(); - NativeContract.NEO.Transfer(clonedCache, to, from, BigInteger.One, true, persistingBlock).Should().BeTrue(); - NativeContract.NEO.BalanceOf(clonedCache, to).Should().Be(0); - clonedCache.GetChangeSet().Count().Should().Be(keyCount - 1); // Remove neo balance from address two + Assert.IsTrue(NativeContract.NEO.Transfer(clonedCache, to, from, BigInteger.One, true, persistingBlock)); + Assert.AreEqual(0, NativeContract.NEO.BalanceOf(clonedCache, to)); + Assert.AreEqual(keyCount - 1, clonedCache.GetChangeSet().Count()); // Remove neo balance from address two // Bad inputs @@ -521,7 +523,7 @@ public void Check_Transfer() // More than balance - NativeContract.NEO.Transfer(clonedCache, to, from, new BigInteger(2), true, persistingBlock).Should().BeFalse(); + Assert.IsFalse(NativeContract.NEO.Transfer(clonedCache, to, from, new BigInteger(2), true, persistingBlock)); } [TestMethod] @@ -530,11 +532,11 @@ public void Check_BalanceOf() var clonedCache = _snapshotCache.CloneCache(); byte[] account = Contract.GetBFTAddress(TestProtocolSettings.Default.StandbyValidators).ToArray(); - NativeContract.NEO.BalanceOf(clonedCache, account).Should().Be(100_000_000); + Assert.AreEqual(100_000_000, NativeContract.NEO.BalanceOf(clonedCache, account)); account[5]++; // Without existing balance - NativeContract.NEO.BalanceOf(clonedCache, account).Should().Be(0); + Assert.AreEqual(0, NativeContract.NEO.BalanceOf(clonedCache, account)); } [TestMethod] @@ -553,13 +555,12 @@ public void Check_CommitteeBonus() }, Transactions = Array.Empty() }; - - Check_PostPersist(clonedCache, persistingBlock).Should().BeTrue(); + Assert.IsTrue(Check_PostPersist(clonedCache, persistingBlock)); var committee = TestProtocolSettings.Default.StandbyCommittee; - NativeContract.GAS.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[0]).ScriptHash.ToArray()).Should().Be(50000000); - NativeContract.GAS.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[1]).ScriptHash.ToArray()).Should().Be(50000000); - NativeContract.GAS.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[2]).ScriptHash.ToArray()).Should().Be(0); + Assert.AreEqual(50000000, NativeContract.GAS.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[0]).ScriptHash)); + Assert.AreEqual(50000000, NativeContract.GAS.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[1]).ScriptHash)); + Assert.AreEqual(0, NativeContract.GAS.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[2]).ScriptHash)); } [TestMethod] @@ -586,8 +587,12 @@ public void TestCalculateBonus() { Balance = -100 })); - Action action = () => NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10).Should().Be(new BigInteger(0)); - action.Should().Throw(); + try + { + NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10); + Assert.Fail("Should have thrown ArgumentOutOfRangeException"); + } + catch (ArgumentOutOfRangeException) { } clonedCache.Delete(key); // Fault range: start >= end @@ -597,7 +602,12 @@ public void TestCalculateBonus() Balance = 100, BalanceHeight = 100 })); - action = () => NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10).Should().Be(new BigInteger(0)); + try + { + NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10); + Assert.Fail("Should have thrown ArgumentOutOfRangeException"); + } + catch (ArgumentOutOfRangeException) { } clonedCache.Delete(key); // Fault range: start >= end @@ -607,7 +617,12 @@ public void TestCalculateBonus() Balance = 100, BalanceHeight = 100 })); - action = () => NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10).Should().Be(new BigInteger(0)); + try + { + NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10); + Assert.Fail("Should have thrown ArgumentOutOfRangeException"); + } + catch (ArgumentOutOfRangeException) { } clonedCache.Delete(key); // Normal 1) votee is non exist @@ -621,7 +636,7 @@ public void TestCalculateBonus() var item = clonedCache.GetAndChange(storageKey).GetInteroperable(); item.Index = 99; - NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 100).Should().Be(new BigInteger(0.5 * 100 * 100)); + Assert.AreEqual(new BigInteger(0.5 * 100 * 100), NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 100)); clonedCache.Delete(key); // Normal 2) votee is not committee @@ -631,7 +646,7 @@ public void TestCalculateBonus() Balance = 100, VoteTo = ECCurve.Secp256r1.G })); - NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 100).Should().Be(new BigInteger(0.5 * 100 * 100)); + Assert.AreEqual(new BigInteger(0.5 * 100 * 100), NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 100)); clonedCache.Delete(key); // Normal 3) votee is committee @@ -642,7 +657,7 @@ public void TestCalculateBonus() VoteTo = TestProtocolSettings.Default.StandbyCommittee[0] })); clonedCache.Add(new KeyBuilder(NativeContract.NEO.Id, 23).Add(TestProtocolSettings.Default.StandbyCommittee[0]).AddBigEndian(uint.MaxValue - 50), new StorageItem() { Value = new BigInteger(50 * 10000L).ToByteArray() }); - NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 100).Should().Be(new BigInteger(50 * 100)); + Assert.AreEqual(new BigInteger(50 * 100), NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 100)); clonedCache.Delete(key); } @@ -651,14 +666,14 @@ public void TestGetNextBlockValidators1() { var snapshotCache = TestBlockchain.GetTestSnapshotCache(); var result = (VM.Types.Array)NativeContract.NEO.Call(snapshotCache, "getNextBlockValidators"); - result.Count.Should().Be(7); - result[0].GetSpan().ToHexString().Should().Be("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"); - result[1].GetSpan().ToHexString().Should().Be("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d"); - result[2].GetSpan().ToHexString().Should().Be("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e"); - result[3].GetSpan().ToHexString().Should().Be("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"); - result[4].GetSpan().ToHexString().Should().Be("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a"); - result[5].GetSpan().ToHexString().Should().Be("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554"); - result[6].GetSpan().ToHexString().Should().Be("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093"); + Assert.AreEqual(7, result.Count); + Assert.AreEqual("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70", result[0].GetSpan().ToHexString()); + Assert.AreEqual("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", result[1].GetSpan().ToHexString()); + Assert.AreEqual("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e", result[2].GetSpan().ToHexString()); + Assert.AreEqual("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", result[3].GetSpan().ToHexString()); + Assert.AreEqual("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", result[4].GetSpan().ToHexString()); + Assert.AreEqual("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554", result[5].GetSpan().ToHexString()); + Assert.AreEqual("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", result[6].GetSpan().ToHexString()); } [TestMethod] @@ -666,14 +681,14 @@ public void TestGetNextBlockValidators2() { var clonedCache = _snapshotCache.CloneCache(); var result = NativeContract.NEO.GetNextBlockValidators(clonedCache, 7); - result.Length.Should().Be(7); - result[0].ToArray().ToHexString().Should().Be("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"); - result[1].ToArray().ToHexString().Should().Be("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d"); - result[2].ToArray().ToHexString().Should().Be("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e"); - result[3].ToArray().ToHexString().Should().Be("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"); - result[4].ToArray().ToHexString().Should().Be("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a"); - result[5].ToArray().ToHexString().Should().Be("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554"); - result[6].ToArray().ToHexString().Should().Be("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093"); + Assert.AreEqual(7, result.Length); + Assert.AreEqual("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70", result[0].ToArray().ToHexString()); + Assert.AreEqual("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", result[1].ToArray().ToHexString()); + Assert.AreEqual("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e", result[2].ToArray().ToHexString()); + Assert.AreEqual("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", result[3].ToArray().ToHexString()); + Assert.AreEqual("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", result[4].ToArray().ToHexString()); + Assert.AreEqual("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554", result[5].ToArray().ToHexString()); + Assert.AreEqual("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", result[6].ToArray().ToHexString()); } [TestMethod] @@ -681,7 +696,7 @@ public void TestGetCandidates1() { var snapshotCache = TestBlockchain.GetTestSnapshotCache(); var array = (VM.Types.Array)NativeContract.NEO.Call(snapshotCache, "getCandidates"); - array.Count.Should().Be(0); + Assert.AreEqual(0, array.Count); } [TestMethod] @@ -689,11 +704,11 @@ public void TestGetCandidates2() { var clonedCache = _snapshotCache.CloneCache(); var result = NativeContract.NEO.GetCandidatesInternal(clonedCache); - result.Count().Should().Be(0); + Assert.AreEqual(0, result.Count()); StorageKey key = NativeContract.NEO.CreateStorageKey(33, ECCurve.Secp256r1.G); clonedCache.Add(key, new StorageItem(new CandidateState() { Registered = true })); - NativeContract.NEO.GetCandidatesInternal(clonedCache).Count().Should().Be(1); + Assert.AreEqual(1, NativeContract.NEO.GetCandidatesInternal(clonedCache).Count()); } [TestMethod] @@ -712,7 +727,7 @@ public void TestCheckCandidate() cloneCache.Add(storageKey, new StorageItem(new CandidateState { Registered = true, Votes = BigInteger.One })); storageKey = new KeyBuilder(NativeContract.NEO.Id, 23).Add(committee[0]); - cloneCache.Find(storageKey.ToArray()).ToArray().Length.Should().Be(1); + Assert.AreEqual(1, cloneCache.Find(storageKey.ToArray()).ToArray().Length); // Pre-persist var persistingBlock = new Block @@ -727,7 +742,7 @@ public void TestCheckCandidate() }, Transactions = Array.Empty() }; - Check_OnPersist(cloneCache, persistingBlock).Should().BeTrue(); + Assert.IsTrue(Check_OnPersist(cloneCache, persistingBlock)); // Clear votes storageKey = new KeyBuilder(NativeContract.NEO.Id, 33).Add(committee[0]); @@ -735,17 +750,17 @@ public void TestCheckCandidate() // Unregister candidate, remove var ret = Check_UnregisterCandidate(cloneCache, point, persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); + Assert.IsTrue(ret.State); + Assert.IsTrue(ret.Result); storageKey = new KeyBuilder(NativeContract.NEO.Id, 23).Add(committee[0]); - cloneCache.Find(storageKey.ToArray()).ToArray().Length.Should().Be(0); + Assert.AreEqual(0, cloneCache.Find(storageKey.ToArray()).ToArray().Length); // Post-persist - Check_PostPersist(cloneCache, persistingBlock).Should().BeTrue(); + Assert.IsTrue(Check_PostPersist(cloneCache, persistingBlock)); storageKey = new KeyBuilder(NativeContract.NEO.Id, 23).Add(committee[0]); - cloneCache.Find(storageKey.ToArray()).ToArray().Length.Should().Be(1); + Assert.AreEqual(1, cloneCache.Find(storageKey.ToArray()).ToArray().Length); } [TestMethod] @@ -753,28 +768,28 @@ public void TestGetCommittee() { var clonedCache = TestBlockchain.GetTestSnapshotCache(); var result = (VM.Types.Array)NativeContract.NEO.Call(clonedCache, "getCommittee"); - result.Count.Should().Be(21); - result[0].GetSpan().ToHexString().Should().Be("020f2887f41474cfeb11fd262e982051c1541418137c02a0f4961af911045de639"); - result[1].GetSpan().ToHexString().Should().Be("03204223f8c86b8cd5c89ef12e4f0dbb314172e9241e30c9ef2293790793537cf0"); - result[2].GetSpan().ToHexString().Should().Be("0222038884bbd1d8ff109ed3bdef3542e768eef76c1247aea8bc8171f532928c30"); - result[3].GetSpan().ToHexString().Should().Be("0226933336f1b75baa42d42b71d9091508b638046d19abd67f4e119bf64a7cfb4d"); - result[4].GetSpan().ToHexString().Should().Be("023a36c72844610b4d34d1968662424011bf783ca9d984efa19a20babf5582f3fe"); - result[5].GetSpan().ToHexString().Should().Be("03409f31f0d66bdc2f70a9730b66fe186658f84a8018204db01c106edc36553cd0"); - result[6].GetSpan().ToHexString().Should().Be("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"); - result[7].GetSpan().ToHexString().Should().Be("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d"); - result[8].GetSpan().ToHexString().Should().Be("02504acbc1f4b3bdad1d86d6e1a08603771db135a73e61c9d565ae06a1938cd2ad"); - result[9].GetSpan().ToHexString().Should().Be("03708b860c1de5d87f5b151a12c2a99feebd2e8b315ee8e7cf8aa19692a9e18379"); - result[10].GetSpan().ToHexString().Should().Be("0288342b141c30dc8ffcde0204929bb46aed5756b41ef4a56778d15ada8f0c6654"); - result[11].GetSpan().ToHexString().Should().Be("02a62c915cf19c7f19a50ec217e79fac2439bbaad658493de0c7d8ffa92ab0aa62"); - result[12].GetSpan().ToHexString().Should().Be("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e"); - result[13].GetSpan().ToHexString().Should().Be("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"); - result[14].GetSpan().ToHexString().Should().Be("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a"); - result[15].GetSpan().ToHexString().Should().Be("03c6aa6e12638b36e88adc1ccdceac4db9929575c3e03576c617c49cce7114a050"); - result[16].GetSpan().ToHexString().Should().Be("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554"); - result[17].GetSpan().ToHexString().Should().Be("02cd5a5547119e24feaa7c2a0f37b8c9366216bab7054de0065c9be42084003c8a"); - result[18].GetSpan().ToHexString().Should().Be("03cdcea66032b82f5c30450e381e5295cae85c5e6943af716cc6b646352a6067dc"); - result[19].GetSpan().ToHexString().Should().Be("03d281b42002647f0113f36c7b8efb30db66078dfaaa9ab3ff76d043a98d512fde"); - result[20].GetSpan().ToHexString().Should().Be("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093"); + Assert.AreEqual(21, result.Count); + Assert.AreEqual("020f2887f41474cfeb11fd262e982051c1541418137c02a0f4961af911045de639", result[0].GetSpan().ToHexString()); + Assert.AreEqual("03204223f8c86b8cd5c89ef12e4f0dbb314172e9241e30c9ef2293790793537cf0", result[1].GetSpan().ToHexString()); + Assert.AreEqual("0222038884bbd1d8ff109ed3bdef3542e768eef76c1247aea8bc8171f532928c30", result[2].GetSpan().ToHexString()); + Assert.AreEqual("0226933336f1b75baa42d42b71d9091508b638046d19abd67f4e119bf64a7cfb4d", result[3].GetSpan().ToHexString()); + Assert.AreEqual("023a36c72844610b4d34d1968662424011bf783ca9d984efa19a20babf5582f3fe", result[4].GetSpan().ToHexString()); + Assert.AreEqual("03409f31f0d66bdc2f70a9730b66fe186658f84a8018204db01c106edc36553cd0", result[5].GetSpan().ToHexString()); + Assert.AreEqual("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70", result[6].GetSpan().ToHexString()); + Assert.AreEqual("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", result[7].GetSpan().ToHexString()); + Assert.AreEqual("02504acbc1f4b3bdad1d86d6e1a08603771db135a73e61c9d565ae06a1938cd2ad", result[8].GetSpan().ToHexString()); + Assert.AreEqual("03708b860c1de5d87f5b151a12c2a99feebd2e8b315ee8e7cf8aa19692a9e18379", result[9].GetSpan().ToHexString()); + Assert.AreEqual("0288342b141c30dc8ffcde0204929bb46aed5756b41ef4a56778d15ada8f0c6654", result[10].GetSpan().ToHexString()); + Assert.AreEqual("02a62c915cf19c7f19a50ec217e79fac2439bbaad658493de0c7d8ffa92ab0aa62", result[11].GetSpan().ToHexString()); + Assert.AreEqual("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e", result[12].GetSpan().ToHexString()); + Assert.AreEqual("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", result[13].GetSpan().ToHexString()); + Assert.AreEqual("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", result[14].GetSpan().ToHexString()); + Assert.AreEqual("03c6aa6e12638b36e88adc1ccdceac4db9929575c3e03576c617c49cce7114a050", result[15].GetSpan().ToHexString()); + Assert.AreEqual("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554", result[16].GetSpan().ToHexString()); + Assert.AreEqual("02cd5a5547119e24feaa7c2a0f37b8c9366216bab7054de0065c9be42084003c8a", result[17].GetSpan().ToHexString()); + Assert.AreEqual("03cdcea66032b82f5c30450e381e5295cae85c5e6943af716cc6b646352a6067dc", result[18].GetSpan().ToHexString()); + Assert.AreEqual("03d281b42002647f0113f36c7b8efb30db66078dfaaa9ab3ff76d043a98d512fde", result[19].GetSpan().ToHexString()); + Assert.AreEqual("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", result[20].GetSpan().ToHexString()); } [TestMethod] @@ -782,36 +797,36 @@ public void TestGetValidators() { var clonedCache = _snapshotCache.CloneCache(); var result = NativeContract.NEO.ComputeNextBlockValidators(clonedCache, TestProtocolSettings.Default); - result[0].ToArray().ToHexString().Should().Be("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"); - result[1].ToArray().ToHexString().Should().Be("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d"); - result[2].ToArray().ToHexString().Should().Be("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e"); - result[3].ToArray().ToHexString().Should().Be("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"); - result[4].ToArray().ToHexString().Should().Be("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a"); - result[5].ToArray().ToHexString().Should().Be("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554"); - result[6].ToArray().ToHexString().Should().Be("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093"); + Assert.AreEqual("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70", result[0].ToArray().ToHexString()); + Assert.AreEqual("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", result[1].ToArray().ToHexString()); + Assert.AreEqual("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e", result[2].ToArray().ToHexString()); + Assert.AreEqual("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", result[3].ToArray().ToHexString()); + Assert.AreEqual("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", result[4].ToArray().ToHexString()); + Assert.AreEqual("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554", result[5].ToArray().ToHexString()); + Assert.AreEqual("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", result[6].ToArray().ToHexString()); } [TestMethod] public void TestOnBalanceChanging() { var ret = Transfer4TesingOnBalanceChanging(new BigInteger(0), false); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); ret = Transfer4TesingOnBalanceChanging(new BigInteger(1), false); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); ret = Transfer4TesingOnBalanceChanging(new BigInteger(1), true); - ret.Result.Should().BeTrue(); - ret.State.Should().BeTrue(); + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); } [TestMethod] public void TestTotalSupply() { var clonedCache = _snapshotCache.CloneCache(); - NativeContract.NEO.TotalSupply(clonedCache).Should().Be(new BigInteger(100000000)); + Assert.AreEqual(new BigInteger(100000000), NativeContract.NEO.TotalSupply(clonedCache)); } [TestMethod] @@ -822,19 +837,19 @@ public void TestEconomicParameter() var persistingBlock = new Block { Header = new Header() }; (BigInteger, bool) result = Check_GetGasPerBlock(clonedCache, persistingBlock); - result.Item2.Should().BeTrue(); - result.Item1.Should().Be(5 * NativeContract.GAS.Factor); + Assert.IsTrue(result.Item2); + Assert.AreEqual(5 * NativeContract.GAS.Factor, result.Item1); persistingBlock = new Block { Header = new Header { Index = 10 } }; (VM.Types.Boolean, bool) result1 = Check_SetGasPerBlock(clonedCache, 10 * NativeContract.GAS.Factor, persistingBlock); - result1.Item2.Should().BeTrue(); - result1.Item1.GetBoolean().Should().BeTrue(); + Assert.IsTrue(result1.Item2); + Assert.IsTrue(result1.Item1.GetBoolean()); var height = clonedCache[NativeContract.Ledger.CreateStorageKey(Prefix_CurrentBlock)].GetInteroperable(); height.Index = persistingBlock.Index + 1; result = Check_GetGasPerBlock(clonedCache, persistingBlock); - result.Item2.Should().BeTrue(); - result.Item1.Should().Be(10 * NativeContract.GAS.Factor); + Assert.IsTrue(result.Item2); + Assert.AreEqual(10 * NativeContract.GAS.Factor, result.Item1); // Check calculate bonus StorageItem storage = clonedCache.GetOrAdd(CreateStorageKey(20, UInt160.Zero.ToArray()), () => new StorageItem(new NeoAccountState())); @@ -842,7 +857,7 @@ public void TestEconomicParameter() state.Balance = 1000; state.BalanceHeight = 0; height.Index = persistingBlock.Index + 1; - NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, persistingBlock.Index + 2).Should().Be(6500); + Assert.AreEqual(6500, NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, persistingBlock.Index + 2)); } [TestMethod] @@ -882,17 +897,17 @@ public void TestClaimGas() }, Transactions = Array.Empty() }; - Check_PostPersist(clonedCache, persistingBlock).Should().BeTrue(); + Assert.IsTrue(Check_PostPersist(clonedCache, persistingBlock)); var committee = TestProtocolSettings.Default.StandbyCommittee.OrderBy(p => p).ToArray(); var accountA = committee[0]; var accountB = committee[TestProtocolSettings.Default.CommitteeMembersCount - 1]; - NativeContract.NEO.BalanceOf(clonedCache, Contract.CreateSignatureContract(accountA).ScriptHash).Should().Be(0); + Assert.AreEqual(0, NativeContract.NEO.BalanceOf(clonedCache, Contract.CreateSignatureContract(accountA).ScriptHash)); StorageItem storageItem = clonedCache.TryGet(new KeyBuilder(NativeContract.NEO.Id, 23).Add(accountA)); - ((BigInteger)storageItem).Should().Be(30000000000); + Assert.AreEqual(30000000000, (BigInteger)storageItem); - clonedCache.TryGet(new KeyBuilder(NativeContract.NEO.Id, 23).Add(accountB).AddBigEndian(uint.MaxValue - 1)).Should().BeNull(); + Assert.IsNull(clonedCache.TryGet(new KeyBuilder(NativeContract.NEO.Id, 23).Add(accountB).AddBigEndian(uint.MaxValue - 1))); // Next block @@ -908,12 +923,12 @@ public void TestClaimGas() }, Transactions = Array.Empty() }; - Check_PostPersist(clonedCache, persistingBlock).Should().BeTrue(); + Assert.IsTrue(Check_PostPersist(clonedCache, persistingBlock)); - NativeContract.NEO.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[1]).ScriptHash).Should().Be(0); + Assert.AreEqual(0, NativeContract.NEO.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[1]).ScriptHash)); storageItem = clonedCache.TryGet(new KeyBuilder(NativeContract.NEO.Id, 23).Add(committee[1])); - ((BigInteger)storageItem).Should().Be(30000000000); + Assert.AreEqual(30000000000, (BigInteger)storageItem); // Next block @@ -929,13 +944,13 @@ public void TestClaimGas() }, Transactions = Array.Empty() }; - Check_PostPersist(clonedCache, persistingBlock).Should().BeTrue(); + Assert.IsTrue(Check_PostPersist(clonedCache, persistingBlock)); accountA = TestProtocolSettings.Default.StandbyCommittee.OrderBy(p => p).ToArray()[2]; - NativeContract.NEO.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[2]).ScriptHash).Should().Be(0); + Assert.AreEqual(0, NativeContract.NEO.BalanceOf(clonedCache, Contract.CreateSignatureContract(committee[2]).ScriptHash)); storageItem = clonedCache.TryGet(new KeyBuilder(NativeContract.NEO.Id, 23).Add(committee[2])); - ((BigInteger)storageItem).Should().Be(30000000000 * 2); + Assert.AreEqual(30000000000 * 2, (BigInteger)storageItem); // Claim GAS @@ -947,20 +962,20 @@ public void TestClaimGas() VoteTo = committee[2], LastGasPerVote = 30000000000, })); - NativeContract.NEO.BalanceOf(clonedCache, account).Should().Be(1999800); + Assert.AreEqual(1999800, NativeContract.NEO.BalanceOf(clonedCache, account)); var storageKey = new KeyBuilder(NativeContract.Ledger.Id, 12); clonedCache.GetAndChange(storageKey).GetInteroperable().Index = 29 + 2; BigInteger value = NativeContract.NEO.UnclaimedGas(clonedCache, account, 29 + 3); - value.Should().Be(1999800 * 30000000000 / 100000000L + (1999800L * 10 * 5 * 29 / 100)); + Assert.AreEqual(1999800 * 30000000000 / 100000000L + (1999800L * 10 * 5 * 29 / 100), value); } [TestMethod] public void TestUnclaimedGas() { var clonedCache = _snapshotCache.CloneCache(); - NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10).Should().Be(new BigInteger(0)); + Assert.AreEqual(BigInteger.Zero, NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10)); clonedCache.Add(CreateStorageKey(20, UInt160.Zero.ToArray()), new StorageItem(new NeoAccountState())); - NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10).Should().Be(new BigInteger(0)); + Assert.AreEqual(BigInteger.Zero, NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, 10)); } [TestMethod] @@ -972,20 +987,20 @@ public void TestVote() StorageKey keyValidator = CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()); _persistingBlock.Header.Index = 1; var ret = Check_Vote(clonedCache, account.ToArray(), ECCurve.Secp256r1.G.ToArray(), false, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeFalse(); + Assert.IsFalse(ret.Result); + Assert.IsTrue(ret.State); ret = Check_Vote(clonedCache, account.ToArray(), ECCurve.Secp256r1.G.ToArray(), true, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeFalse(); + Assert.IsFalse(ret.Result); + Assert.IsTrue(ret.State); clonedCache.Add(keyAccount, new StorageItem(new NeoAccountState())); ret = Check_Vote(clonedCache, account.ToArray(), ECCurve.Secp256r1.G.ToArray(), true, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeFalse(); + Assert.IsFalse(ret.Result); + Assert.IsTrue(ret.State); var (_, _, vote_to_null) = GetAccountState(clonedCache, account); - vote_to_null.Should().BeNull(); + Assert.IsNull(vote_to_null); clonedCache.Delete(keyAccount); clonedCache.GetAndChange(keyAccount, () => new StorageItem(new NeoAccountState @@ -995,18 +1010,18 @@ public void TestVote() })); clonedCache.Add(keyValidator, new StorageItem(new CandidateState() { Registered = true })); ret = Check_Vote(clonedCache, account.ToArray(), ECCurve.Secp256r1.G.ToArray(), true, _persistingBlock); - ret.State.Should().BeTrue(); - ret.Result.Should().BeTrue(); - + Assert.IsTrue(ret.Result); + Assert.IsTrue(ret.State); var (_, _, voteto) = GetAccountState(clonedCache, account); - voteto.ToHexString().Should().Be(ECCurve.Secp256r1.G.ToArray().ToHexString()); + Assert.AreEqual(ECCurve.Secp256r1.G.ToArray().ToHexString(), voteto.ToHexString()); } internal (bool State, bool Result) Transfer4TesingOnBalanceChanging(BigInteger amount, bool addVotes) { var clonedCache = _snapshotCache.CloneCache(); _persistingBlock.Header.Index = 1; - var engine = ApplicationEngine.Create(TriggerType.Application, TestBlockchain.TheNeoSystem.GenesisBlock, clonedCache, _persistingBlock, settings: TestBlockchain.TheNeoSystem.Settings); + var engine = ApplicationEngine.Create(TriggerType.Application, + new Nep17NativeContractExtensions.ManualWitness(UInt160.Zero), clonedCache, _persistingBlock, settings: TestBlockchain.TheNeoSystem.Settings); ScriptBuilder sb = new(); var tmp = engine.ScriptContainer.GetScriptHashesForVerifying(engine.SnapshotCache); UInt160 from = engine.ScriptContainer.GetScriptHashesForVerifying(engine.SnapshotCache)[0]; @@ -1032,7 +1047,7 @@ public void TestVote() var state = engine.Execute(); Console.WriteLine($"{state} {engine.FaultException}"); var result = engine.ResultStack.Peek(); - result.GetType().Should().Be(typeof(VM.Types.Boolean)); + Assert.AreEqual(typeof(VM.Types.Boolean), result.GetType()); return (true, result.GetBoolean()); } @@ -1070,7 +1085,7 @@ internal static (BigInteger Value, bool State) Check_GetGasPerBlock(DataCache cl } var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Integer)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Integer)); return (((VM.Types.Integer)result).GetInteger(), true); } @@ -1078,16 +1093,15 @@ internal static (BigInteger Value, bool State) Check_GetGasPerBlock(DataCache cl internal static (VM.Types.Boolean Value, bool State) Check_SetGasPerBlock(DataCache clonedCache, BigInteger gasPerBlock, Block persistingBlock) { UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(clonedCache); - using var engine = ApplicationEngine.Create(TriggerType.Application, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), clonedCache, persistingBlock, settings: TestBlockchain.TheNeoSystem.Settings); + using var engine = ApplicationEngine.Create(TriggerType.Application, + new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), clonedCache, persistingBlock, settings: TestBlockchain.TheNeoSystem.Settings); var script = new ScriptBuilder(); script.EmitDynamicCall(NativeContract.NEO.Hash, "setGasPerBlock", gasPerBlock); engine.LoadScript(script.ToArray()); if (engine.Execute() == VMState.FAULT) - { return (false, false); - } return (true, true); } @@ -1108,7 +1122,7 @@ internal static (bool State, bool Result) Check_Vote(DataCache clonedCache, byte } var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Boolean)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Boolean)); return (true, result.GetBoolean()); } @@ -1128,7 +1142,7 @@ internal static (bool State, bool Result) Check_RegisterValidator(DataCache clon } var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Boolean)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Boolean)); return (true, result.GetBoolean()); } @@ -1158,7 +1172,7 @@ internal static (bool State, bool Result) Check_RegisterValidatorViaNEP27(DataCa return (false, false); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Boolean)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Boolean)); return (true, result.GetBoolean()); } @@ -1171,10 +1185,10 @@ internal static ECPoint[] Check_GetCommittee(DataCache clonedCache, Block persis script.EmitDynamicCall(NativeContract.NEO.Hash, "getCommittee"); engine.LoadScript(script.ToArray()); - engine.Execute().Should().Be(VMState.HALT); + Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Array)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Array)); return (result as VM.Types.Array).Select(u => ECPoint.DecodePoint(u.GetSpan(), ECCurve.Secp256r1)).ToArray(); } @@ -1194,7 +1208,7 @@ internal static (BigInteger Value, bool State) Check_UnclaimedGas(DataCache clon } var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Integer)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Integer)); return (result.GetInteger(), true); } @@ -1202,23 +1216,23 @@ internal static (BigInteger Value, bool State) Check_UnclaimedGas(DataCache clon internal static void CheckValidator(ECPoint eCPoint, DataCache.Trackable trackable) { BigInteger st = trackable.Item; - st.Should().Be(0); + Assert.AreEqual(0, st); - trackable.Key.Key.Should().BeEquivalentTo(new byte[] { 33 }.Concat(eCPoint.EncodePoint(true))); + CollectionAssert.AreEqual(new byte[] { 33 }.Concat(eCPoint.EncodePoint(true)).ToArray(), trackable.Key.Key.ToArray()); } internal static void CheckBalance(byte[] account, DataCache.Trackable trackable, BigInteger balance, BigInteger height, ECPoint voteTo) { var st = (VM.Types.Struct)BinarySerializer.Deserialize(trackable.Item.Value, ExecutionEngineLimits.Default); - st.Count.Should().Be(3); - st.Select(u => u.GetType()).ToArray().Should().BeEquivalentTo(new Type[] { typeof(VM.Types.Integer), typeof(VM.Types.Integer), typeof(VM.Types.ByteString) }); // Balance + Assert.AreEqual(3, st.Count); + CollectionAssert.AreEqual(new Type[] { typeof(VM.Types.Integer), typeof(VM.Types.Integer), typeof(VM.Types.ByteString) }, st.Select(u => u.GetType()).ToArray()); // Balance - st[0].GetInteger().Should().Be(balance); // Balance - st[1].GetInteger().Should().Be(height); // BalanceHeight - ECPoint.DecodePoint(st[2].GetSpan(), ECCurve.Secp256r1).Should().BeEquivalentTo(voteTo); // Votes + Assert.AreEqual(balance, st[0].GetInteger()); // Balance + Assert.AreEqual(height, st[1].GetInteger()); // BalanceHeight + Assert.AreEqual(voteTo, ECPoint.DecodePoint(st[2].GetSpan(), ECCurve.Secp256r1)); // Votes - trackable.Key.Key.Should().BeEquivalentTo(new byte[] { 20 }.Concat(account)); + CollectionAssert.AreEqual(new byte[] { 20 }.Concat(account).ToArray(), trackable.Key.Key.ToArray()); } internal static StorageKey CreateStorageKey(byte prefix, byte[] key = null) @@ -1248,7 +1262,7 @@ internal static (bool State, bool Result) Check_UnregisterCandidate(DataCache cl } var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Boolean)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Boolean)); return (true, result.GetBoolean()); } @@ -1261,10 +1275,10 @@ internal static (BigInteger balance, BigInteger height, byte[] voteto) GetAccoun script.EmitDynamicCall(NativeContract.NEO.Hash, "getAccountState", account); engine.LoadScript(script.ToArray()); - engine.Execute().Should().Be(VMState.HALT); + Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Struct)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Struct)); VM.Types.Struct state = (result as VM.Types.Struct); var balance = state[0].GetInteger(); diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs index 4791ca7555..ecbcc3c7dc 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -44,12 +43,12 @@ public void Check_Default() var snapshot = _snapshotCache.CloneCache(); var ret = NativeContract.Policy.Call(snapshot, "getFeePerByte"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(1000); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(1000, ret.GetInteger()); ret = NativeContract.Policy.Call(snapshot, "getAttributeFee", new ContractParameter(ContractParameterType.Integer) { Value = (BigInteger)(byte)TransactionAttributeType.Conflicts }); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(PolicyContract.DefaultAttributeFee); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(PolicyContract.DefaultAttributeFee, ret.GetInteger()); Assert.ThrowsException(() => NativeContract.Policy.Call(snapshot, "getAttributeFee", new ContractParameter(ContractParameterType.Integer) { Value = (BigInteger)byte.MaxValue })); } @@ -79,8 +78,8 @@ public void Check_SetAttributeFee() }); var ret = NativeContract.Policy.Call(snapshot, "getAttributeFee", attr); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(0); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(0, ret.GetInteger()); // With signature, wrong value UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(snapshot); @@ -91,26 +90,26 @@ public void Check_SetAttributeFee() }); ret = NativeContract.Policy.Call(snapshot, "getAttributeFee", attr); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(0); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(0, ret.GetInteger()); // Proper set ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "setAttributeFee", attr, new ContractParameter(ContractParameterType.Integer) { Value = 300300 }); - ret.IsNull.Should().BeTrue(); + Assert.IsTrue(ret.IsNull); ret = NativeContract.Policy.Call(snapshot, "getAttributeFee", attr); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(300300); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(300300, ret.GetInteger()); // Set to zero ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "setAttributeFee", attr, new ContractParameter(ContractParameterType.Integer) { Value = 0 }); - ret.IsNull.Should().BeTrue(); + Assert.IsTrue(ret.IsNull); ret = NativeContract.Policy.Call(snapshot, "getAttributeFee", attr); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(0); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(0, ret.GetInteger()); } [TestMethod] @@ -138,18 +137,18 @@ public void Check_SetFeePerByte() }); var ret = NativeContract.Policy.Call(snapshot, "getFeePerByte"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(1000); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(1000, ret.GetInteger()); // With signature UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(snapshot); ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "setFeePerByte", new ContractParameter(ContractParameterType.Integer) { Value = 1 }); - ret.IsNull.Should().BeTrue(); + Assert.IsTrue(ret.IsNull); ret = NativeContract.Policy.Call(snapshot, "getFeePerByte"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(1); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(1, ret.GetInteger()); } [TestMethod] @@ -177,8 +176,8 @@ public void Check_SetBaseExecFee() }); var ret = NativeContract.Policy.Call(snapshot, "getExecFeeFactor"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(30); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(30, ret.GetInteger()); // With signature, wrong value UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(snapshot); @@ -189,17 +188,17 @@ public void Check_SetBaseExecFee() }); ret = NativeContract.Policy.Call(snapshot, "getExecFeeFactor"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(30); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(30, ret.GetInteger()); // Proper set ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "setExecFeeFactor", new ContractParameter(ContractParameterType.Integer) { Value = 50 }); - ret.IsNull.Should().BeTrue(); + Assert.IsTrue(ret.IsNull); ret = NativeContract.Policy.Call(snapshot, "getExecFeeFactor"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(50); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(50, ret.GetInteger()); } [TestMethod] @@ -227,8 +226,8 @@ public void Check_SetStoragePrice() }); var ret = NativeContract.Policy.Call(snapshot, "getStoragePrice"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(100000); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(100000, ret.GetInteger()); // With signature, wrong value UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(snapshot); @@ -239,17 +238,17 @@ public void Check_SetStoragePrice() }); ret = NativeContract.Policy.Call(snapshot, "getStoragePrice"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(100000); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(100000, ret.GetInteger()); // Proper set ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "setStoragePrice", new ContractParameter(ContractParameterType.Integer) { Value = 300300 }); - ret.IsNull.Should().BeTrue(); + Assert.IsTrue(ret.IsNull); ret = NativeContract.Policy.Call(snapshot, "getStoragePrice"); - ret.Should().BeOfType(); - ret.GetInteger().Should().Be(300300); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Integer)); + Assert.AreEqual(300300, ret.GetInteger()); } [TestMethod] @@ -283,29 +282,29 @@ public void Check_BlockAccount() var ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "blockAccount", new ContractParameter(ContractParameterType.ByteArray) { Value = UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01").ToArray() }); - ret.Should().BeOfType(); - ret.GetBoolean().Should().BeTrue(); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Boolean)); + Assert.IsTrue(ret.GetBoolean()); // Same account ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "blockAccount", new ContractParameter(ContractParameterType.ByteArray) { Value = UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01").ToArray() }); - ret.Should().BeOfType(); - ret.GetBoolean().Should().BeFalse(); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Boolean)); + Assert.IsFalse(ret.GetBoolean()); // Account B ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "blockAccount", new ContractParameter(ContractParameterType.ByteArray) { Value = UInt160.Parse("0xb400ff00ff00ff00ff00ff00ff00ff00ff00ff01").ToArray() }); - ret.Should().BeOfType(); - ret.GetBoolean().Should().BeTrue(); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Boolean)); + Assert.IsTrue(ret.GetBoolean()); // Check - NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero).Should().BeFalse(); - NativeContract.Policy.IsBlocked(snapshot, UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01")).Should().BeTrue(); - NativeContract.Policy.IsBlocked(snapshot, UInt160.Parse("0xb400ff00ff00ff00ff00ff00ff00ff00ff00ff01")).Should().BeTrue(); + Assert.IsFalse(NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero)); + Assert.IsTrue(NativeContract.Policy.IsBlocked(snapshot, UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01"))); + Assert.IsTrue(NativeContract.Policy.IsBlocked(snapshot, UInt160.Parse("0xb400ff00ff00ff00ff00ff00ff00ff00ff00ff01"))); } [TestMethod] @@ -333,16 +332,16 @@ public void Check_Block_UnblockAccount() "blockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); }); - NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero).Should().BeFalse(); + Assert.IsFalse(NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero)); // Block with signature var ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "blockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); - ret.Should().BeOfType(); - ret.GetBoolean().Should().BeTrue(); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Boolean)); + Assert.IsTrue(ret.GetBoolean()); - NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero).Should().BeTrue(); + Assert.IsTrue(NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero)); // Unblock without signature @@ -352,16 +351,16 @@ public void Check_Block_UnblockAccount() "unblockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); }); - NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero).Should().BeTrue(); + Assert.IsTrue(NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero)); // Unblock with signature ret = NativeContract.Policy.Call(snapshot, new Nep17NativeContractExtensions.ManualWitness(committeeMultiSigAddr), block, "unblockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); - ret.Should().BeOfType(); - ret.GetBoolean().Should().BeTrue(); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Boolean)); + Assert.IsTrue(ret.GetBoolean()); - NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero).Should().BeFalse(); + Assert.IsFalse(NativeContract.Policy.IsBlocked(snapshot, UInt160.Zero)); } } } diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs index 1b24ff0fe1..5e102d9f41 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -78,8 +77,8 @@ public void TestSetAndGet() ); snapshot1.Commit(); ApplicationEngine.Notify -= ev; - notifications.Count.Should().Be(1); - notifications[0].EventName.Should().Be("Designation"); + Assert.AreEqual(1, notifications.Count); + Assert.AreEqual("Designation", notifications[0].EventName); var snapshot2 = _snapshotCache.CloneCache(); ret = NativeContract.RoleManagement.Call( snapshot2, @@ -87,10 +86,10 @@ public void TestSetAndGet() new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger((int)role) }, new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger(1u) } ); - ret.Should().BeOfType(); - (ret as VM.Types.Array).Count.Should().Be(2); - (ret as VM.Types.Array)[0].GetSpan().ToHexString().Should().Be(publicKeys[0].ToArray().ToHexString()); - (ret as VM.Types.Array)[1].GetSpan().ToHexString().Should().Be(publicKeys[1].ToArray().ToHexString()); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Array)); + Assert.AreEqual(2, (ret as VM.Types.Array).Count); + Assert.AreEqual(publicKeys[0].ToArray().ToHexString(), (ret as VM.Types.Array)[0].GetSpan().ToHexString()); + Assert.AreEqual(publicKeys[1].ToArray().ToHexString(), (ret as VM.Types.Array)[1].GetSpan().ToHexString()); ret = NativeContract.RoleManagement.Call( snapshot2, @@ -98,8 +97,8 @@ public void TestSetAndGet() new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger((int)role) }, new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger(0) } ); - ret.Should().BeOfType(); - (ret as VM.Types.Array).Count.Should().Be(0); + Assert.IsInstanceOfType(ret, typeof(VM.Types.Array)); + Assert.AreEqual(0, (ret as VM.Types.Array).Count); } } diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_StdLib.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_StdLib.cs index 4878e9cc8a..42b0654325 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_StdLib.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_StdLib.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.SmartContract; @@ -56,8 +55,8 @@ public void TestItoaAtoi() Assert.ThrowsException(() => StdLib.Atoi("g", 16)); Assert.ThrowsException(() => StdLib.Atoi("a", 11)); - StdLib.Atoi(StdLib.Itoa(BigInteger.One, 10)).Should().Be(BigInteger.One); - StdLib.Atoi(StdLib.Itoa(BigInteger.MinusOne, 10)).Should().Be(BigInteger.MinusOne); + Assert.AreEqual(BigInteger.One, StdLib.Atoi(StdLib.Itoa(BigInteger.One, 10))); + Assert.AreEqual(BigInteger.MinusOne, StdLib.Atoi(StdLib.Itoa(BigInteger.MinusOne, 10))); } [TestMethod] diff --git a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Contract.cs b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Contract.cs index 0ed01c914b..241432843d 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Contract.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Contract.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.Persistence; @@ -43,7 +42,7 @@ public void TestCreateStandardAccount() Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - new UInt160(result.GetSpan()).Should().Be(Contract.CreateSignatureRedeemScript(settings.StandbyCommittee[0]).ToScriptHash()); + Assert.AreEqual(Contract.CreateSignatureRedeemScript(settings.StandbyCommittee[0]).ToScriptHash(), new UInt160(result.GetSpan())); } [TestMethod] @@ -67,7 +66,7 @@ public void TestCreateStandardMultisigAccount() Assert.AreEqual(VMState.HALT, engine.Execute()); var result = engine.ResultStack.Pop(); - new UInt160(result.GetSpan()).Should().Be(Contract.CreateMultiSigRedeemScript(2, settings.StandbyCommittee.Take(3).ToArray()).ToScriptHash()); + Assert.AreEqual(Contract.CreateMultiSigRedeemScript(2, settings.StandbyCommittee.Take(3).ToArray()).ToScriptHash(), new UInt160(result.GetSpan())); } } } diff --git a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Runtime.cs b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Runtime.cs index df400a9aff..d2ce7e6478 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Runtime.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Runtime.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Network.P2P.Payloads; using Neo.SmartContract; @@ -28,8 +27,8 @@ public void TestGetNetworkAndAddressVersion() var tx = TestUtils.GetTransaction(UInt160.Zero); using var engine = ApplicationEngine.Create(TriggerType.Application, tx, null, TestBlockchain.TheNeoSystem.GenesisBlock, settings: TestBlockchain.TheNeoSystem.Settings, gas: 1100_00000000); - engine.GetNetwork().Should().Be(TestBlockchain.TheNeoSystem.Settings.Network); - engine.GetAddressVersion().Should().Be(TestBlockchain.TheNeoSystem.Settings.AddressVersion); + Assert.AreEqual(TestBlockchain.TheNeoSystem.Settings.Network, engine.GetNetwork()); + Assert.AreEqual(TestBlockchain.TheNeoSystem.Settings.AddressVersion, engine.GetAddressVersion()); } [TestMethod] @@ -75,7 +74,7 @@ public void TestNotSupportedNotification() engine.CurrentContext.GetState().Contract.Manifest.Abi.Events[0].Parameters[0].Type = ContractParameterType.ByteArray; engine.RuntimeNotify(Encoding.ASCII.GetBytes("e1"), array); - engine.Notifications[0].State[0].Type.Should().Be(VM.Types.StackItemType.ByteString); + Assert.AreEqual(VM.Types.StackItemType.ByteString, engine.Notifications[0].State[0].Type); // Pointer @@ -116,17 +115,17 @@ public void TestGetRandomSameBlock() var rand_9 = engine_2.GetRandom(); var rand_10 = engine_2.GetRandom(); - rand_1.Should().Be(BigInteger.Parse("271339657438512451304577787170704246350")); - rand_2.Should().Be(BigInteger.Parse("98548189559099075644778613728143131367")); - rand_3.Should().Be(BigInteger.Parse("247654688993873392544380234598471205121")); - rand_4.Should().Be(BigInteger.Parse("291082758879475329976578097236212073607")); - rand_5.Should().Be(BigInteger.Parse("247152297361212656635216876565962360375")); - - rand_1.Should().Be(rand_6); - rand_2.Should().Be(rand_7); - rand_3.Should().Be(rand_8); - rand_4.Should().Be(rand_9); - rand_5.Should().Be(rand_10); + Assert.AreEqual(BigInteger.Parse("271339657438512451304577787170704246350"), rand_1); + Assert.AreEqual(BigInteger.Parse("98548189559099075644778613728143131367"), rand_2); + Assert.AreEqual(BigInteger.Parse("247654688993873392544380234598471205121"), rand_3); + Assert.AreEqual(BigInteger.Parse("291082758879475329976578097236212073607"), rand_4); + Assert.AreEqual(BigInteger.Parse("247152297361212656635216876565962360375"), rand_5); + + Assert.AreEqual(rand_6, rand_1); + Assert.AreEqual(rand_7, rand_2); + Assert.AreEqual(rand_8, rand_3); + Assert.AreEqual(rand_9, rand_4); + Assert.AreEqual(rand_10, rand_5); } [TestMethod] @@ -163,17 +162,17 @@ public void TestGetRandomDifferentBlock() var rand_9 = engine_2.GetRandom(); var rand_10 = engine_2.GetRandom(); - rand_1.Should().Be(BigInteger.Parse("271339657438512451304577787170704246350")); - rand_2.Should().Be(BigInteger.Parse("98548189559099075644778613728143131367")); - rand_3.Should().Be(BigInteger.Parse("247654688993873392544380234598471205121")); - rand_4.Should().Be(BigInteger.Parse("291082758879475329976578097236212073607")); - rand_5.Should().Be(BigInteger.Parse("247152297361212656635216876565962360375")); - - rand_1.Should().NotBe(rand_6); - rand_2.Should().NotBe(rand_7); - rand_3.Should().NotBe(rand_8); - rand_4.Should().NotBe(rand_9); - rand_5.Should().NotBe(rand_10); + Assert.AreEqual(BigInteger.Parse("271339657438512451304577787170704246350"), rand_1); + Assert.AreEqual(BigInteger.Parse("98548189559099075644778613728143131367"), rand_2); + Assert.AreEqual(BigInteger.Parse("247654688993873392544380234598471205121"), rand_3); + Assert.AreEqual(BigInteger.Parse("291082758879475329976578097236212073607"), rand_4); + Assert.AreEqual(BigInteger.Parse("247152297361212656635216876565962360375"), rand_5); + + Assert.AreNotEqual(rand_6, rand_1); + Assert.AreNotEqual(rand_7, rand_2); + Assert.AreNotEqual(rand_8, rand_3); + Assert.AreNotEqual(rand_9, rand_4); + Assert.AreNotEqual(rand_10, rand_5); } [TestMethod] diff --git a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.cs b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.cs index 2cd76927e0..063ffccfbb 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.SmartContract; @@ -38,20 +37,20 @@ public void TestNotify() const string notifyEvent = "TestEvent"; engine.SendNotification(UInt160.Zero, notifyEvent, new Array()); - eventName.Should().Be(notifyEvent); + Assert.AreEqual(notifyEvent, eventName); ApplicationEngine.Notify += Test_Notify2; engine.SendNotification(UInt160.Zero, notifyEvent, new Array()); - eventName.Should().Be(null); + Assert.AreEqual(null, eventName); eventName = notifyEvent; ApplicationEngine.Notify -= Test_Notify1; engine.SendNotification(UInt160.Zero, notifyEvent, new Array()); - eventName.Should().Be(null); + Assert.AreEqual(null, eventName); ApplicationEngine.Notify -= Test_Notify2; engine.SendNotification(UInt160.Zero, notifyEvent, new Array()); - eventName.Should().Be(null); + Assert.AreEqual(null, eventName); } private void Test_Notify1(object sender, NotifyEventArgs e) @@ -70,9 +69,9 @@ public void TestCreateDummyBlock() var snapshotCache = TestBlockchain.GetTestSnapshotCache(); byte[] SyscallSystemRuntimeCheckWitnessHash = new byte[] { 0x68, 0xf8, 0x27, 0xec, 0x8c }; ApplicationEngine engine = ApplicationEngine.Run(SyscallSystemRuntimeCheckWitnessHash, snapshotCache, settings: TestProtocolSettings.Default); - engine.PersistingBlock.Version.Should().Be(0); - engine.PersistingBlock.PrevHash.Should().Be(TestBlockchain.TheNeoSystem.GenesisBlock.Hash); - engine.PersistingBlock.MerkleRoot.Should().Be(new UInt256()); + Assert.AreEqual(0u, engine.PersistingBlock.Version); + Assert.AreEqual(TestBlockchain.TheNeoSystem.GenesisBlock.Hash, engine.PersistingBlock.PrevHash); + Assert.AreEqual(new UInt256(), engine.PersistingBlock.MerkleRoot); } [TestMethod] @@ -98,13 +97,13 @@ public void TestCheckingHardfork() // If they aren't consecutive, return false. var inc = nextIndex - currentIndex; - inc.Should().Be(1); + Assert.AreEqual(1, inc); } // Check that block numbers are not higher in earlier hardforks than in later ones for (int i = 0; i < sortedHardforks.Count - 1; i++) { - (setting[sortedHardforks[i]] > setting[sortedHardforks[i + 1]]).Should().Be(false); + Assert.IsFalse(setting[sortedHardforks[i]] > setting[sortedHardforks[i + 1]]); } } diff --git a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngineProvider.cs b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngineProvider.cs index e0447e1c12..67ca760715 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngineProvider.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_ApplicationEngineProvider.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Network.P2P.Payloads; using Neo.Persistence; @@ -43,7 +42,7 @@ public void TestSetAppEngineProvider() var snapshot = _snapshotCache.CloneCache(); using var appEngine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, gas: 0, settings: TestBlockchain.TheNeoSystem.Settings); - (appEngine is TestEngine).Should().BeTrue(); + Assert.IsTrue(appEngine is TestEngine); } [TestMethod] @@ -51,7 +50,7 @@ public void TestDefaultAppEngineProvider() { var snapshot = _snapshotCache.CloneCache(); using var appEngine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, gas: 0, settings: TestBlockchain.TheNeoSystem.Settings); - (appEngine is ApplicationEngine).Should().BeTrue(); + Assert.IsTrue(appEngine is ApplicationEngine); } class TestProvider : IApplicationEngineProvider diff --git a/tests/Neo.UnitTests/SmartContract/UT_BinarySerializer.cs b/tests/Neo.UnitTests/SmartContract/UT_BinarySerializer.cs index 3df10208b4..4795872784 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_BinarySerializer.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_BinarySerializer.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.SmartContract; using Neo.VM; @@ -47,7 +46,7 @@ public void TestSerialize() StackItem stackItem4 = new InteropInterface(new object()); Action action4 = () => BinarySerializer.Serialize(stackItem4, ExecutionEngineLimits.Default); - action4.Should().Throw(); + Assert.ThrowsException(action4); List list6 = new List { 1 }; StackItem stackItem62 = new VM.Types.Array(list6); @@ -75,12 +74,12 @@ public void TestSerialize() Map stackItem91 = new Map(); stackItem91[1] = stackItem91; Action action9 = () => BinarySerializer.Serialize(stackItem91, ExecutionEngineLimits.Default); - action9.Should().Throw(); + Assert.ThrowsException(action9); VM.Types.Array stackItem10 = new VM.Types.Array(); stackItem10.Add(stackItem10); Action action10 = () => BinarySerializer.Serialize(stackItem10, ExecutionEngineLimits.Default); - action10.Should().Throw(); + Assert.ThrowsException(action10); } [TestMethod] @@ -104,7 +103,7 @@ public void TestDeserializeStackItem() byte[] byteArray4 = BinarySerializer.Serialize(1, ExecutionEngineLimits.Default); byteArray4[0] = 0x40; Action action4 = () => BinarySerializer.Deserialize(byteArray4, ExecutionEngineLimits.Default); - action4.Should().Throw(); + Assert.ThrowsException(action4); List list5 = new List { 1 }; StackItem stackItem52 = new VM.Types.Array(list5); diff --git a/tests/Neo.UnitTests/SmartContract/UT_Contract.cs b/tests/Neo.UnitTests/SmartContract/UT_Contract.cs index 273ea9faed..fa06adf0f7 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_Contract.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_Contract.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.Network.P2P.Payloads; @@ -112,7 +111,7 @@ public void TestCreateMultiSigRedeemScript() publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); Action action = () => Contract.CreateMultiSigRedeemScript(0, publicKeys); - action.Should().Throw(); + Assert.ThrowsException(() => action()); byte[] script = Contract.CreateMultiSigRedeemScript(2, publicKeys); byte[] expectedArray = new byte[77]; expectedArray[0] = (byte)OpCode.PUSH2; @@ -182,7 +181,7 @@ public void TestSignatureRedeemScriptFee() { engine.LoadScript(invocation.Concat(verification).ToArray(), configureState: p => p.CallFlags = CallFlags.None); engine.Execute(); - engine.FeeConsumed.Should().Be(fee); + Assert.AreEqual(fee, engine.FeeConsumed); } } @@ -212,7 +211,7 @@ public void TestCreateMultiSigRedeemScriptFee() { engine.LoadScript(invocation.Concat(verification).ToArray(), configureState: p => p.CallFlags = CallFlags.None); engine.Execute(); - engine.FeeConsumed.Should().Be(fee); + Assert.AreEqual(fee, engine.FeeConsumed); } } } diff --git a/tests/Neo.UnitTests/SmartContract/UT_ContractParameter.cs b/tests/Neo.UnitTests/SmartContract/UT_ContractParameter.cs index 897bab0e57..983869cf1a 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_ContractParameter.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_ContractParameter.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -77,8 +76,7 @@ public void TestGenerator2() Assert.IsNotNull(contractParameter10); Assert.AreEqual(0, ((List>)contractParameter10.Value).Count); - Action action = () => new ContractParameter(ContractParameterType.Void); - action.Should().Throw(); + Assert.ThrowsException(() => new ContractParameter(ContractParameterType.Void)); } [TestMethod] @@ -127,8 +125,7 @@ public void TestFromAndToJson() ContractParameter contractParameter11 = new(ContractParameterType.String); JObject jobject11 = contractParameter11.ToJson(); jobject11["type"] = "Void"; - Action action = () => ContractParameter.FromJson(jobject11); - action.Should().Throw(); + Assert.ThrowsException(() => ContractParameter.FromJson(jobject11)); } [TestMethod] @@ -155,8 +152,7 @@ public void TestContractParameterCyclicReference() // check cyclic reference value.Add(item); - Action action = () => item.ToJson(); - action.Should().Throw(); + Assert.ThrowsException(() => item.ToJson()); } [TestMethod] @@ -166,8 +162,7 @@ public void TestSetValue() byte[] expectedArray1 = new byte[64]; contractParameter1.SetValue(new byte[64].ToHexString()); Assert.AreEqual(Encoding.Default.GetString(expectedArray1), Encoding.Default.GetString((byte[])contractParameter1.Value)); - Action action1 = () => contractParameter1.SetValue(new byte[50].ToHexString()); - action1.Should().Throw(); + Assert.ThrowsException(() => contractParameter1.SetValue(new byte[50].ToHexString())); ContractParameter contractParameter2 = new(ContractParameterType.Boolean); contractParameter2.SetValue("true"); @@ -206,8 +201,7 @@ public void TestSetValue() Assert.AreEqual("AAA", contractParameter8.Value); ContractParameter contractParameter9 = new(ContractParameterType.Array); - Action action9 = () => contractParameter9.SetValue("AAA"); - action9.Should().Throw(); + Assert.ThrowsException(() => contractParameter9.SetValue("AAA")); } [TestMethod] diff --git a/tests/Neo.UnitTests/SmartContract/UT_ContractParameterContext.cs b/tests/Neo.UnitTests/SmartContract/UT_ContractParameterContext.cs index 972e05a3bd..fe251d3dcb 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_ContractParameterContext.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_ContractParameterContext.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -47,7 +46,7 @@ public void TestGetComplete() var snapshotCache = TestBlockchain.GetTestSnapshotCache(); Transaction tx = TestUtils.GetTransaction(UInt160.Parse("0x1bd5c777ec35768892bd3daab60fb7a1cb905066")); var context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context.Completed.Should().BeFalse(); + Assert.IsFalse(context.Completed); } [TestMethod] @@ -58,7 +57,7 @@ public void TestToString() var context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); context.Add(contract, 0, new byte[] { 0x01 }); string str = context.ToString(); - str.Should().Be(@"{""type"":""Neo.Network.P2P.Payloads.Transaction"",""hash"":""0x602c1fa1c08b041e4e6b87aa9a9f9c643166cd34bdd5215a3dd85778c59cce88"",""data"":""AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAARI="",""items"":{},""network"":" + TestProtocolSettings.Default.Network + "}"); + Assert.AreEqual(@"{""type"":""Neo.Network.P2P.Payloads.Transaction"",""hash"":""0x602c1fa1c08b041e4e6b87aa9a9f9c643166cd34bdd5215a3dd85778c59cce88"",""data"":""AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAARI="",""items"":{},""network"":" + TestProtocolSettings.Default.Network + "}", str); } [TestMethod] @@ -66,8 +65,8 @@ public void TestParse() { var snapshotCache = TestBlockchain.GetTestSnapshotCache(); var ret = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"data\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAARI=\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}],\"signatures\":{\"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c\":\"AQ==\"}}},\"network\":" + TestProtocolSettings.Default.Network + "}", snapshotCache); - ret.ScriptHashes[0].ToString().Should().Be("0x1bd5c777ec35768892bd3daab60fb7a1cb905066"); - ((Transaction)ret.Verifiable).Script.Span.ToHexString().Should().Be(new byte[] { 18 }.ToHexString()); + Assert.AreEqual("0x1bd5c777ec35768892bd3daab60fb7a1cb905066", ret.ScriptHashes[0].ToString()); + Assert.AreEqual(new byte[] { 18 }.ToHexString(), ((Transaction)ret.Verifiable).Script.Span.ToHexString()); } [TestMethod] @@ -75,7 +74,7 @@ public void TestFromJson() { var snapshotCache = TestBlockchain.GetTestSnapshotCache(); Action action = () => ContractParametersContext.Parse("{\"type\":\"wrongType\",\"data\":\"00000000007c97764845172d827d3c863743293931a691271a0000000000000000000000000000000000000000000100\",\"items\":{\"0x1bd5c777ec35768892bd3daab60fb7a1cb905066\":{\"script\":\"21026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca1650680a906ad4\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"01\"}]}}}", snapshotCache); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -84,13 +83,13 @@ public void TestAdd() var snapshotCache = TestBlockchain.GetTestSnapshotCache(); Transaction tx = TestUtils.GetTransaction(UInt160.Zero); var context1 = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context1.Add(contract, 0, new byte[] { 0x01 }).Should().BeFalse(); + Assert.IsFalse(context1.Add(contract, 0, new byte[] { 0x01 })); tx = TestUtils.GetTransaction(UInt160.Parse("0x902e0d38da5e513b6d07c1c55b85e77d3dce8063")); var context2 = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context2.Add(contract, 0, new byte[] { 0x01 }).Should().BeTrue(); + Assert.IsTrue(context2.Add(contract, 0, new byte[] { 0x01 })); //test repeatlly createItem - context2.Add(contract, 0, new byte[] { 0x01 }).Should().BeTrue(); + Assert.IsTrue(context2.Add(contract, 0, new byte[] { 0x01 })); } [TestMethod] @@ -99,11 +98,11 @@ public void TestGetParameter() var snapshotCache = TestBlockchain.GetTestSnapshotCache(); Transaction tx = TestUtils.GetTransaction(UInt160.Parse("0x902e0d38da5e513b6d07c1c55b85e77d3dce8063")); var context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context.GetParameter(tx.Sender, 0).Should().BeNull(); + Assert.IsNull(context.GetParameter(tx.Sender, 0)); context.Add(contract, 0, new byte[] { 0x01 }); var ret = context.GetParameter(tx.Sender, 0); - ((byte[])ret.Value).ToHexString().Should().Be(new byte[] { 0x01 }.ToHexString()); + Assert.AreEqual(new byte[] { 0x01 }.ToHexString(), ((byte[])ret.Value).ToHexString()); } [TestMethod] @@ -114,9 +113,9 @@ public void TestGetWitnesses() var context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); context.Add(contract, 0, new byte[] { 0x01 }); Witness[] witnesses = context.GetWitnesses(); - witnesses.Length.Should().Be(1); - witnesses[0].InvocationScript.Span.ToHexString().Should().Be(new byte[] { (byte)OpCode.PUSHDATA1, 0x01, 0x01 }.ToHexString()); - witnesses[0].VerificationScript.Span.ToHexString().Should().Be(contract.Script.ToHexString()); + Assert.AreEqual(1, witnesses.Length); + Assert.AreEqual(new byte[] { (byte)OpCode.PUSHDATA1, 0x01, 0x01 }.ToHexString(), witnesses[0].InvocationScript.Span.ToHexString()); + Assert.AreEqual(contract.Script.ToHexString(), witnesses[0].VerificationScript.Span.ToHexString()); } [TestMethod] @@ -129,16 +128,16 @@ public void TestAddSignature() //singleSign var context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context.AddSignature(contract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue(); + Assert.IsTrue(context.AddSignature(contract, key.PublicKey, new byte[] { 0x01 })); var contract1 = Contract.CreateSignatureContract(key.PublicKey); contract1.ParameterList = Array.Empty(); context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse(); + Assert.IsFalse(context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 })); contract1.ParameterList = new[] { ContractParameterType.Signature, ContractParameterType.Signature }; Action action1 = () => context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 }); - action1.Should().Throw(); + Assert.ThrowsException(action1); //multiSign @@ -156,12 +155,12 @@ public void TestAddSignature() var multiSender = UInt160.Parse("0xf76b51bc6605ac3cfcd188173af0930507f51210"); tx = TestUtils.GetTransaction(multiSender); context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue(); - context.AddSignature(multiSignContract, key2.PublicKey, new byte[] { 0x01 }).Should().BeTrue(); + Assert.IsTrue(context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 })); + Assert.IsTrue(context.AddSignature(multiSignContract, key2.PublicKey, new byte[] { 0x01 })); tx = TestUtils.GetTransaction(singleSender); context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); - context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse(); + Assert.IsFalse(context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 })); tx = TestUtils.GetTransaction(multiSender); context = new ContractParametersContext(snapshotCache, tx, TestProtocolSettings.Default.Network); @@ -170,7 +169,7 @@ public void TestAddSignature() 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03 }; var key3 = new KeyPair(privateKey3); - context.AddSignature(multiSignContract, key3.PublicKey, new byte[] { 0x01 }).Should().BeFalse(); + Assert.IsFalse(context.AddSignature(multiSignContract, key3.PublicKey, new byte[] { 0x01 })); } } } diff --git a/tests/Neo.UnitTests/SmartContract/UT_ContractState.cs b/tests/Neo.UnitTests/SmartContract/UT_ContractState.cs index f4e9e87bd5..86ed33b644 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_ContractState.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_ContractState.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Json; using Neo.SmartContract; @@ -49,9 +48,9 @@ public void TestSetup() public void TestGetScriptHash() { // _scriptHash == null - contract.Hash.Should().Be(script.ToScriptHash()); + Assert.AreEqual(script.ToScriptHash(), contract.Hash); // _scriptHash != null - contract.Hash.Should().Be(script.ToScriptHash()); + Assert.AreEqual(script.ToScriptHash(), contract.Hash); } [TestMethod] @@ -59,8 +58,8 @@ public void TestIInteroperable() { IInteroperable newContract = new ContractState(); newContract.FromStackItem(contract.ToStackItem(null)); - ((ContractState)newContract).Manifest.ToJson().ToString().Should().Be(contract.Manifest.ToJson().ToString()); - ((ContractState)newContract).Script.Span.SequenceEqual(contract.Script.Span).Should().BeTrue(); + Assert.AreEqual(contract.Manifest.ToJson().ToString(), ((ContractState)newContract).Manifest.ToJson().ToString()); + Assert.IsTrue(((ContractState)newContract).Script.Span.SequenceEqual(contract.Script.Span)); } [TestMethod] @@ -75,9 +74,9 @@ public void TestCanCall() public void TestToJson() { JObject json = contract.ToJson(); - json["hash"].AsString().Should().Be("0x820944cfdc70976602d71b0091445eedbc661bc5"); - json["nef"]["script"].AsString().Should().Be("AQ=="); - json["manifest"].AsString().Should().Be(manifest.ToJson().AsString()); + Assert.AreEqual("0x820944cfdc70976602d71b0091445eedbc661bc5", json["hash"].AsString()); + Assert.AreEqual("AQ==", json["nef"]["script"].AsString()); + Assert.AreEqual(manifest.ToJson().AsString(), json["manifest"].AsString()); } } } diff --git a/tests/Neo.UnitTests/SmartContract/UT_InteropPrices.cs b/tests/Neo.UnitTests/SmartContract/UT_InteropPrices.cs index d70828bc4d..c5d566d620 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_InteropPrices.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_InteropPrices.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Persistence; using Neo.SmartContract; @@ -38,7 +37,7 @@ public void ApplicationEngineFixedPrices() using (ApplicationEngine ae = ApplicationEngine.Create(TriggerType.Application, null, snapshot, gas: 0)) { ae.LoadScript(SyscallSystemRuntimeCheckWitnessHash); - ApplicationEngine.System_Runtime_CheckWitness.FixedPrice.Should().Be(0_00001024L); + Assert.AreEqual(0_00001024L, ApplicationEngine.System_Runtime_CheckWitness.FixedPrice); } // System.Storage.GetContext: 9bf667ce (price is 1) @@ -46,7 +45,7 @@ public void ApplicationEngineFixedPrices() using (ApplicationEngine ae = ApplicationEngine.Create(TriggerType.Application, null, snapshot, gas: 0)) { ae.LoadScript(SyscallSystemStorageGetContextHash); - ApplicationEngine.System_Storage_GetContext.FixedPrice.Should().Be(0_00000016L); + Assert.AreEqual(0_00000016L, ApplicationEngine.System_Storage_GetContext.FixedPrice); } // System.Storage.Get: 925de831 (price is 100) @@ -54,7 +53,7 @@ public void ApplicationEngineFixedPrices() using (ApplicationEngine ae = ApplicationEngine.Create(TriggerType.Application, null, snapshot, gas: 0)) { ae.LoadScript(SyscallSystemStorageGetHash); - ApplicationEngine.System_Storage_Get.FixedPrice.Should().Be(32768L); + Assert.AreEqual(32768L, ApplicationEngine.System_Storage_Get.FixedPrice); } } @@ -86,7 +85,7 @@ public void ApplicationEngineRegularPut() debugger.StepInto(); var setupPrice = ae.FeeConsumed; debugger.Execute(); - (ae.FeeConsumed - setupPrice).Should().Be(ae.StoragePrice * value.Length + (1 << 15) * 30); + Assert.AreEqual(ae.StoragePrice * value.Length + (1 << 15) * 30, ae.FeeConsumed - setupPrice); } /// @@ -117,7 +116,7 @@ public void ApplicationEngineReusedStorage_FullReuse() debugger.StepInto(); var setupPrice = applicationEngine.FeeConsumed; debugger.Execute(); - (applicationEngine.FeeConsumed - setupPrice).Should().Be(1 * applicationEngine.StoragePrice + (1 << 15) * 30); + Assert.AreEqual(1 * applicationEngine.StoragePrice + (1 << 15) * 30, applicationEngine.FeeConsumed - setupPrice); } /// @@ -151,7 +150,7 @@ public void ApplicationEngineReusedStorage_PartialReuse() var setupPrice = ae.FeeConsumed; debugger.StepInto(); debugger.StepInto(); - (ae.FeeConsumed - setupPrice).Should().Be((1 + (oldValue.Length / 4) + value.Length - oldValue.Length) * ae.StoragePrice + (1 << 15) * 30); + Assert.AreEqual((1 + (oldValue.Length / 4) + value.Length - oldValue.Length) * ae.StoragePrice + (1 << 15) * 30, ae.FeeConsumed - setupPrice); } /// @@ -188,7 +187,7 @@ public void ApplicationEngineReusedStorage_PartialReuseTwice() debugger.StepInto(); //syscall Storage.GetContext var setupPrice = ae.FeeConsumed; debugger.StepInto(); //syscall Storage.Put - (ae.FeeConsumed - setupPrice).Should().Be((sItem.Value.Length / 4 + 1) * ae.StoragePrice + (1 << 15) * 30); // = PUT basic fee + Assert.AreEqual((sItem.Value.Length / 4 + 1) * ae.StoragePrice + (1 << 15) * 30, ae.FeeConsumed - setupPrice); // = PUT basic fee } private static byte[] CreateMultiplePutScript(byte[] key, byte[] value, int times = 2) diff --git a/tests/Neo.UnitTests/SmartContract/UT_InteropService.NEO.cs b/tests/Neo.UnitTests/SmartContract/UT_InteropService.NEO.cs index 7c671359ad..42c230f465 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_InteropService.NEO.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_InteropService.NEO.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -39,9 +38,9 @@ public void TestCheckSig() var keyPair = new KeyPair(privateKey); var pubkey = keyPair.PublicKey; var signature = Crypto.Sign(message, privateKey); - engine.CheckSig(pubkey.EncodePoint(false), signature).Should().BeTrue(); + Assert.IsTrue(engine.CheckSig(pubkey.EncodePoint(false), signature)); Action action = () => engine.CheckSig(new byte[70], signature); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -73,7 +72,7 @@ public void TestCrypto_CheckMultiSig() signature1, signature2 }; - engine.CheckMultisig(pubkeys, signatures).Should().BeTrue(); + Assert.IsTrue(engine.CheckMultisig(pubkeys, signatures)); pubkeys = new byte[0][]; Assert.ThrowsException(() => engine.CheckMultisig(pubkeys, signatures)); @@ -96,7 +95,7 @@ public void TestCrypto_CheckMultiSig() signature1, new byte[64] }; - engine.CheckMultisig(pubkeys, signatures).Should().BeFalse(); + Assert.IsFalse(engine.CheckMultisig(pubkeys, signatures)); pubkeys = new[] { @@ -149,7 +148,7 @@ public void TestContract_Create() manifest = TestUtils.CreateDefaultManifest(); var ret = snapshotCache.DeployContract(UInt160.Zero, nefFile, manifest.ToJson().ToByteArray(false)); - ret.Hash.ToString().Should().Be("0x7b37d4bd3d87f53825c3554bd1a617318235a685"); + Assert.AreEqual("0x7b37d4bd3d87f53825c3554bd1a617318235a685", ret.Hash.ToString()); Assert.ThrowsException(() => snapshotCache.DeployContract(UInt160.Zero, nefFile, manifest.ToJson().ToByteArray(false))); var state = TestUtils.GetContract(); @@ -200,14 +199,14 @@ public void TestContract_Update() }; snapshotCache.AddContract(state.Hash, state); snapshotCache.Add(storageKey, storageItem); - state.UpdateCounter.Should().Be(0); + Assert.AreEqual(0, state.UpdateCounter); snapshotCache.UpdateContract(state.Hash, nef.ToArray(), manifest.ToJson().ToByteArray(false)); var ret = NativeContract.ContractManagement.GetContract(snapshotCache, state.Hash); - snapshotCache.Find(BitConverter.GetBytes(state.Id)).ToList().Count().Should().Be(1); - ret.UpdateCounter.Should().Be(1); - ret.Id.Should().Be(state.Id); - ret.Manifest.ToJson().ToString().Should().Be(manifest.ToJson().ToString()); - ret.Script.Span.ToHexString().Should().Be(nef.Script.Span.ToHexString().ToString()); + Assert.AreEqual(1, snapshotCache.Find(BitConverter.GetBytes(state.Id)).ToList().Count()); + Assert.AreEqual(1, ret.UpdateCounter); + Assert.AreEqual(state.Id, ret.Id); + Assert.AreEqual(manifest.ToJson().ToString(), ret.Manifest.ToJson().ToString()); + Assert.AreEqual(nef.Script.Span.ToHexString().ToString(), ret.Script.Span.ToHexString()); } [TestMethod] @@ -268,7 +267,7 @@ public void TestStorage_Find() }, new byte[] { 0x01 }, FindOptions.ValuesOnly); iterator.Next(); var ele = iterator.Value(null); - ele.GetSpan().ToHexString().Should().Be(storageItem.Value.Span.ToHexString()); + Assert.AreEqual(storageItem.Value.Span.ToHexString(), ele.GetSpan().ToHexString()); } } } diff --git a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs index 6cee5c7edf..edaffb9c4d 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs @@ -11,7 +11,6 @@ using Akka.TestKit.Xunit2; using Akka.Util.Internal; -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Cryptography.ECC; @@ -281,7 +280,7 @@ private static void AssertNotification(StackItem stackItem, UInt160 scriptHash, [TestMethod] public void TestExecutionEngine_GetScriptContainer() { - GetEngine(true).GetScriptContainer().Should().BeOfType(); + Assert.IsInstanceOfType(GetEngine(true).GetScriptContainer(), typeof(VM.Types.Array)); } [TestMethod] @@ -290,7 +289,7 @@ public void TestExecutionEngine_GetCallingScriptHash() // Test without var engine = GetEngine(true); - engine.CallingScriptHash.Should().BeNull(); + Assert.IsNull(engine.CallingScriptHash); // Test real @@ -309,19 +308,19 @@ public void TestExecutionEngine_GetCallingScriptHash() Assert.AreEqual(VMState.HALT, engine.Execute()); - engine.ResultStack.Pop().GetSpan().ToHexString().Should().Be(scriptB.ToArray().ToScriptHash().ToArray().ToHexString()); + Assert.AreEqual(scriptB.ToArray().ToScriptHash().ToArray().ToHexString(), engine.ResultStack.Pop().GetSpan().ToHexString()); } [TestMethod] public void TestContract_GetCallFlags() { - GetEngine().GetCallFlags().Should().Be(CallFlags.All); + Assert.AreEqual(CallFlags.All, GetEngine().GetCallFlags()); } [TestMethod] public void TestRuntime_Platform() { - ApplicationEngine.GetPlatform().Should().Be("NEO"); + Assert.AreEqual("NEO", ApplicationEngine.GetPlatform()); } [TestMethod] @@ -336,14 +335,14 @@ public void TestRuntime_CheckWitness() ((Transaction)engine.ScriptContainer).Signers[0].Account = Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash(); ((Transaction)engine.ScriptContainer).Signers[0].Scopes = WitnessScope.CalledByEntry; - engine.CheckWitness(pubkey.EncodePoint(true)).Should().BeTrue(); - engine.CheckWitness(((Transaction)engine.ScriptContainer).Sender.ToArray()).Should().BeTrue(); + Assert.IsTrue(engine.CheckWitness(pubkey.EncodePoint(true))); + Assert.IsTrue(engine.CheckWitness(((Transaction)engine.ScriptContainer).Sender.ToArray())); ((Transaction)engine.ScriptContainer).Signers = System.Array.Empty(); - engine.CheckWitness(pubkey.EncodePoint(true)).Should().BeFalse(); + Assert.IsFalse(engine.CheckWitness(pubkey.EncodePoint(true))); Action action = () => engine.CheckWitness(System.Array.Empty()); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -356,7 +355,7 @@ public void TestRuntime_CheckWitness_Null_ScriptContainer() var engine = GetEngine(); - engine.CheckWitness(pubkey.EncodePoint(true)).Should().BeFalse(); + Assert.IsFalse(engine.CheckWitness(pubkey.EncodePoint(true))); } [TestMethod] @@ -366,7 +365,7 @@ public void TestRuntime_Log() var message = "hello"; ApplicationEngine.Log += LogEvent; engine.RuntimeLog(Encoding.UTF8.GetBytes(message)); - ((Transaction)engine.ScriptContainer).Script.Span.ToHexString().Should().Be(new byte[] { 0x01, 0x02, 0x03 }.ToHexString()); + Assert.AreEqual(new byte[] { 0x01, 0x02, 0x03 }.ToHexString(), ((Transaction)engine.ScriptContainer).Script.Span.ToHexString()); ApplicationEngine.Log -= LogEvent; } @@ -375,7 +374,7 @@ public void TestRuntime_GetTime() { Block block = new() { Header = new Header() }; var engine = GetEngine(true, hasBlock: true); - engine.GetTime().Should().Be(block.Timestamp); + Assert.AreEqual(block.Timestamp, engine.GetTime()); } [TestMethod] @@ -407,7 +406,7 @@ public void TestRuntime_GetCurrentSigners_SysCall() Assert.AreEqual(engineA.State, VMState.HALT); var result = engineA.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Null)); + Assert.IsInstanceOfType(result, typeof(VM.Types.Null)); // Not null @@ -418,11 +417,11 @@ public void TestRuntime_GetCurrentSigners_SysCall() Assert.AreEqual(engineB.State, VMState.HALT); result = engineB.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Array)); - (result as VM.Types.Array).Count.Should().Be(1); + Assert.IsInstanceOfType(result, typeof(VM.Types.Array)); + Assert.AreEqual(1, (result as VM.Types.Array).Count); result = (result as VM.Types.Array)[0]; - result.Should().BeOfType(typeof(VM.Types.Array)); - (result as VM.Types.Array).Count.Should().Be(5); + Assert.IsInstanceOfType(result, typeof(VM.Types.Array)); + Assert.AreEqual(5, (result as VM.Types.Array).Count); result = (result as VM.Types.Array)[0]; // Address Assert.AreEqual(UInt160.Zero, new UInt160(result.GetSpan())); } @@ -438,7 +437,7 @@ public void TestCrypto_Verify() KeyPair keyPair = new(privateKey); var pubkey = keyPair.PublicKey; var signature = Crypto.Sign(message, privateKey); - engine.CheckSig(pubkey.EncodePoint(false), signature).Should().BeTrue(); + Assert.IsTrue(engine.CheckSig(pubkey.EncodePoint(false), signature)); var wrongkey = pubkey.EncodePoint(false); wrongkey[0] = 5; @@ -449,7 +448,7 @@ public void TestCrypto_Verify() public void TestBlockchain_GetHeight() { var engine = GetEngine(true, true); - NativeContract.Ledger.CurrentIndex(engine.SnapshotCache).Should().Be(0); + Assert.AreEqual((uint)0, NativeContract.Ledger.CurrentIndex(engine.SnapshotCache)); } [TestMethod] @@ -457,14 +456,14 @@ public void TestBlockchain_GetBlock() { var engine = GetEngine(true, true); - NativeContract.Ledger.GetBlock(engine.SnapshotCache, UInt256.Zero).Should().BeNull(); + Assert.IsNull(NativeContract.Ledger.GetBlock(engine.SnapshotCache, UInt256.Zero)); var data1 = new byte[] { 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}; - NativeContract.Ledger.GetBlock(engine.SnapshotCache, new UInt256(data1)).Should().BeNull(); - NativeContract.Ledger.GetBlock(engine.SnapshotCache, TestBlockchain.TheNeoSystem.GenesisBlock.Hash).Should().NotBeNull(); + Assert.IsNull(NativeContract.Ledger.GetBlock(engine.SnapshotCache, new UInt256(data1))); + Assert.IsNotNull(NativeContract.Ledger.GetBlock(engine.SnapshotCache, TestBlockchain.TheNeoSystem.GenesisBlock.Hash)); } [TestMethod] @@ -475,7 +474,7 @@ public void TestBlockchain_GetTransaction() 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; - NativeContract.Ledger.GetTransaction(engine.SnapshotCache, new UInt256(data1)).Should().BeNull(); + Assert.IsNull(NativeContract.Ledger.GetTransaction(engine.SnapshotCache, new UInt256(data1))); } [TestMethod] @@ -496,8 +495,8 @@ public void TestBlockchain_GetTransactionHeight() Assert.AreEqual(engine.State, VMState.HALT); var result = engine.ResultStack.Pop(); - result.Should().BeOfType(typeof(VM.Types.Integer)); - result.GetInteger().Should().Be(0); + Assert.IsInstanceOfType(result, typeof(VM.Types.Integer)); + Assert.AreEqual(0, result.GetInteger()); } [TestMethod] @@ -508,13 +507,13 @@ public void TestBlockchain_GetContract() 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }; - NativeContract.ContractManagement.GetContract(engine.SnapshotCache, new UInt160(data1)).Should().BeNull(); + Assert.IsNull(NativeContract.ContractManagement.GetContract(engine.SnapshotCache, new UInt160(data1))); var state = TestUtils.GetContract(); engine.SnapshotCache.AddContract(state.Hash, state); engine = ApplicationEngine.Create(TriggerType.Application, null, engine.SnapshotCache); engine.LoadScript(new byte[] { 0x01 }); - NativeContract.ContractManagement.GetContract(engine.SnapshotCache, state.Hash).Hash.Should().Be(state.Hash); + Assert.AreEqual(state.Hash, NativeContract.ContractManagement.GetContract(engine.SnapshotCache, state.Hash).Hash); } [TestMethod] @@ -522,16 +521,16 @@ public void TestBlockchain_GetContractById() { var engine = GetEngine(true, true); var contract = NativeContract.ContractManagement.GetContractById(engine.SnapshotCache, -1); - contract.Id.Should().Be(-1); - contract.Manifest.Name.Should().Be(nameof(ContractManagement)); + Assert.AreEqual(-1, contract.Id); + Assert.AreEqual(nameof(ContractManagement), contract.Manifest.Name); } [TestMethod] public void TestBlockchain_HasMethod() { var engine = GetEngine(true, true); - NativeContract.ContractManagement.HasMethod(engine.SnapshotCache, NativeContract.NEO.Hash, "symbol", 0).Should().Be(true); - NativeContract.ContractManagement.HasMethod(engine.SnapshotCache, NativeContract.NEO.Hash, "transfer", 4).Should().Be(true); + Assert.IsTrue(NativeContract.ContractManagement.HasMethod(engine.SnapshotCache, NativeContract.NEO.Hash, "symbol", 0)); + Assert.IsTrue(NativeContract.ContractManagement.HasMethod(engine.SnapshotCache, NativeContract.NEO.Hash, "transfer", 4)); } [TestMethod] @@ -539,16 +538,16 @@ public void TestBlockchain_ListContracts() { var engine = GetEngine(true, true); var list = NativeContract.ContractManagement.ListContracts(engine.SnapshotCache); - list.ForEach(p => p.Id.Should().BeLessThan(0)); + list.ForEach(p => Assert.IsTrue(p.Id < 0)); var state = TestUtils.GetContract(); engine.SnapshotCache.AddContract(state.Hash, state); engine = ApplicationEngine.Create(TriggerType.Application, null, engine.SnapshotCache); engine.LoadScript(new byte[] { 0x01 }); - NativeContract.ContractManagement.GetContract(engine.SnapshotCache, state.Hash).Hash.Should().Be(state.Hash); + Assert.AreEqual(state.Hash, NativeContract.ContractManagement.GetContract(engine.SnapshotCache, state.Hash).Hash); var list2 = NativeContract.ContractManagement.ListContracts(engine.SnapshotCache); - list2.Count().Should().Be(list.Count()); + Assert.AreEqual(list.Count(), list2.Count()); } [TestMethod] @@ -558,7 +557,7 @@ public void TestStorage_GetContext() var state = TestUtils.GetContract(); engine.SnapshotCache.AddContract(state.Hash, state); engine.LoadScript(state.Script); - engine.GetStorageContext().IsReadOnly.Should().BeFalse(); + Assert.IsFalse(engine.GetStorageContext().IsReadOnly); } [TestMethod] @@ -568,7 +567,7 @@ public void TestStorage_GetReadOnlyContext() var state = TestUtils.GetContract(); engine.SnapshotCache.AddContract(state.Hash, state); engine.LoadScript(state.Script); - engine.GetReadOnlyContext().IsReadOnly.Should().BeTrue(); + Assert.IsTrue(engine.GetReadOnlyContext().IsReadOnly); } [TestMethod] @@ -592,11 +591,11 @@ public void TestStorage_Get() var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshotCache); engine.LoadScript(new byte[] { 0x01 }); - engine.Get(new StorageContext + Assert.AreEqual(storageItem.Value.Span.ToHexString(), engine.Get(new StorageContext { Id = state.Id, IsReadOnly = false - }, new byte[] { 0x01 }).Value.Span.ToHexString().Should().Be(storageItem.Value.Span.ToHexString()); + }, new byte[] { 0x01 }).Value.Span.ToHexString()); } [TestMethod] @@ -698,7 +697,7 @@ public void TestStorageContext_AsReadOnly() Id = state.Id, IsReadOnly = false }; - ApplicationEngine.AsReadOnly(storageContext).IsReadOnly.Should().BeTrue(); + Assert.IsTrue(ApplicationEngine.AsReadOnly(storageContext).IsReadOnly); } [TestMethod] @@ -714,8 +713,8 @@ public void TestContract_Call() engine.SnapshotCache.AddContract(state.Hash, state); engine.CallContract(state.Hash, method, CallFlags.All, args); - engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[0]); - engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[1]); + Assert.AreEqual(args[0], engine.CurrentContext.EvaluationStack.Pop()); + Assert.AreEqual(args[1], engine.CurrentContext.EvaluationStack.Pop()); state.Manifest.Permissions[0].Methods = WildcardContainer.Create("a"); engine.SnapshotCache.DeleteContract(state.Hash); @@ -751,20 +750,20 @@ public void TestContract_Destroy() snapshotCache.AddContract(scriptHash, state); snapshotCache.Add(storageKey, storageItem); snapshotCache.DestroyContract(scriptHash); - snapshotCache.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse(); + Assert.IsFalse(snapshotCache.Find(BitConverter.GetBytes(0x43000000)).Any()); //storages are removed state = TestUtils.GetContract(); snapshotCache.AddContract(scriptHash, state); snapshotCache.DestroyContract(scriptHash); - snapshotCache.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse(); + Assert.IsFalse(snapshotCache.Find(BitConverter.GetBytes(0x43000000)).Any()); } [TestMethod] public void TestContract_CreateStandardAccount() { var pubkey = ECPoint.Parse("024b817ef37f2fc3d4a33fe36687e592d9f30fe24b3e28187dc8f12b3b3b2b839e", ECCurve.Secp256r1); - GetEngine().CreateStandardAccount(pubkey).ToArray().ToHexString().Should().Be("c44ea575c5f79638f0e73f39d7bd4b3337c81691"); + Assert.AreEqual("c44ea575c5f79638f0e73f39d7bd4b3337c81691", GetEngine().CreateStandardAccount(pubkey).ToArray().ToHexString()); } public static void LogEvent(object sender, LogEventArgs args) @@ -796,11 +795,11 @@ public void TestVerifyWithECDsaV0() var signatureK1 = Crypto.Sign(hexMessage, privateKey, Neo.Cryptography.ECC.ECCurve.Secp256k1); var result = CryptoLib.VerifyWithECDsaV0(hexMessage, publicKeyR1, signatureR1, NamedCurveHash.secp256r1SHA256); - result.Should().BeTrue(); + Assert.IsTrue(result); result = CryptoLib.VerifyWithECDsaV0(hexMessage, publicKeyK1, signatureK1, NamedCurveHash.secp256k1SHA256); - result.Should().BeTrue(); + Assert.IsTrue(result); result = CryptoLib.VerifyWithECDsaV0(hexMessage, publicKeyK1, new byte[0], NamedCurveHash.secp256k1SHA256); - result.Should().BeFalse(); + Assert.IsFalse(result); Assert.ThrowsException(() => CryptoLib.VerifyWithECDsaV0(hexMessage, publicKeyK1, new byte[64], NamedCurveHash.secp256r1Keccak256)); } @@ -810,7 +809,7 @@ public void TestSha256() var input = "Hello, world!"u8.ToArray(); var actualHash = CryptoLib.Sha256(input); var expectedHash = "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"; - actualHash.ToHexString().Should().Be(expectedHash); + Assert.AreEqual(expectedHash, actualHash.ToHexString()); } [TestMethod] @@ -819,7 +818,7 @@ public void TestRIPEMD160() var input = "Hello, world!"u8.ToArray(); var actualHash = CryptoLib.RIPEMD160(input); var expectedHash = "58262d1fbdbe4530d8865d3518c6d6e41002610f"; - actualHash.ToHexString().Should().Be(expectedHash); + Assert.AreEqual(expectedHash, actualHash.ToHexString()); } [TestMethod] @@ -828,7 +827,7 @@ public void TestMurmur32() var input = "Hello, world!"u8.ToArray(); var actualHash = CryptoLib.Murmur32(input, 0); var expectedHash = "433e36c0"; - actualHash.ToHexString().Should().Be(expectedHash); + Assert.AreEqual(expectedHash, actualHash.ToHexString()); } [TestMethod] @@ -838,10 +837,10 @@ public void TestGetBlockHash() var hash = LedgerContract.Ledger.GetBlockHash(snapshotCache, 0); var hash2 = LedgerContract.Ledger.GetBlock(snapshotCache, 0).Hash; var hash3 = LedgerContract.Ledger.GetHeader(snapshotCache, 0).Hash; - hash.ToString().Should().Be(hash2.ToString()); - hash.ToString().Should().Be(hash3.ToString()); - hash.ToString().Should().Be("0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15"); - LedgerContract.Ledger.ContainsBlock(snapshotCache, hash).Should().BeTrue(); + Assert.AreEqual(hash.ToString(), hash2.ToString()); + Assert.AreEqual(hash.ToString(), hash3.ToString()); + Assert.AreEqual("0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15", hash.ToString()); + Assert.IsTrue(LedgerContract.Ledger.ContainsBlock(snapshotCache, hash)); } [TestMethod] @@ -849,25 +848,26 @@ public void TestGetCandidateVote() { var snapshotCache = GetEngine(true, true).SnapshotCache; var vote = LedgerContract.NEO.GetCandidateVote(snapshotCache, new ECPoint()); - vote.Should().Be(-1); + Assert.AreEqual(-1, vote); } [TestMethod] public void TestContractPermissionDescriptorEquals() { var descriptor1 = ContractPermissionDescriptor.CreateWildcard(); - descriptor1.Equals(null).Should().BeFalse(); - descriptor1.Equals(null as object).Should().BeFalse(); + Assert.IsFalse(descriptor1.Equals(null)); + Assert.IsFalse(descriptor1.Equals(null as object)); var descriptor2 = ContractPermissionDescriptor.Create(LedgerContract.NEO.Hash); var descriptor3 = ContractPermissionDescriptor.Create(hash: null); - descriptor1.Equals(descriptor3).Should().BeTrue(); - descriptor1.Equals(descriptor3 as object).Should().BeTrue(); + Assert.IsTrue(descriptor1.Equals(descriptor3)); + Assert.IsTrue(descriptor1.Equals(descriptor3 as object)); var descriptor4 = ContractPermissionDescriptor.Create(group: null); var descriptor5 = ContractPermissionDescriptor.Create(group: new ECPoint()); - descriptor1.Equals(descriptor4).Should().BeTrue(); - descriptor2.Equals(descriptor3).Should().BeFalse(); - descriptor5.Equals(descriptor3).Should().BeFalse(); - descriptor5.Equals(descriptor5).Should().BeTrue(); + Assert.IsTrue(descriptor1.Equals(descriptor4)); + Assert.IsTrue(descriptor1.Equals(descriptor4 as object)); + Assert.IsFalse(descriptor2.Equals(descriptor3)); + Assert.IsFalse(descriptor5.Equals(descriptor3)); + Assert.IsTrue(descriptor5.Equals(descriptor5)); } } } diff --git a/tests/Neo.UnitTests/SmartContract/UT_NefFile.cs b/tests/Neo.UnitTests/SmartContract/UT_NefFile.cs index 358314c104..3be1702cb8 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_NefFile.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_NefFile.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -88,15 +87,15 @@ public void TestDeserialize() file.CheckSum = NefFile.ComputeChecksum(file); var data = file.ToArray(); var newFile1 = data.AsSerializable(); - newFile1.Compiler.Should().Be(file.Compiler); - newFile1.CheckSum.Should().Be(file.CheckSum); - newFile1.Script.Span.SequenceEqual(file.Script.Span).Should().BeTrue(); + Assert.AreEqual(file.Compiler, newFile1.Compiler); + Assert.AreEqual(file.CheckSum, newFile1.CheckSum); + Assert.IsTrue(newFile1.Script.Span.SequenceEqual(file.Script.Span)); } [TestMethod] public void TestGetSize() { - file.Size.Should().Be(4 + 32 + 32 + 2 + 1 + 2 + 4 + 4); + Assert.AreEqual(4 + 32 + 32 + 2 + 1 + 2 + 4 + 4, file.Size); } [TestMethod] diff --git a/tests/Neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs b/tests/Neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs index 5896718c6c..4a53c03e59 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Network.P2P.Payloads; using Neo.Persistence; @@ -36,7 +35,7 @@ public void TestGetScriptContainer() IVerifiable container = new TestVerifiable(); UInt160 script_hash = new byte[] { 0x00 }.ToScriptHash(); NotifyEventArgs args = new NotifyEventArgs(container, script_hash, "Test", null); - args.ScriptContainer.Should().Be(container); + Assert.AreEqual(container, args.ScriptContainer); } [TestMethod] diff --git a/tests/Neo.UnitTests/TestUtils.cs b/tests/Neo.UnitTests/TestUtils.cs index 0678055d90..4a93ae7741 100644 --- a/tests/Neo.UnitTests/TestUtils.cs +++ b/tests/Neo.UnitTests/TestUtils.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Cryptography.ECC; @@ -80,7 +79,7 @@ public static NEP6Wallet GenerateTestWallet(string password) wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = null; - wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"1.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}"); + Assert.AreEqual("{\"name\":\"noname\",\"version\":\"1.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}", wallet.ToString()); return new NEP6Wallet(null, password, TestProtocolSettings.Default, wallet); } diff --git a/tests/Neo.UnitTests/UT_BigDecimal.cs b/tests/Neo.UnitTests/UT_BigDecimal.cs index 75e9cd9599..668498523c 100644 --- a/tests/Neo.UnitTests/UT_BigDecimal.cs +++ b/tests/Neo.UnitTests/UT_BigDecimal.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Numerics; @@ -24,66 +23,66 @@ public void TestChangeDecimals() { BigDecimal originalValue = new(new BigInteger(12300), 5); BigDecimal result1 = originalValue.ChangeDecimals(7); - result1.Value.Should().Be(new BigInteger(1230000)); - result1.Decimals.Should().Be(7); + Assert.AreEqual(new BigInteger(1230000), result1.Value); + Assert.AreEqual(7, result1.Decimals); BigDecimal result2 = originalValue.ChangeDecimals(3); - result2.Value.Should().Be(new BigInteger(123)); - result2.Decimals.Should().Be(3); + Assert.AreEqual(new BigInteger(123), result2.Value); + Assert.AreEqual(3, result2.Decimals); BigDecimal result3 = originalValue.ChangeDecimals(5); - result3.Value.Should().Be(originalValue.Value); + Assert.AreEqual(originalValue.Value, result3.Value); Action action = () => originalValue.ChangeDecimals(2); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] public void TestBigDecimalConstructor() { BigDecimal value = new(new BigInteger(45600), 7); - value.Value.Should().Be(new BigInteger(45600)); - value.Decimals.Should().Be(7); + Assert.AreEqual(new BigInteger(45600), value.Value); + Assert.AreEqual(7, value.Decimals); value = new BigDecimal(new BigInteger(0), 5); - value.Value.Should().Be(new BigInteger(0)); - value.Decimals.Should().Be(5); + Assert.AreEqual(new BigInteger(0), value.Value); + Assert.AreEqual(5, value.Decimals); value = new BigDecimal(new BigInteger(-10), 0); - value.Value.Should().Be(new BigInteger(-10)); - value.Decimals.Should().Be(0); + Assert.AreEqual(new BigInteger(-10), value.Value); + Assert.AreEqual(0, value.Decimals); value = new BigDecimal(123.456789M, 6); - value.Value.Should().Be(new BigInteger(123456789)); - value.Decimals.Should().Be(6); + Assert.AreEqual(new BigInteger(123456789), value.Value); + Assert.AreEqual(6, value.Decimals); value = new BigDecimal(-123.45M, 3); - value.Value.Should().Be(new BigInteger(-123450)); - value.Decimals.Should().Be(3); + Assert.AreEqual(new BigInteger(-123450), value.Value); + Assert.AreEqual(3, value.Decimals); value = new BigDecimal(123.45M, 2); - value.Value.Should().Be(new BigInteger(12345)); - value.Decimals.Should().Be(2); + Assert.AreEqual(new BigInteger(12345), value.Value); + Assert.AreEqual(2, value.Decimals); value = new BigDecimal(123M, 0); - value.Value.Should().Be(new BigInteger(123)); - value.Decimals.Should().Be(0); + Assert.AreEqual(new BigInteger(123), value.Value); + Assert.AreEqual(0, value.Decimals); value = new BigDecimal(0M, 0); - value.Value.Should().Be(new BigInteger(0)); - value.Decimals.Should().Be(0); + Assert.AreEqual(new BigInteger(0), value.Value); + Assert.AreEqual(0, value.Decimals); value = new BigDecimal(5.5M, 1); var b = new BigDecimal(55M); - value.Value.Should().Be(b.Value); + Assert.AreEqual(b.Value, value.Value); } [TestMethod] public void TestGetDecimals() { BigDecimal value = new(new BigInteger(45600), 7); - value.Sign.Should().Be(1); + Assert.AreEqual(1, value.Sign); value = new BigDecimal(new BigInteger(0), 5); - value.Sign.Should().Be(0); + Assert.AreEqual(0, value.Sign); value = new BigDecimal(new BigInteger(-10), 0); - value.Sign.Should().Be(-1); + Assert.AreEqual(-1, value.Sign); } [TestMethod] @@ -92,23 +91,23 @@ public void TestCompareDecimals() BigDecimal a = new(5.5M, 1); BigDecimal b = new(55M); BigDecimal c = new(55M, 1); - a.Equals(b).Should().Be(false); - a.Equals(c).Should().Be(false); - b.Equals(c).Should().Be(true); - a.CompareTo(b).Should().Be(-1); - a.CompareTo(c).Should().Be(-1); - b.CompareTo(c).Should().Be(0); + Assert.IsFalse(a.Equals(b)); + Assert.IsFalse(a.Equals(c)); + Assert.IsTrue(b.Equals(c)); + Assert.AreEqual(-1, a.CompareTo(b)); + Assert.AreEqual(-1, a.CompareTo(c)); + Assert.AreEqual(0, b.CompareTo(c)); } [TestMethod] public void TestGetSign() { BigDecimal value = new(new BigInteger(45600), 7); - value.Sign.Should().Be(1); + Assert.AreEqual(1, value.Sign); value = new BigDecimal(new BigInteger(0), 5); - value.Sign.Should().Be(0); + Assert.AreEqual(0, value.Sign); value = new BigDecimal(new BigInteger(-10), 0); - value.Sign.Should().Be(-1); + Assert.AreEqual(-1, value.Sign); } [TestMethod] @@ -116,20 +115,20 @@ public void TestParse() { string s = "12345"; byte decimals = 0; - BigDecimal.Parse(s, decimals).Should().Be(new BigDecimal(new BigInteger(12345), 0)); + Assert.AreEqual(new BigDecimal(new BigInteger(12345), 0), BigDecimal.Parse(s, decimals)); s = "abcdEfg"; Action action = () => BigDecimal.Parse(s, decimals); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] public void TestToString() { BigDecimal value = new(new BigInteger(100000), 5); - value.ToString().Should().Be("1"); + Assert.AreEqual("1", value.ToString()); value = new BigDecimal(new BigInteger(123456), 5); - value.ToString().Should().Be("1.23456"); + Assert.AreEqual("1.23456", value.ToString()); } [TestMethod] @@ -137,102 +136,102 @@ public void TestTryParse() { string s = "12345"; byte decimals = 0; - BigDecimal.TryParse(s, decimals, out BigDecimal result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(12345), 0)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out BigDecimal result)); + Assert.AreEqual(new BigDecimal(new BigInteger(12345), 0), result); s = "12345E-5"; decimals = 5; - BigDecimal.TryParse(s, decimals, out result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(12345), 5)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(new BigDecimal(new BigInteger(12345), 5), result); s = "abcdEfg"; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "123.45"; decimals = 2; - BigDecimal.TryParse(s, decimals, out result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(12345), 2)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(new BigDecimal(new BigInteger(12345), 2), result); s = "123.45E-5"; decimals = 7; - BigDecimal.TryParse(s, decimals, out result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(12345), 7)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(new BigDecimal(new BigInteger(12345), 7), result); s = "12345E-5"; decimals = 3; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "1.2345"; decimals = 3; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "1.2345E-5"; decimals = 3; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "12345"; decimals = 3; - BigDecimal.TryParse(s, decimals, out result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(12345000), 3)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(new BigDecimal(new BigInteger(12345000), 3), result); s = "12345E-2"; decimals = 3; - BigDecimal.TryParse(s, decimals, out result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(123450), 3)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(new BigDecimal(new BigInteger(123450), 3), result); s = "123.45"; decimals = 3; - BigDecimal.TryParse(s, decimals, out result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(123450), 3)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(new BigDecimal(new BigInteger(123450), 3), result); s = "123.45E3"; decimals = 3; - BigDecimal.TryParse(s, decimals, out result).Should().BeTrue(); - result.Should().Be(new BigDecimal(new BigInteger(123450000), 3)); + Assert.IsTrue(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(new BigDecimal(new BigInteger(123450000), 3), result); s = "a456bcdfg"; decimals = 0; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "a456bce-5"; decimals = 5; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "a4.56bcd"; decimals = 5; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "a4.56bce3"; decimals = 2; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "a456bcd"; decimals = 2; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "a456bcdE3"; decimals = 2; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "a456b.cd"; decimals = 5; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); s = "a456b.cdE3"; decimals = 5; - BigDecimal.TryParse(s, decimals, out result).Should().BeFalse(); - result.Should().Be(default(BigDecimal)); + Assert.IsFalse(BigDecimal.TryParse(s, decimals, out result)); + Assert.AreEqual(default(BigDecimal), result); } } } diff --git a/tests/Neo.UnitTests/UT_Helper.cs b/tests/Neo.UnitTests/UT_Helper.cs index 3401231d10..60f4fed8da 100644 --- a/tests/Neo.UnitTests/UT_Helper.cs +++ b/tests/Neo.UnitTests/UT_Helper.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO.Caching; @@ -32,7 +31,7 @@ public void GetSignData() { TestVerifiable verifiable = new(); byte[] res = verifiable.GetSignData(TestProtocolSettings.Default.Network); - res.ToHexString().Should().Be("4e454f3350b51da6bb366be3ea50140cda45ba7df575287c0371000b2037ed3898ff8bf5"); + Assert.AreEqual("4e454f3350b51da6bb366be3ea50140cda45ba7df575287c0371000b2037ed3898ff8bf5", res.ToHexString()); } [TestMethod] @@ -40,7 +39,7 @@ public void Sign() { TestVerifiable verifiable = new(); byte[] res = verifiable.Sign(new KeyPair(TestUtils.GetByteArray(32, 0x42)), TestProtocolSettings.Default.Network); - res.Length.Should().Be(64); + Assert.AreEqual(64, res.Length); } [TestMethod] @@ -48,7 +47,7 @@ public void ToScriptHash() { byte[] testByteArray = TestUtils.GetByteArray(64, 0x42); UInt160 res = testByteArray.ToScriptHash(); - res.Should().Be(UInt160.Parse("2d3b96ae1bcc5a585e075e3b81920210dec16302")); + Assert.AreEqual(UInt160.Parse("2d3b96ae1bcc5a585e075e3b81920210dec16302"), res); } [TestMethod] @@ -84,14 +83,14 @@ public void TestToHexString() byte[] nullStr = null; Assert.ThrowsException(() => nullStr.ToHexString()); byte[] empty = Array.Empty(); - empty.ToHexString().Should().Be(""); - empty.ToHexString(false).Should().Be(""); - empty.ToHexString(true).Should().Be(""); + Assert.AreEqual("", empty.ToHexString()); + Assert.AreEqual("", empty.ToHexString(false)); + Assert.AreEqual("", empty.ToHexString(true)); byte[] str1 = new byte[] { (byte)'n', (byte)'e', (byte)'o' }; - str1.ToHexString().Should().Be("6e656f"); - str1.ToHexString(false).Should().Be("6e656f"); - str1.ToHexString(true).Should().Be("6f656e"); + Assert.AreEqual("6e656f", str1.ToHexString()); + Assert.AreEqual("6e656f", str1.ToHexString(false)); + Assert.AreEqual("6f656e", str1.ToHexString(true)); } [TestMethod] @@ -103,7 +102,7 @@ public void TestGetVersion() .Where(u => u.FullName == "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null") .FirstOrDefault(); string version = asm?.GetVersion() ?? ""; - version.Should().Be("0.0.0"); + Assert.AreEqual("0.0.0", version); } [TestMethod] @@ -121,21 +120,21 @@ public void TestNextBigIntegerForRandom() { Random ran = new(); Action action1 = () => ran.NextBigInteger(-1); - action1.Should().Throw(); + Assert.ThrowsException(() => action1()); - ran.NextBigInteger(0).Should().Be(0); - ran.NextBigInteger(8).Should().NotBeNull(); - ran.NextBigInteger(9).Should().NotBeNull(); + Assert.AreEqual(0, ran.NextBigInteger(0)); + Assert.IsNotNull(ran.NextBigInteger(8)); + Assert.IsNotNull(ran.NextBigInteger(9)); } [TestMethod] public void TestUnmapForIPAddress() { var addr = new IPAddress(new byte[] { 127, 0, 0, 1 }); - addr.UnMap().Should().Be(addr); + Assert.AreEqual(addr, addr.UnMap()); var addr2 = addr.MapToIPv6(); - addr2.UnMap().Should().Be(addr); + Assert.AreEqual(addr, addr2.UnMap()); } [TestMethod] @@ -143,11 +142,11 @@ public void TestUnmapForIPEndPoin() { var addr = new IPAddress(new byte[] { 127, 0, 0, 1 }); var endPoint = new IPEndPoint(addr, 8888); - endPoint.UnMap().Should().Be(endPoint); + Assert.AreEqual(endPoint, endPoint.UnMap()); var addr2 = addr.MapToIPv6(); var endPoint2 = new IPEndPoint(addr2, 8888); - endPoint2.UnMap().Should().Be(endPoint); + Assert.AreEqual(endPoint, endPoint2.UnMap()); } } } diff --git a/tests/Neo.UnitTests/UT_NeoSystem.cs b/tests/Neo.UnitTests/UT_NeoSystem.cs index add0a8e515..16d11188b1 100644 --- a/tests/Neo.UnitTests/UT_NeoSystem.cs +++ b/tests/Neo.UnitTests/UT_NeoSystem.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Neo.UnitTests @@ -26,12 +25,12 @@ public void Setup() } [TestMethod] - public void TestGetBlockchain() => neoSystem.Blockchain.Should().NotBeNull(); + public void TestGetBlockchain() => Assert.IsNotNull(neoSystem.Blockchain); [TestMethod] - public void TestGetLocalNode() => neoSystem.LocalNode.Should().NotBeNull(); + public void TestGetLocalNode() => Assert.IsNotNull(neoSystem.LocalNode); [TestMethod] - public void TestGetTaskManager() => neoSystem.TaskManager.Should().NotBeNull(); + public void TestGetTaskManager() => Assert.IsNotNull(neoSystem.TaskManager); } } diff --git a/tests/Neo.UnitTests/UT_ProtocolSettings.cs b/tests/Neo.UnitTests/UT_ProtocolSettings.cs index 945d27c47a..9c6de902f1 100644 --- a/tests/Neo.UnitTests/UT_ProtocolSettings.cs +++ b/tests/Neo.UnitTests/UT_ProtocolSettings.cs @@ -9,12 +9,14 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Wallets; using System; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Text.RegularExpressions; namespace Neo.UnitTests { @@ -25,28 +27,28 @@ public class UT_ProtocolSettings public void CheckFirstLetterOfAddresses() { UInt160 min = UInt160.Parse("0x0000000000000000000000000000000000000000"); - min.ToAddress(TestProtocolSettings.Default.AddressVersion)[0].Should().Be('N'); + Assert.AreEqual('N', min.ToAddress(TestProtocolSettings.Default.AddressVersion)[0]); UInt160 max = UInt160.Parse("0xffffffffffffffffffffffffffffffffffffffff"); - max.ToAddress(TestProtocolSettings.Default.AddressVersion)[0].Should().Be('N'); + Assert.AreEqual('N', max.ToAddress(TestProtocolSettings.Default.AddressVersion)[0]); } [TestMethod] public void Default_Network_should_be_mainnet_Network_value() { var mainNetNetwork = 0x334F454Eu; - TestProtocolSettings.Default.Network.Should().Be(mainNetNetwork); + Assert.AreEqual(mainNetNetwork, TestProtocolSettings.Default.Network); } [TestMethod] public void TestGetMemoryPoolMaxTransactions() { - TestProtocolSettings.Default.MemoryPoolMaxTransactions.Should().Be(50000); + Assert.AreEqual(50000, TestProtocolSettings.Default.MemoryPoolMaxTransactions); } [TestMethod] public void TestGetMillisecondsPerBlock() { - TestProtocolSettings.Default.MillisecondsPerBlock.Should().Be(15000); + Assert.AreEqual((uint)15000, (uint)TestProtocolSettings.Default.MillisecondsPerBlock); } [TestMethod] @@ -59,16 +61,16 @@ public void HardForkTestBAndNotA() ProtocolSettings settings = ProtocolSettings.Load(file); File.Delete(file); - settings.Hardforks[Hardfork.HF_Aspidochelone].Should().Be(0); - settings.Hardforks[Hardfork.HF_Basilisk].Should().Be(4120000); + Assert.AreEqual((uint)0, settings.Hardforks[Hardfork.HF_Aspidochelone]); + Assert.AreEqual((uint)4120000, settings.Hardforks[Hardfork.HF_Basilisk]); // Check IsHardforkEnabled - settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 0).Should().BeTrue(); - settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 10).Should().BeTrue(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 0).Should().BeFalse(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 10).Should().BeFalse(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 4120000).Should().BeTrue(); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 0)); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 10)); + Assert.IsFalse(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 0)); + Assert.IsFalse(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 10)); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 4120000)); } [TestMethod] @@ -81,16 +83,16 @@ public void HardForkTestAAndNotB() ProtocolSettings settings = ProtocolSettings.Load(file); File.Delete(file); - settings.Hardforks[Hardfork.HF_Aspidochelone].Should().Be(0); - settings.Hardforks.ContainsKey(Hardfork.HF_Basilisk).Should().BeFalse(); + Assert.AreEqual((uint)0, settings.Hardforks[Hardfork.HF_Aspidochelone]); + Assert.IsFalse(settings.Hardforks.ContainsKey(Hardfork.HF_Basilisk)); // Check IsHardforkEnabled - settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 0).Should().BeTrue(); - settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 10).Should().BeTrue(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 0).Should().BeFalse(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 10).Should().BeFalse(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 4120000).Should().BeFalse(); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 0)); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 10)); + Assert.IsFalse(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 0)); + Assert.IsFalse(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 10)); + Assert.IsFalse(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 4120000)); } [TestMethod] @@ -103,15 +105,15 @@ public void HardForkTestNone() ProtocolSettings settings = ProtocolSettings.Load(file); File.Delete(file); - settings.Hardforks[Hardfork.HF_Aspidochelone].Should().Be(0); - settings.Hardforks[Hardfork.HF_Basilisk].Should().Be(0); + Assert.AreEqual((uint)0, settings.Hardforks[Hardfork.HF_Aspidochelone]); + Assert.AreEqual((uint)0, settings.Hardforks[Hardfork.HF_Basilisk]); // Check IsHardforkEnabled - settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 0).Should().BeTrue(); - settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 10).Should().BeTrue(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 0).Should().BeTrue(); - settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 10).Should().BeTrue(); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 0)); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Aspidochelone, 10)); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 0)); + Assert.IsTrue(settings.IsHardforkEnabled(Hardfork.HF_Basilisk, 10)); } [TestMethod] @@ -178,7 +180,7 @@ internal static string CreateHFSettings(string hf) [TestMethod] public void TestGetSeedList() { - TestProtocolSettings.Default.SeedList.Should().BeEquivalentTo(new string[] { "seed1.neo.org:10333", "seed2.neo.org:10333", "seed3.neo.org:10333", "seed4.neo.org:10333", "seed5.neo.org:10333", }); + CollectionAssert.AreEqual(new string[] { "seed1.neo.org:10333", "seed2.neo.org:10333", "seed3.neo.org:10333", "seed4.neo.org:10333", "seed5.neo.org:10333" }, TestProtocolSettings.Default.SeedList.ToArray()); } [TestMethod] @@ -186,51 +188,53 @@ public void TestStandbyCommitteeAddressesFormat() { foreach (var point in TestProtocolSettings.Default.StandbyCommittee) { - point.ToString().Should().MatchRegex("^[0-9A-Fa-f]{66}$"); // ECPoint is 66 hex characters + StringAssert.Matches(point.ToString(), new System.Text.RegularExpressions.Regex("^[0-9A-Fa-f]{66}$")); // ECPoint is 66 hex characters } } [TestMethod] public void TestValidatorsCount() { - TestProtocolSettings.Default.StandbyCommittee.Count.Should().Be(TestProtocolSettings.Default.ValidatorsCount * 3); + Assert.AreEqual(TestProtocolSettings.Default.ValidatorsCount * 3, TestProtocolSettings.Default.StandbyCommittee.Count); } [TestMethod] public void TestMaxTransactionsPerBlock() { - TestProtocolSettings.Default.MaxTransactionsPerBlock.Should().BePositive().And.BeLessThanOrEqualTo(50000); // Assuming 50000 as a reasonable upper limit + Assert.IsTrue(TestProtocolSettings.Default.MaxTransactionsPerBlock > 0); + Assert.IsTrue(TestProtocolSettings.Default.MaxTransactionsPerBlock <= 50000); // Assuming 50000 as a reasonable upper limit } [TestMethod] public void TestMaxTraceableBlocks() { - TestProtocolSettings.Default.MaxTraceableBlocks.Should().BePositive(); + Assert.IsTrue(TestProtocolSettings.Default.MaxTraceableBlocks > 0); } [TestMethod] public void TestInitialGasDistribution() { - TestProtocolSettings.Default.InitialGasDistribution.Should().BeGreaterThan(0); + Assert.IsTrue(TestProtocolSettings.Default.InitialGasDistribution > 0); } [TestMethod] public void TestHardforksSettings() { - TestProtocolSettings.Default.Hardforks.Should().NotBeNull(); + Assert.IsNotNull(TestProtocolSettings.Default.Hardforks); } [TestMethod] public void TestAddressVersion() { - TestProtocolSettings.Default.AddressVersion.Should().BeInRange(0, 255); // Address version is a byte + Assert.IsTrue(TestProtocolSettings.Default.AddressVersion >= 0); + Assert.IsTrue(TestProtocolSettings.Default.AddressVersion <= 255); // Address version is a byte } [TestMethod] public void TestNetworkSettingsConsistency() { - TestProtocolSettings.Default.Network.Should().BePositive(); - TestProtocolSettings.Default.SeedList.Should().NotBeEmpty(); + Assert.IsTrue(TestProtocolSettings.Default.Network > 0); + Assert.IsNotNull(TestProtocolSettings.Default.SeedList); } [TestMethod] @@ -239,7 +243,14 @@ public void TestECPointParsing() foreach (var point in TestProtocolSettings.Default.StandbyCommittee) { Action act = () => ECPoint.Parse(point.ToString(), ECCurve.Secp256r1); - act.Should().NotThrow(); + try + { + act(); + } + catch (Exception ex) + { + Assert.Fail($"Expected no exception, but got: {ex.Message}"); + } } } @@ -248,69 +259,69 @@ public void TestSeedListFormatAndReachability() { foreach (var seed in TestProtocolSettings.Default.SeedList) { - seed.Should().MatchRegex(@"^[\w.-]+:\d+$"); // Format: domain:port + StringAssert.Matches(seed, new System.Text.RegularExpressions.Regex(@"^[\w.-]+:\d+$")); // Format: domain:port } } [TestMethod] public void TestDefaultNetworkValue() { - ProtocolSettings.Default.Network.Should().Be(0); + Assert.AreEqual((uint)0, ProtocolSettings.Default.Network); } [TestMethod] public void TestDefaultAddressVersionValue() { - TestProtocolSettings.Default.AddressVersion.Should().Be(ProtocolSettings.Default.AddressVersion); + Assert.AreEqual(ProtocolSettings.Default.AddressVersion, TestProtocolSettings.Default.AddressVersion); } [TestMethod] public void TestDefaultValidatorsCountValue() { - ProtocolSettings.Default.ValidatorsCount.Should().Be(0); + Assert.AreEqual(0, ProtocolSettings.Default.ValidatorsCount); } [TestMethod] public void TestDefaultMillisecondsPerBlockValue() { - TestProtocolSettings.Default.MillisecondsPerBlock.Should().Be(ProtocolSettings.Default.MillisecondsPerBlock); + Assert.AreEqual(ProtocolSettings.Default.MillisecondsPerBlock, TestProtocolSettings.Default.MillisecondsPerBlock); } [TestMethod] public void TestDefaultMaxTransactionsPerBlockValue() { - TestProtocolSettings.Default.MaxTransactionsPerBlock.Should().Be(ProtocolSettings.Default.MaxTransactionsPerBlock); + Assert.AreEqual(ProtocolSettings.Default.MaxTransactionsPerBlock, TestProtocolSettings.Default.MaxTransactionsPerBlock); } [TestMethod] public void TestDefaultMemoryPoolMaxTransactionsValue() { - TestProtocolSettings.Default.MemoryPoolMaxTransactions.Should().Be(ProtocolSettings.Default.MemoryPoolMaxTransactions); + Assert.AreEqual(ProtocolSettings.Default.MemoryPoolMaxTransactions, TestProtocolSettings.Default.MemoryPoolMaxTransactions); } [TestMethod] public void TestDefaultMaxTraceableBlocksValue() { - TestProtocolSettings.Default.MaxTraceableBlocks.Should().Be(ProtocolSettings.Default.MaxTraceableBlocks); + Assert.AreEqual(ProtocolSettings.Default.MaxTraceableBlocks, TestProtocolSettings.Default.MaxTraceableBlocks); } [TestMethod] public void TestDefaultInitialGasDistributionValue() { - TestProtocolSettings.Default.InitialGasDistribution.Should().Be(ProtocolSettings.Default.InitialGasDistribution); + Assert.AreEqual(ProtocolSettings.Default.InitialGasDistribution, TestProtocolSettings.Default.InitialGasDistribution); } [TestMethod] public void TestDefaultHardforksValue() { - TestProtocolSettings.Default.Hardforks.Should().BeEquivalentTo(ProtocolSettings.Default.Hardforks); + CollectionAssert.AreEqual(ProtocolSettings.Default.Hardforks, TestProtocolSettings.Default.Hardforks); } [TestMethod] public void TestTimePerBlockCalculation() { var expectedTimeSpan = TimeSpan.FromMilliseconds(TestProtocolSettings.Default.MillisecondsPerBlock); - TestProtocolSettings.Default.TimePerBlock.Should().Be(expectedTimeSpan); + Assert.AreEqual(expectedTimeSpan, TestProtocolSettings.Default.TimePerBlock); } [TestMethod] @@ -319,20 +330,20 @@ public void TestLoad() var loadedSetting = ProtocolSettings.Load("test.config.json"); // Comparing all properties - TestProtocolSettings.Default.Network.Should().Be(loadedSetting.Network); - TestProtocolSettings.Default.AddressVersion.Should().Be(loadedSetting.AddressVersion); - TestProtocolSettings.Default.StandbyCommittee.Should().BeEquivalentTo(loadedSetting.StandbyCommittee); - TestProtocolSettings.Default.ValidatorsCount.Should().Be(loadedSetting.ValidatorsCount); - TestProtocolSettings.Default.SeedList.Should().BeEquivalentTo(loadedSetting.SeedList); - TestProtocolSettings.Default.MillisecondsPerBlock.Should().Be(loadedSetting.MillisecondsPerBlock); - TestProtocolSettings.Default.MaxTransactionsPerBlock.Should().Be(loadedSetting.MaxTransactionsPerBlock); - TestProtocolSettings.Default.MemoryPoolMaxTransactions.Should().Be(loadedSetting.MemoryPoolMaxTransactions); - TestProtocolSettings.Default.MaxTraceableBlocks.Should().Be(loadedSetting.MaxTraceableBlocks); - TestProtocolSettings.Default.InitialGasDistribution.Should().Be(loadedSetting.InitialGasDistribution); - TestProtocolSettings.Default.Hardforks.Should().BeEquivalentTo(loadedSetting.Hardforks); + Assert.AreEqual(TestProtocolSettings.Default.Network, loadedSetting.Network); + Assert.AreEqual(TestProtocolSettings.Default.AddressVersion, loadedSetting.AddressVersion); + CollectionAssert.AreEqual(TestProtocolSettings.Default.StandbyCommittee.ToList(), loadedSetting.StandbyCommittee.ToList()); + Assert.AreEqual(TestProtocolSettings.Default.ValidatorsCount, loadedSetting.ValidatorsCount); + CollectionAssert.AreEqual(TestProtocolSettings.Default.SeedList, loadedSetting.SeedList); + Assert.AreEqual(TestProtocolSettings.Default.MillisecondsPerBlock, loadedSetting.MillisecondsPerBlock); + Assert.AreEqual(TestProtocolSettings.Default.MaxTransactionsPerBlock, loadedSetting.MaxTransactionsPerBlock); + Assert.AreEqual(TestProtocolSettings.Default.MemoryPoolMaxTransactions, loadedSetting.MemoryPoolMaxTransactions); + Assert.AreEqual(TestProtocolSettings.Default.MaxTraceableBlocks, loadedSetting.MaxTraceableBlocks); + Assert.AreEqual(TestProtocolSettings.Default.InitialGasDistribution, loadedSetting.InitialGasDistribution); + CollectionAssert.AreEqual(TestProtocolSettings.Default.Hardforks, loadedSetting.Hardforks); // If StandbyValidators is a derived property, comparing it as well - TestProtocolSettings.Default.StandbyValidators.Should().BeEquivalentTo(loadedSetting.StandbyValidators); + CollectionAssert.AreEqual(TestProtocolSettings.Default.StandbyValidators.ToList(), loadedSetting.StandbyValidators.ToList()); } } } diff --git a/tests/Neo.UnitTests/UT_UInt160.cs b/tests/Neo.UnitTests/UT_UInt160.cs index a6544fcbbb..6eb0326ef6 100644 --- a/tests/Neo.UnitTests/UT_UInt160.cs +++ b/tests/Neo.UnitTests/UT_UInt160.cs @@ -11,7 +11,6 @@ #pragma warning disable CS1718 // Comparison made to same variable -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using System; @@ -79,13 +78,16 @@ public void TestEquals() public void TestParse() { Action action = () => UInt160.Parse(null); - action.Should().Throw(); + Assert.ThrowsException(action); UInt160 result = UInt160.Parse("0x0000000000000000000000000000000000000000"); Assert.AreEqual(UInt160.Zero, result); Action action1 = () => UInt160.Parse("000000000000000000000000000000000000000"); - action1.Should().Throw(); + Assert.ThrowsException(action1); UInt160 result1 = UInt160.Parse("0000000000000000000000000000000000000000"); Assert.AreEqual(UInt160.Zero, result1); + + ushort b = 10; + var a = -b; } [TestMethod] diff --git a/tests/Neo.UnitTests/UT_UInt256.cs b/tests/Neo.UnitTests/UT_UInt256.cs index abc60cdd41..550a1a25bd 100644 --- a/tests/Neo.UnitTests/UT_UInt256.cs +++ b/tests/Neo.UnitTests/UT_UInt256.cs @@ -11,7 +11,6 @@ #pragma warning disable CS1718 -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.IO; @@ -105,11 +104,11 @@ public void TestEquals2() public void TestParse() { Action action = () => UInt256.Parse(null); - action.Should().Throw(); + Assert.ThrowsException(() => action()); UInt256 result = UInt256.Parse("0x0000000000000000000000000000000000000000000000000000000000000000"); Assert.AreEqual(UInt256.Zero, result); Action action1 = () => UInt256.Parse("000000000000000000000000000000000000000000000000000000000000000"); - action1.Should().Throw(); + Assert.ThrowsException(() => action1()); UInt256 result1 = UInt256.Parse("0000000000000000000000000000000000000000000000000000000000000000"); Assert.AreEqual(UInt256.Zero, result1); } diff --git a/tests/Neo.UnitTests/UT_UIntBenchmarks.cs b/tests/Neo.UnitTests/UT_UIntBenchmarks.cs index 8d09bd16ac..9a19c08e80 100644 --- a/tests/Neo.UnitTests/UT_UIntBenchmarks.cs +++ b/tests/Neo.UnitTests/UT_UIntBenchmarks.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Diagnostics; @@ -63,11 +62,11 @@ public void Test_UInt160_Parse() { string uint160strbig = "0x0001020304050607080900010203040506070809"; UInt160 num1 = UInt160.Parse(uint160strbig); - num1.ToString().Should().Be("0x0001020304050607080900010203040506070809"); + Assert.AreEqual("0x0001020304050607080900010203040506070809", num1.ToString()); string uint160strbig2 = "0X0001020304050607080900010203040506070809"; UInt160 num2 = UInt160.Parse(uint160strbig2); - num2.ToString().Should().Be("0x0001020304050607080900010203040506070809"); + Assert.AreEqual("0x0001020304050607080900010203040506070809", num2.ToString()); } private byte[] RandomBytes(int count) @@ -147,9 +146,9 @@ public void Benchmark_CompareTo_UInt256() return checksum; }).Item2; - checksum0.Should().Be(checksum1); - checksum0.Should().Be(checksum2); - checksum0.Should().Be(checksum3); + Assert.AreEqual(checksum1, checksum0); + Assert.AreEqual(checksum2, checksum0); + Assert.AreEqual(checksum3, checksum0); } [TestMethod] @@ -209,9 +208,9 @@ public void Benchmark_CompareTo_UInt160() return checksum; }).Item2; - checksum0.Should().Be(checksum1); - checksum0.Should().Be(checksum2); - checksum0.Should().Be(checksum3); + Assert.AreEqual(checksum1, checksum0); + Assert.AreEqual(checksum2, checksum0); + Assert.AreEqual(checksum3, checksum0); } [TestMethod] @@ -219,12 +218,12 @@ public void Benchmark_UInt_IsCorrect_Self_CompareTo() { for (var i = 0; i < MAX_TESTS; i++) { - code1_UInt160CompareTo(base_20_1[i], base_20_1[i]).Should().Be(0); - code2_UInt160CompareTo(base_20_1[i], base_20_1[i]).Should().Be(0); - code3_UInt160CompareTo(base_20_1[i], base_20_1[i]).Should().Be(0); - code1_UInt256CompareTo(base_32_1[i], base_32_1[i]).Should().Be(0); - code2_UInt256CompareTo(base_32_1[i], base_32_1[i]).Should().Be(0); - code3_UInt256CompareTo(base_32_1[i], base_32_1[i]).Should().Be(0); + Assert.AreEqual(0, code1_UInt160CompareTo(base_20_1[i], base_20_1[i])); + Assert.AreEqual(0, code2_UInt160CompareTo(base_20_1[i], base_20_1[i])); + Assert.AreEqual(0, code3_UInt160CompareTo(base_20_1[i], base_20_1[i])); + Assert.AreEqual(0, code1_UInt256CompareTo(base_32_1[i], base_32_1[i])); + Assert.AreEqual(0, code2_UInt256CompareTo(base_32_1[i], base_32_1[i])); + Assert.AreEqual(0, code3_UInt256CompareTo(base_32_1[i], base_32_1[i])); } } diff --git a/tests/Neo.UnitTests/VM/UT_Helper.cs b/tests/Neo.UnitTests/VM/UT_Helper.cs index ea0f2a4dd8..79dcb2fd39 100644 --- a/tests/Neo.UnitTests/VM/UT_Helper.cs +++ b/tests/Neo.UnitTests/VM/UT_Helper.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Extensions; @@ -335,6 +334,7 @@ private void TestEmitPush2String() sb.EmitPush(new ContractParameter(ContractParameterType.String)); byte[] tempArray = new byte[2]; tempArray[0] = (byte)OpCode.PUSHDATA1; + tempArray[1] = 0x00; CollectionAssert.AreEqual(tempArray, sb.ToArray()); } @@ -447,7 +447,7 @@ public void TestEmitPush3() ScriptBuilder sb = new ScriptBuilder(); Action action = () => sb.EmitPush(new object()); - action.Should().Throw(); + Assert.ThrowsException(() => action()); } @@ -723,7 +723,7 @@ public void TestCyclicReference() // check cyclic reference map[2] = item; var action = () => item.ToJson(); - action.Should().Throw(); + Assert.ThrowsException(() => action()); } } } diff --git a/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs b/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs index 01f5ea2ad2..05e6f36cfc 100644 --- a/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs +++ b/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Json; @@ -50,26 +49,26 @@ public void TestSetup() public void TestChangePassword() { _account = new NEP6Account(_wallet, _hash, _nep2); - _account.ChangePasswordPrepare("b", "Satoshi").Should().BeTrue(); + Assert.IsTrue(_account.ChangePasswordPrepare("b", "Satoshi")); _account.ChangePasswordCommit(); _account.Contract = new Contract(); - _account.ChangePasswordPrepare("b", "Satoshi").Should().BeFalse(); - _account.ChangePasswordPrepare("Satoshi", "b").Should().BeTrue(); + Assert.IsFalse(_account.ChangePasswordPrepare("b", "Satoshi")); + Assert.IsTrue(_account.ChangePasswordPrepare("Satoshi", "b")); _account.ChangePasswordCommit(); - _account.VerifyPassword("b").Should().BeTrue(); - _account.ChangePasswordPrepare("b", "Satoshi").Should().BeTrue(); + Assert.IsTrue(_account.VerifyPassword("b")); + Assert.IsTrue(_account.ChangePasswordPrepare("b", "Satoshi")); _account.ChangePasswordCommit(); - _account.ChangePasswordPrepare("Satoshi", "b").Should().BeTrue(); + Assert.IsTrue(_account.ChangePasswordPrepare("Satoshi", "b")); _account.ChangePasswordRollback(); - _account.VerifyPassword("Satoshi").Should().BeTrue(); + Assert.IsTrue(_account.VerifyPassword("Satoshi")); } [TestMethod] public void TestConstructorWithNep2Key() { - _account.ScriptHash.Should().Be(_hash); - _account.Decrypted.Should().BeTrue(); - _account.HasKey.Should().BeFalse(); + Assert.AreEqual(_hash, _account.ScriptHash); + Assert.IsTrue(_account.Decrypted); + Assert.IsFalse(_account.HasKey); } [TestMethod] @@ -80,9 +79,9 @@ public void TestConstructorWithKeyPair() byte[] array1 = { 0x01 }; var hash = new UInt160(Crypto.Hash160(array1)); NEP6Account account = new(wallet, hash, _keyPair, password); - account.ScriptHash.Should().Be(hash); - account.Decrypted.Should().BeTrue(); - account.HasKey.Should().BeTrue(); + Assert.AreEqual(hash, account.ScriptHash); + Assert.IsTrue(account.Decrypted); + Assert.IsTrue(account.HasKey); } [TestMethod] @@ -97,35 +96,35 @@ public void TestFromJson() json["contract"] = null; json["extra"] = null; NEP6Account account = NEP6Account.FromJson(json, _wallet); - account.ScriptHash.Should().Be("NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf".ToScriptHash(TestProtocolSettings.Default.AddressVersion)); - account.Label.Should().BeNull(); - account.IsDefault.Should().BeTrue(); - account.Lock.Should().BeFalse(); - account.Contract.Should().BeNull(); - account.Extra.Should().BeNull(); - account.GetKey().Should().BeNull(); + Assert.AreEqual("NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf".ToScriptHash(TestProtocolSettings.Default.AddressVersion), account.ScriptHash); + Assert.IsNull(account.Label); + Assert.IsTrue(account.IsDefault); + Assert.IsFalse(account.Lock); + Assert.IsNull(account.Contract); + Assert.IsNull(account.Extra); + Assert.IsNull(account.GetKey()); json["key"] = "6PYRjVE1gAbCRyv81FTiFz62cxuPGw91vMjN4yPa68bnoqJtioreTznezn"; json["label"] = "label"; account = NEP6Account.FromJson(json, _wallet); - account.Label.Should().Be("label"); - account.HasKey.Should().BeTrue(); + Assert.AreEqual("label", account.Label); + Assert.IsTrue(account.HasKey); } [TestMethod] public void TestGetKey() { - _account.GetKey().Should().BeNull(); + Assert.IsNull(_account.GetKey()); _account = new NEP6Account(_wallet, _hash, _nep2); - _account.GetKey().Should().Be(_keyPair); + Assert.AreEqual(_keyPair, _account.GetKey()); } [TestMethod] public void TestGetKeyWithString() { - _account.GetKey("Satoshi").Should().BeNull(); + Assert.IsNull(_account.GetKey("Satoshi")); _account = new NEP6Account(_wallet, _hash, _nep2); - _account.GetKey("Satoshi").Should().Be(_keyPair); + Assert.AreEqual(_keyPair, _account.GetKey("Satoshi")); } [TestMethod] @@ -144,25 +143,25 @@ public void TestToJson() nep6contract["deployed"] = false; _account.Contract = NEP6Contract.FromJson(nep6contract); JObject json = _account.ToJson(); - json["address"].AsString().Should().Be("NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf"); - json["label"].Should().BeNull(); - json["isDefault"].ToString().Should().Be("false"); - json["lock"].ToString().Should().Be("false"); - json["key"].Should().BeNull(); - json["contract"]["script"].ToString().Should().Be(@"""IQNgPziA63rqCtRQCJOSXkpC/qSKRO5viYoQs8fOBdKiZ6w="""); - json["extra"].Should().BeNull(); + Assert.AreEqual("NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf", json["address"].AsString()); + Assert.IsNull(json["label"]); + Assert.AreEqual("false", json["isDefault"].ToString()); + Assert.AreEqual("false", json["lock"].ToString()); + Assert.IsNull(json["key"]); + Assert.AreEqual(@"""IQNgPziA63rqCtRQCJOSXkpC/qSKRO5viYoQs8fOBdKiZ6w=""", json["contract"]["script"].ToString()); + Assert.IsNull(json["extra"]); _account.Contract = null; json = _account.ToJson(); - json["contract"].Should().BeNull(); + Assert.IsNull(json["contract"]); } [TestMethod] public void TestVerifyPassword() { _account = new NEP6Account(_wallet, _hash, _nep2); - _account.VerifyPassword("Satoshi").Should().BeTrue(); - _account.VerifyPassword("b").Should().BeFalse(); + Assert.IsTrue(_account.VerifyPassword("Satoshi")); + Assert.IsFalse(_account.VerifyPassword("b")); } } } diff --git a/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs b/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs index e55215059a..77dcd82398 100644 --- a/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs +++ b/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Contract.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.Json; @@ -26,7 +25,7 @@ public class UT_NEP6Contract public void TestFromNullJson() { NEP6Contract nep6Contract = NEP6Contract.FromJson(null); - nep6Contract.Should().BeNull(); + Assert.IsNull(nep6Contract); } [TestMethod] @@ -37,12 +36,12 @@ public void TestFromJson() JObject @object = (JObject)JToken.Parse(json); NEP6Contract nep6Contract = NEP6Contract.FromJson(@object); - nep6Contract.Script.Should().BeEquivalentTo("2103ef891df4c0b7eefb937d21ea0fb88cde8e0d82a7ff11872b5e7047969dafb4eb68747476aa".HexToBytes()); - nep6Contract.ParameterList.Length.Should().Be(1); - nep6Contract.ParameterList[0].Should().Be(ContractParameterType.Signature); - nep6Contract.ParameterNames.Length.Should().Be(1); - nep6Contract.ParameterNames[0].Should().Be("signature"); - nep6Contract.Deployed.Should().BeFalse(); + CollectionAssert.AreEqual("2103ef891df4c0b7eefb937d21ea0fb88cde8e0d82a7ff11872b5e7047969dafb4eb68747476aa".HexToBytes(), nep6Contract.Script); + Assert.AreEqual(1, nep6Contract.ParameterList.Length); + Assert.AreEqual(ContractParameterType.Signature, nep6Contract.ParameterList[0]); + Assert.AreEqual(1, nep6Contract.ParameterNames.Length); + Assert.AreEqual("signature", nep6Contract.ParameterNames[0]); + Assert.IsFalse(nep6Contract.Deployed); } [TestMethod] @@ -58,23 +57,23 @@ public void TestToJson() JObject @object = nep6Contract.ToJson(); JString jString = (JString)@object["script"]; - jString.Value.Should().Be(Convert.ToBase64String(nep6Contract.Script, Base64FormattingOptions.None)); + Assert.AreEqual(Convert.ToBase64String(nep6Contract.Script, Base64FormattingOptions.None), jString.Value); JBoolean jBoolean = (JBoolean)@object["deployed"]; - jBoolean.Value.Should().BeFalse(); + Assert.IsFalse(jBoolean.Value); JArray parameters = (JArray)@object["parameters"]; - parameters.Count.Should().Be(2); + Assert.AreEqual(2, parameters.Count); jString = (JString)parameters[0]["name"]; - jString.Value.Should().Be("param1"); + Assert.AreEqual("param1", jString.Value); jString = (JString)parameters[0]["type"]; - jString.Value.Should().Be(ContractParameterType.Boolean.ToString()); + Assert.AreEqual(ContractParameterType.Boolean.ToString(), jString.Value); jString = (JString)parameters[1]["name"]; - jString.Value.Should().Be("param2"); + Assert.AreEqual("param2", jString.Value); jString = (JString)parameters[1]["type"]; - jString.Value.Should().Be(ContractParameterType.Integer.ToString()); + Assert.AreEqual(ContractParameterType.Integer.ToString(), jString.Value); } } } diff --git a/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs b/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs index 06362def3a..e6d2f69cbb 100644 --- a/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs +++ b/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; using Neo.Json; @@ -110,10 +109,10 @@ public void TestChangePassword() File.WriteAllText(wPath, wallet.ToString()); uut = new NEP6Wallet(wPath, "123", TestProtocolSettings.Default); uut.CreateAccount(keyPair.PrivateKey); - uut.ChangePassword("456", "123").Should().BeFalse(); - uut.ChangePassword("123", "456").Should().BeTrue(); - uut.VerifyPassword("456").Should().BeTrue(); - uut.ChangePassword("456", "123").Should().BeTrue(); + Assert.IsFalse(uut.ChangePassword("456", "123")); + Assert.IsTrue(uut.ChangePassword("123", "456")); + Assert.IsTrue(uut.VerifyPassword("456")); + Assert.IsTrue(uut.ChangePassword("456", "123")); } [TestMethod] @@ -138,7 +137,7 @@ public void TestConstructorWithJObject() wallet["scrypt"] = ScryptParameters.Default.ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); - wallet.ToString().Should().Be("{\"name\":\"test\",\"version\":\"1.0\",\"scrypt\":{\"n\":16384,\"r\":8,\"p\":8},\"accounts\":[],\"extra\":{}}"); + Assert.AreEqual("{\"name\":\"test\",\"version\":\"1.0\",\"scrypt\":{\"n\":16384,\"r\":8,\"p\":8},\"accounts\":[],\"extra\":{}}", wallet.ToString()); NEP6Wallet w = new(null, "123", TestProtocolSettings.Default, wallet); Assert.AreEqual("test", w.Name); Assert.AreEqual(Version.Parse("1.0").ToString(), w.Version.ToString()); @@ -387,7 +386,7 @@ public void TestSave() public void TestToJson() { var json = uut.ToJson(); - json.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"1.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}"); + Assert.AreEqual("{\"name\":\"noname\",\"version\":\"1.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}", json.ToString()); } [TestMethod] @@ -418,10 +417,10 @@ public void TestVerifyPassword() [TestMethod] public void Test_NEP6Wallet_Json() { - uut.Name.Should().Be("noname"); - uut.Version.Should().Be(new Version("1.0")); - uut.Scrypt.Should().NotBeNull(); - uut.Scrypt.N.Should().Be(new ScryptParameters(2, 1, 1).N); + Assert.AreEqual("noname", uut.Name); + Assert.AreEqual(new Version("1.0"), uut.Version); + Assert.IsNotNull(uut.Scrypt); + Assert.AreEqual(new ScryptParameters(2, 1, 1).N, uut.Scrypt.N); } [TestMethod] diff --git a/tests/Neo.UnitTests/Wallets/NEP6/UT_ScryptParameters.cs b/tests/Neo.UnitTests/Wallets/NEP6/UT_ScryptParameters.cs index 2fbf60ac2a..11da78ae4c 100644 --- a/tests/Neo.UnitTests/Wallets/NEP6/UT_ScryptParameters.cs +++ b/tests/Neo.UnitTests/Wallets/NEP6/UT_ScryptParameters.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Json; using Neo.Wallets.NEP6; @@ -30,18 +29,18 @@ public void TestSetup() [TestMethod] public void Test_Default_ScryptParameters() { - uut.N.Should().Be(16384); - uut.R.Should().Be(8); - uut.P.Should().Be(8); + Assert.AreEqual(16384, uut.N); + Assert.AreEqual(8, uut.R); + Assert.AreEqual(8, uut.P); } [TestMethod] public void Test_ScryptParameters_Default_ToJson() { JObject json = ScryptParameters.Default.ToJson(); - json["n"].AsNumber().Should().Be(ScryptParameters.Default.N); - json["r"].AsNumber().Should().Be(ScryptParameters.Default.R); - json["p"].AsNumber().Should().Be(ScryptParameters.Default.P); + Assert.AreEqual(ScryptParameters.Default.N, json["n"].AsNumber()); + Assert.AreEqual(ScryptParameters.Default.R, json["r"].AsNumber()); + Assert.AreEqual(ScryptParameters.Default.P, json["p"].AsNumber()); } [TestMethod] @@ -53,9 +52,9 @@ public void Test_Default_ScryptParameters_FromJson() json["p"] = 8; ScryptParameters uut2 = ScryptParameters.FromJson(json); - uut2.N.Should().Be(ScryptParameters.Default.N); - uut2.R.Should().Be(ScryptParameters.Default.R); - uut2.P.Should().Be(ScryptParameters.Default.P); + Assert.AreEqual(ScryptParameters.Default.N, uut2.N); + Assert.AreEqual(ScryptParameters.Default.R, uut2.R); + Assert.AreEqual(ScryptParameters.Default.P, uut2.P); } [TestMethod] @@ -63,9 +62,9 @@ public void TestScryptParametersConstructor() { int n = 1, r = 2, p = 3; ScryptParameters parameter = new ScryptParameters(n, r, p); - parameter.N.Should().Be(n); - parameter.R.Should().Be(r); - parameter.P.Should().Be(p); + Assert.AreEqual(n, parameter.N); + Assert.AreEqual(r, parameter.R); + Assert.AreEqual(p, parameter.P); } } } diff --git a/tests/Neo.UnitTests/Wallets/UT_AssetDescriptor.cs b/tests/Neo.UnitTests/Wallets/UT_AssetDescriptor.cs index 48243b87e8..cd87d873f3 100644 --- a/tests/Neo.UnitTests/Wallets/UT_AssetDescriptor.cs +++ b/tests/Neo.UnitTests/Wallets/UT_AssetDescriptor.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.SmartContract.Native; using System; @@ -27,7 +26,7 @@ public void TestConstructorWithNonexistAssetId() { var descriptor = new Neo.Wallets.AssetDescriptor(snapshotCache, TestProtocolSettings.Default, UInt160.Parse("01ff00ff00ff00ff00ff00ff00ff00ff00ff00a4")); }; - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -35,11 +34,11 @@ public void Check_GAS() { var snapshotCache = TestBlockchain.GetTestSnapshotCache(); var descriptor = new Neo.Wallets.AssetDescriptor(snapshotCache, TestProtocolSettings.Default, NativeContract.GAS.Hash); - descriptor.AssetId.Should().Be(NativeContract.GAS.Hash); - descriptor.AssetName.Should().Be(nameof(GasToken)); - descriptor.ToString().Should().Be(nameof(GasToken)); - descriptor.Symbol.Should().Be("GAS"); - descriptor.Decimals.Should().Be(8); + Assert.AreEqual(NativeContract.GAS.Hash, descriptor.AssetId); + Assert.AreEqual(nameof(GasToken), descriptor.AssetName); + Assert.AreEqual(nameof(GasToken), descriptor.ToString()); + Assert.AreEqual("GAS", descriptor.Symbol); + Assert.AreEqual(8, descriptor.Decimals); } [TestMethod] @@ -47,11 +46,11 @@ public void Check_NEO() { var snapshotCache = TestBlockchain.GetTestSnapshotCache(); var descriptor = new Neo.Wallets.AssetDescriptor(snapshotCache, TestProtocolSettings.Default, NativeContract.NEO.Hash); - descriptor.AssetId.Should().Be(NativeContract.NEO.Hash); - descriptor.AssetName.Should().Be(nameof(NeoToken)); - descriptor.ToString().Should().Be(nameof(NeoToken)); - descriptor.Symbol.Should().Be("NEO"); - descriptor.Decimals.Should().Be(0); + Assert.AreEqual(NativeContract.NEO.Hash, descriptor.AssetId); + Assert.AreEqual(nameof(NeoToken), descriptor.AssetName); + Assert.AreEqual(nameof(NeoToken), descriptor.ToString()); + Assert.AreEqual("NEO", descriptor.Symbol); + Assert.AreEqual(0, descriptor.Decimals); } } } diff --git a/tests/Neo.UnitTests/Wallets/UT_KeyPair.cs b/tests/Neo.UnitTests/Wallets/UT_KeyPair.cs index d8f7295b71..197c05a595 100644 --- a/tests/Neo.UnitTests/Wallets/UT_KeyPair.cs +++ b/tests/Neo.UnitTests/Wallets/UT_KeyPair.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Cryptography.ECC; @@ -31,22 +30,22 @@ public void TestConstructor() privateKey[i] = (byte)random.Next(256); KeyPair keyPair = new KeyPair(privateKey); ECPoint publicKey = ECCurve.Secp256r1.G * privateKey; - keyPair.PrivateKey.Should().BeEquivalentTo(privateKey); - keyPair.PublicKey.Should().Be(publicKey); + CollectionAssert.AreEqual(privateKey, keyPair.PrivateKey); + Assert.AreEqual(publicKey, keyPair.PublicKey); byte[] privateKey96 = new byte[96]; for (int i = 0; i < privateKey96.Length; i++) privateKey96[i] = (byte)random.Next(256); keyPair = new KeyPair(privateKey96); publicKey = ECPoint.DecodePoint(new byte[] { 0x04 }.Concat(privateKey96.Skip(privateKey96.Length - 96).Take(64)).ToArray(), ECCurve.Secp256r1); - keyPair.PrivateKey.Should().BeEquivalentTo(privateKey96.Skip(64).Take(32)); - keyPair.PublicKey.Should().Be(publicKey); + CollectionAssert.AreEqual(privateKey96.Skip(64).Take(32).ToArray(), keyPair.PrivateKey); + Assert.AreEqual(publicKey, keyPair.PublicKey); byte[] privateKey31 = new byte[31]; for (int i = 0; i < privateKey31.Length; i++) privateKey31[i] = (byte)random.Next(256); Action action = () => new KeyPair(privateKey31); - action.Should().Throw(); + Assert.ThrowsException(action); } [TestMethod] @@ -58,10 +57,10 @@ public void TestEquals() privateKey[i] = (byte)random.Next(256); KeyPair keyPair = new KeyPair(privateKey); KeyPair keyPair2 = keyPair; - keyPair.Equals(keyPair2).Should().BeTrue(); + Assert.IsTrue(keyPair.Equals(keyPair2)); KeyPair keyPair3 = null; - keyPair.Equals(keyPair3).Should().BeFalse(); + Assert.IsFalse(keyPair.Equals(keyPair3)); byte[] privateKey1 = { 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}; @@ -69,7 +68,7 @@ public void TestEquals() 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02}; KeyPair keyPair4 = new KeyPair(privateKey1); KeyPair keyPair5 = new KeyPair(privateKey2); - keyPair4.Equals(keyPair5).Should().BeFalse(); + Assert.IsFalse(keyPair4.Equals(keyPair5)); } [TestMethod] @@ -81,7 +80,7 @@ public void TestEqualsWithObj() privateKey[i] = (byte)random.Next(256); KeyPair keyPair = new KeyPair(privateKey); Object keyPair2 = keyPair; - keyPair.Equals(keyPair2).Should().BeTrue(); + Assert.IsTrue(keyPair.Equals(keyPair2)); } [TestMethod] @@ -92,7 +91,7 @@ public void TestExport() byte[] data = { 0x80, 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, 0x01}; KeyPair keyPair = new KeyPair(privateKey); - keyPair.Export().Should().Be(Base58.Base58CheckEncode(data)); + Assert.AreEqual(Base58.Base58CheckEncode(data), keyPair.Export()); } [TestMethod] @@ -101,7 +100,7 @@ public void TestGetPublicKeyHash() 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 keyPair = new KeyPair(privateKey); - keyPair.PublicKeyHash.ToString().Should().Be("0x4ab3d6ac3a0609e87af84599c93d57c2d0890406"); + Assert.AreEqual("0x4ab3d6ac3a0609e87af84599c93d57c2d0890406", keyPair.PublicKeyHash.ToString()); } [TestMethod] @@ -111,7 +110,7 @@ public void TestGetHashCode() 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; KeyPair keyPair1 = new KeyPair(privateKey); KeyPair keyPair2 = new KeyPair(privateKey); - keyPair1.GetHashCode().Should().Be(keyPair2.GetHashCode()); + Assert.AreEqual(keyPair2.GetHashCode(), keyPair1.GetHashCode()); } [TestMethod] @@ -120,7 +119,7 @@ public void TestToString() 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 keyPair = new KeyPair(privateKey); - keyPair.ToString().Should().Be("026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca16"); + Assert.AreEqual("026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca16", keyPair.ToString()); } } } diff --git a/tests/Neo.UnitTests/Wallets/UT_Wallet.cs b/tests/Neo.UnitTests/Wallets/UT_Wallet.cs index 3580b864d0..139094d2c8 100644 --- a/tests/Neo.UnitTests/Wallets/UT_Wallet.cs +++ b/tests/Neo.UnitTests/Wallets/UT_Wallet.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography.ECC; using Neo.Network.P2P.Payloads; @@ -130,15 +129,21 @@ public static void ClassInit(TestContext ctx) public void TestContains() { MyWallet wallet = new(); - Action action = () => wallet.Contains(UInt160.Zero); - action.Should().NotThrow(); + try + { + wallet.Contains(UInt160.Zero); + } + catch (Exception) + { + Assert.Fail(); + } } [TestMethod] public void TestCreateAccount1() { MyWallet wallet = new(); - wallet.CreateAccount(new byte[32]).Should().NotBeNull(); + Assert.IsNotNull(wallet.CreateAccount(new byte[32])); } [TestMethod] @@ -147,11 +152,11 @@ public void TestCreateAccount2() MyWallet wallet = new(); Contract contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 }); WalletAccount account = wallet.CreateAccount(contract, UT_Crypto.GenerateCertainKey(32).PrivateKey); - account.Should().NotBeNull(); + Assert.IsNotNull(account); wallet = new(); account = wallet.CreateAccount(contract, (byte[])(null)); - account.Should().NotBeNull(); + Assert.IsNotNull(account); } [TestMethod] @@ -159,28 +164,28 @@ public void TestCreateAccount3() { MyWallet wallet = new(); Contract contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 }); - wallet.CreateAccount(contract, glkey).Should().NotBeNull(); + Assert.IsNotNull(wallet.CreateAccount(contract, glkey)); } [TestMethod] public void TestCreateAccount4() { MyWallet wallet = new(); - wallet.CreateAccount(UInt160.Zero).Should().NotBeNull(); + Assert.IsNotNull(wallet.CreateAccount(UInt160.Zero)); } [TestMethod] public void TestGetName() { MyWallet wallet = new(); - wallet.Name.Should().Be("MyWallet"); + Assert.AreEqual("MyWallet", wallet.Name); } [TestMethod] public void TestGetVersion() { MyWallet wallet = new(); - wallet.Version.Should().Be(Version.Parse("0.0.1")); + Assert.AreEqual(Version.Parse("0.0.1"), wallet.Version); } [TestMethod] @@ -189,23 +194,36 @@ public void TestGetAccount1() MyWallet wallet = new(); wallet.CreateAccount(UInt160.Parse("0x7efe7ee0d3e349e085388c351955e5172605de66")); WalletAccount account = wallet.GetAccount(ECCurve.Secp256r1.G); - account.ScriptHash.Should().Be(UInt160.Parse("0x7efe7ee0d3e349e085388c351955e5172605de66")); + Assert.AreEqual(UInt160.Parse("0x7efe7ee0d3e349e085388c351955e5172605de66"), account.ScriptHash); } [TestMethod] public void TestGetAccount2() { MyWallet wallet = new(); - Action action = () => wallet.GetAccount(UInt160.Zero); - action.Should().NotThrow(); + + try + { + wallet.GetAccount(UInt160.Zero); + } + catch (Exception) + { + Assert.Fail(); + } } [TestMethod] public void TestGetAccounts() { MyWallet wallet = new(); - Action action = () => wallet.GetAccounts(); - action.Should().NotThrow(); + try + { + wallet.GetAccounts(); + } + catch (Exception) + { + Assert.Fail(); + } } [TestMethod] @@ -222,7 +240,7 @@ public void TestGetAvailable() var entry = snapshotCache.GetAndChange(key, () => new StorageItem(new AccountState())); entry.GetInteroperable().Balance = 10000 * NativeContract.GAS.Factor; - wallet.GetAvailable(snapshotCache, NativeContract.GAS.Hash).Should().Be(new BigDecimal(new BigInteger(1000000000000M), 8)); + Assert.AreEqual(new BigDecimal(new BigInteger(1000000000000M), 8), wallet.GetAvailable(snapshotCache, NativeContract.GAS.Hash)); entry = snapshotCache.GetAndChange(key, () => new StorageItem(new AccountState())); entry.GetInteroperable().Balance = 0; @@ -242,8 +260,8 @@ public void TestGetBalance() var entry = snapshotCache.GetAndChange(key, () => new StorageItem(new AccountState())); entry.GetInteroperable().Balance = 10000 * NativeContract.GAS.Factor; - wallet.GetBalance(snapshotCache, UInt160.Zero, new UInt160[] { account.ScriptHash }).Should().Be(new BigDecimal(BigInteger.Zero, 0)); - wallet.GetBalance(snapshotCache, NativeContract.GAS.Hash, new UInt160[] { account.ScriptHash }).Should().Be(new BigDecimal(new BigInteger(1000000000000M), 8)); + Assert.AreEqual(new BigDecimal(BigInteger.Zero, 0), wallet.GetBalance(snapshotCache, UInt160.Zero, new UInt160[] { account.ScriptHash })); + Assert.AreEqual(new BigDecimal(new BigInteger(1000000000000M), 8), wallet.GetBalance(snapshotCache, NativeContract.GAS.Hash, new UInt160[] { account.ScriptHash })); entry = snapshotCache.GetAndChange(key, () => new StorageItem(new AccountState())); entry.GetInteroperable().Balance = 0; @@ -253,38 +271,38 @@ public void TestGetBalance() public void TestGetPrivateKeyFromNEP2() { Action action = () => Wallet.GetPrivateKeyFromNEP2("3vQB7B6MrGQZaxCuFg4oh", "TestGetPrivateKeyFromNEP2", ProtocolSettings.Default.AddressVersion, 2, 1, 1); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => Wallet.GetPrivateKeyFromNEP2(nep2Key, "Test", ProtocolSettings.Default.AddressVersion, 2, 1, 1); - action.Should().Throw(); + Assert.ThrowsException(action); - Wallet.GetPrivateKeyFromNEP2(nep2Key, "pwd", ProtocolSettings.Default.AddressVersion, 2, 1, 1).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 }); + CollectionAssert.AreEqual(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 }, Wallet.GetPrivateKeyFromNEP2(nep2Key, "pwd", ProtocolSettings.Default.AddressVersion, 2, 1, 1)); } [TestMethod] public void TestGetPrivateKeyFromWIF() { Action action = () => Wallet.GetPrivateKeyFromWIF(null); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => Wallet.GetPrivateKeyFromWIF("3vQB7B6MrGQZaxCuFg4oh"); - action.Should().Throw(); + Assert.ThrowsException(action); - 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 }); + CollectionAssert.AreEqual(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 }, Wallet.GetPrivateKeyFromWIF("L3tgppXLgdaeqSGSFw1Go3skBiy8vQAM7YMXvTHsKQtE16PBncSU")); } [TestMethod] public void TestImport1() { MyWallet wallet = new(); - wallet.Import("L3tgppXLgdaeqSGSFw1Go3skBiy8vQAM7YMXvTHsKQtE16PBncSU").Should().NotBeNull(); + Assert.IsNotNull(wallet.Import("L3tgppXLgdaeqSGSFw1Go3skBiy8vQAM7YMXvTHsKQtE16PBncSU")); } [TestMethod] public void TestImport2() { MyWallet wallet = new(); - wallet.Import(nep2Key, "pwd", 2, 1, 1).Should().NotBeNull(); + Assert.IsNotNull(wallet.Import(nep2Key, "pwd", 2, 1, 1)); } [TestMethod] @@ -306,7 +324,7 @@ public void TestMakeTransaction1() Data = "Dec 12th" } }, UInt160.Zero); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => wallet.MakeTransaction(snapshotCache, new TransferOutput[] { @@ -318,7 +336,7 @@ public void TestMakeTransaction1() Data = "Dec 12th" } }, account.ScriptHash); - action.Should().Throw(); + Assert.ThrowsException(action); action = () => wallet.MakeTransaction(snapshotCache, new TransferOutput[] { @@ -330,7 +348,7 @@ public void TestMakeTransaction1() Data = "Dec 12th" } }, account.ScriptHash); - action.Should().Throw(); + Assert.ThrowsException(action); // Fake balance var key = NativeContract.GAS.CreateStorageKey(20, account.ScriptHash); @@ -350,7 +368,7 @@ public void TestMakeTransaction1() Value = new BigDecimal(BigInteger.One,8) } }); - tx.Should().NotBeNull(); + Assert.IsNotNull(tx); tx = wallet.MakeTransaction(snapshotCache, new TransferOutput[] { @@ -362,7 +380,7 @@ public void TestMakeTransaction1() Data = "Dec 12th" } }); - tx.Should().NotBeNull(); + Assert.IsNotNull(tx); entry1 = snapshotCache.GetAndChange(key, () => new StorageItem(new AccountState())); entry2 = snapshotCache.GetAndChange(key, () => new StorageItem(new AccountState())); @@ -376,7 +394,7 @@ public void TestMakeTransaction2() var snapshotCache = TestBlockchain.GetTestSnapshotCache(); MyWallet wallet = new(); Action action = () => wallet.MakeTransaction(snapshotCache, Array.Empty(), null, null, Array.Empty()); - action.Should().Throw(); + Assert.ThrowsException(action); Contract contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 }); WalletAccount account = wallet.CreateAccount(contract, glkey.PrivateKey); @@ -393,10 +411,10 @@ public void TestMakeTransaction2() Scopes = WitnessScope.CalledByEntry }}, Array.Empty()); - tx.Should().NotBeNull(); + Assert.IsNotNull(tx); tx = wallet.MakeTransaction(snapshotCache, Array.Empty(), null, null, Array.Empty()); - tx.Should().NotBeNull(); + Assert.IsNotNull(tx); entry = snapshotCache.GetAndChange(key, () => new StorageItem(new AccountState())); entry.GetInteroperable().Balance = 0; @@ -406,8 +424,14 @@ public void TestMakeTransaction2() public void TestVerifyPassword() { MyWallet wallet = new(); - Action action = () => wallet.VerifyPassword("Test"); - action.Should().NotThrow(); + try + { + wallet.VerifyPassword(null); + } + catch (Exception) + { + Assert.Fail(); + } } } } diff --git a/tests/Neo.UnitTests/Wallets/UT_WalletAccount.cs b/tests/Neo.UnitTests/Wallets/UT_WalletAccount.cs index 17070d3e0e..349845714f 100644 --- a/tests/Neo.UnitTests/Wallets/UT_WalletAccount.cs +++ b/tests/Neo.UnitTests/Wallets/UT_WalletAccount.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.SmartContract; using Neo.Wallets; @@ -44,16 +43,16 @@ public class UT_WalletAccount public void TestGetAddress() { MyWalletAccount walletAccount = new MyWalletAccount(UInt160.Zero); - walletAccount.Address.Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf"); + Assert.AreEqual("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf", walletAccount.Address); } [TestMethod] public void TestGetWatchOnly() { MyWalletAccount walletAccount = new MyWalletAccount(UInt160.Zero); - walletAccount.WatchOnly.Should().BeTrue(); + Assert.IsTrue(walletAccount.WatchOnly); walletAccount.Contract = new Contract(); - walletAccount.WatchOnly.Should().BeFalse(); + Assert.IsFalse(walletAccount.WatchOnly); } } } diff --git a/tests/Neo.UnitTests/Wallets/UT_Wallets_Helper.cs b/tests/Neo.UnitTests/Wallets/UT_Wallets_Helper.cs index c7e55917e0..5c25e549ba 100644 --- a/tests/Neo.UnitTests/Wallets/UT_Wallets_Helper.cs +++ b/tests/Neo.UnitTests/Wallets/UT_Wallets_Helper.cs @@ -9,7 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Cryptography; using Neo.Extensions; @@ -27,10 +26,10 @@ public void TestToScriptHash() { byte[] array = { 0x01 }; UInt160 scriptHash = new UInt160(Crypto.Hash160(array)); - "NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf".ToScriptHash(TestProtocolSettings.Default.AddressVersion).Should().Be(scriptHash); + Assert.AreEqual(scriptHash, "NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf".ToScriptHash(TestProtocolSettings.Default.AddressVersion)); Action action = () => "3vQB7B6MrGQZaxCuFg4oh".ToScriptHash(TestProtocolSettings.Default.AddressVersion); - action.Should().Throw(); + Assert.ThrowsException(action); var address = scriptHash.ToAddress(ProtocolSettings.Default.AddressVersion); Span data = stackalloc byte[21]; @@ -39,7 +38,7 @@ public void TestToScriptHash() scriptHash.ToArray().CopyTo(data[1..]); address = Base58.Base58CheckEncode(data); action = () => address.ToScriptHash(ProtocolSettings.Default.AddressVersion); - action.Should().Throw(); + Assert.ThrowsException(action); } } } From 2e1845709c7451e498ee380462bdab862a516145 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 30 Jan 2025 18:59:36 +0100 Subject: [PATCH 2/5] Update UT_OrderedDictionary.cs --- tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs b/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs index 457ff65155..d4ab7436b2 100644 --- a/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs +++ b/tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs @@ -28,6 +28,7 @@ public void SetUp() { "c", 3 } }; } + [TestMethod] public void TestClear() { From 5f569488398a242df96a984372042ba60156f2bb Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 30 Jan 2025 19:20:34 +0100 Subject: [PATCH 3/5] Removed dummy new code --- tests/Neo.UnitTests/UT_UInt160.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Neo.UnitTests/UT_UInt160.cs b/tests/Neo.UnitTests/UT_UInt160.cs index 6eb0326ef6..793681cd4b 100644 --- a/tests/Neo.UnitTests/UT_UInt160.cs +++ b/tests/Neo.UnitTests/UT_UInt160.cs @@ -85,9 +85,6 @@ public void TestParse() Assert.ThrowsException(action1); UInt160 result1 = UInt160.Parse("0000000000000000000000000000000000000000"); Assert.AreEqual(UInt160.Zero, result1); - - ushort b = 10; - var a = -b; } [TestMethod] From 8d297380a50b7f14a51ce853437b50c625d916c6 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 30 Jan 2025 19:22:10 +0100 Subject: [PATCH 4/5] Update tests/Neo.UnitTests/Wallets/UT_Wallet.cs --- tests/Neo.UnitTests/Wallets/UT_Wallet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.UnitTests/Wallets/UT_Wallet.cs b/tests/Neo.UnitTests/Wallets/UT_Wallet.cs index 139094d2c8..933f940e0e 100644 --- a/tests/Neo.UnitTests/Wallets/UT_Wallet.cs +++ b/tests/Neo.UnitTests/Wallets/UT_Wallet.cs @@ -426,7 +426,7 @@ public void TestVerifyPassword() MyWallet wallet = new(); try { - wallet.VerifyPassword(null); + wallet.VerifyPassword("Test"); } catch (Exception) { From 4b8aefd33c518ab277a22900a65b3fd5b024d34c Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 31 Jan 2025 10:17:16 +0800 Subject: [PATCH 5/5] add missing files back and apply shargon suggestion --- .../UT_RpcServer.Blockchain.cs | 24 ++----- .../Cryptography/UT_MerkleTreeNode.cs | 62 +++++++++++++++++++ .../Neo.UnitTests/Cryptography/UT_Murmur32.cs | 53 ++++++++++++++++ 3 files changed, 121 insertions(+), 18 deletions(-) diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs index 405d1ed312..95c18018f5 100644 --- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs +++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs @@ -161,25 +161,13 @@ public void TestGetContractState() snapshot.DeleteContract(contractState.Hash); snapshot.Commit(); - try - { - _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Hash)); - Assert.Fail("Expected RpcException was not thrown."); - } - catch (RpcException ex) - { - Assert.AreEqual(RpcError.UnknownContract.Message, ex.Message); - } + var ex1 = Assert.ThrowsException(() => + _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Hash))); + Assert.AreEqual(RpcError.UnknownContract.Message, ex1.Message); - try - { - _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Id)); - Assert.Fail("Expected RpcException was not thrown."); - } - catch (RpcException ex) - { - Assert.AreEqual(RpcError.UnknownContract.Message, ex.Message); - } + var ex2 = Assert.ThrowsException(() => + _rpcServer.GetContractState(new ContractNameOrHashOrId(contractState.Id))); + Assert.AreEqual(RpcError.UnknownContract.Message, ex2.Message); } [TestMethod] diff --git a/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs b/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs index e69de29bb2..97ebf0a35e 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs @@ -0,0 +1,62 @@ +// Copyright (C) 2015-2025 The Neo Project. +// +// UT_MerkleTreeNode.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.Cryptography; +using System.Text; + +namespace Neo.UnitTests.Cryptography +{ + [TestClass] + public class UT_MerkleTreeNode + { + private readonly MerkleTreeNode node = new MerkleTreeNode(); + + [TestInitialize] + public void TestSetup() + { + node.Hash = null; + node.Parent = null; + node.LeftChild = null; + node.RightChild = null; + } + + [TestMethod] + public void TestConstructor() + { + byte[] byteArray = Encoding.ASCII.GetBytes("hello world"); + var hash = new UInt256(Crypto.Hash256(byteArray)); + node.Hash = hash; + + Assert.AreEqual(hash, node.Hash); + Assert.IsNull(node.Parent); + Assert.IsNull(node.LeftChild); + Assert.IsNull(node.RightChild); + } + + [TestMethod] + public void TestGetIsLeaf() + { + Assert.IsTrue(node.IsLeaf); + + MerkleTreeNode child = new MerkleTreeNode(); + node.LeftChild = child; + Assert.IsFalse(node.IsLeaf); + } + + [TestMethod] + public void TestGetIsRoot() + { + Assert.IsTrue(node.IsRoot); + } + } +} diff --git a/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs b/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs index e69de29bb2..f2104c4b6f 100644 --- a/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs +++ b/tests/Neo.UnitTests/Cryptography/UT_Murmur32.cs @@ -0,0 +1,53 @@ +// Copyright (C) 2015-2025 The Neo Project. +// +// UT_Murmur32.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.Cryptography; +using System.Buffers.Binary; + +namespace Neo.UnitTests.Cryptography +{ + [TestClass] + public class UT_Murmur32 + { + [TestMethod] + public void TestGetHashSize() + { + Assert.AreEqual(32, Murmur32.HashSizeInBits); + } + + [TestMethod] + public void TestHashToUInt32() + { + byte[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }; + Assert.AreEqual(378574820u, array.Murmur32(10u)); + } + + [TestMethod] + public void TestComputeHash() + { + var murmur3 = new Murmur32(10u); + var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }; + var buffer = murmur3.ComputeHash(data); + var hash = BinaryPrimitives.ReadUInt32LittleEndian(buffer); + Assert.AreEqual(378574820u, hash); + } + + [TestMethod] + public void TestComputeHashUInt32() + { + var murmur3 = new Murmur32(10u); + var hash = murmur3.ComputeHashUInt32("hello worldhello world"u8.ToArray()); + Assert.AreEqual(60539726u, hash); + } + } +}