Skip to content

Commit

Permalink
Merge pull request #2365 from Taraxa-project/fix-network-test
Browse files Browse the repository at this point in the history
chore: fix transfer_lot_of_blocks test
  • Loading branch information
MatusKysel authored Mar 3, 2023
2 parents db82bd0 + 2732aac commit d428742
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tests/network_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<uint64_t> estimations(trxs.size(), estimation);

// node1 add one valid block
const auto proposal_level = 1;
Expand All @@ -106,9 +104,9 @@ 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();
dag_mgr1->addDagBlock(std::move(blk), {trxs[0]});
std::vector<std::shared_ptr<DagBlock>> dag_blocks;
dag_blocks.emplace_back(std::make_shared<DagBlock>(std::move(blk)));

// creating lot of blocks just for size
std::vector<trx_hash_t> trx_hashes;
Expand All @@ -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<DagBlock>(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<DagBlock>(blk));
}
}

for (auto trx : verified_transactions)
Expand All @@ -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<network::tarcap::GetDagSyncPacketHandler>()->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) {
Expand Down

0 comments on commit d428742

Please sign in to comment.