static bool KeysEqual(SecurityKey k1, SecurityKey k2) { return (k1 != null && k2 != null && k1.GetType() == k2.GetType() && k1 is SymmetricSecurityKey k1s && k2 is SymmetricSecurityKey k2s && HelperTools.AreByteArraysEqual(k1s.Key, k2s.Key)); }
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); }