From 62e6989bd41e2e81e453d7844ced9eccdecc5e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Sat, 29 Aug 2026 11:08:43 +0200 Subject: [PATCH] test: Give BlockHeader's scalars default initializers Six of them had none, so a default-initialized BlockchainTest carried whatever was on the stack. Nothing in production noticed, because the JSON loader fills every field, but a hand-built fixture did: the blockchain runner test reported a genesis block number of 100566652073168 and worked around it with value-initialization. state::BlockInfo, the type this parallels, initializes every scalar. --- test/unittests/blockchaintest_runner_test.cpp | 5 ++--- test/utils/blockchaintest.hpp | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/test/unittests/blockchaintest_runner_test.cpp b/test/unittests/blockchaintest_runner_test.cpp index 6a28ea1870..f16abd5ca9 100644 --- a/test/unittests/blockchaintest_runner_test.cpp +++ b/test/unittests/blockchaintest_runner_test.cpp @@ -23,10 +23,9 @@ constexpr auto GENESIS_HASH = 0x9e11_bytes32; constexpr int64_t GAS_LIMIT = 0x100000; /// A fixture with one block that validate_block() accepts, for a test to then break in one way. -/// BlockHeader has no default member initializers, hence the value-initialization. BlockchainTest one_block_fixture() { - BlockchainTest t{}; + BlockchainTest t; t.name = "unit"; t.network = "Prague"; @@ -37,7 +36,7 @@ BlockchainTest one_block_fixture() g.withdrawal_root = state::EMPTY_MPT_HASH; g.hash = GENESIS_HASH; - TestBlock b{}; + TestBlock b; b.block_info.number = g.block_number + 1; b.block_info.parent_hash = g.hash; b.block_info.gas_limit = g.gas_limit; diff --git a/test/utils/blockchaintest.hpp b/test/utils/blockchaintest.hpp index 0fa18fc2a3..56ee86ec79 100644 --- a/test/utils/blockchaintest.hpp +++ b/test/utils/blockchaintest.hpp @@ -28,14 +28,14 @@ struct BlockHeader hash256 state_root; hash256 receipts_root; state::BloomFilter logs_bloom; - int64_t difficulty; + int64_t difficulty = 0; bytes32 prev_randao; - int64_t block_number; - int64_t gas_limit; - int64_t gas_used; - int64_t timestamp; + int64_t block_number = 0; + int64_t gas_limit = 0; + int64_t gas_used = 0; + int64_t timestamp = 0; bytes extra_data; - uint64_t base_fee_per_gas; + uint64_t base_fee_per_gas = 0; hash256 hash; hash256 transactions_root; hash256 withdrawal_root;