Example #1
0
        public void MiningBenchmark()
        {
            var       controller = new ChainAuthority();
            var       id         = Guid.NewGuid();
            const int mineAmount = 10;

            TimeSpan span;
            var      watch = new Stopwatch();

            for (var i = 0; i < mineAmount; i++)
            {
                watch.Start();
                controller.Mine(id.ToString());
                watch.Stop();
                span += watch.Elapsed;

                watch.Reset();
            }

            span /= mineAmount;

            var average = span.TotalSeconds;

            Console.WriteLine($"Average mining time is {average} seconds for {mineAmount} mined blocks.");
        }
Example #2
0
        public void CanMine()
        {
            var controller = new ChainAuthority();

            var id = Guid.NewGuid();

            controller.Mine(id.ToString());

            var chain = controller.GetFullChain();

            Assert.AreEqual(chain.Length, 2);
        }
        public void CanAddTransaction()
        {
            var controller = new ChainAuthority();

            var index = controller.CreateTransaction("ABC", "DEF", 1500432);

            var id = Guid.NewGuid();

            controller.Mine(id.ToString());

            var transaction = controller.GetFullChain()[index].Transactions
                              .FirstOrDefault(d => d.Sender == "ABC" && d.Recipient == "DEF" && d.Amount == 1500432);

            Assert.IsNotNull(transaction);
        }
Example #4
0
        public void CanSend()
        {
            var       id     = Guid.NewGuid();
            const int amount = 3;

            var controller = new ChainAuthority();

            for (var i = 0; i < amount; i++)
            {
                controller.Mine(id.ToString());
            }

            var canSend = controller.CanSend(id.ToString(), 2);

            Assert.IsTrue(canSend);
        }
Example #5
0
        public void CanGetBalance()
        {
            var       id     = Guid.NewGuid();
            const int amount = 3;

            var controller = new ChainAuthority();

            for (var i = 0; i < amount; i++)
            {
                controller.Mine(id.ToString());
            }

            var balance = controller.GetBalance(id.ToString());

            Assert.AreEqual(Convert.ToDecimal(amount), balance);
        }