public async Task TestBigBlocks(double txsCount) { var node = NodeRepository.GetNodes().First(); var rpcClient = rpcClientFactoryMock.Create(node.Host, node.Port, node.Username, node.Password); var stream = new MemoryStream(Encoders.Hex.DecodeData(File.ReadAllText(@"Data/16mb_tx.txt"))); var bStream = new BitcoinStream(stream, false) { MaxArraySize = unchecked ((int)uint.MaxValue) }; var tx = Transaction.Create(Network.Main); tx.ReadWrite(bStream); var txId = tx.GetHash(int.MaxValue).ToString(); _ = await CreateAndInsertTxAsync(false, true, 2, new string[] { txId.ToString() }); List <Transaction> txs = new(); for (int i = 0; i < txsCount; i++) { txs.Add(tx); } (_, string blockHash) = await CreateAndPublishNewBlockWithTxs(rpcClient, null, txs.ToArray(), true, true); var block = await TxRepositoryPostgres.GetBestBlockAsync(); Assert.IsFalse(HelperTools.AreByteArraysEqual(block.BlockHash, new uint256(blockHash).ToBytes())); PublishBlockHashToEventBus(blockHash); WaitUntilEventBusIsIdle(); block = await TxRepositoryPostgres.GetBestBlockAsync(); Assert.IsTrue(HelperTools.AreByteArraysEqual(block.BlockHash, new uint256(blockHash).ToBytes())); Assert.AreEqual(0, (await TxRepositoryPostgres.GetUnparsedBlocksAsync()).Length); // check if block was correctly parsed var blockStream = await RpcClient.GetBlockAsStreamAsync(await RpcClient.GetBestBlockHashAsync()); var parsedBlock = HelperTools.ParseByteStreamToBlock(blockStream); Assert.AreEqual(txsCount + 1, parsedBlock.Transactions.Count); }
public virtual async Task TestSkipParsing() { var node = NodeRepository.GetNodes().First(); var rpcClient = (Mock.RpcClientMock)rpcClientFactoryMock.Create(node.Host, node.Port, node.Username, node.Password); long blockCount = await RpcClient.GetBlockCountAsync(); var blockStream = await RpcClient.GetBlockAsStreamAsync(await RpcClient.GetBestBlockHashAsync()); var firstBlock = HelperTools.ParseByteStreamToBlock(blockStream); rpcClientFactoryMock.AddKnownBlock(blockCount++, firstBlock.ToBytes()); var tx = Transaction.Parse(Tx1Hex, Network.Main); await CreateAndPublishNewBlock(rpcClient, null, tx, true); Assert.AreEqual(0, (await TxRepositoryPostgres.GetUnparsedBlocksAsync()).Length); var block = await TxRepositoryPostgres.GetBestBlockAsync(); // we publish same NewBlockAvailableInDB as before var block2Parse = block; EventBus.Publish(new NewBlockAvailableInDB { BlockDBInternalId = block2Parse.BlockInternalId, BlockHash = new uint256(block2Parse.BlockHash).ToString() }); WaitUntilEventBusIsIdle(); // best block must stay the same, since parsing was skipped var blockAfterRepublish = await TxRepositoryPostgres.GetBestBlockAsync(); Assert.AreEqual(block.BlockInternalId, blockAfterRepublish.BlockInternalId); Assert.AreEqual(block.ParsedForMerkleAt, blockAfterRepublish.ParsedForMerkleAt); Assert.AreEqual(block.ParsedForDSAt, blockAfterRepublish.ParsedForDSAt); }