Checkpoints valudation, PoW reward calculation and continue working on block index.
[NovacoinLibrary.git] / NovacoinTest / Program.cs
index 9dbb5c5..43a5ed8 100644 (file)
@@ -12,6 +12,7 @@ namespace NovacoinTest
     {
         static void Main(string[] args)
         {
+#if false
             /// Transaction decoding/encoding tests
             string strUserTx = "0100000078b4c95306340d96b77ec4ee9d42b31cadc2fab911e48d48c36274d516f226d5e85bbc512c010000006b483045022100c8df1fc17b6ea1355a39b92146ec67b3b53565e636e028010d3a8a87f6f805f202203888b9b74df03c3960773f2a81b2dfd1efb08bb036a8f3600bd24d5ed694cd5a0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4cffffffff364c640420de8fa77313475970bf09ce4d0b1f8eabb8f1d6ea49d90c85b202ee010000006b483045022100b651bf3a6835d714d2c990c742136d769258d0170c9aac24803b986050a8655b0220623651077ff14b0a9d61e30e30f2c15352f70491096f0ec655ae1c79a44e53aa0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4cffffffff7adbd5f2e521f567bfea2cb63e65d55e66c83563fe253464b75184a5e462043d000000006a4730440220183609f2b995993acc9df241aff722d48b9a731b0cd376212934565723ed81f00220737e7ce75ef39bdc061d0dcdba3ee24e43b899696a7c96803cee0a79e1f78ecb0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4cffffffff999eb03e00a41c2f9fde8865a554ceebbc48d30f4c8ba22dd88da8c9b46fa920030000006b483045022100ec1ab104ef086ba79b0f2611ebf1bfdd22a7a1020f6630fa1c6707546626e0db022056093d4048a999392185ccc735ef736a5497bd68f60b42e6c0c93ba770b54d010121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4cffffffffc0543b86be257ddd85b014a76718a70fab9eaa3c477460e4ca187094d86f369c0500000069463043021f24275c72f952043174daf01d7f713f878625f0522124a3cab48a0a2e12604202201b47742e6697b0ebdd1e4ba49c74baf142a0228ad0e0ee847488994c9dce78470121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4cffffffffe1793d4519147782293dd1db6d90e461265d91db2cc6889c37209394d42ad10d050000006a473044022018a0c3d73b2765d75380614ab36ee8e3c937080894a19166128b1e3357b208fb0220233c9609985f535547381431526867ad0255ec4969afe5c360544992ed6b3ed60121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4cffffffff02e5420000000000001976a91457d84c814b14bd86bf32f106b733baa693db7dc788ac409c0000000000001976a91408c8768d5d6bf7c1d9609da4e766c3f1752247b188ac00000000";
 
@@ -20,19 +21,19 @@ namespace NovacoinTest
             var tx = new CTransaction(Interop.HexToArray(strUserTx));
             var txCoinbase = new CTransaction(Interop.HexToArray(strCoinbaseTx));
 
-            Console.WriteLine("User TX:{0}\n", tx.ToString());
-            Console.WriteLine("Coinbase TX: {0}\n", txCoinbase.ToString());
+            Console.WriteLine("User TX:{0}\n", tx);
+            Console.WriteLine("Coinbase TX: {0}\n", txCoinbase);
 
             /// Block encoding/decoding tests
             string strBlock1 = "0600000086e539d77573abc0d81feb7896e1aef41a866001bc78bd24f5fe1a0000000000f5822cea59d999f37d896f66899c86e01e764ed6014706f3ceb58281ed55d0e55ab7d155ada3001d0000000005010000005ab7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0363ff02026d05062f503253482fffffffff0100000000000000000000000000010000005ab7d15501a768f8ed022f4080e3c8866bbe8292c7610b826cd467c49a06a1d0ff2ef7cdd6000000006b483045022100dce689d8cda64ebaffd6b96321952f16df34494256c58d2fd83069db7bce40e5022016020f55dc747d845d2057547c650412aa27d7d628e72238579f72e572dafdfe012102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ffffffff03000000000000000000d0f1440300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093acc23f450300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ac000000000100000091b4d15502c252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d010000004847304402204bee0faac004364cdf6483d492333d00ad6f7c925faa3750fef2c79a9065a28102204a5e2b970f776ea1af2c2c03e36e6381d3d69b529d90b512363ae44815a321c601ffffffffc252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d02000000494830450221008bf152a838f6f14f0ed1b2afc27821717e43a528e27aec3569ab42fc82f468aa02202cf6c962ef97db6e5ba32ccdd235afdc9a3cbb7907bfe879f8109446485d66dc01ffffffff0116467210000000001976a914edbf189bece45d4afa9848276e949183936bf6a488ac000000000100000017b5d1550229c74fb0004d45fba5baaefed1d9c229a8f1c85c36590cedf3ce6635335963d5000000006a4730440220319a4dfcf1607682d493c6d90087dc35d778a8bfcebe3549bae0af69e8daecb902206e6622367be30d9ccd4fdd27ed09c2fbcc9e5c858b26dfcdd927a8aba637b327012103b103f5d7e9717bc37cc99984b23babc3fff4677728be6b9c1847f6ce78e557f5ffffffff24b91fa6e9c160cc8da306e485942ee76137117aa8adecf531f6af1aef4e9b680000000049483045022100c9b311b7a7f5adeb0e72f962fb81b4cc1d105e32cfd7b1a7641a0fcc014d67c50220527161371a17301448bae87a26df201598b46d00ff452893177e9aed665c357c01ffffffff028e380000000000001976a91400afc350f81916a642a88b5ce8f73508663b531188ac67f46b00000000001976a91420c10f267f55ff4e05a083a8e1f4e882fbca1f4988ac0000000001000000efb6d15501626835db281e1fe6271620b8f67999f2174bb96df0eb3935fc99771e4ff45acf000000006a47304402206c34deb9c07c5477c47d398eaf91dbdf74aff5229c448e82ed0c1d8e2ee30e2d02203fe609434844b3eee21e747e313bcbf98efa4326727db6d2efba7bb627d2e0ce0121030c86c72f59c66824297aa78e433fe7057fd064e03e44c62ec49201ee0184149bffffffff028be30300000000001976a91481fc5cfb7f41afb3baf4138626022b3081b84e1788ac6abd0000000000001976a91499346dcd8ddfa10326697d5387b7df765004f4e388ac0000000046304402205189911c97354edb2965b4a119e6d76281f4c5da8fcead19c97bf6bcc9990fe102200f56d9dd967b036627b32b1e3ef2f819deaaafcc3244332472df7acfe19f1aa5";
             var b1 = new CBlock(Interop.HexToArray(strBlock1));
 
-            string strBlock1Bytes = Interop.ToHex(b1.Bytes);
+            string strBlock1Bytes = Interop.ToHex(b1);
 
             string strBlock2 = "06000000eb5ab262c7382e7e009ad0b65c707131b8b6b846f8920a1a6697d929203a22f70e8cbd6bee1c0519a9d06b749b5eb6e599c154b12b732170807e603b6c326abbe0b7d15560e2211b15085b8f0101000000e0b7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff270364ff02062f503253482f04c7b7d15508300000032b0000000d2f6e6f64655374726174756d2f0000000002f87d6b000000000023210287753c456abfc248d1bd155f44742d2ea72a2f29a5290c815fea0e9c55c4e2d0ac488a0000000000001976a914276cdbe21aaab75d58e151e01efea2860d3ef3d088ac0000000000";
             var b2 = new CBlock(Interop.HexToArray(strBlock2));
 
-            string strBlock2Bytes = Interop.ToHex(b2.Bytes);
+            string strBlock2Bytes = Interop.ToHex(b2);
 
             Console.WriteLine(b1.ToString());
             Console.WriteLine("OK: {0}\n", strBlock1 == strBlock1Bytes);
@@ -43,7 +44,7 @@ namespace NovacoinTest
             /// ECDSA keypair generation test
 
             var keyPair1 = new CKeyPair();
-            var keyPair2 = new CKeyPair(keyPair1.SecretBytes);
+            var keyPair2 = new CKeyPair((byte[])keyPair1);
             var pubKey = keyPair2.PubKey;
 
             string strPrivKeyBase58 = keyPair1.ToString();
@@ -62,24 +63,24 @@ namespace NovacoinTest
             /// Address generation test
 
             var keyID = keyPair1.KeyID;
-            Console.WriteLine("Key ID: {0}", Interop.ToHex(keyID.hashBytes));
-            Console.WriteLine("Novacoin address: {0}\n", keyID.ToString());
+            Console.WriteLine("Key ID: {0}", Interop.ToHex(keyID));
+            Console.WriteLine("Novacoin address: {0}\n", keyID);
 
             /// Privkey deserialization test
             var keyPair4 = new CKeyPair("MEP3qCtFGmWo3Gurf8fMnUNaDHGNf637DqjoeG8rKium2jSj51sf");
             Console.WriteLine("\nHard-coded privkey in Hex: {0}", keyPair4.ToHex());
-            Console.WriteLine("Hard-Coded privkey address: {0}", keyPair4.KeyID.ToString());
+            Console.WriteLine("Hard-Coded privkey address: {0}", keyPair4.KeyID);
             Console.WriteLine("Hard-Coded privkey: {0}\n", keyPair4.ToString());
 
             // Privkey hex deserialization test
-            CKeyPair keyPair5 = new CKeyPair(keyPair4.SecretBytes.ToArray());
+            CKeyPair keyPair5 = new CKeyPair((byte[])keyPair4);
             Console.WriteLine("Decoded privkey in Hex: {0}", keyPair5.ToHex());
-            Console.WriteLine("Decoded privkey address: {0}\n", keyPair5.KeyID.ToString());
+            Console.WriteLine("Decoded privkey address: {0}\n", keyPair5.KeyID);
 
             /// ECDSA keypair signing test
 
             var data = "Превед!";
-            var sigHash =  Hash256.Compute256(Encoding.UTF8.GetBytes(data));
+            uint256 sigHash = CryptoUtils.ComputeHash256(Encoding.UTF8.GetBytes(data));
             var signature = keyPair1.Sign(sigHash);
 
             Console.WriteLine("Signature: {0}", Interop.ToHex(signature));
@@ -101,10 +102,10 @@ namespace NovacoinTest
             Console.WriteLine("Address reserialization is OK: {0}", donationAddress.ToString() == pubKeyTest.KeyID.ToString());
 
             /// Block header hashing test
-            var dataBytesForScrypt = b1.header.Bytes;
-            var scryptHash = ScryptHash256.Compute256(dataBytesForScrypt);
+            byte[] dataBytesForScrypt = b1.header;
+            uint256 scryptHash = CryptoUtils.ComputeScryptHash256(dataBytesForScrypt);
 
-            Console.WriteLine("\nblock1 header hash: {0}", scryptHash.ToString());
+            Console.WriteLine("\nblock1 header hash: {0}", scryptHash);
 
             /// Solver tests
             var scriptPubKey = new CScript(Interop.HexToArray("21021ad6ae76a602310e86957d4ca752c81a8725f142fd2fc40f6a7fc2310bb2c749ac"));
@@ -117,27 +118,27 @@ namespace NovacoinTest
             Console.WriteLine("scriptPubKey address: {0}\n", new CPubKey(solutions.First()).KeyID.ToString());
 
             Console.WriteLine("scriptPubKeyHash solved: {0}", ScriptCode.Solver(scriptPubKeyHash, out typeRet, out solutions));
-            Console.WriteLine("scriptPubKeyHash address: {0}\n", new CKeyID(new Hash160(solutions.First())).ToString());
+            Console.WriteLine("scriptPubKeyHash address: {0}\n", new CKeyID(solutions.First()).ToString());
 
             /// Some SetDestination tests
             var scriptDestinationTest = new CScript();
 
-            
-            Console.WriteLine("Creating and decoding new destination with {0} as public key.\n", keyPair1.PubKey.ToString());
+
+            Console.WriteLine("Creating and decoding new destination with {0} as public key.\n", keyPair1.PubKey);
 
             Console.WriteLine("Pay-to-Pubkey:");
 
             scriptDestinationTest.SetDestination(keyPair1.PubKey);
 
             Console.WriteLine("\tscriptDestinationTest solved: {0}", ScriptCode.Solver(scriptDestinationTest, out typeRet, out solutions));
-            Console.WriteLine("\tscriptDestinationTest address: {0}\n", new CPubKey(solutions.First()).KeyID.ToString());
+            Console.WriteLine("\tscriptDestinationTest address: {0}\n", new CPubKey(solutions.First()).KeyID);
 
             Console.WriteLine("Pay-to-PubkeyHash:");
 
             scriptDestinationTest.SetDestination(keyPair1.PubKey.KeyID);
 
             Console.WriteLine("\tscriptDestinationTest solved: {0}", ScriptCode.Solver(scriptDestinationTest, out typeRet, out solutions));
-            Console.WriteLine("\tscriptDestinationTest address: {0}\n", new CKeyID(new Hash160(solutions.First())).ToString());
+            Console.WriteLine("\tscriptDestinationTest address: {0}\n", new CKeyID(solutions.First()));
 
             Console.WriteLine("Multisig with three random keys:");
 
@@ -153,12 +154,12 @@ namespace NovacoinTest
 
             foreach (var keyBytes in solutions.Skip(1).Take(nKeys))
             {
-                Console.WriteLine("\t{0}", (new CPubKey(keyBytes)).KeyID.ToString());
+                Console.WriteLine("\t{0}", (new CPubKey(keyBytes)).KeyID);
             }
 
             Console.WriteLine("\nnRequired={0}\n", nRequired);
 
-            Console.WriteLine("Script code: \n\n{0}", scriptDestinationTest.ToString());
+            Console.WriteLine("Script code: \n\n{0}", scriptDestinationTest);
 
             Console.WriteLine("\nPay-to-ScriptHash with same script:\n");
 
@@ -166,20 +167,20 @@ namespace NovacoinTest
             scriptP2SHTest.SetDestination(scriptDestinationTest.ScriptID);
 
             Console.WriteLine("\tscriptP2SHTest solved: {0}", ScriptCode.Solver(scriptP2SHTest, out typeRet, out solutions));
-            Console.WriteLine("\tscriptP2SHTest address: {0}\n", new CScriptID(new Hash160(solutions.First())).ToString());
+            Console.WriteLine("\tscriptP2SHTest address: {0}\n", new CScriptID(solutions.First()));
 
             // SignatureHash tests
             var txS = new CTransaction(Interop.HexToArray("01000000ccfe9e550d083902781746c80954e3af56e930235befb798f987667021a2f32dc0099499cd010000006b483045022100b5f6783af4f7f60866c889fd668c93ee110ecc3751208fe0b49cc7ace47e52e8022075652e1e960a50b27436ab04f2728b3bba09d07a858691559d99c1ac5dd74f16012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff2c6009a7494f38f7797bb9ef2aeafb093ae433208171a504367373df4164399d010000004847304402205f1b74bbc37219918f3de13ff645ecc7093512fecda4fcbcac2174c44144361102202149f1adcfcd473ec8a662b5b166b600208d92596e30b33fb402b4720bac3da101ffffffffbf1dd11394d2c0d3cbd4e0b56c74e7463ed5a19f22fe219ee700c61f834b3948010000006a473044022004824a9e071c40707e5309e510fd2cc105fd430504ceefce48aeed1c8fcf3bd7022023f4a43c58e4012284d8df25b55940199d19d4ca664053e2d5c1cc93ef441c3c012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffffea06d18d8034a3645a8d5da75ed5c5f68a9dd09a798a876bef5d2cc9db8819390100000048473044022018e016973d87a53d6f14ae9929aa3c426d3d3a76eb81b3f1e996f0ec24ebacb302203668f165e6e9d5818eb3d108d23e2390213a6921ddfd51dbfca4ffebad73029601ffffffff5bda9a2a98debbda4ddad400a340190fcba4f4b3268f0a9d88eb5541bd7dadfc0100000049483045022100c4d210a6cd3edc6bc9cbfee1a8506ff239ef60baf7ebd46ffefb43e20a575d6c022019ea10cf480dadbb6332a03a404a3991437ffc9fef044c07112e2d15f3de74de01ffffffff5bda9a2a98debbda4ddad400a340190fcba4f4b3268f0a9d88eb5541bd7dadfc020000004948304502210084f5781ff88c201caca29b724f89fad5d72320a578239a3a2834ba669ea92b7e02207651ef9f7c60c2cc4fe187c98587252f3196fb1c31ed8f6c1f1f41e9a90d75ff01ffffffff61a9d75745092786bcbd48cc5860845beea607b8994790e9734f9fa68951bb66010000006b483045022100d2d3f925472970b9a0d365a120a9a6c9b7b0b3b3aacedaa40532397c6252da2f02206939d3cade4bada339799a4d651a7a33cb381640f6acef5fbecbe55ae1fa2364012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff635c711ba32bd587d349521475d2bd133a402c178543183c027cc1414a7837500100000049483045022100aece1ca9d902eaece08ec9704005196046f3a0b6f561cd17e9b09c01fed1447602207e68e21be4fcb895f045337741b42f43d218bb5c681f8e2eac5f9f3ffc8caf8301ffffffff7ddd7385fd7b81f19ccaa6ccd629bd2ab2a0af7ca69831c6dbb3b02c31de95db0100000049483045022100b260f2065dea407006e424d3cbb20009c807f422cee4ac8fb3553e4a81d62a7702204c67c99e792542cfe19a6956b101b4fd754a01fb1538b54e5f2141210729f09b01ffffffff8faebe377bc4211e41bd7e4a551e1de530040f8a55797f82e12d4d3c6a0b9fff010000004847304402204637911286c073fa0a8211e8427a6c63201bdac73e7b2760d3d9c7d748c9267c02205df709fdd06e3fb600ab81a17a1becc829769f1cb117b1520755d4f2a38429f001fffffffff1be969005bfcab4bcdaf835470680e2a309290b97d79fe63f7cbe904560b2d601000000484730440220352ad1a1ea5d92ddc13b7507a05180574c7309822f684ecf7321b7e925e5104302201e6a06e2f2d05a3d665cc6180fafacb658514a2f1bb632de99e88e4c26149e2501fffffffffa2019204a766fb4614be3d12bfb1ab35ad756e144193249e83660ca78898b3b0200000048473044022024f21eaf955291a9aec2cd45f42add62d8a30626aa9246664226fb3b56bf632f02205a3b46ec2857fec2fcb73663a57f99e4fcda328e8f1283198e8e9c5b4a2a3e0f01ffffffffd25e023fbdcd571ae346bf7aa142f5e32ca1aec23adae314ee209af22572cf1f000000006a4730440220551627592cbb7d970222a4d57a32aed50f1e93e81ae69958f26e56ca3b561715022019b12e560ff31013d0941ca2100ecdf9a3c3602b5c76b83d3b3c87d723d32ce3012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff02402d0000000000001976a91479f1d300be0da277e7ae217e99c6cc8a4f8717fe88ac00943577000000001976a914cbc5a055ae068d34b4a93e4c9adb9cb10262ae4f88ac00000000"));
 
-            Hash256 sigHashAll = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_ALL);
-            Hash256 sigHashNone = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_NONE);
-            Hash256 sigHashSingle = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_SINGLE);
-            Hash256 sigHashAnyone = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_ANYONECANPAY);
+            uint256 sigHashAll = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_ALL);
+            uint256 sigHashNone = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_NONE);
+            uint256 sigHashSingle = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_SINGLE);
+            uint256 sigHashAnyone = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_ANYONECANPAY);
 
