test: Add a new unit test for chain.cpp #25069

pull hunglun wants to merge 1 commits into bitcoin:master from hunglun:master changing 2 files +27 −0
  1. hunglun commented at 3:30 PM on May 5, 2022: none

    test: Add a new unit test for chain.cpp

  2. DrahtBot added the label Build system on May 5, 2022
  3. in src/test/chain_tests.cpp:15 in 25e08aa11e outdated
      10 | +
      11 | +BOOST_AUTO_TEST_CASE( get_median_time_past )
      12 | +{
      13 | +    CBlockIndex blocks[11];
      14 | +    blocks[0].nTime=0;
      15 | +    for (int i=1; i<11;i++)
    


    jonatack commented at 4:22 PM on May 5, 2022:
    • prefer prefix iterator per doc/developer-notes.md
        for (int i = 1; i < 11; ++i) {
    
    • please run clang-format on your changes
    -BOOST_AUTO_TEST_CASE( get_median_time_past )
    +BOOST_AUTO_TEST_CASE(get_median_time_past)
     {
         CBlockIndex blocks[11];
    -    blocks[0].nTime=0;
    -    for (int i=1; i<11;i++)
    -    {
    +    blocks[0].nTime = 0;
    +    for (int i = 1; i < 11; i++) {
             blocks[i].nTime = i;
    -        blocks[i].pprev = &blocks[i-1];
    +        blocks[i].pprev = &blocks[i - 1];
         }
         // block nTime already sorted in increasing order
    -    BOOST_CHECK( blocks[10].GetMedianTimePast() == blocks[5].nTime);
    +    BOOST_CHECK(blocks[10].GetMedianTimePast() == blocks[5].nTime);
     }
    

    hunglun commented at 9:44 AM on May 6, 2022:

    I followed your advice to check the unit test code coverage for chain.h. chain.h::ToString() and GetBlockHeader() are not covered by unit test.

    I would like to add new test cases about ToString and GetBlockHeader() to chain_tests.cpp

    I also checked existing tests about GetMedianPastTime. Some tests check that the MedianPastTime is within certain bounds; but none of the existing tests is very precise about the expected value of the median past time.

  4. jonatack commented at 4:29 PM on May 5, 2022: member

    Hi @hunglun, have you looked at the existing tests (i.e. git grep -ni GetMedianTimePast src/test/) and the coverage reports at https://marcofalke.github.io/btc_cov to see if there isn't already test coverage on this, and if not, whether it can be added into one of the existing test files? Also, it's best to squash your commits into a final form ready for review (see CONTRIBUTING.md). Thanks!

  5. test: add a new unit test file for chain.h and chain.cpp 654593dc47
  6. hunglun requested review from jonatack on May 6, 2022
  7. hunglun closed this on May 9, 2022

  8. jonatack commented at 4:48 PM on May 9, 2022: member

    @hunglun if you closed because review seemed slow, please don't be discouraged. It can take time to receive review.

  9. DrahtBot locked this on May 9, 2023
Contributors


jonatack


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-05-01 15:13 UTC

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