test: Add a new unit test for chain.cpp
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-
hunglun commented at 3:30 PM on May 5, 2022: none
- DrahtBot added the label Build system on May 5, 2022
-
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.
jonatack commented at 4:29 PM on May 5, 2022: memberHi @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 (seeCONTRIBUTING.md). Thanks!test: add a new unit test file for chain.h and chain.cpp 654593dc47hunglun requested review from jonatack on May 6, 2022hunglun closed this on May 9, 2022DrahtBot locked this on May 9, 2023
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
More mirrored repositories can be found on mirror.b10c.me