Skip to content

Commit

Permalink
Merge pull request #2337 from Taraxa-project/network-test-segfault
Browse files Browse the repository at this point in the history
chore: fix segfault on network test
  • Loading branch information
MatusKysel authored Feb 27, 2023
2 parents 9971877 + c3816ec commit 2460587
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TransactionPacketHandler final : public PacketHandler {
* @param transactions serialized transactions
*
*/
void sendTransactions(std::shared_ptr<TaraxaPeer> const& peer,
void sendTransactions(std::shared_ptr<TaraxaPeer> peer,
std::vector<std::shared_ptr<Transaction>>&& transactions);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ void TransactionPacketHandler::periodicSendTransactions(SharedTransactions &&tra
}
}

void TransactionPacketHandler::sendTransactions(std::shared_ptr<TaraxaPeer> const &peer,
void TransactionPacketHandler::sendTransactions(std::shared_ptr<TaraxaPeer> peer,
std::vector<std::shared_ptr<Transaction>> &&transactions) {
if (!peer) return;
const auto peer_id = peer->getId();
LOG(log_tr_) << "sendTransactions " << transactions.size() << " to " << peer_id;

Expand Down
11 changes: 7 additions & 4 deletions tests/network_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ TEST_F(NetworkTest, transfer_transaction) {
nw1->start();
nw2->start();

EXPECT_HAPPENS({10s, 200ms}, [&](auto& ctx) {
EXPECT_HAPPENS({20s, 100ms}, [&](auto& ctx) {
nw1->setPendingPeersToReady();
nw2->setPendingPeersToReady();
WAIT_EXPECT_EQ(ctx, nw1->getPeerCount(), 1)
Expand All @@ -336,15 +336,18 @@ TEST_F(NetworkTest, transfer_transaction) {

auto nw1_nodeid = nw1->getNodeId();
auto nw2_nodeid = nw2->getNodeId();
EXPECT_NE(nw1->getPeer(nw2_nodeid), nullptr);
EXPECT_NE(nw2->getPeer(nw1_nodeid), nullptr);

const auto peer2 = nw1->getPeer(nw2_nodeid);
const auto peer1 = nw2->getPeer(nw1_nodeid);
EXPECT_NE(peer2, nullptr);
EXPECT_NE(peer1, nullptr);

SharedTransactions transactions;
transactions.push_back(g_signed_trx_samples[0]);
transactions.push_back(g_signed_trx_samples[1]);
transactions.push_back(g_signed_trx_samples[2]);

nw2->getSpecificHandler<network::tarcap::TransactionPacketHandler>()->sendTransactions(nw2->getPeer(nw1_nodeid),
nw2->getSpecificHandler<network::tarcap::TransactionPacketHandler>()->sendTransactions(peer1,
std::move(transactions));

EXPECT_HAPPENS({2s, 200ms}, [&](auto& ctx) { WAIT_EXPECT_EQ(ctx, nw1->getReceivedTransactionsCount(), 3) });
Expand Down

0 comments on commit 2460587

Please sign in to comment.