test: add mocked Sock that can read/write custom data and/or CNetMessages #30205

pull vasild wants to merge 2 commits into bitcoin:master from vasild:DynSock changing 2 files +407 −74
  1. vasild commented at 3:49 pm on May 30, 2024: contributor

    Put the generic parts from StaticContentsSock into a separate class ZeroSock so that they can be reused in other mocked Sock implementations.

    Add a new DynSock whose Recv() and Send() methods can be controlled after the object is created. To achieve that, the caller/creator of DynSock provides to its constructor two pipes (FIFOs) - recv-pipe and send-pipe. Whatever data is written to recv-pipe is later received by DynSock::Recv() method and whatever data is written to the socket using DynSock::Send() can later be found in the send-pipe. For convenience there are also two methods to send and receive CNetMessages.


    This is used in #26812 (first two commits from that PR). Extracting as a separate PR suggested here: #30043 (review).

  2. test: put the generic parts from StaticContentsSock into a separate class
    This allows reusing them in other mocked implementations.
    
    Also move the implementation (method definitions) to
    `test/util/net.cpp` to make the header `test/util/net.h` easier to follow.
    e180405d99
  3. test: add a mocked Sock that allows inspecting what has been Send() to it
    And also allows gradually providing the data to be returned by `Recv()`
    and sending and receiving net messages (`CNetMessage`).
    06b21ab6cb
  4. DrahtBot commented at 3:49 pm on May 30, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  5. DrahtBot added the label Tests on May 30, 2024
  6. Sjors commented at 4:31 pm on May 30, 2024: member
    This seems very useful. I’ll try to use it for the (currently very brittle) Sv2Transport tests in #29432, and review it along the way.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-06-29 07:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me