Пример #1
0
        public void ConstructorsTest()
        {
            using var sha256 = SHA256.Create();
            var data   = new TestBlockData("1234654235143");
            var target = new Target(new byte[] { 30, 255, 0, 0 });

            byte[] hashPrevBlock = Convert.FromBase64String("CYoIPu0innBYIdJgwQT1ceFccDgBCwfSAxCKKpCQiPA="),
            hashMerkleRoot = ((IBlockData)data).GetHashMerkleRoot(sha256);
            var header = new BlockHeader(hashPrevBlock, hashMerkleRoot, target.ToBits());

            var blocks = new List <Block <TestBlockData> >()
            {
                new Block <TestBlockData>(header, data),
                Block <TestBlockData> .Create(hashPrevBlock, data, target, sha256)
            };

            blocks.Add(new Block <TestBlockData>(blocks[0].ToArray()));

            AreEqualTest(blocks);
            GetBlockHeaderTest(blocks[0], header);
            GetDataTest(blocks[0], data);
            GetSizeTest(blocks[0]);
        }
Пример #2
0
        public void ConstructorsTest()
        {
            using var sha256 = SHA256.Create();
            var data   = new TestBlockData("1234654235143");
            var target = new Target(new byte[] { 8, 21, 21, 21 });

            byte[] hashPrevBlock = Convert.FromBase64String("CYoIPu0innBYIdJgwQT1ceFccDgBCwfSAxCKKpCQiPA="),
            hashMerkleRoot = ((IBlockData)data).GetHashMerkleRoot(sha256);

            var headers = new List <BlockHeader>()
            {
                new BlockHeader(hashPrevBlock, hashMerkleRoot, target.ToBits()),
                BlockHeader.Create(hashPrevBlock, data, target, sha256)
            };

            headers.Add(new BlockHeader(headers[0].ToArray()));

            AreEqualTest(headers);
            HashPrevBlockTest(headers[0], hashPrevBlock);
            HashMerkleRootTest(headers[0], hashMerkleRoot);
            TimeTest(headers[0]);
            BitsTest(headers[0], target);
            NonceTest(headers[0]);
        }
Пример #3
0
 private void GetDataTest(Block <TestBlockData> block, TestBlockData data)
 {
     Assert.IsTrue(TestHelper.ArrayEquals(block.GetData().ToArray(), data.ToArray()),
                   "Data is different from Data in the block");
 }