test: use MiniWallet for getblockstats test data generation #35177

pull AgusR7 wants to merge 1 commits into bitcoin:master from AgusR7:test/getblockstats-gen-miniwallet changing 2 files +188 −179
  1. AgusR7 commented at 2:55 AM on April 29, 2026: none

    Fixes #31838. Follow-up to #33184.

    This updates rpc_getblockstats.py --gen-test-data to generate its fixture data using MiniWallet instead of wallet RPCs.

    The normal test path still loads predefined block/stat data from rpc_getblockstats.json, so the test continues to compare getblockstats results against fixed expected data rather than against freshly computed RPC output.

    This keeps the generator independent of wallet behavior while preserving the existing regression-test structure.

    Tested on a wallet-disabled Linux build:

    • python3 /tmp/bitcoin-build/test/functional/rpc_getblockstats.py
    • python3 /tmp/bitcoin-build/test/functional/rpc_getblockstats.py --gen-test-data --test-data /tmp/rpc_getblockstats.generated.json
    • python3 /tmp/bitcoin-build/test/functional/rpc_getblockstats.py --test-data /tmp/rpc_getblockstats.generated.json
  2. DrahtBot added the label Tests on Apr 29, 2026
  3. DrahtBot commented at 2:55 AM on April 29, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35177.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK theStack
    Stale ACK mercie-ux

    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. maflcko commented at 7:18 AM on April 29, 2026: member

    In the pull description: You can start the test from the build dir, to pick up the ini automatically. That is python3 test/functional/rpc_getblockstats.py --configfile=/tmp/bitcoin-build/test/config.ini becomes python3 /tmp/bitcoin-build/test/functional/rpc_getblockstats.py etc.

  5. AgusR7 commented at 7:23 AM on April 29, 2026: none

    In the pull description: You can start the test from the build dir, to pick up the ini automatically. That is python3 test/functional/rpc_getblockstats.py --configfile=/tmp/bitcoin-build/test/config.ini becomes python3 /tmp/bitcoin-build/test/functional/rpc_getblockstats.py etc.

    Updated the test commands in the PR description, thanks.

  6. mercie-ux commented at 2:13 PM on May 5, 2026: none

    ACK d05f32e

    Confirmed minfee/maxfee coverage is meaningful — the fixture has a 31× spread (1000 sats vs 31200 sats).

  7. fanquake commented at 9:23 AM on May 22, 2026: member

    @theStack maybe you can review here?

  8. in test/functional/rpc_getblockstats.py:70 in d05f32e035
      80 | -        self.nodes[0].send(outputs={"data": "21"}, fee_rate=self.fee_rate)
      81 | -        self.sync_all()
      82 | -        self.generate(self.nodes[0], 1)
      83 | +        tx = wallet.create_self_transfer()
      84 | +        tx["tx"].vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b"\x21"])))
      85 | +        wallet.sendrawtransaction(from_node=node, tx_hex=tx["tx"].serialize().hex())
    


    theStack commented at 12:31 PM on May 23, 2026:

    nit: could probably simplify this by using MiniWallet's send_to method here as well


    AgusR7 commented at 12:21 AM on May 25, 2026:

    Done in the latest push. The OP_RETURN transaction now uses MiniWallet.send_to with the same higher fee to preserve minfee/maxfee coverage.

  9. theStack commented at 12:33 PM on May 23, 2026: contributor

    Concept ACK

    Can you rebase on master and re-generate the blocks? There were some recent changes in coinbase generation (https://github.com/bitcoin/bitcoin/pull/34860) that cause the data to be slightly different. (Of course it would also work with the PR as-is and the data will get out-dated at some point again, but better to start off synced, so contributors running --gen-test-data don't see a diff for now.)

  10. test: use MiniWallet for getblockstats test data generation b7cbd80428
  11. AgusR7 force-pushed on May 25, 2026
  12. AgusR7 commented at 12:22 AM on May 25, 2026: none

    Rebased on current master and regenerated rpc_getblockstats.json.

    Also updated the OP_RETURN transaction to use MiniWallet.send_to while preserving the minfee/maxfee coverage (1000/31200 sats).

  13. in test/functional/rpc_getblockstats.py:58 in b7cbd80428
      72 | +
      73 | +        wallet = MiniWallet(node)
      74 | +
      75 | +        self.generate(wallet, COINBASE_MATURITY + 1)
      76 | +
      77 | +        external_script = address_to_scriptpubkey(node.get_deterministic_priv_key().address)
    


    theStack commented at 2:23 PM on May 31, 2026:

    nit: now that the Bitcoin Core wallet isn't involved, could just send to an arbitrary address (of the same size), it doesn't have to be related to the test framework's deterministic private keys anymore

  14. in test/functional/rpc_getblockstats.py:192 in b7cbd80428
     186 | @@ -178,9 +187,9 @@ def run_test(self):
     187 |          self.log.info('Test tip including OP_RETURN')
     188 |          tip_stats = self.nodes[0].getblockstats(tip)
     189 |          assert_equal(tip_stats["utxo_increase"], 6)
     190 | -        assert_equal(tip_stats["utxo_size_inc"], 435)
     191 | +        assert_equal(tip_stats["utxo_size_inc"], 444)
     192 |          assert_equal(tip_stats["utxo_increase_actual"], 4)
     193 | -        assert_equal(tip_stats["utxo_size_inc_actual"], 296)
     194 | +        assert_equal(tip_stats["utxo_size_inc_actual"], 305)
    


    theStack commented at 2:28 PM on May 31, 2026:

    hint for other reviewers: the differences here seem to be caused by the fact that MiniWallet uses a different output script type than the code on master (P2TR vs. P2PKH, 34 vs. 25 bytes); the delta between utxo_size_inc and utxo_size_inc_actual, caused by the OP_RETURN outputs remains unchanged though

  15. theStack approved
  16. theStack commented at 2:40 PM on May 31, 2026: contributor

    ACK b7cbd804284bb70f40c5beebf8d1d3ff614ae406

    Thanks for following up! Verified that this PR fixes #31838 and the test data generation works without wallet (i.e. -DENABLE_WALLET=OFF build). I guess with some more effort the tip_stats would yield the exact same than on master (see below), but I'm not sure if it matters all that much.


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-06-11 00:51 UTC

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