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 async Task GetBlockByHash_Test() { var block = new BlockWithTransactions { Header = _osTestHelper.GenerateBlock(HashHelper.ComputeFrom("PreBlockHash"), 100).Header }; var mockClient = new Mock <PeerService.PeerServiceClient>(); mockClient.Setup(c => c.RequestBlockAsync(It.IsAny <BlockRequest>(), It.IsAny <Metadata>(), null, CancellationToken.None)) .Returns(MockAsyncUnaryCall(new BlockReply { Block = block })); var grpcPeer = CreatePeer(mockClient.Object); var result = await grpcPeer.GetBlockByHashAsync(block.GetHash()); result.ShouldBe(block); var metrics = grpcPeer.GetRequestMetrics(); metrics["GetBlock"].Count.ShouldBe(1); metrics["GetBlock"][0].MethodName.ShouldContain("GetBlock"); metrics["GetBlock"][0].Info.ShouldContain("Block request for"); }
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 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 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(); _transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); _block = _osTestHelper.GenerateBlock(chain.BestChainHash, chain.BestChainHeight, _transactions); }
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) { _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 async Task LibAnnouncementBroadcastStream_Test() { var chain = await _blockchainService.GetChainAsync(); var irreversibleBlockHeight = (int)chain.LastIrreversibleBlockHeight; var bestBlockHeight = (int)chain.BestChainHeight; var requestLibAnnouncements = new List <LibAnnouncement>(); var preBlockHash = chain.LastIrreversibleBlockHash; var preBlockHeight = irreversibleBlockHeight; for (var i = irreversibleBlockHeight + 1; i <= bestBlockHeight; i++) { var libBlock = _osTestHelper.GenerateBlock(preBlockHash, preBlockHeight); requestLibAnnouncements.Add(new LibAnnouncement { LibHeight = preBlockHeight, LibHash = preBlockHash }); preBlockHash = libBlock.GetHash(); preBlockHeight++; } var requestStream = new TestAsyncStreamReader <LibAnnouncement>(requestLibAnnouncements); var pubKey = NetworkTestConstants.FakePubkey2; Metadata metadata = new Metadata { { GrpcConstants.PubkeyMetadataKey, pubKey } }; var context = BuildServerCallContext(metadata); var result = await _serverService.LibAnnouncementBroadcastStream(requestStream, context); result.ShouldBe(new VoidReply()); var peer = _peerPool.FindPeerByPublicKey(pubKey); var lastBlock = requestLibAnnouncements.Last(); peer.LastKnownLibHash.ShouldBe(lastBlock.LibHash); peer.LastKnownLibHeight.ShouldBe(lastBlock.LibHeight); }