Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/test/p2p_messaging_tests.cpp
| Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(process_version_msg) { | ||||
| CService addr_to = vAddr[0]; | CService addr_to = vAddr[0]; | ||||
| uint64_t addr_to_services = vAddr[0].nServices; | uint64_t addr_to_services = vAddr[0].nServices; | ||||
| CService addr_from; | CService addr_from; | ||||
| uint64_t nonce = 0; | uint64_t nonce = 0; | ||||
| std::string user_agent = "/Bitcoin ABC:0.0.0(seeder)/"; | std::string user_agent = "/Bitcoin ABC:0.0.0(seeder)/"; | ||||
| // Don't include the time in CAddress serialization. See D14753. | // Don't include the time in CAddress serialization. See D14753. | ||||
| versionMessage << INIT_PROTO_VERSION << serviceflags << GetTime() | versionMessage << INIT_PROTO_VERSION << serviceflags << GetTime() | ||||
| << addr_to_services << addr_to << serviceflags << addr_from | << addr_to_services << WithParams(CNetAddr::V1, addr_to) | ||||
| << serviceflags << WithParams(CNetAddr::V1, addr_from) | |||||
| << nonce << user_agent << GetRequireHeight(); | << nonce << user_agent << GetRequireHeight(); | ||||
| // Verify the version is set as the initial value | // Verify the version is set as the initial value | ||||
| BOOST_CHECK_EQUAL(testNode->CSeederNode::GetClientVersion(), | BOOST_CHECK_EQUAL(testNode->CSeederNode::GetClientVersion(), | ||||
| SEEDER_INIT_VERSION); | SEEDER_INIT_VERSION); | ||||
| testNode->TestProcessMessage(NetMsgType::VERSION, versionMessage, | testNode->TestProcessMessage(NetMsgType::VERSION, versionMessage, | ||||
| PeerMessagingState::AwaitingMessages); | PeerMessagingState::AwaitingMessages); | ||||
| // Verify the version has been updated | // Verify the version has been updated | ||||
| Show All 28 Lines | BOOST_FIXTURE_TEST_CASE(process_verack_msg, MainNetSeederTestingSetup) { | ||||
| BOOST_CHECK(locator.vHave == expectedLocator); | BOOST_CHECK(locator.vHave == expectedLocator); | ||||
| BOOST_CHECK(hashStop == uint256()); | BOOST_CHECK(hashStop == uint256()); | ||||
| } | } | ||||
| static CDataStream CreateAddrMessage(std::vector<CAddress> sendAddrs, | static CDataStream CreateAddrMessage(std::vector<CAddress> sendAddrs, | ||||
| uint32_t nVersion = INIT_PROTO_VERSION) { | uint32_t nVersion = INIT_PROTO_VERSION) { | ||||
| CDataStream payload(SER_NETWORK, 0); | CDataStream payload(SER_NETWORK, 0); | ||||
| payload.SetVersion(nVersion); | payload.SetVersion(nVersion); | ||||
| payload << sendAddrs; | payload << WithParams(CAddress::V1_NETWORK, sendAddrs); | ||||
| return payload; | return payload; | ||||
| } | } | ||||
| BOOST_FIXTURE_TEST_CASE(process_addr_msg, MainNetSeederTestingSetup) { | BOOST_FIXTURE_TEST_CASE(process_addr_msg, MainNetSeederTestingSetup) { | ||||
| // First, must send headers to satisfy the criteria that both ADDR/ADDRV2 | // First, must send headers to satisfy the criteria that both ADDR/ADDRV2 | ||||
| // *and* HEADERS must arrive before TestNode can advance to the Finished | // *and* HEADERS must arrive before TestNode can advance to the Finished | ||||
| // state | // state | ||||
| BlockHash recentCheckpoint = | BlockHash recentCheckpoint = | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(good_checkpoint, MainNetSeederTestingSetup) { | ||||
| // Process a HEADERS message with a first header that immediately follows | // Process a HEADERS message with a first header that immediately follows | ||||
| // our most recent checkpoint, check that it is accepted. | // our most recent checkpoint, check that it is accepted. | ||||
| auto header = CBlockHeader{}; | auto header = CBlockHeader{}; | ||||
| header.hashPrevBlock = recentCheckpoint; | header.hashPrevBlock = recentCheckpoint; | ||||
| testNode->setStartingHeight(recentCheckpointHeight + 1); | testNode->setStartingHeight(recentCheckpointHeight + 1); | ||||
| CDataStream headersOnCorrectChain(SER_NETWORK, 0); | CDataStream headersOnCorrectChain(SER_NETWORK, 0); | ||||
| headersOnCorrectChain.SetVersion(INIT_PROTO_VERSION); | headersOnCorrectChain.SetVersion(INIT_PROTO_VERSION); | ||||
| // The following .reserve() call is a workaround for a spurious | |||||
| // [-Werror=stringop-overflow=] warning in gcc <= 12.2. | |||||
| // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100366#c20 | |||||
| headersOnCorrectChain.reserve(4); | |||||
| WriteCompactSize(headersOnCorrectChain, 1); | WriteCompactSize(headersOnCorrectChain, 1); | ||||
| headersOnCorrectChain << header; | headersOnCorrectChain << header; | ||||
| testNode->TestProcessMessage(NetMsgType::HEADERS, headersOnCorrectChain, | testNode->TestProcessMessage(NetMsgType::HEADERS, headersOnCorrectChain, | ||||
| PeerMessagingState::AwaitingMessages); | PeerMessagingState::AwaitingMessages); | ||||
| BOOST_CHECK_EQUAL(testNode->GetBan(), 0); | BOOST_CHECK_EQUAL(testNode->GetBan(), 0); | ||||
| BOOST_CHECK(testNode->IsCheckpointVerified()); | BOOST_CHECK(testNode->IsCheckpointVerified()); | ||||
| } | } | ||||
| Show All 34 Lines | |||||