test: add unittests for CheckProofOfWork #16931

pull soroosh-sdi wants to merge 1 commits into bitcoin:master from soroosh-sdi:21-09-19-pow-unit-tests changing 1 files +54 −0
  1. soroosh-sdi commented at 6:17 PM on September 21, 2019: contributor

    following situations are covered:

    • negative target
    • overflow target
    • target easier then powLimit
    • invalid hash (hash > target)

    Signed-off-by: soroosh-sdi soroosh.sardari@gmail.com

  2. DrahtBot added the label Tests on Sep 21, 2019
  3. in src/test/pow_tests.cpp:73 in f403368ff8 outdated
      68 | +    nBits = UintToArith256(chainParams->GetConsensus().powLimit).GetCompact(true);
      69 | +    hash.SetHex("0x1");
      70 | +    BOOST_CHECK(!CheckProofOfWork(hash, nBits, chainParams->GetConsensus()));
      71 | +}
      72 | +
      73 | +
    


    promag commented at 9:16 AM on September 22, 2019:

    nit, remove.

  4. promag commented at 9:17 AM on September 22, 2019: member

    Concept ACK.

    Looks like you could also add test for when bnTarget == 0?

  5. soroosh-sdi force-pushed on Sep 22, 2019
  6. in src/test/pow_tests.cpp:111 in 9ede4535c5 outdated
     106 | +BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
     107 | +{
     108 | +    const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
     109 | +    uint256 hash;
     110 | +    unsigned int nBits;
     111 | +    arith_uint256 hash_arith;
    


    promag commented at 9:13 PM on September 22, 2019:

    arith_uint256 hash_arith{0} and remove line below.


    soroosh-sdi commented at 10:50 AM on September 23, 2019:

    please check it again @promag

  7. soroosh-sdi force-pushed on Sep 23, 2019
  8. soroosh-sdi requested review from promag on Sep 27, 2019
  9. promag commented at 6:59 AM on September 27, 2019: member

    ACK 1d65373e5563ae6ea39dac7bfbe62eeed55b1e76, just code review.

    nit, I'd prefer the following regardless of surrounding tests:

    const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
    
  10. soroosh-sdi commented at 10:27 AM on September 27, 2019: contributor

    ACK 1d65373, just code review.

    nit, I'd prefer the following regardless of surrounding tests:

    const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
    

    I agree, in next commit I will change as you said; and in another merge request I will change other tests as you suggested.

  11. soroosh-sdi force-pushed on Sep 27, 2019
  12. in src/test/pow_tests.cpp:124 in ff34d112e9 outdated
     120 | +}
     121 | +
     122 |  BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
     123 |  {
     124 | -    const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
     125 | +    const auto consenses = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();;
    


    promag commented at 11:15 AM on September 27, 2019:

    Please don't change existing tests here, there's no real benefit.

  13. in src/test/pow_tests.cpp:66 in ff34d112e9 outdated
      59 | @@ -60,14 +60,73 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
      60 |      BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00e1fdU);
      61 |  }
      62 |  
      63 | +BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
      64 | +{
      65 | +    const auto consenses = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
      66 | +    ;
    


    promag commented at 11:15 AM on September 27, 2019:

    👀 Also typo in "consenses"


    soroosh-sdi commented at 12:43 PM on September 27, 2019:

    Also typo in "consenses"

    That was bad :) pushed another commit.

  14. test: add unittests for CheckProofOfWork
    following situations are covered:
    - negative target
    - overflow target
    - target easier then powLimit
    - invalid hash (hash > target)
    - zero target
    
    Signed-off-by: soroosh-sdi <soroosh.sardari@gmail.com>
    0cc7dd74e0
  15. soroosh-sdi force-pushed on Sep 27, 2019
  16. soroosh-sdi requested review from promag on Sep 28, 2019
  17. promag commented at 6:55 AM on September 28, 2019: member

    ACK 0cc7dd74e0af735dddf7e786f4ed136c382a4ad5, just read the code.

  18. promag approved
  19. laanwj commented at 9:42 AM on September 30, 2019: member

    thanks for adding tests ! :tada: ACK 0cc7dd74e0af735dddf7e786f4ed136c382a4ad5

  20. laanwj referenced this in commit b658ca71b3 on Sep 30, 2019
  21. laanwj merged this on Sep 30, 2019
  22. laanwj closed this on Sep 30, 2019

  23. sidhujag referenced this in commit ec048afcdb on Oct 2, 2019
  24. jasonbcox referenced this in commit a87c1a8f23 on Oct 20, 2020
  25. PastaPastaPasta referenced this in commit 5a403adb9e on Jun 27, 2021
  26. PastaPastaPasta referenced this in commit d267e1c5fb on Jun 28, 2021
  27. PastaPastaPasta referenced this in commit 2f8c4239a9 on Jun 29, 2021
  28. PastaPastaPasta referenced this in commit 5aa7eab3b0 on Jul 1, 2021
  29. PastaPastaPasta referenced this in commit afab941cea on Jul 1, 2021
  30. PastaPastaPasta referenced this in commit 3ed8eba559 on Jul 12, 2021
  31. PastaPastaPasta referenced this in commit 7364529556 on Jul 13, 2021
  32. PastaPastaPasta referenced this in commit 732b4bcc63 on Jul 13, 2021
  33. DrahtBot locked this on Dec 16, 2021
Labels

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-04-28 06:14 UTC

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