Ejemplo n.º 1
0
        public async Task ValidateBlockBeforeExecute_Repackaged_ReturnFalse()
        {
            var transaction = _kernelTestHelper.GenerateTransaction();
            var block       = await _kernelTestHelper.AttachBlockToBestChain(new List <Transaction>
            {
                transaction
            });

            await _transactionBlockIndexService.AddBlockIndexAsync(new List <Hash> {
                transaction.GetHash()
            },
                                                                   new BlockIndex
            {
                BlockHash   = block.GetHash(),
                BlockHeight = block.Height
            });

            var validateResult = await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(block);

            validateResult.ShouldBeTrue();

            var repackagedBlock = await _kernelTestHelper.AttachBlockToBestChain(new List <Transaction>
            {
                transaction
            });

            validateResult = await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(repackagedBlock);

            validateResult.ShouldBeFalse();
        }
Ejemplo n.º 2
0
        public async Task Start_Test()
        {
            var transactions = new List <Transaction>
            {
                _kernelTestHelper.GenerateTransaction(),
                _kernelTestHelper.GenerateTransaction()
            };

            var dto = new BlockchainNodeContextStartDto
            {
                ChainId = 1234,
                ZeroSmartContractType = typeof(IBlockchainNodeContextService),
                Transactions          = transactions.ToArray()
            };

            _kernelNodeTestContext.MockConsensusService.Verify(
                s => s.TriggerConsensusAsync(It.IsAny <ChainContext>()), Times.Never);

            var context = await _blockchainNodeContextService.StartAsync(dto);

            _kernelNodeTestContext.MockConsensusService.Verify(
                s => s.TriggerConsensusAsync(It.IsAny <ChainContext>()), Times.Once);

            context.ChainId.ShouldBe(dto.ChainId);
            var chain = await _blockchainService.GetChainAsync();

            chain.Id.ShouldBe(dto.ChainId);
            chain.BestChainHeight.ShouldBe(1);
            var block = await _blockchainService.GetBlockByHashAsync(chain.BestChainHash);

            block.Body.TransactionIds.Count.ShouldBe(2);
            block.Body.TransactionIds.ShouldContain(transactions[0].GetHash());
            block.Body.TransactionIds.ShouldContain(transactions[1].GetHash());

            var block2 = await _kernelTestHelper.AttachBlockToBestChain();

            var block3 = await _kernelTestHelper.AttachBlockToBestChain();

            chain = await _blockchainService.GetChainAsync();

            chain.BestChainHeight.ShouldBe(3);
            chain.BestChainHash.ShouldBe(block3.GetHash());

            await _blockchainService.SetIrreversibleBlockAsync(chain, block2.Height, block2.GetHash());

            chain = await _blockchainService.GetChainAsync();

            chain.LastIrreversibleBlockHeight.ShouldBe(2);

            context = await _blockchainNodeContextService.StartAsync(dto);

            chain = await _blockchainService.GetChainAsync();

            context.ChainId.ShouldBe(dto.ChainId);
            chain.BestChainHeight.ShouldBe(2);
            chain.BestChainHash.ShouldBe(block2.GetHash());

            _kernelNodeTestContext.MockConsensusService.Verify(
                s => s.TriggerConsensusAsync(It.IsAny <ChainContext>()), Times.Exactly(2));
        }
Ejemplo n.º 3
0
        public async Task SmartContractAddress_Get_WithHeightLargeThanLIB_Test()
        {
            await _smartContractHelper.CreateChainAsync();

            var block = await _kernelTestHelper.AttachBlockToBestChain();

            var chainContext = new ChainContext
            {
                BlockHash   = block.GetHash(),
                BlockHeight = block.Height
            };
            var contractName = Hash.Empty.ToStorageKey();
            await _smartContractAddressService.SetSmartContractAddressAsync(chainContext, contractName,
                                                                            SampleAddress.AddressList[0]);

            var address = await _smartContractAddressService.GetAddressByContractNameAsync(chainContext, contractName);

            address.ShouldBe(SampleAddress.AddressList[0]);

            var smartContractAddressDto = await _smartContractAddressService.GetSmartContractAddressAsync(chainContext, contractName);

            smartContractAddressDto.SmartContractAddress.ShouldBe(new SmartContractAddress
            {
                Address     = SampleAddress.AddressList[0],
                BlockHash   = block.GetHash(),
                BlockHeight = block.Height
            });
            smartContractAddressDto.Irreversible.ShouldBeFalse();
        }
Ejemplo n.º 4
0
        public async Task Put_Executive_Success()
        {
            var chain = await _smartContractHelper.CreateChainWithGenesisContractAsync();

            var chainContext = new ChainContext
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            };
            var address   = _defaultContractZeroCodeProvider.ContractZeroAddress;
            var executive = await _smartContractExecutiveService
                            .GetExecutiveAsync(chainContext, address);

            _smartContractExecutiveProvider.TryGetValue(address, out var pool);
            pool.Count.ShouldBe(0);

            var code = _smartContractHelper.Codes["AElf.Contracts.Configuration"];
            await _smartContractRegistrationProvider.SetSmartContractRegistrationAsync(chainContext,
                                                                                       address, new SmartContractRegistration
            {
                Category = KernelConstants.DefaultRunnerCategory,
                Code     = ByteString.CopyFrom(code),
                CodeHash = HashHelper.ComputeFrom(code)
            });

            await _smartContractExecutiveService.PutExecutiveAsync(chainContext, address, executive);

            _smartContractExecutiveProvider.TryGetValue(address, out pool);
            pool.Count.ShouldBe(1);

            await _smartContractRegistrationProvider.SetSmartContractRegistrationAsync(chainContext, address,
                                                                                       _defaultContractZeroCodeProvider.DefaultContractZeroRegistration);

            var block = await _kernelTestHelper.AttachBlockToBestChain();

            chainContext.BlockHash   = block.GetHash();
            chainContext.BlockHeight = block.Height;
            pool.TryTake(out _);
            pool.Count.ShouldBe(0);
            await _smartContractExecutiveService.PutExecutiveAsync(chainContext, address, executive);

            pool.Count.ShouldBe(1);
        }
        protected async Task <BlockStateSet> AddBlockStateSetAsync(BlockStateSet previousBlockStateSet)
        {
            var block = await KernelTestHelper.AttachBlockToBestChain();

            var blockStateSet = new BlockStateSet
            {
                BlockHash    = block.GetHash(),
                BlockHeight  = block.Height,
                PreviousHash = previousBlockStateSet.BlockHash
            };
            await BlockStateSetManger.SetBlockStateSetAsync(blockStateSet);

            return(blockStateSet);
        }
Ejemplo n.º 6
0
        public async Task Test_TxHub()
        {
            {
                // Empty transaction pool
                // Chain:
                //         BestChainHeight: 11
                // TxHub:
                //         BestChainHeight: 0
                //          AllTransaction: 0
                //   ExecutableTransaction: 0
                ExecutableTransactionShouldBe(Hash.Empty, 0);

                TransactionPoolSizeShouldBe(0);
            }

            var transactionHeight100 = _kernelTestHelper.GenerateTransaction(100);
            {
                // Receive a feature transaction twice
                // Chain:
                //         BestChainHeight: 11
                // TxHub:
                //         BestChainHeight: 0
                //          AllTransaction: 1
                //   ExecutableTransaction: 0

                // Receive the transaction first time
                await _txHub.HandleTransactionsReceivedAsync(new TransactionsReceivedEvent
                {
                    Transactions = new List <Transaction> {
                        transactionHeight100
                    }
                });

                ExecutableTransactionShouldBe(Hash.Empty, 0);

                TransactionPoolSizeShouldBe(1);
                TransactionShouldInPool(transactionHeight100);

                // Receive the same transaction again
                await _txHub.HandleTransactionsReceivedAsync(new TransactionsReceivedEvent
                {
                    Transactions = new List <Transaction> {
                        transactionHeight100
                    }
                });

                ExecutableTransactionShouldBe(Hash.Empty, 0);

                TransactionPoolSizeShouldBe(1);
                TransactionShouldInPool(transactionHeight100);
            }

            {
                // Receive a valid transaction
                // Chain:
                //         BestChainHeight: 11
                // TxHub:
                //         BestChainHeight: 0
                //          AllTransaction: 2
                //   ExecutableTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                var transactionValid = _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);

                await _txHub.HandleTransactionsReceivedAsync(new TransactionsReceivedEvent
                {
                    Transactions = new List <Transaction> {
                        transactionValid
                    }
                });

                TransactionPoolSizeShouldBe(2);
                TransactionShouldInPool(transactionHeight100);
                TransactionShouldInPool(transactionValid);

                // Receive a block
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 0
                //          AllTransaction: 1
                //   ExecutableTransaction: 0
                var transactionNotInPool = _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);

                var newBlock = await _kernelTestHelper.AttachBlockToBestChain(new List <Transaction>
                {
                    transactionValid,
                    transactionNotInPool
                });

                await _txHub.HandleBlockAcceptedAsync(new BlockAcceptedEvent
                {
                    BlockHeader = newBlock.Header
                });

                TransactionPoolSizeShouldBe(1);
                TransactionShouldInPool(transactionHeight100);
            }

            {
                // Receive best chain found event
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 1
                //   ExecutableTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
                {
                    BlockHash   = chain.BestChainHash,
                    BlockHeight = chain.BestChainHeight
                });

                ExecutableTransactionShouldBe(chain.BestChainHash, chain.BestChainHeight);

                TransactionPoolSizeShouldBe(1);
                TransactionShouldInPool(transactionHeight100);
            }

            {
                // Receive a valid transaction and a invalid transaction
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 3
                //   ExecutableTransaction: 1
                var chain = await _blockchainService.GetChainAsync();

                var transactionValid   = _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);
                var transactionInvalid = _kernelTestHelper.GenerateTransaction(chain.BestChainHeight - 1);

                await _txHub.HandleTransactionsReceivedAsync(new TransactionsReceivedEvent
                {
                    Transactions = new List <Transaction>
                    {
                        transactionValid,
                        transactionInvalid
                    }
                });

                ExecutableTransactionShouldBe(chain.BestChainHash, chain.BestChainHeight, new List <Transaction>
                {
                    transactionValid
                });

                TransactionPoolSizeShouldBe(3);
                TransactionShouldInPool(transactionHeight100);
                TransactionShouldInPool(transactionValid);
                TransactionShouldInPool(transactionInvalid);

                // Receive lib found event
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 2
                //   ExecutableTransaction: 1
                await _txHub.HandleNewIrreversibleBlockFoundAsync(new NewIrreversibleBlockFoundEvent
                {
                    BlockHash   = chain.BestChainHash,
                    BlockHeight = chain.BestChainHeight
                });

                ExecutableTransactionShouldBe(chain.BestChainHash, chain.BestChainHeight, new List <Transaction>
                {
                    transactionValid
                });

                TransactionPoolSizeShouldBe(2);
                TransactionShouldInPool(transactionHeight100);
                TransactionShouldInPool(transactionValid);
            }

            {
                // After 513 blocks
                // Chain:
                //         BestChainHeight: 525
                // TxHub:
                //         BestChainHeight: 525
                //          AllTransaction: 0
                //   ExecutableTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                var bestChainHeight = chain.BestChainHeight;
                for (var i = 0; i < KernelConstants.ReferenceBlockValidPeriod + 1; i++)
                {
                    var transaction = _kernelTestHelper.GenerateTransaction(bestChainHeight + i);
                    await _kernelTestHelper.AttachBlockToBestChain(new List <Transaction> {
                        transaction
                    });

                    chain = await _blockchainService.GetChainAsync();

                    await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
                    {
                        BlockHash   = chain.BestChainHash,
                        BlockHeight = chain.BestChainHeight
                    });

                    await _txHub.HandleNewIrreversibleBlockFoundAsync(new NewIrreversibleBlockFoundEvent
                    {
                        BlockHash   = chain.BestChainHash,
                        BlockHeight = chain.BestChainHeight
                    });
                }

                ExecutableTransactionShouldBe(chain.BestChainHash, chain.BestChainHeight);

                TransactionPoolSizeShouldBe(0);
            }
        }
Ejemplo n.º 7
0
        public async Task TxHub_Test()
        {
            TransactionValidationStatusChangedEvent transactionValidationStatusChangedEventData = null;

            _eventBus.Subscribe <TransactionValidationStatusChangedEvent>(d =>
            {
                transactionValidationStatusChangedEventData = d;
                return(Task.CompletedTask);
            });

            TransactionAcceptedEvent transactionAcceptedEvent = null;

            _eventBus.Subscribe <TransactionAcceptedEvent>(d =>
            {
                transactionAcceptedEvent = d;
                return(Task.CompletedTask);
            });

            {
                // Empty transaction pool
                // Chain:
                //         BestChainHeight: 11
                // TxHub:
                //         BestChainHeight: 0
                //          AllTransaction: 0
                //    ValidatedTransaction: 0
                await TxHubBestChainShouldBeAsync(Hash.Empty, 0);
                await TransactionPoolSizeShouldBeAsync(0, 0);

                transactionValidationStatusChangedEventData.ShouldBeNull();
                transactionAcceptedEvent.ShouldBeNull();
            }

            {
                // Receive a valid transaction
                // Chain:
                //         BestChainHeight: 11
                // TxHub:
                //         BestChainHeight: 0
                //          AllTransaction: 0
                //    ValidatedTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                var transactionValid =
                    _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);

                await AddTransactionsAsync(new List <Transaction> {
                    transactionValid
                });
                await TxHubBestChainShouldBeAsync(Hash.Empty, 0);
                await TransactionPoolSizeShouldBeAsync(0, 0);
                await CheckTransactionInPoolAsync(transactionValid, false);

                transactionValidationStatusChangedEventData.ShouldBeNull();
                transactionAcceptedEvent.ShouldBeNull();
            }

            {
                // Receive best chain found event
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 0
                //    ValidatedTransaction: 0
                await _kernelTestHelper.AttachBlockToBestChain();

                var chain = await _blockchainService.GetChainAsync();

                await _txHub.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight);
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(0, 0);
            }

            {
                // Receive a different branch transaction
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 1
                //    ValidatedTransaction: 0
                var transactionDifferent = _kernelTestHelper.GenerateTransaction(12);
                var chain = await _blockchainService.GetChainAsync();
                await AddTransactionsAsync(new List <Transaction> {
                    transactionDifferent
                });
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(1, 0);
                await CheckTransactionInPoolAsync(transactionDifferent, true);

                transactionValidationStatusChangedEventData.ShouldBeNull();
                transactionAcceptedEvent.ShouldBeNull();
            }

            {
                // Receive a future transaction
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 1
                //    ValidatedTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                var transactionFuture = _kernelTestHelper.GenerateTransaction(chain.BestChainHeight + 1);
                await AddTransactionsAsync(new List <Transaction> {
                    transactionFuture
                });
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(1, 0);
                await CheckTransactionInPoolAsync(transactionFuture, false);

                transactionAcceptedEvent.ShouldBeNull();
                transactionValidationStatusChangedEventData.ShouldNotBeNull();
                transactionValidationStatusChangedEventData.TransactionId.ShouldBe(transactionFuture.GetHash());
                transactionValidationStatusChangedEventData.TransactionResultStatus.ShouldBe(TransactionResultStatus
                                                                                             .NodeValidationFailed);
                transactionValidationStatusChangedEventData.Error.ShouldContain("Transaction expired");

                transactionValidationStatusChangedEventData = null;
            }

            {
                // Receive a invalid transaction
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 1
                //    ValidatedTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                var transactionInvalid =
                    _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);
                transactionInvalid.Signature = ByteString.Empty;
                await AddTransactionsAsync(new List <Transaction> {
                    transactionInvalid
                });
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(1, 0);
                await CheckTransactionInPoolAsync(transactionInvalid, false);

                transactionValidationStatusChangedEventData.ShouldNotBeNull();
                transactionValidationStatusChangedEventData.TransactionId.ShouldBe(transactionInvalid.GetHash());
                transactionValidationStatusChangedEventData.TransactionResultStatus.ShouldBe(TransactionResultStatus
                                                                                             .NodeValidationFailed);
                transactionValidationStatusChangedEventData.Error.ShouldBe("Incorrect transaction signature.");
                transactionAcceptedEvent.ShouldBeNull();

                transactionValidationStatusChangedEventData = null;
            }

            {
                // Receive a transaction already in DB
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 1
                //    ValidatedTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                var transactionInDB =
                    _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);
                await _blockchainService.AddTransactionsAsync(new List <Transaction> {
                    transactionInDB
                });
                await AddTransactionsAsync(new List <Transaction> {
                    transactionInDB
                });
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(1, 0);
                await CheckTransactionInPoolAsync(transactionInDB, false);

                transactionValidationStatusChangedEventData.ShouldBeNull();
                transactionAcceptedEvent.ShouldBeNull();
            }

            {
                // Receive a valid transaction
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 2
                //    ValidatedTransaction: 1
                var chain = await _blockchainService.GetChainAsync();

                var transactionValid =
                    _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);

                await AddTransactionsAsync(new List <Transaction> {
                    transactionValid
                });

                await _txHub.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight);
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(2, 1);
                await CheckTransactionInPoolAsync(transactionValid, true);

                transactionValidationStatusChangedEventData.ShouldBeNull();
                transactionAcceptedEvent.ShouldNotBeNull();
                transactionAcceptedEvent.Transaction.ShouldBe(transactionValid);
                transactionAcceptedEvent.ChainId.ShouldBe(chain.Id);

                transactionAcceptedEvent = null;

                // Receive the valid transaction again
                // Chain:
                //         BestChainHeight: 12
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 2
                //    ValidatedTransaction: 1
                await AddTransactionsAsync(new List <Transaction> {
                    transactionValid
                });
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(2, 1);
                await CheckTransactionInPoolAsync(transactionValid, true);

                transactionValidationStatusChangedEventData.ShouldBeNull();
                transactionAcceptedEvent.ShouldBeNull();

                // Mined a block
                // Chain:
                //         BestChainHeight: 13
                // TxHub:
                //         BestChainHeight: 12
                //          AllTransaction: 1
                //    ValidatedTransaction: 0
                var transactionNotInPool =
                    _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);

                var newBlock = await _kernelTestHelper.AttachBlockToBestChain(new List <Transaction>
                {
                    transactionValid,
                    transactionNotInPool
                });

                await _txHub.CleanByTransactionIdsAsync(newBlock.TransactionIds);
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 12);
                await TransactionPoolSizeShouldBeAsync(1, 1);
                await CheckTransactionInPoolAsync(transactionValid, false);
            }

            {
                // Receive best chain found event
                // Chain:
                //         BestChainHeight: 13
                // TxHub:
                //         BestChainHeight: 13
                //          AllTransaction: 1
                //    ValidatedTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                await _txHub.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight);

                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 13);
                await TransactionPoolSizeShouldBeAsync(1, 0);
            }

            {
                // Receive a valid transaction and a expired transaction
                // Chain:
                //         BestChainHeight: 13
                // TxHub:
                //         BestChainHeight: 13
                //          AllTransaction: 2
                //    ValidatedTransaction: 1
                var chain = await _blockchainService.GetChainAsync();

                var transactionValid =
                    _kernelTestHelper.GenerateTransaction(chain.BestChainHeight, chain.BestChainHash);
                var transactionExpired = _kernelTestHelper.GenerateTransaction(chain.BestChainHeight + 100);

                await AddTransactionsAsync(new List <Transaction>
                {
                    transactionValid,
                    transactionExpired
                });

                await _txHub.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight);
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 13);
                await TransactionPoolSizeShouldBeAsync(2, 1);
                await CheckTransactionInPoolAsync(transactionValid, true);
                await CheckTransactionInPoolAsync(transactionExpired, false);

                transactionValidationStatusChangedEventData.ShouldNotBeNull();
                transactionValidationStatusChangedEventData.TransactionId.ShouldBe(transactionExpired.GetHash());
                transactionValidationStatusChangedEventData.TransactionResultStatus.ShouldBe(TransactionResultStatus
                                                                                             .NodeValidationFailed);
                transactionValidationStatusChangedEventData.Error.ShouldContain("Transaction expired");

                transactionAcceptedEvent.ShouldNotBeNull();
                transactionAcceptedEvent.Transaction.ShouldBe(transactionValid);
                transactionAcceptedEvent.ChainId.ShouldBe(chain.Id);

                transactionAcceptedEvent = null;
                transactionValidationStatusChangedEventData = null;
            }

            {
                // Set lib 12
                // Chain:
                //         BestChainHeight: 13
                // TxHub:
                //         BestChainHeight: 13
                //          AllTransaction: 1
                //    ValidatedTransaction: 1
                var chain = await _blockchainService.GetChainAsync();

                await _txHub.CleanByHeightAsync(12);
                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 13);
                await TransactionPoolSizeShouldBeAsync(1, 1);
            }

            {
                // After 513 blocks
                // Chain:
                //         BestChainHeight: 526
                // TxHub:
                //         BestChainHeight: 526
                //          AllTransaction: 1
                //    ValidatedTransaction: 0
                var chain = await _blockchainService.GetChainAsync();

                var bestChainHeight = chain.BestChainHeight;
                for (var i = 0; i < KernelConstants.ReferenceBlockValidPeriod + 1; i++)
                {
                    var transaction = _kernelTestHelper.GenerateTransaction(bestChainHeight + i);
                    await _kernelTestHelper.AttachBlockToBestChain(new List <Transaction> {
                        transaction
                    });

                    chain = await _blockchainService.GetChainAsync();

                    await _txHub.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight);
                }

                await TxHubBestChainShouldBeAsync(chain.BestChainHash, 526);

                await TransactionPoolSizeShouldBeAsync(0, 0);
            }
        }