public async Task ExecuteBlocksAttachedToLongestChain_ExecuteFailed() { var chain = await _blockchainService.GetChainAsync(); var bestChainHeight = chain.BestChainHeight; var bestChainHash = chain.BestChainHash; var newBlock = _kernelTestHelper.GenerateBlock(chain.BestChainHeight, chain.BestChainHash, new List <Transaction> { _kernelTestHelper.GenerateTransaction() }); await _blockchainService.AddBlockAsync(newBlock); var status = await _blockchainService.AttachBlockToChainAsync(chain, newBlock); var attachResult = await _fullBlockchainExecutingService.ExecuteBlocksAttachedToLongestChain(chain, status); attachResult.Count.ShouldBe(1); attachResult.Last().Height.ShouldBe(16); attachResult.Last().BlockHash.ShouldBe(newBlock.GetHash()); chain = await _blockchainService.GetChainAsync(); var newBlockLink = await _chainManager.GetChainBlockLinkAsync(newBlock.GetHash()); newBlockLink.ExecutionStatus.ShouldBe(ChainBlockLinkExecutionStatus.ExecutionFailed); chain.BestChainHash.ShouldBe(bestChainHash); chain.BestChainHeight.ShouldBe(bestChainHeight); }
public async Task Attach_Block_To_Chain_ReturnNull() { var chain = await _blockchainService.GetChainAsync(); var newBlock = _kernelTestHelper.GenerateBlock(chain.BestChainHeight, Hash.Empty, new List <Transaction> { _kernelTestHelper.GenerateTransaction() }); var status = await _blockchainService.AttachBlockToChainAsync(chain, newBlock); var attachResult = await _fullBlockchainExecutingService.ExecuteBlocksAttachedToLongestChain(chain, status); attachResult.ShouldBeNull(); }
public async Task ExecuteBlocksAttachedToLongestChain_ValidateFailed() { var chain = await _blockchainService.GetChainAsync(); var bestChainHeight = chain.BestChainHeight; var bestChainHash = chain.BestChainHash; var previousHash = chain.BestChainHash; var previousHeight = chain.BestChainHeight; BlockAttachOperationStatus status = BlockAttachOperationStatus.None; var blockList = new List <Block>(); // Block lastBlock = null; int count = 0; while (!status.HasFlag(BlockAttachOperationStatus.LongestChainFound)) { var transactions = new List <Transaction> { _kernelTestHelper.GenerateTransaction() }; var lastBlock = _kernelTestHelper.GenerateBlock(previousHeight, previousHash, transactions); await _blockchainService.AddBlockAsync(lastBlock); await _blockchainService.AddTransactionsAsync(transactions); status = await _blockchainService.AttachBlockToChainAsync(chain, lastBlock); count++; previousHash = lastBlock.GetHash(); previousHeight = lastBlock.Height; blockList.Add(lastBlock); } var attachResult = await _fullBlockchainExecutingService.ExecuteBlocksAttachedToLongestChain(chain, status); attachResult.ShouldBeNull(); chain = await _blockchainService.GetChainAsync(); var newBlockLink = await _chainManager.GetChainBlockLinkAsync(blockList.First().GetHash()); newBlockLink.ExecutionStatus.ShouldBe(ChainBlockLinkExecutionStatus.ExecutionFailed); chain.BestChainHash.ShouldBe(bestChainHash); chain.BestChainHeight.ShouldBe(bestChainHeight); chain.LongestChainHash.ShouldBe(bestChainHash); chain.LongestChainHeight.ShouldBe(bestChainHeight); chain.Branches.ShouldNotContainKey(previousHash.ToStorageKey()); }
public async Task ExecuteBlocksAttachedToLongestChain_ValidateFailed() { var chain = await _blockchainService.GetChainAsync(); var bestChainHeight = chain.BestChainHeight; var bestChainHash = chain.BestChainHash; var transactions = new List <Transaction> { _kernelTestHelper.GenerateTransaction() }; var newBlock = _kernelTestHelper.GenerateBlock(chain.BestChainHeight, chain.BestChainHash, transactions); await _blockchainService.AddBlockAsync(newBlock); await _blockchainService.AddTransactionsAsync(transactions); var status = await _blockchainService.AttachBlockToChainAsync(chain, newBlock); chain = await _blockchainService.GetChainAsync(); chain.LongestChainHash.ShouldBe(newBlock.GetHash()); chain.LongestChainHeight.ShouldBe(newBlock.Height); chain.Branches.ShouldContainKey(newBlock.GetHash().ToStorageKey()); var attachResult = await _fullBlockchainExecutingService.ExecuteBlocksAttachedToLongestChain(chain, status); attachResult.ShouldBeNull(); chain = await _blockchainService.GetChainAsync(); var newBlockLink = await _chainManager.GetChainBlockLinkAsync(newBlock.GetHash()); newBlockLink.ExecutionStatus.ShouldBe(ChainBlockLinkExecutionStatus.ExecutionFailed); chain.BestChainHash.ShouldBe(bestChainHash); chain.BestChainHeight.ShouldBe(bestChainHeight); chain.LongestChainHash.ShouldBe(bestChainHash); chain.LongestChainHeight.ShouldBe(bestChainHeight); chain.Branches.ShouldNotContainKey(newBlock.GetHash().ToStorageKey()); }