From 8b71f1a9102df4518cf03b57407cb6b21fd8d186 Mon Sep 17 00:00:00 2001 From: frstrtr Date: Mon, 22 Jun 2026 04:40:25 +0000 Subject: [PATCH] fix(dgb): pin reconstruct test merkle_root to actual tx-vector root The CoinbaseFirstThenRefOrder test asserted the won-block header merkle_root equals gentx_hash for the empty-merkle_link case. That held under the old reconstruct_block_header merkle_link walk, but b91facef8 (#303 bad-txnmrklroot fix) correctly recomputes the header root over the ACTUAL block tx vector ([gentx_hash] ++ other-tx txids) so header and body stay consistent for tx-bearing won blocks. With 2 other_txs the root is no longer gentx_hash, so the stale assertion failed on master. Re-pin the assertion to the production invariant via the same build_block_merkle_root + compute_txid SSOT the assembler uses, so the test now guards header/body merkle consistency instead of the obsolete empty-walk identity. Test-only; no behavior change. --- src/impl/dgb/test/reconstruct_won_block_test.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/impl/dgb/test/reconstruct_won_block_test.cpp b/src/impl/dgb/test/reconstruct_won_block_test.cpp index c908e8323..6a4347e59 100644 --- a/src/impl/dgb/test/reconstruct_won_block_test.cpp +++ b/src/impl/dgb/test/reconstruct_won_block_test.cpp @@ -196,8 +196,20 @@ TEST(DgbReconstructWonBlock, CoinbaseFirstThenRefOrder) BlockType blk; ps >> blk; - EXPECT_EQ(blk.m_merkle_root, gh); // empty link => root == gentx_hash ASSERT_EQ(blk.m_txs.size(), 3u); // gentx + 2 others + // Header merkle_root is recomputed over the ACTUAL block tx vector + // ([gentx_hash] ++ each other-tx txid), per the #303 bad-txnmrklroot fix -- + // NOT the empty-merkle_link walk (which would yield gentx_hash alone). Pin + // header/body consistency via the same build_block_merkle_root SSOT. + { + std::vector expect_txids = { + gh, + dgb::coin::compute_txid(blk.m_txs[1]), + dgb::coin::compute_txid(blk.m_txs[2]), + }; + EXPECT_EQ(blk.m_merkle_root, + dgb::coin::build_block_merkle_root(expect_txids)); + } EXPECT_EQ(blk.m_txs[0].vin[0].prevout.index, 0xffffffffu); // coinbase at 0 EXPECT_TRUE(blk.m_txs[0].vin[0].prevout.hash.IsNull()); EXPECT_EQ(blk.m_txs[1].vout[0].value, 11); // c1 -> make_tx(11), ref order