-            Console.WriteLine("sigHashAll={0}", sigHashAll.ToString());
-            Console.WriteLine("sigHashNone={0}", sigHashNone.ToString());
-            Console.WriteLine("sigHashSingle={0}", sigHashSingle.ToString());
-            Console.WriteLine("sigHashAnyone={0}\n", sigHashAnyone.ToString());
+            Console.WriteLine("sigHashAll={0}", sigHashAll);
+            Console.WriteLine("sigHashNone={0}", sigHashNone);
+            Console.WriteLine("sigHashSingle={0}", sigHashSingle);
+            Console.WriteLine("sigHashAnyone={0}\n", sigHashAnyone);
 
             // Testing some opcode functionality
 
@@ -207,8 +208,6 @@ namespace NovacoinTest
 
             Console.WriteLine("--- Pay-to-ScriptHash test ---");
 
-            // TODO: this test doesn't pass correctly, something wrong here.
-
             var txFrom = new CTransaction(Interop.HexToArray("010000009c2011520173dc34b7fba54bcc9bd6e08e5b112fa69320879b7e43cb4f4f1992a14571a43c140000006a473044022031966a63cbf90d4f8aea72c14a4d6762446b4985963f537ca5c3ddf5a110a7d702205e49f2fee16a4cf8da1ab26ddd819fb127d00b63409878a989b3b86d41d88e250121023842ed96bb829f62559dca2c94fbd146e76597695f3f967cb789216c7fa5adc3ffffffff02ec36f910000000001976a9140fa4d848a8faa1097a3f186ce5edcaed5ee260ee88ac20a107000000000017a91482cc61dbc6840b36e8ed42c6e9c16425a3bad3508700000000"));
             var txToP2SH = new CTransaction(Interop.HexToArray("010000004c23115201d33e0feda63734135abcae51dd91a7d905b335ba0da1ac02cc02680c2d33096501000000dc00493046022100d449e5c7bd81db06f47546538b18d92092b0cb0210f549022db3880d569ab34202210083f7f93ed9f30c44bfb19541c4cccfb54e1c7004611417f9cb785e0def1a6ff90148304502207c44b870abfb35f58cbe48283010417d009101100bd18ba491b9c9783b822eb40221009aa4d966b7ef6dec66cc56f53fc352b087761bd1807b05c01897a74697cb31f9014752210205be3a707f5ff2a547a00466b729454ef052c3e83029f21f39d1052e1441ac74210373c1aee17cfd9fda5df7179a105236c18ab79fab8050ebc312fc95d580c209d452aeffffffff01107a0700000000001976a91420d9eab07eb7d1a0b610166009194a8d3d6eb2fd88ac00000000"));
 
