diff --git a/libraries/core_libs/network/include/network/tarcap/packets_handlers/transaction_packet_handler.hpp b/libraries/core_libs/network/include/network/tarcap/packets_handlers/transaction_packet_handler.hpp index d205ec2470..dd38d286fa 100644 --- a/libraries/core_libs/network/include/network/tarcap/packets_handlers/transaction_packet_handler.hpp +++ b/libraries/core_libs/network/include/network/tarcap/packets_handlers/transaction_packet_handler.hpp @@ -27,7 +27,7 @@ class TransactionPacketHandler final : public PacketHandler { * @param transactions serialized transactions * */ - void sendTransactions(std::shared_ptr const& peer, + void sendTransactions(std::shared_ptr peer, std::vector>&& transactions); /** diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/transaction_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/transaction_packet_handler.cpp index 0b7d5387fc..d106786a85 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/transaction_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/transaction_packet_handler.cpp @@ -159,8 +159,9 @@ void TransactionPacketHandler::periodicSendTransactions(SharedTransactions &&tra } } -void TransactionPacketHandler::sendTransactions(std::shared_ptr const &peer, +void TransactionPacketHandler::sendTransactions(std::shared_ptr peer, std::vector> &&transactions) { + if (!peer) return; const auto peer_id = peer->getId(); LOG(log_tr_) << "sendTransactions " << transactions.size() << " to " << peer_id; diff --git a/tests/network_test.cpp b/tests/network_test.cpp index efc4b92f99..4807599669 100644 --- a/tests/network_test.cpp +++ b/tests/network_test.cpp @@ -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) @@ -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()->sendTransactions(nw2->getPeer(nw1_nodeid), + nw2->getSpecificHandler()->sendTransactions(peer1, std::move(transactions)); EXPECT_HAPPENS({2s, 200ms}, [&](auto& ctx) { WAIT_EXPECT_EQ(ctx, nw1->getReceivedTransactionsCount(), 3) });