Scrypt hashing is working now
[NovacoinLibrary.git] / NovacoinTest / Program.cs
index d7242ad..b74e14a 100644 (file)
@@ -1,13 +1,12 @@
 \feffusing System;
-using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
 
 
 namespace NovacoinTest
 {
     using Novacoin;
+    using System.Collections.Generic;
 
     class Program
     {
@@ -39,22 +38,72 @@ namespace NovacoinTest
             Console.WriteLine("OK: {0}\n", strBlock1 == strBlock1Bytes);
 
             Console.WriteLine(b2.ToString());
-            Console.WriteLine("OK: {0}\n", strBlock2 == strBlock2Bytes);
+            Console.WriteLine("Reserialization is OK: {0}\n", strBlock2 == strBlock2Bytes);
 
             /// ECDSA keypair generation test
 
             CKeyPair keyPair1 = new CKeyPair();
             CKeyPair keyPair2 = new CKeyPair(keyPair1.Secret);
-       
-            Console.WriteLine(keyPair1.ToString());
-            Console.WriteLine("OK: {0}\n", keyPair1.ToString() == keyPair2.ToString());
+            CPubKey pubKey = keyPair2.GetPubKey();
+
+            string strPrivKeyBase58 = keyPair1.ToString();
+
+            Console.WriteLine("Privkey in Base58: {0}", strPrivKeyBase58);
+            Console.WriteLine("Privkey in Hex: {0}", keyPair1.ToHex());
+
+            CKeyPair keyPair3 = new CKeyPair(strPrivKeyBase58);
+            Console.WriteLine("Privkey base58 deserialization is OK: {0}", keyPair3.GetKeyID().ToString() == keyPair1.GetKeyID().ToString());
+
+            Console.WriteLine("Pubkey in Base58: {0}", pubKey.ToString());
+            Console.WriteLine("Pubkey in Hex: {0}", pubKey.ToHex());
+
+            Console.WriteLine("Reinitialization is OK: {0}\n", keyPair1.ToString() == keyPair2.ToString());
+
+            /// Address generation test
+
+            CKeyID keyID = keyPair1.GetKeyID();
+            Console.WriteLine("Key ID: {0}", Interop.ToHex(keyID.hashBytes));
+            Console.WriteLine("Novacoin address: {0}\n", keyID.ToString());
+
+            /// Privkey deserialization test
+            CKeyPair keyPair4 = new CKeyPair("MEP3qCtFGmWo3Gurf8fMnUNaDHGNf637DqjoeG8rKium2jSj51sf");
+            Console.WriteLine("\nHard-coded privkey in Hex: {0}", keyPair4.ToHex());
+            Console.WriteLine("Hard-Coded privkey address: {0}", keyPair4.GetKeyID().ToString());
+            Console.WriteLine("Hard-Coded privkey: {0}\n", keyPair4.ToString());
+
+            // Privkey hex deserialization test
+            CKeyPair keyPair5 = new CKeyPair(keyPair4.Secret.ToArray());
+            Console.WriteLine("Decoded privkey in Hex: {0}", keyPair5.ToHex());
+            Console.WriteLine("Decoded privkey address: {0}\n", keyPair5.GetKeyID().ToString());
 
             /// ECDSA keypair signing test
 
             string data = "Превед!";
-            byte[] signature = keyPair1.Sign(Encoding.UTF8.GetBytes(data)).ToArray();
+            byte[] dataBytes = Encoding.UTF8.GetBytes(data);
+            byte[] signature = keyPair1.Sign(dataBytes).ToArray();
 
             Console.WriteLine("Signature: {0}", Interop.ToHex(signature));
+            Console.WriteLine("Signature is OK: {0} (CKeyPair)", keyPair1.VerifySignature(dataBytes, signature));
+            Console.WriteLine("Signature is OK: {0} (CPubKey)", pubKey.VerifySignature(dataBytes, signature));
+
+            /// Donation address
+
+            string strPubKeyTest = "029780fac8b85b4a47a616acb4e19d7958eaf02acc5123f65e7824ce720b1ae788";
+            CPubKey pubKeyTest = new CPubKey(Interop.ParseHex(strPubKeyTest));
+            string strDonationAddress = pubKeyTest.GetKeyID().ToString();
+            Console.WriteLine("\nDonations may be sent to: {0}", strDonationAddress);
+            Console.WriteLine("Address generation is OK: {0}", strDonationAddress == "4T2t8uiDtyHceMwMjMHPn88TyJB3trCg3o");
+
+            /// Address deserialization test
+
+            CNovacoinAddress donationAddress = new CNovacoinAddress(strDonationAddress);
+            Console.WriteLine("Address reserialization is OK: {0}", donationAddress.ToString() == pubKeyTest.GetKeyID().ToString());
+
+            /// Block header hashing test
+            IEnumerable<byte> dataBytesForScrypt = b1.header.ToBytes();
+            ScryptHash256 scryptHash = ScryptHash256.Compute256(dataBytesForScrypt);
+
+            Console.WriteLine("block1 header hash: {0}", scryptHash.ToString());
 
             Console.ReadLine();
         }