Skip to content

Commit

Permalink
Merge bitcoin#28489: tests: fix incorrect assumption in v2transport_test
Browse files Browse the repository at this point in the history
3f4e1bb tests: fix incorrect assumption in v2transport_test (Pieter Wuille)

Pull request description:

  One part of the current `v2transport_test` introduced in bitcoin#28196 assumes that if a bit gets modified in a message, failure should instantly be detected after sending that message. This is not correct in case the length descriptor is modified, as that may cause the receiver to need more data first. Fix this by sending more messages until failure actually occurs.

  Discovered in bitcoin#27495 (comment).

ACKs for top commit:
  theStack:
    ACK 3f4e1bb

Tree-SHA512: faa90bf91996cbaaef62d764e746cb222eaf6796316b0d0e13709e528750b7c0ef09172f7fecfe814dbb8c136c5259f65ca1ac79318e6768a0bfc4e626a63249
  • Loading branch information
fanquake authored and Frank-GER committed Sep 18, 2023
1 parent 775a2bc commit d3181ea
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/test/net_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,11 +1358,19 @@ BOOST_AUTO_TEST_CASE(v2transport_test)
BOOST_CHECK(!(*ret)[1]);
BOOST_CHECK((*ret)[2] && (*ret)[2]->m_type == "tx" && Span{(*ret)[2]->m_recv} == MakeByteSpan(msg_data_2));

// Then send a message with a bit error, expecting failure.
// Then send a message with a bit error, expecting failure. It's possible this failure does
// not occur immediately (when the length descriptor was modified), but it should come
// eventually, and no messages can be delivered anymore.
tester.SendMessage("bad", msg_data_1);
tester.Damage();
ret = tester.Interact();
BOOST_CHECK(!ret);
while (true) {
ret = tester.Interact();
if (!ret) break; // failure
BOOST_CHECK(ret->size() == 0); // no message can be delivered
// Send another message.
auto msg_data_3 = g_insecure_rand_ctx.randbytes<uint8_t>(InsecureRandRange(10000));
tester.SendMessage(uint8_t(12), msg_data_3); // getheaders short id
}
}

// Normal scenario, with a transport in responder node.
Expand Down

0 comments on commit d3181ea

Please sign in to comment.