From 9a028f2781f520ea3e497da2e377fa8505dc1bf9 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Thu, 2 Mar 2023 16:55:33 +0100 Subject: [PATCH] chore: fix transfer_lot_of_blocks test --- tests/network_test.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/network_test.cpp b/tests/network_test.cpp index 4807599669..cd799a5a9a 100644 --- a/tests/network_test.cpp +++ b/tests/network_test.cpp @@ -73,8 +73,7 @@ TEST_F(NetworkTest, transfer_block) { ASSERT_EQ(1, num_received); } -// Test creates two Network setup and verifies sending blocks between is successfull -// This test can not work anymore as we are marking other nodes as malicous becasue of invalid dag blocks +// Test creates two Network setup and verifies sending blocks between is successful TEST_F(NetworkTest, transfer_lot_of_blocks) { auto node_cfgs = make_node_cfgs(2, 1, 20); auto nodes = launch_nodes(node_cfgs); @@ -91,9 +90,8 @@ TEST_F(NetworkTest, transfer_lot_of_blocks) { const auto nw1 = node1->getNetwork(); const auto nw2 = node2->getNetwork(); - const auto trxs = samples::createSignedTrxSamples(0, 1500, g_secret); + auto trxs = samples::createSignedTrxSamples(0, 1500, g_secret); const auto estimation = node1->getTransactionManager()->estimateTransactionGas(trxs[0], {}); - const std::vector estimations(trxs.size(), estimation); // node1 add one valid block const auto proposal_level = 1; @@ -106,7 +104,7 @@ TEST_F(NetworkTest, transfer_lot_of_blocks) { dev::bytes vdf_msg = DagManager::getVdfMessage(dag_genesis, {trxs[0]}); vdf.computeVdfSolution(sortition_params, vdf_msg, false); DagBlock blk(dag_genesis, proposal_level, {}, {trxs[0]->getHash()}, estimation, vdf, node1->getSecretKey()); - auto block_hash = blk.getHash(); + const auto block_hash = blk.getHash(); std::vector> dag_blocks; dag_blocks.emplace_back(std::make_shared(std::move(blk))); @@ -120,15 +118,20 @@ TEST_F(NetworkTest, transfer_lot_of_blocks) { trx_hashes.push_back(trx->getHash()); verified_transactions.push_back(trx); } - - for (int i = 0; i < 100; ++i) { + { const auto proposal_period = *db1->getProposalPeriodForDagLevel(proposal_level + 1); const auto period_block_hash = db1->getPeriodBlockHash(proposal_period); const auto sortition_params = dag_mgr1->sortitionParamsManager().getSortitionParams(proposal_period); - vdf_sortition::VdfSortition vdf(sortition_params, node1->getVrfSecretKey(), - VrfSortitionBase::makeVrfInput(proposal_level + 1, period_block_hash), 1, 1); - DagBlock blk(block_hash, proposal_level + 1, {}, {trxs[i + 1]->getHash()}, {}, vdf, node1->getSecretKey()); - dag_blocks.emplace_back(std::make_shared(blk)); + + for (int i = 0; i < 100; ++i) { + vdf_sortition::VdfSortition vdf(sortition_params, node1->getVrfSecretKey(), + VrfSortitionBase::makeVrfInput(proposal_level + 1, period_block_hash), 1, 1); + dev::bytes vdf_msg = DagManager::getVdfMessage(block_hash, {trxs[i + 1]}); + vdf.computeVdfSolution(sortition_params, vdf_msg, false); + DagBlock blk(block_hash, proposal_level + 1, {}, {trxs[i + 1]->getHash()}, estimation, vdf, + node1->getSecretKey()); + dag_blocks.emplace_back(std::make_shared(blk)); + } } for (auto trx : verified_transactions) @@ -138,16 +141,13 @@ TEST_F(NetworkTest, transfer_lot_of_blocks) { dag_mgr1->addDagBlock(DagBlock(*dag_blocks[i]), {trxs[i]}); } wait({1s, 200ms}, [&](auto& ctx) { WAIT_EXPECT_NE(ctx, dag_mgr1->getDagBlock(block_hash), nullptr) }); - - taraxa::thisThreadSleepForSeconds(1); const auto node1_period = node1->getPbftChain()->getPbftChainSize(); const auto node2_period = node2->getPbftChain()->getPbftChainSize(); std::cout << "node1 period " << node1_period << ", node2 period " << node2_period << std::endl; nw1->getSpecificHandler()->sendBlocks( - nw2->getNodeId(), std::move(dag_blocks), {}, node2_period, node1_period); - + nw2->getNodeId(), std::move(dag_blocks), std::move(trxs), node2_period, node1_period); std::cout << "Waiting Sync ..." << std::endl; - wait({30s, 200ms}, [&](auto& ctx) { WAIT_EXPECT_NE(ctx, dag_mgr2->getDagBlock(block_hash), nullptr) }); + wait({120s, 200ms}, [&](auto& ctx) { WAIT_EXPECT_NE(ctx, dag_mgr2->getDagBlock(block_hash), nullptr) }); } TEST_F(NetworkTest, update_peer_chainsize) {