public async Task GetBlock_Header_And_Body_Test()
        {
            var block     = _kernelTestHelper.GenerateBlock(0, Hash.Empty);
            var blockHash = block.GetHash();
            await _blockManager.AddBlockHeaderAsync(block.Header);

            var blockHeader = await _blockManager.GetBlockHeaderAsync(blockHash);

            Assert.Equal(blockHeader, block.Header);

            var storedBlock = await _blockManager.GetBlockAsync(blockHash);

            storedBlock.ShouldBeNull();

            await _blockManager.AddBlockBodyAsync(blockHash, block.Body);

            storedBlock = await _blockManager.GetBlockAsync(blockHash);

            Assert.Equal(storedBlock.Header, block.Header);
            Assert.Equal(storedBlock.Body, block.Body);

            (await _blockManager.HasBlockAsync(blockHash)).ShouldBeTrue();

            await _blockManager.RemoveBlockAsync(blockHash);

            await _blockManager.AddBlockBodyAsync(blockHash, block.Body);

            storedBlock = await _blockManager.GetBlockAsync(blockHash);

            storedBlock.ShouldBeNull();

            (await _blockManager.HasBlockAsync(blockHash)).ShouldBeFalse();
        }
示例#2
0
        public async Task GetBlock_Header_And_Body_Test()
        {
            var header = new BlockHeader()
            {
                ChainId = _chainId,
                Height  = 1
            };
            var hash = header.GetHash();
            await _blockManager.AddBlockHeaderAsync(header);

            var h = await _blockManager.GetBlockHeaderAsync(hash);

            Assert.Equal(header, h);

            var body = new BlockBody()
            {
                BlockHeader = hash
            };
            await _blockManager.AddBlockBodyAsync(hash, body);

            var block = await _blockManager.GetBlockAsync(hash);

            Assert.Equal(block.Header, header);
            Assert.Equal(block.Body, body);
        }
示例#3
0
        public async Task <Block> GetBlockByHashAsync(Hash blockId)
        {
            var block = await _blockManager.GetBlockAsync(blockId);

            if (block == null)
            {
                return(null);
            }

            var body = block.Body;

            foreach (var txId in body.Transactions)
            {
                var tx = await _transactionManager.GetTransaction(txId);

                body.TransactionList.Add(tx);
            }

            return(block);
        }
示例#4
0
 public async Task <Block> GetBlockByHashAsync(Hash blockId)
 {
     return(await _blockManager.GetBlockAsync(blockId));
 }