@@ -230,15 +229,14 @@ namespace NovacoinTest
             elapsedMs = watch.ElapsedMilliseconds;
             Console.WriteLine("Unserialization time: {0} ms\n", elapsedMs);
 
+            uint256 merkleroot = null;
 
-            Hash256 merkleroot = null;
-
-            Console.WriteLine("\nRinning 1000 iterations of merkle tree computation for very big block...");
+            Console.WriteLine("\nRinning 100 iterations of merkle tree computation for very big block...");
 
             watch = Stopwatch.StartNew();
             // the code that you want to measure comes here
 
-            for (int i = 0; i < 1000; i++)
+            for (int i = 0; i < 100; i++)
             {
                 merkleroot = veryBigBlock.hashMerkleRoot;
             }
@@ -246,8 +244,82 @@ namespace NovacoinTest
             watch.Stop();
             elapsedMs = watch.ElapsedMilliseconds;
             Console.WriteLine("Calculation time: {0} ms\n", elapsedMs);
-            Console.WriteLine("Merkle tree is OK: {0}", merkleroot.hashBytes.SequenceEqual(veryBigBlock.header.merkleRoot.hashBytes));
+            Console.WriteLine("Merkle tree is OK: {0}", ((byte[])merkleroot).SequenceEqual((byte[])veryBigBlock.header.merkleRoot));
+
+            // Initialization of key store
+
+            Console.WriteLine("Initialization of key store...");
+            watch = Stopwatch.StartNew();
+            var keyStore = new CKeyStore();
+
+            Console.WriteLine("Initialization done in {0} ms, adding and querying new key pair.", watch.ElapsedMilliseconds);
+            var kp1 = new CKeyPair();
+            keyStore.AddKey(kp1);
+
+            CKeyPair kp2;
+            var queryRes = keyStore.GetKey(kp1.KeyID, out kp2);
+            Console.WriteLine("KeyID={0} exists in database: {1}", kp1.KeyID, queryRes);
+
+            if (queryRes)
+            {
+                Console.WriteLine("KeyID={0} is identical to inserted one: {1}", kp2.KeyID, kp2.KeyID.ToString() == kp1.KeyID.ToString());
+            }
+
+            watch = Stopwatch.StartNew();
+            Console.WriteLine("Resetting key store...");
+            keyStore.ResetPool();
+            Console.WriteLine("Done in {0} ms.", watch.ElapsedMilliseconds);
 
