示例#1
0
        public async Task Use_Same_Resource_Key_With_SystemTransaction_Test()
        {
            var chain = await _blockchainService.GetChainAsync();

            var accountAddress = await _accountService.GetAccountAsync();

            var startBalance = await _parallelTestHelper.QueryBalanceAsync(accountAddress, "ELF", chain.BestChainHash,
                                                                           chain.BestChainHeight);

            var systemTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var cancellableTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var allTransactions = systemTransactions.Concat(cancellableTransactions).ToList();
            await _parallelTestHelper.BroadcastTransactions(allTransactions);

            var block = _parallelTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, allTransactions);

            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, systemTransactions,
                                                                   cancellableTransactions, CancellationToken.None);

            var endBalance = await _parallelTestHelper.QueryBalanceAsync(accountAddress, "ELF", block.GetHash(), block.Height);

            (startBalance - endBalance).ShouldBe(20);
        }
示例#2
0
        public async Task Use_Same_Resource_Key_With_SystemTransaction_Test()
        {
            var chain = await _blockchainService.GetChainAsync();

            var accountAddress = await _accountService.GetAccountAsync();

            var startBalance = await _parallelTestHelper.QueryBalanceAsync(accountAddress, "ELF", chain.BestChainHash,
                                                                           chain.BestChainHeight);

            var systemTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var cancellableTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var allTransactions = systemTransactions.Concat(cancellableTransactions).ToList();
            await _parallelTestHelper.BroadcastTransactions(allTransactions);

            var block = _parallelTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, allTransactions);

            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, systemTransactions,
                                                                   cancellableTransactions, CancellationToken.None);

            var transactionResults = await GetTransactionResultsAsync(block.Body.TransactionIds.ToList(), block.Header);

            var fee        = transactionResults.Sum(t => t.TransactionFee.Value["ELF"]);
            var amount     = allTransactions.Sum(t => TransferInput.Parser.ParseFrom(t.Params).Amount);
            var endBalance = await _parallelTestHelper.QueryBalanceAsync(accountAddress, "ELF", block.GetHash(), block.Height);

            (startBalance - endBalance).ShouldBe(amount + fee);
        }
        public async Task Use_Same_Resource_Key_With_SystemTransaction_Test()
        {
            var chain = await _blockchainService.GetChainAsync();

            var accountAddress = await _accountService.GetAccountAsync();

            var startBalance = await _parallelTestHelper.QueryBalanceAsync(accountAddress, "ELF", chain.BestChainHash,
                                                                           chain.BestChainHeight);

            var systemTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var cancellableTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var allTransactions = systemTransactions.Concat(cancellableTransactions).ToList();
            await _parallelTestHelper.BroadcastTransactions(allTransactions);

            var block = _parallelTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, allTransactions);

            block = (await _blockExecutingService.ExecuteBlockAsync(block.Header, systemTransactions,
                                                                    cancellableTransactions, CancellationToken.None)).Block;

            var transactionResults = await GetTransactionResultsAsync(block.Body.TransactionIds.ToList(), block.Header);

            var totalFee = transactionResults
                           .Select(transactionResult =>
                                   transactionResult.Logs.Single(l => l.Name == nameof(TransactionFeeCharged)))
                           .Select(relatedLog => TransactionFeeCharged.Parser.ParseFrom(relatedLog.NonIndexed))
                           .Where(chargedEvent => chargedEvent.Symbol == "ELF").Sum(chargedEvent => chargedEvent.Amount);
            var amount     = allTransactions.Sum(t => TransferInput.Parser.ParseFrom(t.Params).Amount);
            var endBalance =
                await _parallelTestHelper.QueryBalanceAsync(accountAddress, "ELF", block.GetHash(), block.Height);

            (startBalance - endBalance).ShouldBe(amount + totalFee);
        }