Exemple #1
0
        public async Task ExecuteBlocks_ValidateFailed()
        {
            var chain = await _blockchainService.GetChainAsync();

            var previousHash   = chain.BestChainHash;
            var previousHeight = chain.BestChainHeight;

            var blockList = new List <Block>();

            for (var i = 0; i < 3; i++)
            {
                var transactions = new List <Transaction> {
                    _kernelTestHelper.GenerateTransaction()
                };
                var lastBlock = _kernelTestHelper.GenerateBlock(previousHeight, previousHash, transactions);

                await _blockchainService.AddBlockAsync(lastBlock);

                await _blockchainService.AddTransactionsAsync(transactions);

                await _blockchainService.AttachBlockToChainAsync(chain, lastBlock);

                previousHash   = lastBlock.GetHash();
                previousHeight = lastBlock.Height;
                blockList.Add(lastBlock);
            }

            var executionResult =
                await _fullBlockchainExecutingService.ExecuteBlocksAsync(blockList);

            executionResult.SuccessBlockExecutedSets.Count.ShouldBe(0);
            executionResult.ExecutedFailedBlocks.Count.ShouldBe(1);
            executionResult.ExecutedFailedBlocks[0].GetHash().ShouldBe(blockList[0].GetHash());
        }
Exemple #2
0
        private async Task ExecuteBlocksAsync(List <Block> blockList)
        {
            foreach (var block in blockList)
            {
                await _blockchainService.AddBlockAsync(block);
            }

            var executionResult =
                await _fullBlockchainExecutingService.ExecuteBlocksAsync(blockList);

            executionResult.SuccessBlockExecutedSets.Count.ShouldBe(blockList.Count());
            for (var i = 0; i < blockList.Count; i++)
            {
                executionResult.SuccessBlockExecutedSets[i].GetHash().ShouldBe(blockList[i].GetHash());
            }
            executionResult.ExecutedFailedBlocks.Count.ShouldBe(0);
        }