test: Add ParseMoney and ParseScript tests #23185

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2110-ToIntegral changing 3 files +69 −1
  1. MarcoFalke commented at 12:16 PM on October 5, 2021: member

    Add missing tests

  2. practicalswift commented at 12:26 PM on October 5, 2021: contributor

    Concept ACK

  3. DrahtBot added the label Build system on Oct 5, 2021
  4. MarcoFalke removed the label Build system on Oct 5, 2021
  5. MarcoFalke added the label Tests on Oct 5, 2021
  6. shaavan commented at 4:34 PM on October 5, 2021: contributor

    Concept ACK

    The new tests look good and logically suffices with the code of both the functions.

    I would like to propose some additions to the test. I am not yet proficient in writing tests for functions, so I might be wrong. I was understanding the ParseScript function’s code, and I think it would be good to do some additions to the testing of this function

    • BOOST_CHECK_EQUAL(HexStr(ParseScript("-9")), "59"); To test the line: (w->front() == '-' && w->size() > 1 && std::all_of(w->begin()+1, w->end(), ::IsDigit)))

    And,

    • BOOST_CHECK_EXCEPTION(ParseScript("11111111111111111111111"), std::runtime_error, HasReason("script parse error: decimal numeric value only allowed in the range -0xFFFFFFFF...0xFFFFFFFF")); To test the line: throw std::runtime_error("script parse error: decimal numeric value only allowed in the " "range -0xFFFFFFFF...0xFFFFFFFF");

    I hope my suggestion might help you improve upon the PR.

  7. in src/test/util_tests.cpp:1245 in fa326b1c7c outdated
    1238 | @@ -1239,6 +1239,11 @@ BOOST_AUTO_TEST_CASE(util_FormatMoney)
    1239 |  BOOST_AUTO_TEST_CASE(util_ParseMoney)
    1240 |  {
    1241 |      BOOST_CHECK_EQUAL(ParseMoney("0.0").value(), 0);
    1242 | +    BOOST_CHECK_EQUAL(ParseMoney(".").value(), 0);
    1243 | +    BOOST_CHECK_EQUAL(ParseMoney("0.").value(), 0);
    1244 | +    BOOST_CHECK_EQUAL(ParseMoney(".0").value(), 0);
    1245 | +    BOOST_CHECK_EQUAL(ParseMoney(".6789").value(), 6789'0000);
    


    practicalswift commented at 9:14 AM on October 6, 2021:
        BOOST_CHECK_EQUAL(ParseMoney(".6789").value(), 67'890'000);
    

    MarcoFalke commented at 9:20 AM on October 6, 2021:

    I am reading satoshis in groups of 4 :sweat_smile:


    jonatack commented at 9:31 AM on October 6, 2021:

    I am reading satoshis in groups of 4 :sweat_smile:

    Same!


    practicalswift commented at 9:46 AM on October 6, 2021:

    ¯_(ツ)_/¯

  8. practicalswift commented at 9:14 AM on October 6, 2021: contributor

    cr ACK fa326b1c7c82cdace70ad7b897e09ac2797a16a6

  9. in src/test/util_tests.cpp:1242 in fa326b1c7c outdated
    1238 | @@ -1239,6 +1239,11 @@ BOOST_AUTO_TEST_CASE(util_FormatMoney)
    1239 |  BOOST_AUTO_TEST_CASE(util_ParseMoney)
    1240 |  {
    1241 |      BOOST_CHECK_EQUAL(ParseMoney("0.0").value(), 0);
    1242 | +    BOOST_CHECK_EQUAL(ParseMoney(".").value(), 0);
    


    kiminuo commented at 10:02 AM on October 6, 2021:

    Maybe it would be worth checking two-dots cases like:

    ParseMoney("..")
    ParseMoney("0..0")
    

    From whitespace characters, I can see covered spaces but not tabulators (for example; pattern for TrimString is const std::string& pattern = " \f\n\r\t\v"). Maybe it would be good to add tests for this too.


    MarcoFalke commented at 11:01 AM on October 6, 2021:

    Thanks, done

  10. MarcoFalke force-pushed on Oct 6, 2021
  11. MarcoFalke commented at 11:01 AM on October 6, 2021: member

    Force pushed with ideas by @kiminuo and @shaavan. Thanks!

  12. DrahtBot commented at 11:56 AM on October 6, 2021: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #14752 (tests: Unit tests for IsPayToWitnessScriptHash and IsWitnessProgram by domob1812)

    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.

  13. shaavan commented at 12:57 PM on October 6, 2021: contributor

    Updates since my last review:

    1. New test lines have been added to the test of the ParseScript and ParseMoney functions.

    The new checks work correctly and compile successfully. I would like to suggest one more addition, which I somehow missed when I reviewed this PR earlier.

    In the ParseScript function:

    boost::algorithm::split(words, s, boost::algorithm::is_any_of(" \t\n"), boost::algorithm::token_compress_on);
    
        for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
        {
            …
        }
    

    That means it can work for multiple integer values given to it. But there is no explicit check for it. Some further checks like: BOOST_CHECK_EQUAL(HexStr(ParseScript("1 2")), "5152"); & BOOST_CHECK_EQUAL(HexStr(ParseScript("1 -9")), "510189");

    Should be added.

  14. test: Add ParseMoney and ParseScript tests fa1477e706
  15. MarcoFalke force-pushed on Oct 6, 2021
  16. MarcoFalke commented at 6:04 PM on October 6, 2021: member

    Thanks, done

  17. practicalswift commented at 7:43 AM on October 7, 2021: contributor

    cr ACK fa1477e706504f45a7a0f51b9f4b8014ee6a7d8d

  18. shaavan approved
  19. shaavan commented at 2:02 PM on October 7, 2021: contributor

    tACK fa1477e706504f45a7a0f51b9f4b8014ee6a7d8d

    Updates since my last review:

    1. Test for multiple integer input in one string is added to ParseScript tests.
  20. MarcoFalke merged this on Oct 8, 2021
  21. MarcoFalke closed this on Oct 8, 2021

  22. MarcoFalke deleted the branch on Oct 8, 2021
  23. sidhujag referenced this in commit 51fb415617 on Oct 8, 2021
  24. DrahtBot locked this on Oct 30, 2022

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

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