public void TestEncryptBlock()
        {
            BlockBase b = new BlockBase(1);

            String result = e.Encrypt(b);

            Assert.AreEqual("f6aefbd1d0e4fe63ce121c227ef6d80344763428", result);
        }
        public void Mine(BlockData b, int starting = 0, int ending = 1000000)
        {
            EncryptionBlock e = new EncryptionBlock();

            for (int i = starting; i <= 1000000; i++)
            {
                //Set the nonce on the block:
                b.SetNonce(i);

                //hash the block:
                String hash = e.Encrypt(b);

                // if hash found:
                if (CompareHashAgainstDifficulty(hash))
                {
                    //attach the previous blocks to this block:
                    b.SetPreviousBlock(Blockchain);

                    //set this block as the current blockchain:
                    Blockchain = b;

                    //return something:
                    return;
                }
            }

            // no result found:
            throw new Exception("No result found between [" + starting + "]-[" + ending + "] with a difficulty of [ unknown ]");
        }
Exemplo n.º 3
0
        public void TestMinerBaseDifficulty()
        {
            mb.SetDifficulty(2);

            mb.Mine(b1);

            int nonce = mb.GetBlockchain().GetNonce();

            Assert.AreEqual(690, nonce);

            // Let's see the Hash:
            EncryptionBlock e    = new EncryptionBlock();
            String          hash = e.Encrypt(b1);
            //Assert.AreEqual("0086f15ccc3f3164004aeff5792c3e054d746d5a", hash);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Return the hashed value or compute hash if not set.
        /// Hash is saved to prevent StackOverflow when converting the object ToString()
        /// </summary>
        /// <returns>Computed Hash</returns>
        public String GetHash()
        {
            //prevents overflow?
            //if (Hash != null)
            //    return Hash;

            //calculate previous block if not null (loop):
            if (PreviousBlock != null)
            {
                PreviousBlock.GetHash();
            }

            EncryptionBlock e = new EncryptionBlock();

            Hash = e.Encrypt(this);

            return(Hash);
        }
Exemplo n.º 5
0
        public void TestMinerBlockBaseMine()
        {
            mb.SetDifficulty(1);

            mb.Mine(b1);

            int nonce = mb.GetBlockchain().GetNonce();

            // Assert the nonce:
            Assert.AreEqual(2, nonce);

            // Is the nonce set on the block?
            Assert.AreEqual(b1.GetNonce(), nonce);

            // Check the hash's starting 0:
            EncryptionBlock e    = new EncryptionBlock();
            String          hash = e.Encrypt(b1);
            //Assert.AreEqual("06c24c8fe5e39f038a3570e562fc279e37af97d3", hash);
        }
Exemplo n.º 6
0
        public void TestBaseBlockBlockChainHash()
        {
            Assert.AreEqual(b2Hash, e.Encrypt(b2));

            Assert.AreEqual(b2Hash, b2.GetHash());
        }