test: FakeNodeClock follow-ups in unit tests #35497

pull maflcko wants to merge 3 commits into bitcoin:master from maflcko:2606-tests-mocktime-refactor changing 9 files +38 −47
  1. maflcko commented at 5:48 PM on June 9, 2026: member

    This switches the remaining cases in the unit tests from SetMockTime to FakeNodeClock for clarity, as explained in the commit messages.

  2. DrahtBot added the label Tests on Jun 9, 2026
  3. DrahtBot commented at 5:48 PM on June 9, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35497.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK frankomosh, sedited, w0xlt

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35173 (util: shorten thread names to avoid Linux truncation by l0rinc)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. test: Add FakeNodeClock m_clock to TestChain100Setup
    Currently, all test cases using TestChain100Setup or a derived class
    like BuildChainTestingSetup are using mocktime by default due to the
    SetMockTime call in the TestChain100Setup ctor.
    
    This is confusing, because test cases using mocktime explicitly seem to
    imply that before they set the mocktime, real time was used.
    
    E.g. index_reorg_crash claimed in a comment to "Enable mock time".
    
    Fix this issue by adding a FakeNodeClock m_clock field to
    TestChain100Setup. Then, use the m_clock instead of explicit calls to
    SetMockTime or to a (now) shadowing local FakeNodeClock variable.
    fae9623c8d
  5. test: Use FakeNodeClock in more places
    The context is easier to reason about: E.g.,
    
    * in TestBasicMining it allows to drop manual SetMockTime(0) calls,
    * in connections_desirable_service_flags it allows to drop manual calls
      to SetMockTime(GetTime<std::chrono::seconds>() + _n_) and replace them
      by operator+=(_n_)
    * in wallet_tests it clarifies that the mocktime does not persist
      outside the AddTx function
    fa3716c439
  6. test: Use SteadyClockContext in pcp_tests
    This is easier to reason about, because it will automatically take care
    of properly setting INITIAL_MOCK_TIME in the ctor. Also, it allows to
    drop the ElapseTime and replace it with a call to operator+=()
    fa03852e9c
  7. maflcko force-pushed on Jun 9, 2026
  8. DrahtBot added the label CI failed on Jun 9, 2026
  9. DrahtBot removed the label CI failed on Jun 9, 2026
  10. in src/test/util/setup_common.h:230 in fa03852e9c
     226 | @@ -226,6 +227,7 @@ struct TestChain100Setup : public TestingSetup {
     227 |       */
     228 |      std::vector<CTransactionRef> PopulateMempool(FastRandomContext& det_rand, size_t num_transactions, bool submit);
     229 |  
     230 | +    FakeNodeClock m_clock{std::chrono::seconds{1598887952}};
    


    pablomartin4btc commented at 8:09 PM on June 9, 2026:

    Could any fixed timestamp work here? If not, adding a brief comment (and/ or a named constant) indicating the UTC date corresponding to 1598887952 might make the intent clearer.

        static constexpr auto TEST_TIME{std::chrono::seconds{1598887952}};
        FakeNodeClock m_clock{TEST_TIME};
    

    maflcko commented at 8:14 PM on June 9, 2026:

    The constant was added in 31d225274ff1a4b245aea0a69f0e5224b0e64ca2 and is the AuthorDate of that commit. Any other constant would probably also work.


    w0xlt commented at 9:55 PM on June 10, 2026:

    nit:

        FakeNodeClock m_clock{std::chrono::seconds{1598887952}}; // 2020-08-31, arbitrary
    
  11. frankomosh commented at 8:09 AM on June 10, 2026: contributor

    crACK fa03852e9cc4f5aa5f62f55f61986663286dddb7. This PR continues the FakeNodeClock migration from #35114.

  12. sedited approved
  13. sedited commented at 7:57 PM on June 10, 2026: contributor

    ACK fa03852e9cc4f5aa5f62f55f61986663286dddb7

  14. w0xlt commented at 9:56 PM on June 10, 2026: contributor

    ACK fa03852e9cc4f5aa5f62f55f61986663286dddb7

  15. sedited merged this on Jun 11, 2026
  16. sedited closed this on Jun 11, 2026

  17. maflcko deleted the branch on Jun 11, 2026

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: 2026-06-11 10:51 UTC

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