bitcoin/test/functional/data
Sjors Provoost 4c3c1f42cf
test: add block 2016 to mock mainnet
The next commit requires an additional mainnet block which changes the difficulty.

Also fix a few minor mistakes in the test (suite):
- rename the create_coinbase retarger_period argument to halving_period. Before bitcoin#31583 this was hardcoded for regtest where these values are the same.
- drop unused fees argument from mine helper

Finally the CPU miner instructions for generating the alternative mainnet chain are expanded.
2025-09-20 21:36:39 +02:00
..
util move-only util data to test/functional/data/util 2025-06-13 13:07:12 +02:00
README.md test: add block 2016 to mock mainnet 2025-09-20 21:36:39 +02:00
__init__.py lint: enable mypy checking for missing imports 2021-10-16 09:14:37 +08:00
invalid_txs.py scripted-diff: validation: rename mandatory errors into block errors 2025-08-13 11:05:54 -04:00
mainnet_alt.json test: add block 2016 to mock mainnet 2025-09-20 21:36:39 +02:00
rpc_bip67.json Test sortedmulti descriptor using BIP 67 tests 2019-10-08 13:56:56 -04:00
rpc_decodescript.json descriptor: InferScript, do not return top-level only func as sub descriptor 2023-07-20 11:04:52 -03:00
rpc_getblockstats.json test: Test exclusion of OP_RETURN from getblockstats 2022-10-23 01:33:41 +02:00
rpc_psbt.json tests: Add BIP 373 test vectors 2025-04-17 16:31:57 -07:00

README.md

Various test vectors

mainnet_alt.json

For easier testing the difficulty is maximally increased in the first (and only) retarget period, by producing blocks approximately 2 minutes apart.

The alternate mainnet chain was generated as follows:

  • use faketime to set node clock to 2 minutes after genesis block
  • mine a block using a CPU miner such as https://github.com/pooler/cpuminer
  • restart node with a faketime 2 minutes later
for i in {1..2016}
do
 t=$(( 1231006505 + $i * 120 ))
 faketime "`date -d @$t  +'%Y-%m-%d %H:%M:%S'`" \
 bitcoind -connect=0 -nocheckpoints -stopatheight=$i
done

The CPU miner is kept running as follows:

./minerd -u ... -p ... -o http://127.0.0.1:8332 --no-stratum \
        --coinbase-addr 1NQpH6Nf8QtR2HphLRcvuVqfhXBXsiWn8r \
        --algo sha256d --no-longpoll --scantime 3 --retry-pause 1

The payout address is derived from first BIP32 test vector master key:

pkh(xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi/44h/0h/0h/<0;1>/*)#fkjtr0yn

It uses pkh() because tr() outputs at low heights are not spendable (unexpected-witness).

This makes each block deterministic except for its timestamp and nonce, which are stored in mainnet_alt.json and used to reconstruct the chain without having to redo the proof-of-work.

The timestamp was not kept constant because at difficulty 1 it's not sufficient to only grind the nonce. Grinding the extra_nonce or version field instead would have required additional (stratum) software. It would also make it more complicated to reconstruct the blocks in this test.

The getblocktemplate RPC code needs to be patched to ignore not being connected to any peers, and to ignore the IBD status check.

On macOS use faketime "@$t" instead.