public void EncodeDecodeBlock()
        {
            BlockEncoder encoder = new BlockEncoder();
            Hash         hash    = new Hash();
            Block        block   = new Block(1, hash);

            var result = encoder.Decode(encoder.Encode(block));

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Number);
            Assert.AreEqual(hash, result.ParentHash);
        }
예제 #2
0
        public void DecodeBlock()
        {
            BlockEncoder encoder = new BlockEncoder(new KeyScheduler {
                Key = Key, IV = IV
            });
            BlockEncoder decoder = new BlockEncoder(new KeyScheduler {
                Key = Key, IV = IV
            });

            byte[] block   = hasher.ComputeHash(Key);
            byte[] encoded = encoder.Encode(block, iterations: 1);
            byte[] decoded = decoder.Decode(block, iterations: 1);
        }
        public void EncodeDecodeBlockWithTransaction()
        {
            BlockEncoder encoder     = new BlockEncoder();
            Address      from        = new Address();
            Address      to          = new Address();
            Transaction  transaction = new Transaction(from, to, new BigInteger(2));

            Block original = new Block(0, null, new Transaction[] { transaction });
            Block block    = encoder.Decode(encoder.Encode(original));

            Assert.IsNotNull(block.Transactions);
            Assert.AreEqual(1, block.Transactions.Count);

            Transaction result = block.Transactions.First();

            Assert.AreEqual(new BigInteger(2), result.Value);
        }
예제 #4
0
 public void Decode()
 {
     for (int i = CryptoTransform.MinRounds; i < CryptoTransform.MinRounds + CryptoTransform.MaxAdditionalRounds; i++)
     {
         BlockEncoder encoder = new BlockEncoder(new KeyScheduler {
             Key = Key, IV = IV
         });
         BlockEncoder decoder = new BlockEncoder(new KeyScheduler {
             Key = Key, IV = IV
         });
         byte[] block   = hasher.ComputeHash(Key);
         byte[] copy    = (byte[])block.Clone();
         byte[] encoded = encoder.Encode(block, i);
         //check to see whether it's being altered by accident
         CollectionAssert.AreEqual(copy, block);
         byte[] decoded = decoder.Decode(encoded, i);
         Assert.IsTrue(block.Length == decoded.Length);
         CollectionAssert.AreEqual(decoded, block);
     }
 }