diff --git a/BasicBlockChain.Core.Tests/BasicBlockChain.Core.Tests.csproj b/BasicBlockChain.Core.Tests/BasicBlockChain.Core.Tests.csproj new file mode 100644 index 0000000..a776eee --- /dev/null +++ b/BasicBlockChain.Core.Tests/BasicBlockChain.Core.Tests.csproj @@ -0,0 +1,106 @@ + + + + + Debug + AnyCPU + {F3B0EB12-6F98-4AFE-8405-BD687A04E8D0} + Library + Properties + BasicBlockChain.Core.Tests + BasicBlockChain.Core.Tests + v4.8 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + + + + + + {919BC116-C8FC-4B65-B742-226B38437C48} + BasicBlockChain.Core + + + + + + + False + + + False + + + False + + + False + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/BasicBlockChain.Core.Tests/BlockChain_Tests.cs b/BasicBlockChain.Core.Tests/BlockChain_Tests.cs new file mode 100644 index 0000000..f168ff8 --- /dev/null +++ b/BasicBlockChain.Core.Tests/BlockChain_Tests.cs @@ -0,0 +1,79 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace BasicBlockChain.Core.Tests +{ + [TestClass()] + public class BlockChain_Tests + { + #region Test Data + + private BlockChain GenerateTestData() + { + BlockChain nullCoin = new BlockChain(genesisDate: new DateTime(2000, 1, 1), difficulty: 2); + nullCoin.AddTransaction(new Transaction("VAR", "NAM", 10_000_000, new DateTime(2000, 1, 2))); + nullCoin.ProcessPendingTransactions(new DateTime(2000, 1, 2), "Kable"); + nullCoin.AddTransaction(new Transaction("NAM", "VAR", 5_000_000, new DateTime(2000, 1, 3))); + nullCoin.ProcessPendingTransactions(new DateTime(2000, 1, 3), "Kable"); + nullCoin.AddTransaction(new Transaction("NAM", "VAR", 5_000_000, new DateTime(2000, 1, 4))); + nullCoin.ProcessPendingTransactions(new DateTime(2000, 1, 4), "Kable"); + return nullCoin; + } + + #endregion Test Data + + #region Verify + + [TestMethod()] + public void Verify__Null() + { + BlockChain nullCoin = new BlockChain(); + + bool result = nullCoin.Verify(); + + Assert.AreEqual(true, result); + } + + [TestMethod()] + public void Verify__Valid() + { + BlockChain nullCoin = GenerateTestData(); + + bool result = nullCoin.Verify(); + + Assert.AreEqual(true, result); + } + + [TestMethod()] + public void Verify__Tampered() + { + BlockChain nullCoin = GenerateTestData(); + nullCoin.Chain[1].Transactions[0].MicroCoinAmount = 1000_000_000; + + bool result = nullCoin.Verify(); + + Assert.AreEqual(false, result); + } + + #endregion Verify + + #region GetMicroCoinBalance + + [TestMethod()] + public void GetMicroCoinBalance__Test() + { + BlockChain nullCoin = GenerateTestData(); + + long balanceVAR = nullCoin.GetMicroCoinBalance("VAR"); + long balanceNAM = nullCoin.GetMicroCoinBalance("NAM"); + long balanceKable = nullCoin.GetMicroCoinBalance("Kable"); + long expectedBlananceKable = nullCoin.Reward * 3; + + Assert.AreEqual(0, balanceVAR); + Assert.AreEqual(0, balanceNAM); + Assert.AreEqual(expectedBlananceKable, balanceKable); + } + + #endregion GetMicroCoinBalance + } +} \ No newline at end of file diff --git a/BasicBlockChain.Core.Tests/Properties/AssemblyInfo.cs b/BasicBlockChain.Core.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..881e6bc --- /dev/null +++ b/BasicBlockChain.Core.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("BasicBlockChain.Core.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BasicBlockChain.Core.Tests")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f3b0eb12-6f98-4afe-8405-bd687a04e8d0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BasicBlockChain.Core.Tests/packages.config b/BasicBlockChain.Core.Tests/packages.config new file mode 100644 index 0000000..fcf029f --- /dev/null +++ b/BasicBlockChain.Core.Tests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/BasicBlockChain.sln b/BasicBlockChain.sln index 87164b6..8841690 100644 --- a/BasicBlockChain.sln +++ b/BasicBlockChain.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicBlockChain", "BasicBlo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicBlockChain.Core", "BasicBlockChain.Core\BasicBlockChain.Core.csproj", "{919BC116-C8FC-4B65-B742-226B38437C48}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicBlockChain.Core.Tests", "BasicBlockChain.Core.Tests\BasicBlockChain.Core.Tests.csproj", "{F3B0EB12-6F98-4AFE-8405-BD687A04E8D0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {919BC116-C8FC-4B65-B742-226B38437C48}.Debug|Any CPU.Build.0 = Debug|Any CPU {919BC116-C8FC-4B65-B742-226B38437C48}.Release|Any CPU.ActiveCfg = Release|Any CPU {919BC116-C8FC-4B65-B742-226B38437C48}.Release|Any CPU.Build.0 = Release|Any CPU + {F3B0EB12-6F98-4AFE-8405-BD687A04E8D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3B0EB12-6F98-4AFE-8405-BD687A04E8D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3B0EB12-6F98-4AFE-8405-BD687A04E8D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3B0EB12-6F98-4AFE-8405-BD687A04E8D0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE