public async Task Add_Block_Success()
        {
            var transactions = new List <Transaction>();

            for (var i = 0; i < 3; i++)
            {
                var transaction = _kernelTestHelper.GenerateTransaction();
                transactions.Add(transaction);
            }

            var block = _kernelTestHelper.GenerateBlock(0, Hash.Empty, transactions);

            var existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.ShouldBeNull();

            await _fullBlockchainService.AddBlockAsync(block);

            existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.ShouldBe(block);

            var blockHeader = await _fullBlockchainService.GetBlockHeaderByHashAsync(block.GetHash());

            blockHeader.ShouldBe(block.Header);
        }
        public async Task Create_Chain_Success()
        {
            var transactions = new List <Transaction>
            {
                _kernelTestHelper.GenerateTransaction(),
                _kernelTestHelper.GenerateTransaction()
            };

            var block = _kernelTestHelper.GenerateBlock(0, Hash.Empty, transactions);

            var chain = await _fullBlockchainService.GetChainAsync();

            chain.ShouldBeNull();

            var existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.ShouldBeNull();

            var createChainResult = await _fullBlockchainService.CreateChainAsync(block, transactions);

            chain = await _fullBlockchainService.GetChainAsync();

            chain.ShouldNotBeNull();
            chain.ShouldBe(createChainResult);

            existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.GetHash().ShouldBe(block.GetHash());

            var existTransactions = await _fullBlockchainService.GetTransactionsAsync(transactions.Select(t => t.GetHash()));

            existTransactions.ShouldContain(transactions[0]);
            existTransactions.ShouldContain(transactions[1]);
        }
Exemplo n.º 3
0
        public async Task Add_Block_Success()
        {
            var transactions = new List <Transaction>();

            for (var i = 0; i < 3; i++)
            {
                var transaction = _kernelTestHelper.GenerateTransaction();
                transactions.Add(transaction);
            }

            var block = _kernelTestHelper.GenerateBlock(0, Hash.Empty, transactions);

            var existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.ShouldBeNull();

            await _fullBlockchainService.AddBlockAsync(block);

            await _fullBlockchainService.AddTransactionsAsync(transactions);

            existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.GetHash().ShouldBe(block.GetHash());
            existBlock.Body.TransactionsCount.ShouldBe(3);

            foreach (var tx in transactions)
            {
                var existTransaction = await _transactionManager.GetTransactionAsync(tx.GetHash());

                existTransaction.ShouldBe(tx);
            }
        }
Exemplo n.º 4
0
        public async Task Create_Chain_Success()
        {
            var block = new Block
            {
                Header = new BlockHeader
                {
                    Height            = KernelConstants.GenesisBlockHeight,
                    PreviousBlockHash = Hash.Empty,
                    Time = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                Body = new BlockBody()
            };

            var chain = await _fullBlockchainService.GetChainAsync();

            chain.ShouldBeNull();
            var existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.ShouldBeNull();

            var createChainResult = await _fullBlockchainService.CreateChainAsync(block);

            chain = await _fullBlockchainService.GetChainAsync();

            chain.ShouldNotBeNull();
            chain.ShouldBe(createChainResult);

            existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.GetHash().ShouldBe(block.GetHash());
        }
        public async Task Add_Block_Success()
        {
            var block = new Block
            {
                Height = 2,
                Header = new BlockHeader(),
                Body   = new BlockBody()
            };

            for (var i = 0; i < 3; i++)
            {
                block.Body.AddTransaction(_kernelTestHelper.GenerateTransaction());
            }

            var existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.ShouldBeNull();

            await _fullBlockchainService.AddBlockAsync(block);

            existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.GetHash().ShouldBe(block.GetHash());
            existBlock.Body.TransactionsCount.ShouldBe(3);

            foreach (var tx in block.Body.TransactionList)
            {
                var existTransaction = await _transactionManager.GetTransaction(tx.GetHash());

                existTransaction.ShouldBe(tx);
            }
        }
Exemplo n.º 6
0
        public async Task Create_Chain_Success()
        {
            var block = _kernelTestHelper.GenerateBlock(0, Hash.Empty, new List <Transaction>());

            var chain = await _fullBlockchainService.GetChainAsync();

            chain.ShouldBeNull();

            var existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.ShouldBeNull();

            var createChainResult = await _fullBlockchainService.CreateChainAsync(block, new List <Transaction>());

            chain = await _fullBlockchainService.GetChainAsync();

            chain.ShouldNotBeNull();
            chain.ShouldBe(createChainResult);

            existBlock = await _fullBlockchainService.GetBlockByHashAsync(block.GetHash());

            existBlock.GetHash().ShouldBe(block.GetHash());
        }