test: Add more tests for the BIP21 implementation #27928

pull kiminuo wants to merge 1 commits into bitcoin:master from kiminuo:feature/2023-BIP21-URI-tests changing 1 files +26 −0
  1. kiminuo commented at 7:33 PM on June 21, 2023: contributor

    This PR is an attempt to make it clear how the current BIP21 implementation behaves in Bitcoin Core. Especially, I'm interested whether one can specify multiple amount (message, etc.) parameters.

    My primary end goal is to answer this question of mine but I figured that maybe it's worth a PR. If not, I'll close the PR.

  2. DrahtBot commented at 7:33 PM on June 21, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK MarcoFalke, kevkevinpal

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. Add more tests for the BIP21 implementation f1d807e383
  4. kiminuo force-pushed on Jun 21, 2023
  5. DrahtBot added the label CI failed on Jun 21, 2023
  6. kiminuo renamed this:
    Add more tests for the BIP21 implementation
    test: Add more tests for the BIP21 implementation
    on Jun 22, 2023
  7. maflcko commented at 8:56 AM on June 22, 2023: member

    lgtm ACK f1d807e383942ae20e080174d33ac17afd649351

  8. maflcko removed the label CI failed on Jun 22, 2023
  9. DrahtBot added the label Tests on Jun 22, 2023
  10. kevkevinpal commented at 6:44 PM on June 22, 2023: contributor

    ACK f1d807e

    you mentioned you wanted to test multiple message params but I'm only seeing you do multiple amount params

  11. kiminuo commented at 9:15 PM on June 22, 2023: contributor

    @kevkevinpal My original understanding was that having multiple amount parameters will end up with an error. However, it's clear from the implementation that it's not what is actually happening in Bitcoin Core. I'm happy that this PR can make it clear.

    I can add more tests to show that this actually happens for label and message as well if you like.

    One reason why I'm a bit concerned about allowing amount multiple times in BIP21 (in actual implementations) is that one can try to use it to attempt to trick people. Say a Bitcoin wallet would trim a BIP21 URI like this:

    bitcoin:<address>?amount=0.01&message=someLongText&amount=1.0

    to something like

    bitcoin:<address>?amount=0.01&message=someLongText...

    User looks at that, it looks OK, clicks a confirm button fast ... Obviously, the mentioned example is pretty lame, and I believe/hope it's an artificial example that cannot happen in practice. Though, it feels like this is asking for these kinds of clever/social attempts to trick people. I'm not exactly sure if there is a pro for supporting multiple amount parameters (or message, and label).

    If there is something I'm missing, please let me know.

  12. ryanofsky merged this on Jul 19, 2023
  13. ryanofsky closed this on Jul 19, 2023

  14. in src/qt/test/uritests.cpp:91 in f1d807e383
      86 | +    // Escape sequences are not supported.
      87 | +    uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=%3F"));
      88 | +    QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
      89 | +    QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
      90 | +    QVERIFY(rv.amount == 10000000000LL);
      91 | +    QVERIFY(rv.label == QString("%3F"));
    


    kristapsk commented at 10:05 PM on July 19, 2023:

    It this correct? I mean, according to BIP21, not existing code. BIP21 specifies it as "valid characters of an RFC 3986 URI query component, excluding the "=" and "&" characters" and %xx should be decoded according to RFC 3986. That should be only way how to present "=" and "&" in message and label.

  15. in src/qt/test/uritests.cpp:77 in f1d807e383
      72 | +    QVERIFY(rv.amount == 20000000000LL);
      73 | +    QVERIFY(rv.label == QString("Wikipedia Example"));
      74 | +
      75 | +    // The first amount value is correct. However, the second amount value is not valid. Hence, the URI is not valid.
      76 | +    uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&amount=1,000&label=Wikipedia Example"));
      77 | +    QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
    


    kristapsk commented at 10:22 PM on July 19, 2023:

    Guess should also check the case when the first amount value is invalid, second valid. Should it be considered valid or invalid URI then?

  16. kiminuo deleted the branch on Jul 20, 2023
  17. sidhujag referenced this in commit 15fae78a61 on Jul 21, 2023
  18. kristapsk referenced this in commit 3e4a69b86a on Aug 19, 2023
  19. bitcoin locked this on Jul 19, 2024

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-27 03:14 UTC

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