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

            var tokenAmount = _transactionCount / _groupCount;

            var(prepareTransactions, keyPairs) =
                await _parallelTestHelper.PrepareTokenForParallel(_groupCount, tokenAmount);

            await _parallelTestHelper.BroadcastTransactions(prepareTransactions);

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

            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, prepareTransactions);

            var transactions = await _parallelTestHelper.GenerateApproveTransactions(keyPairs, tokenAmount);

            await _parallelTestHelper.BroadcastTransactions(transactions);

            block = _parallelTestHelper.GenerateBlock(block.GetHash(), block.Height, transactions);
            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, transactions);

            var systemTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var cancellableTransactions =
                await _parallelTestHelper.GenerateTransferFromTransactionsWithoutConflict(keyPairs, tokenAmount);

            await _parallelTestHelper.BroadcastTransactions(systemTransactions.Concat(cancellableTransactions));

            var groupedTransactions = await _grouper.GroupAsync(
                new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height },
                cancellableTransactions);

            groupedTransactions.Parallelizables.Count.ShouldBe(_groupCount);
            groupedTransactions.NonParallelizables.Count.ShouldBe(0);

            block = _parallelTestHelper.GenerateBlock(block.GetHash(), block.Height,
                                                      systemTransactions.Concat(cancellableTransactions));
            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, systemTransactions,
                                                                   cancellableTransactions, CancellationToken.None);

            var codeRemarks =
                await _codeRemarksManager.GetCodeRemarksAsync(Hash.FromRawBytes(_parallelTestHelper.TokenContractCode));

            codeRemarks.ShouldBeNull();

            groupedTransactions = await _grouper.GroupAsync(
                new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height },
                cancellableTransactions);

            groupedTransactions.Parallelizables.Count.ShouldBe(_groupCount);
            groupedTransactions.NonParallelizables.Count.ShouldBe(0);

            block.TransactionIds.Count().ShouldBe(systemTransactions.Count + cancellableTransactions.Count);
        }
Beispiel #2
0
        public async Task TokenTransferFromParallelTest()
        {
            var chain = await _blockchainService.GetChainAsync();

            var tokenAmount = _transactionCount / _groupCount;

            var(prepareTransactions, keyPairs) =
                await _parallelTestHelper.PrepareTokenForParallel(_groupCount, 1000000000);

            await _parallelTestHelper.BroadcastTransactions(prepareTransactions);

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

            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, prepareTransactions);

            await _blockchainService.AddBlockAsync(block);

            await _blockAttachService.AttachBlockAsync(block);

            var transactions = await _parallelTestHelper.GenerateApproveTransactions(keyPairs, 1000000000);

            await _parallelTestHelper.BroadcastTransactions(transactions);

            block = _parallelTestHelper.GenerateBlock(block.GetHash(), block.Height, transactions);
            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, transactions);

            await _blockchainService.AddBlockAsync(block);

            await _blockAttachService.AttachBlockAsync(block);

            var systemTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            var cancellableTransactions =
                await _parallelTestHelper.GenerateTransferFromTransactionsWithoutConflict(keyPairs, tokenAmount);

            await _parallelTestHelper.BroadcastTransactions(systemTransactions.Concat(cancellableTransactions));

            var groupedTransactions = await _grouper.GroupAsync(
                new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height },
                cancellableTransactions);

            groupedTransactions.Parallelizables.Count.ShouldBe(1);
            groupedTransactions.NonParallelizables.Count.ShouldBe(0);

            block = _parallelTestHelper.GenerateBlock(block.GetHash(), block.Height,
                                                      systemTransactions.Concat(cancellableTransactions));
            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, systemTransactions,
                                                                   cancellableTransactions, CancellationToken.None);

            await _blockchainService.AddBlockAsync(block);

            await _blockAttachService.AttachBlockAsync(block);

            var tokenContractAddress =
                _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name);
            var tokenContractCodeHash = Hash.FromRawBytes(_parallelTestHelper.TokenContractCode);
            var codeRemark            =
                await _contractRemarksService.GetCodeRemarkAsync(new ChainContext
            {
                BlockHash   = block.GetHash(),
                BlockHeight = block.Height
            }, tokenContractAddress, tokenContractCodeHash);

            codeRemark.NonParallelizable.ShouldBeFalse();
            codeRemark.CodeHash.ShouldBe(tokenContractCodeHash);

            groupedTransactions = await _grouper.GroupAsync(
                new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height },
                cancellableTransactions);

            groupedTransactions.Parallelizables.Count.ShouldBe(1);
            groupedTransactions.NonParallelizables.Count.ShouldBe(0);

            block.TransactionIds.Count().ShouldBe(systemTransactions.Count + cancellableTransactions.Count);

            systemTransactions = await _parallelTestHelper.GenerateTransferTransactions(1);

            cancellableTransactions =
                _parallelTestHelper.GenerateTransferFromTransactionsWithoutConflictWithMultiSender(keyPairs,
                                                                                                   tokenAmount);
            await _parallelTestHelper.BroadcastTransactions(systemTransactions.Concat(cancellableTransactions));

            groupedTransactions = await _grouper.GroupAsync(
                new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height },
                cancellableTransactions);

            groupedTransactions.Parallelizables.Count.ShouldBe(_groupCount);
            groupedTransactions.NonParallelizables.Count.ShouldBe(0);

            block = _parallelTestHelper.GenerateBlock(block.GetHash(), block.Height,
                                                      systemTransactions.Concat(cancellableTransactions));
            block = await _blockExecutingService.ExecuteBlockAsync(block.Header, systemTransactions,
                                                                   cancellableTransactions, CancellationToken.None);

            await _blockchainService.AddBlockAsync(block);

            await _blockAttachService.AttachBlockAsync(block);

            codeRemark =
                await _contractRemarksService.GetCodeRemarkAsync(
                    new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height }, tokenContractAddress,
                    Hash.FromRawBytes(_parallelTestHelper.TokenContractCode));

            codeRemark.NonParallelizable.ShouldBeFalse();
            codeRemark.CodeHash.ShouldBe(Hash.FromRawBytes(_parallelTestHelper.TokenContractCode));

            groupedTransactions = await _grouper.GroupAsync(
                new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height },
                cancellableTransactions);

            groupedTransactions.Parallelizables.Count.ShouldBe(_groupCount);
            groupedTransactions.NonParallelizables.Count.ShouldBe(0);

            block.TransactionIds.Count().ShouldBe(systemTransactions.Count + cancellableTransactions.Count);
        }