+            /* uint256 tests */
+            var test1 = new uint256("0000000000021173331e7742b51afe6c853158a8881f7ad871f4391a7ddcfa4e");
+            var test2 = new uint256("0000000000093bf84cea580ede01206c3ffc75487ec46771e533e38d9bda972d");
+
+            Console.WriteLine(test1 < test2);
+            Console.WriteLine(test1 > test2);
+            Console.WriteLine(test1 == test2);
+            Console.WriteLine(test1 != test2);
+
+            Console.WriteLine(test1 - 1);
+            Console.WriteLine(test1 + 1);
+
+            Console.WriteLine(test1 << 32);
+            Console.WriteLine(test1 >> 32);
+
+            /*
+            Output:
+
+            True
+            False
+            False
+            True
+            0000000000021173331e7742b51afe6c853158a8881f7ad871f4391a7ddcfa4d
+            0000000000021173331e7742b51afe6c853158a8881f7ad871f4391a7ddcfa4f
+            00021173331e7742b51afe6c853158a8881f7ad871f4391a7ddcfa4e00000000
+            000000000000000000021173331e7742b51afe6c853158a8881f7ad871f4391a
+            */
+
+            var target = new uint256("0000000000138d5e000000000000000000000000000000000000000000000000");
+            uint compact = target.Compact;
+
+            Console.WriteLine(Interop.ToHex(Interop.ReverseBytes(BitConverter.GetBytes(compact))));
+
+            var target1 = new uint256();
+            target1.Compact = 0x1b136944;
+
+            Console.WriteLine(target1);
+
+            /*
+            Output:
+
+            1b138d5e
+            0000000000136944000000000000000000000000000000000000000000000000
+            */
+#endif
+
+            Console.WriteLine("Reading the block file...");
+            var bs = new CBlockStore();
+            bs.ParseBlockFile();
+            
             Console.ReadLine();
         }
     }