test: split `test_IsStandard` into independent test cases #36831

pull yuvicc wants to merge 3 commits into bitcoin:master from yuvicc:test-split-isstandard changing 1 files +168 −172
  1. yuvicc commented at 7:51 PM on November 10, 2026: contributor

    Part of #36692: This splits it into one test case per policy rule, each building its own transaction.

    The first commit replaces g_dust and g_bare_multi globals by a StandardPolicy struct, which defaults to the node defaults and is passed to each check, e.g. CheckIsStandard(t, {.max_op_return_relay = 83}), so no case changes policy for another.

    Second commit splits test_IsStandard into independent test cases i.e. one test case per policy rule. Each starts from its own standard transaction built by a new MakeTx helper. Since transactions are no longer carried over between checks, some values that are irrelevant to the rule under test differ from before.

    Third commit builds IsStandard test transactions declaratively. Each check constructs its transaction in one expression instead of mutating a shared one. CheckDustThreshold helper also deduplicates repeated "not dust at the threshold, dust one satoshi below" from test cases.

  2. DrahtBot added the label Tests on Nov 10, 2026
  3. DrahtBot commented at 7:51 PM on November 10, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK janb84, alexanderwiederin

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. yuvicc marked this as ready for review on Nov 11, 2026
  5. in src/test/transaction_tests.cpp:828 in d7c55fea54
     857 |  
     858 | -    // Disallowed version
     859 | -    t.version = std::numeric_limits<uint32_t>::max();
     860 | -    CheckIsNotStandard(t, "version");
     861 | +    // Check dust with odd relay fee to verify rounding:
     862 | +    // nDustThreshold = 182 * 3702 / 1000
    


    janb84 commented at 1:55 PM on November 11, 2026:

    NIT: rename nDustThreshold to snake_case

        const CAmount dust_threshold{182 * CFeeRate{DUST_RELAY_TX_FEE}.GetFeePerK() / 1000};
        BOOST_CHECK_EQUAL(dust_threshold, 546);
    
        // Add dust outputs up to allowed maximum, still standard!
        CMutableTransaction t{MakeTx({StandardOutput()})};
        for (size_t i{0}; i < MAX_DUST_OUTPUTS_PER_TX; ++i) {
            t.vout.emplace_back(0, t.vout[0].scriptPubKey);
            CheckIsStandard(t);
        }
    
        CheckDustThreshold(P2PKHScript(), dust_threshold);
    
        // Check dust with odd relay fee to verify rounding:
        // dust_threshold = 182 * 3702 / 1000
    
  6. in src/test/transaction_tests.cpp:812 in d7c55fea54
     831 | +BOOST_AUTO_TEST_CASE(test_IsStandard)
     832 | +{
     833 | +    CheckIsStandard(MakeTx({StandardOutput()}));
     834 | +}
     835 | +
     836 | +BOOST_AUTO_TEST_CASE(test_IsStandard_dust)
    


    janb84 commented at 1:58 PM on November 11, 2026:

    NIT (non-blocking): rename test from test_IsStandard_dust to test_IsStandard_dust_limit to be more clear that it is different from test_IsStandard_dust_thresholds

    BOOST_AUTO_TEST_CASE(test_IsStandard_dust_limit)
    
  7. in src/test/transaction_tests.cpp:862 in d7c55fea54 outdated
     915 |  
     916 |      // Custom 83-byte TxoutType::NULL_DATA (standard with max_op_return_relay of 83)
     917 | -    t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
     918 | -    BOOST_CHECK_EQUAL(83, t.vout[0].scriptPubKey.size());
     919 | -    CheckIsStandard(t, /*max_op_return_relay=*/83);
     920 | +    const CScript op_return_83{CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex};
    


    janb84 commented at 2:00 PM on November 11, 2026:

    on line 886 this is also a op_return80?

    const CScript op_return_83{CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex};
    
    vs 
    
     const CScript op_return_80{CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex};
    

    yuvicc commented at 5:41 AM on November 13, 2026:

    Good catch, they are the same script.

  8. janb84 commented at 2:01 PM on November 11, 2026: contributor

    Concept ACK

    Looks good, in my review I ran across a few questions / NITS

  9. yuvicc force-pushed on Nov 13, 2026
  10. yuvicc force-pushed on Nov 13, 2026
  11. DrahtBot added the label CI failed on Nov 13, 2026
  12. yuvicc commented at 5:44 AM on November 13, 2026: contributor

    Addressed nits from @janb84:

    • Renamed nDustThreshold to dust_threshold comment
    • Renamed test_IsStandard_dust to test_IsStandard_dust_limit
    • op_return_80 → op_return_83
    • op_return_40 → op_return_42
  13. DrahtBot removed the label CI failed on Nov 13, 2026
  14. janb84 commented at 12:54 PM on November 13, 2026: contributor

    ACK 20fecda22cc8dc396229377b6632dbba798aa3b0

    Thanks for taking my suggestions!

    I think it's ok but depending if you are nitpicking or how you are reading the commit message it can be misunderstood what is ment by "no check is added" while adding BOOST_CHECK_EQUAL(42, op_return_42.size()) and a second BOOST_CHECK_EQUAL(83, ...) . "no policy check" would remove the possible mis-understanding. Just to highlight it but i'm fine with it.

  15. maflcko commented at 1:53 PM on November 13, 2026: member

    How should this be reviewed? This looks like it is removing 200 lines of test code and adding 200 other lines.

    I understand that #36692 can be "fixed" with LLMs and that LLMs can "review" the "fix", but if this isn't trivial for humans to review, then I don't think it is worth it.

    If there are 50 pull requests (each for a file), and each takes 10 minutes to review, it will be ~10hours/person if everything goes well. Just raising this to focus on creating pulls that are trivial to review.

    I haven't looked closely, but maybe the globals removal like g_dust can be split off into a commit?

  16. test: pass policy to IsStandard checks instead of using globals
    The g_dust and g_bare_multi globals are replaced by a StandardPolicy
    struct, which defaults to the node defaults and is passed to each
    check.
    
    The CheckIsStandard and CheckIsNotStandard lambdas become free
    functions, so that they can be shared by the test cases split out in
    the next commit.
    
    No policy check is added or removed.
    9a630b9e45
  17. test: split test_IsStandard into independent test cases
    Split the test into one test case per policy rule.
    
    Each case starts from its own standard transaction, built by the new
    MakeTx helper, instead of from whatever the previous checks left
    behind.
    
    Values irrelevant to the rule under test may differ, since each case
    now starts from a fresh transaction.
    
    No policy check is added or removed.
    62fabe8cb9
  18. test: build IsStandard test transactions declaratively
    Construct the transaction for each check in one expression, instead of
    mutating a shared transaction between checks. The input of every check
    is now visible at the call site.
    
    The repeated "not dust at the threshold, dust one satoshi below" pairs
    are folded into a CheckDustThreshold helper.
    
    No policy check is added or removed. The size of the 42-byte OP_RETURN
    script, previously only implied by the hex literal, is now asserted
    alongside the 83-byte one.
    4d01b07cd5
  19. yuvicc force-pushed on Nov 14, 2026
  20. yuvicc commented at 5:40 AM on November 14, 2026: contributor

    Thanks for taking a look.

    How should this be reviewed? This looks like it is removing 200 lines of test code and adding 200 other lines. Just raising this to focus on creating pulls that are trivial to review.

    I have split the PR into three commits, which should make it easier to review. The first two commits should be easy and quick. The last one is not a mechanical change, and I am happy to drop it if reviewers feel it is better to keep the PR focused on the changes that are trivial to review.

    I haven't looked closely, but maybe the globals removal like g_dust can be split off into a commit?

    I've split the globals removal into its own commit. Also, I have added "no policy check" in the commit message.

  21. janb84 commented at 3:38 PM on November 16, 2026: contributor

    re- ACK4d01b07cd5896283571dcc11497b62110f62ba72

    changes since last ack; changes separated in several commits.

    Although I found it doable to review in one commit I have to confess that the separation makes it easier.

  22. alexanderwiederin approved
  23. alexanderwiederin commented at 9:22 AM on November 18, 2026: contributor

    ACK 4d01b07cd5896283571dcc11497b62110f62ba72


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-11-18 16:51 UTC

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