public async Task IterationSetup() { var transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); await _txHub.HandleTransactionsReceivedAsync(new TransactionsReceivedEvent { Transactions = transactions }); var chain = await _blockchainService.GetChainAsync(); _block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, transactions); await _blockchainService.AddBlockAsync(_block); await _chainBlockLinks.SetAsync( chain.Id.ToStorageKey() + KernelConstants.StorageKeySeparator + _block.GetHash().ToStorageKey(), new ChainBlockLink() { BlockHash = _block.GetHash(), Height = _block.Height, PreviousBlockHash = _block.Header.PreviousBlockHash, IsLinked = true }); await _blockchainService.SetBestChainAsync(chain, _block.Height, _block.GetHash()); }
public void Setup(BenchmarkContext context) { _blockchainService = GetRequiredService <IBlockchainService>(); _blockExecutingService = GetRequiredService <IBlockExecutingService>(); _osTestHelper = GetRequiredService <OSTestHelper>(); _counter = context.GetCounter("TestCounter"); AsyncHelper.RunSync(async() => { var chain = await _blockchainService.GetChainAsync(); _block = new Block { Header = new BlockHeader { ChainId = chain.Id, Height = chain.BestChainHeight + 1, PreviousBlockHash = chain.BestChainHash, Time = Timestamp.FromDateTime(DateTime.UtcNow) }, Body = new BlockBody() }; _transactions = await _osTestHelper.GenerateTransferTransactions(1000); }); }
public async Task AttachBlockWithTransactions_Test() { var chain = await _blockchainService.GetChainAsync(); var transactions = await _osTestHelper.GenerateTransferTransactions(2); var block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, transactions); var executedBlock = (await _blockExecutingService.ExecuteBlockAsync(block.Header, transactions)).Block; var blockWithTransactions = new BlockWithTransactions { Header = executedBlock.Header, Transactions = { transactions } }; var attachFinished = false; await _blockSyncAttachService.AttachBlockWithTransactionsAsync(blockWithTransactions, "pubkey", () => { attachFinished = true; return(Task.CompletedTask); }); chain = await _blockchainService.GetChainAsync(); chain.BestChainHash.ShouldBe(blockWithTransactions.GetHash()); chain.BestChainHeight.ShouldBe(blockWithTransactions.Height); attachFinished.ShouldBeTrue(); var txs = await _blockchainService.GetTransactionsAsync(transactions.Select(t => t.GetHash())); txs.Count.ShouldBe(2); }
public async Task IterationSetup() { var chain = await _blockchainService.GetChainAsync(); var tokenAmount = TransactionCount / GroupCount; (_prepareTransactions, _keyPairs) = await _osTestHelper.PrepareTokenForParallel(GroupCount, tokenAmount); _block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, _prepareTransactions); await _blockExecutingService.ExecuteBlockAsync(_block.Header, _prepareTransactions); await _osTestHelper.BroadcastTransactions(_prepareTransactions); _block = (await _minerService.MineAsync(chain.BestChainHash, chain.BestChainHeight, TimestampHelper.GetUtcNow(), TimestampHelper.DurationFromSeconds(4))).Block; _systemTransactions = await _osTestHelper.GenerateTransferTransactions(1); _cancellableTransactions = await _osTestHelper.GenerateTransactionsWithoutConflictAsync(_keyPairs, tokenAmount); chain = await _blockchainService.GetChainAsync(); _block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, _systemTransactions.Concat(_cancellableTransactions)); }
public void Setup(BenchmarkContext context) { _blockchainService = GetRequiredService <IBlockchainService>(); _blockchainExecutingService = GetRequiredService <IBlockchainExecutingService>(); _chainManager = GetRequiredService <IChainManager>(); _osTestHelper = GetRequiredService <OSTestHelper>(); _counter = context.GetCounter("TestCounter"); AsyncHelper.RunSync(async() => { var chain = await _blockchainService.GetChainAsync(); var transactions = await _osTestHelper.GenerateTransferTransactions(1000); _block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, transactions); await _blockchainService.AddTransactionsAsync(transactions); await _blockchainService.AddBlockAsync(_block); chain = await _blockchainService.GetChainAsync(); await _blockchainService.AttachBlockToChainAsync(chain, _block); }); }
public async Task GlobalSetup() { _chains = GetRequiredService <IBlockchainStore <Chain> >(); _chainStateInfoCollection = GetRequiredService <IStateStore <ChainStateInfo> >(); _blockchainStateService = GetRequiredService <IBlockchainStateService>(); _blockStateSetManger = GetRequiredService <IBlockStateSetManger>(); _blockchainService = GetRequiredService <IBlockchainService>(); _osTestHelper = GetRequiredService <OSTestHelper>(); _chainManager = GetRequiredService <IChainManager>(); _blockManager = GetRequiredService <IBlockManager>(); _transactionManager = GetRequiredService <ITransactionManager>(); _transactionPoolService = GetRequiredService <ITransactionPoolService>(); _blockStateSets = new List <BlockStateSet>(); _blocks = new List <Block>(); _chain = await _blockchainService.GetChainAsync(); var blockHash = _chain.BestChainHash; while (true) { var blockState = await _blockStateSetManger.GetBlockStateSetAsync(blockHash); _blockStateSets.Add(blockState); var blockHeader = await _blockchainService.GetBlockHeaderByHashAsync(blockHash); blockHash = blockHeader.PreviousBlockHash; if (blockHash == _chain.LastIrreversibleBlockHash) { break; } } await _blockchainStateService.MergeBlockStateAsync(_chain.BestChainHeight, _chain.BestChainHash); for (var i = 0; i < BlockCount; i++) { var transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); await _osTestHelper.BroadcastTransactions(transactions); var block = await _osTestHelper.MinedOneBlock(); _blocks.Add(block); var blockState = await _blockStateSetManger.GetBlockStateSetAsync(block.GetHash()); _blockStateSets.Add(blockState); } var chain = await _blockchainService.GetChainAsync(); await _chainManager.SetIrreversibleBlockAsync(chain, chain.BestChainHash); _chainStateInfo = await _chainStateInfoCollection.GetAsync(chain.Id.ToStorageKey()); }
public async Task IterationSetup() { var chain = await _blockchainService.GetChainAsync(); _transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); _block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, _transactions); }
public async Task BroadcastBlockWithTxs_ShouldAddToBlockCache() { var peer = _peerPool.GetPeers(true).First(); var pubkey = peer.Info.Pubkey; var metadata = new Metadata { { GrpcConstants.PubkeyMetadataKey, pubkey } }; var block = _osTestHelper.GenerateBlockWithTransactions(Hash.FromString("block1"), 1, (await _osTestHelper.GenerateTransferTransactions(1)).ToList()); var requestStream = new TestAsyncStreamReader <BlockWithTransactions>(new List <BlockWithTransactions> { block }); await _serverService.BlockBroadcastStream(requestStream, BuildServerCallContext(metadata)); peer.TryAddKnownBlock(block.GetHash()).ShouldBeFalse(); }
public async Task IterationSetup() { var transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); await _blockchainService.AddTransactionsAsync(transactions); _block = _osTestHelper.GenerateBlock(_chain.BestChainHash, _chain.BestChainHeight, transactions); await _blockchainService.AddBlockAsync(_block); }
public void Setup(BenchmarkContext context) { _osTestHelper = GetRequiredService <OSTestHelper>(); _txHub = GetRequiredService <ITxHub>(); _counter = context.GetCounter("TestCounter"); AsyncHelper.RunSync(async() => { _transactions = await _osTestHelper.GenerateTransferTransactions(1000); }); }
public async Task ValidateBlockBeforeAttach_Success() { var chain = await _blockchainService.GetChainAsync(); var transactions = await _osTestHelper.GenerateTransferTransactions(3); var block = _osTestHelper.GenerateBlockWithTransactions(chain.BestChainHash, chain.BestChainHeight, transactions); var result = await _blockSyncValidationService.ValidateBlockBeforeAttachAsync(block); result.ShouldBeTrue(); }
public void Setup(BenchmarkContext context) { _blockchainService = GetRequiredService <IBlockchainService>(); _blockExecutingService = GetRequiredService <IBlockExecutingService>(); _osTestHelper = GetRequiredService <OSTestHelper>(); _counter = context.GetCounter("TestCounter"); AsyncHelper.RunSync(async() => { var chain = await _blockchainService.GetChainAsync(); _transactions = await _osTestHelper.GenerateTransferTransactions(1000); _block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, _transactions); }); }
public void Setup(BenchmarkContext context) { _blockchainService = GetRequiredService <IBlockchainService>(); _osTestHelper = GetRequiredService <OSTestHelper>(); _minerService = GetRequiredService <IMinerService>(); _txHub = GetRequiredService <ITxHub>(); _blockAttachService = GetRequiredService <IBlockAttachService>(); _counter = context.GetCounter("TestCounter"); AsyncHelper.RunSync(async() => { var transactions = await _osTestHelper.GenerateTransferTransactions(1000); await _osTestHelper.BroadcastTransactions(transactions); }); }
public async Task BlockBroadcastStream_UnknownPeer_Test() { var metadata = new Metadata { { GrpcConstants.PubkeyMetadataKey, "UnknownPeerPubkey" } }; var block = _osTestHelper.GenerateBlockWithTransactions(HashHelper.ComputeFrom("block1"), 1, (await _osTestHelper.GenerateTransferTransactions(1)).ToList()); var requestStream = new TestAsyncStreamReader <BlockWithTransactions>(new List <BlockWithTransactions> { block }); await _serverService.BlockBroadcastStream(requestStream, BuildServerCallContext(metadata)) .ShouldThrowAsync <RpcException>(); }
public async Task SendTransactionAsync_Success() { TransactionsReceivedEvent received = null; _eventBus.Subscribe <TransactionsReceivedEvent>(t => { received = t; return(Task.CompletedTask); }); var transactions = await _osTestHelper.GenerateTransferTransactions(1); await _grpcPeer.SendTransactionAsync(transactions.First()); received.ShouldNotBeNull(); received.Transactions.Count().ShouldBe(1); received.Transactions.First().From.ShouldBe(transactions.First().From); }
public async Task IterationSetup() { var chain = await _blockchainService.GetChainAsync(); _block = new Block { Header = new BlockHeader { ChainId = chain.Id, Height = chain.BestChainHeight + 1, PreviousBlockHash = chain.BestChainHash, Time = Timestamp.FromDateTime(DateTime.UtcNow) }, Body = new BlockBody() }; _transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); }
public void Setup(BenchmarkContext context) { _blockchainStateService = GetRequiredService <IBlockchainStateService>(); _blockchainService = GetRequiredService <IBlockchainService>(); _osTestHelper = GetRequiredService <OSTestHelper>(); _chainManager = GetRequiredService <IChainManager>(); _counter = context.GetCounter("TestCounter"); AsyncHelper.RunSync(async() => { var transactions = await _osTestHelper.GenerateTransferTransactions(1000); await _osTestHelper.BroadcastTransactions(transactions); await _osTestHelper.MinedOneBlock(); var chain = await _blockchainService.GetChainAsync(); await _chainManager.SetIrreversibleBlockAsync(chain, chain.BestChainHash); }); }
public void Setup(BenchmarkContext context) { _osTestHelper = GetRequiredService <OSTestHelper>(); _txHub = GetRequiredService <ITxHub>(); _blockchainService = GetRequiredService <IBlockchainService>(); _counter = context.GetCounter("TestCounter"); AsyncHelper.RunSync(async() => { var transactions = await _osTestHelper.GenerateTransferTransactions(1000); await _txHub.HandleTransactionsReceivedAsync(new TransactionsReceivedEvent { Transactions = transactions }); await _osTestHelper.MinedOneBlock(); }); }
public async Task BroadcastBlockWithTxs_FromStream_Test() { var received = new List <BlockReceivedEvent>(); _eventBus.Subscribe <BlockReceivedEvent>(a => { received.Add(a); return(Task.CompletedTask); }); var blocks = new List <BlockWithTransactions>(); blocks.Add(_osTestHelper.GenerateBlockWithTransactions(Hash.FromString("block1"), 1, (await _osTestHelper.GenerateTransferTransactions(1)).ToList())); blocks.Add(_osTestHelper.GenerateBlockWithTransactions(Hash.FromString("block2"), 2, (await _osTestHelper.GenerateTransferTransactions(2)).ToList())); blocks.Add(_osTestHelper.GenerateBlockWithTransactions(Hash.FromString("block3"), 3, (await _osTestHelper.GenerateTransferTransactions(3)).ToList())); var context = BuildServerCallContext(); var requestStream = new TestAsyncStreamReader <BlockWithTransactions>(blocks.ToArray()); var result = await _service.BlockBroadcastStream(requestStream, context); result.ShouldBe(new VoidReply()); received.Count.ShouldBe(3); }
public async Task IterationSetup() { _transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); await _osTestHelper.BroadcastTransactions(_transactions); }