Skip to content

test: pin hash and compact regression values - #265

Open
NikhilSharmaWe wants to merge 2 commits into
berachain:mainfrom
NikhilSharmaWe:test/hash-compress-regression-tests
Open

test: pin hash and compact regression values#265
NikhilSharmaWe wants to merge 2 commits into
berachain:mainfrom
NikhilSharmaWe:test/hash-compress-regression-tests

Conversation

@NikhilSharmaWe

@NikhilSharmaWe NikhilSharmaWe commented Jun 23, 2026

Copy link
Copy Markdown

Closes #89

Summary

This adds regression coverage for hash and compact encoding paths across Berachain-specific primitives, pinning fixed expected values so upstream or internal encoding changes fail tests instead of silently breaking compatibility.

  • Add src/test_utils/regression_fixtures.rs with shared deterministic fixtures and an ignored generator for regenerating snapshots
  • Add header regression tests: Reth v1.11.4 Holesky compact anchor, header hash pins, and Berachain extension field compact/hash pins
  • Add transaction regression tests for minimal PoL tx hash/compact, envelope compact, Berachain tx type compact literals, and production-like PoL hash/compact
  • Add Bepolia and mainnet genesis hash regression tests

Test plan

  • cargo test regression
  • make pr (fmt, dprint, clippy, deny, machete, docs, nextest)
  • Verified new regression tests pass:
    • holesky_compact_matches_reth_v1_11_4
    • holesky_hash_regression
    • prev_proposer_pubkey_compact_regression
    • prev_proposer_pubkey_hash_regression
    • minimal_pol_tx_hash_regression
    • minimal_pol_tx_compact_regression
    • minimal_pol_envelope_compact_regression
    • test_berachain_tx_type_compact_regression
    • test_pol_transaction_hash_regression
    • test_pol_transaction_compact_regression
    • test_bepolia_genesis_hash_regression
    • test_mainnet_genesis_hash_regression

Summary by CodeRabbit

  • Tests
    • Added comprehensive regression tests for genesis hash validation across Berachain networks.
    • Added regression tests for header and transaction encoding/decoding behavior.
    • Expanded test fixture utilities to support regression testing coverage.

Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
Copilot AI review requested due to automatic review settings June 23, 2026 18:32
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds hardcoded snapshot regression tests pinning hash_slow(), compress_to_buf()/decompress(), to_compact(), and genesis_hash() outputs to fixed byte/B256 constants for Berachain headers, PoL transactions, BerachainTxType, and genesis chain specs (Bepolia and Mainnet). A new test_utils::regression_fixtures submodule provides shared fixture constructors used across all tests.

Changes

Regression snapshot tests

Layer / File(s) Summary
Shared regression fixture constructors
src/test_utils.rs, src/test_utils/regression_fixtures.rs
Adds a #[cfg(test)]-gated regression_fixtures submodule exposing holesky_berachain_header(), holesky_berachain_header_with_proposer_pubkey(), minimal_pol_tx(), and an ignored print_regression_values test that generates snapshot constants.
Header compact encoding and hash regression
src/primitives/header.rs
Adds a tests::regression module with byte-level snapshot constants and tests for CompactBerachainHeader bitflag size, compress_to_buf/decompress roundtrip, and hash_slow() for headers with and without prev_proposer_pubkey.
PoL transaction type and envelope regression
src/transaction/txtype.rs, src/transaction/mod.rs, src/transaction/pol.rs
Adds BerachainTxType::Berachain compact encoding regression, snapshot tests for minimal_pol_tx hash_slow()/to_compact()/envelope compact roundtrip, and production PoL transaction hash and compact regression.
Genesis hash regression for Bepolia and Mainnet
src/chainspec/mod.rs
Updates test imports to include b256 and adds test_bepolia_genesis_hash_regression and test_mainnet_genesis_hash_regression that load JSON fixture files, build BerachainChainSpec, and assert genesis_hash() equals hardcoded B256 constants.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • berachain/bera-reth#154: Adds prague2 genesis config/validation that changes Berachain genesis-derived chain-spec fields, directly affecting the genesis hash values asserted in this PR's new regression tests.
  • berachain/bera-reth#246: Modifies src/chainspec/mod.rs test coverage around Mainnet/Bepolia using the same genesis fixtures; its added depositContractAddress field can directly affect the genesis_hash() regression outputs asserted here.

Suggested reviewers

  • calbera
  • fridrik01

Poem

🐰 Hop, hop, hash that block!
Fixed bytes tick like a clock.
Snapshots pinned with careful care,
No upstream change can dare compare.
If the hash drifts, tests will squeak —
The rabbit guards what numbers speak! 🔒

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: pin hash and compact regression values' directly and clearly summarizes the main change: adding regression tests that pin hash and compact encoding values.
Linked Issues check ✅ Passed The PR fully addresses issue #89 by adding comprehensive regression tests for hash and compress calculations across Berachain primitives with pinned expected values.
Out of Scope Changes check ✅ Passed All changes directly support the stated regression testing objective: fixture helpers, hash/compact snapshots, and regression test modules across chainspec, header, transaction, and txtype components.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (6)
src/transaction/txtype.rs (1)

196-197: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert against protocol constants, not raw literals.

Line 196 and Line 197 should assert against named constants (e.g., compact extended identifier flag and POL_TX_TYPE) instead of 3usize/0x7e.

As per coding guidelines, src/**/*.rs: Extract magic numbers into documented constants.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/transaction/txtype.rs` around lines 196 - 197, Replace the magic number
literals in the assert_eq calls with named constants. Extract 3usize (the
compact extended identifier flag) and 0x7e (POL_TX_TYPE) into properly
documented constant definitions, then use these constants in place of the raw
literals in the assertion statements within the test function. This aligns with
the coding guideline to extract magic numbers into documented constants for
improved code clarity and maintainability.

Source: Coding guidelines

src/transaction/pol.rs (2)

260-263: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove inline snapshot comments in this Rust source file.

Line 260 through Line 263 introduces inline comments that conflict with the repository’s Rust-file comment rule.

As per coding guidelines, src/**/*.rs: No comments in code unless explicitly requested.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/transaction/pol.rs` around lines 260 - 263, Remove the entire multi-line
comment block that describes the self-generated snapshot and references
compress_to_buf output and test_pol_transaction_hash_regression. This comment
violates the repository's coding guideline that prohibits comments in Rust
source files (src/**/*.rs) unless explicitly requested. Delete all lines
containing the snapshot explanation and cargo test instruction.

Source: Coding guidelines


242-242: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared test inputs into named constants.

Line 242 and Line 271 repeat raw values (10, 1000) for the same regression fixture path; promote them to constants to avoid drift between tests.

As per coding guidelines, src/**/*.rs: Extract magic numbers into documented constants.

Also applies to: 271-271

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/transaction/pol.rs` at line 242, The magic numbers `10` and `1000` are
hardcoded in multiple test calls to `create_pol_transaction` on lines 242 and
271, which violates the coding guideline to extract magic numbers into
documented constants. Define named constants at the module level with
descriptive names that explain what these values represent (e.g., their role in
the test fixture), then replace all hardcoded occurrences of `10` and `1000` in
both `create_pol_transaction` invocations with these constants to ensure
consistency and maintainability across the test suite.

Source: Coding guidelines

src/primitives/header.rs (2)

985-988: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace bitflag literals with named constants.

Line 986 and Line 987 hardcode 4 and 1; use named constants so the test contract stays explicit and resilient to future encoding changes.

As per coding guidelines, src/**/*.rs: Extract magic numbers into documented constants.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/primitives/header.rs` around lines 985 - 988, The test function
compact_bitflag_layout contains hardcoded magic numbers 4 and 1 in the
assertions for CompactBerachainHeader::bitflag_encoded_bytes() and
BerachainHeaderExt::bitflag_encoded_bytes() respectively. Extract these magic
numbers into named constants with descriptive names that document their purpose
(for example, constants like COMPACT_BERACHAIN_HEADER_BITFLAG_SIZE and
BERACHAIN_HEADER_EXT_BITFLAG_SIZE), define them at the module level or in an
appropriate scope, and then replace the hardcoded values 4 and 1 with these
named constants in the respective assert_eq! calls to improve code
maintainability and resilience.

Source: Coding guidelines


958-980: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove inline comments from the new regression block.

Line 958 through Line 980 introduces new inline comments in Rust code, which conflicts with the repo rule for src/**/*.rs.

As per coding guidelines, src/**/*.rs: No comments in code unless explicitly requested.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/primitives/header.rs` around lines 958 - 980, Remove all inline comments
from the regression test block containing the constants HOLESKY_COMPACT,
HOLESKY_HASH, and WITH_PROPOSER_COMPACT. Delete all comment lines that begin
with "//" in this test section while keeping the const declarations and hex
value assignments intact. This aligns with the repository rule that prohibits
inline comments in Rust source files under src/**/*.rs.

Source: Coding guidelines

src/transaction/mod.rs (1)

1237-1250: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop the new inline explanatory comments in this test module.

Line 1237 through Line 1250 adds inline comments that violate the Rust path rule for this repository.

As per coding guidelines, src/**/*.rs: No comments in code unless explicitly requested.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/transaction/mod.rs` around lines 1237 - 1250, Remove all the inline
explanatory comments in the test module around the constant definitions.
Specifically, delete the comment lines preceding the MINIMAL_POL_HASH constant
definition, the MINIMAL_POL_COMPACT constant definition, and the
BerachainTxEnvelope compress_to_buf() output comment section. Keep only the
actual constant declarations and their assignments, as the repository coding
guidelines prohibit explanatory comments in src/**/*.rs files unless explicitly
requested.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/primitives/header.rs`:
- Around line 985-988: The test function compact_bitflag_layout contains
hardcoded magic numbers 4 and 1 in the assertions for
CompactBerachainHeader::bitflag_encoded_bytes() and
BerachainHeaderExt::bitflag_encoded_bytes() respectively. Extract these magic
numbers into named constants with descriptive names that document their purpose
(for example, constants like COMPACT_BERACHAIN_HEADER_BITFLAG_SIZE and
BERACHAIN_HEADER_EXT_BITFLAG_SIZE), define them at the module level or in an
appropriate scope, and then replace the hardcoded values 4 and 1 with these
named constants in the respective assert_eq! calls to improve code
maintainability and resilience.
- Around line 958-980: Remove all inline comments from the regression test block
containing the constants HOLESKY_COMPACT, HOLESKY_HASH, and
WITH_PROPOSER_COMPACT. Delete all comment lines that begin with "//" in this
test section while keeping the const declarations and hex value assignments
intact. This aligns with the repository rule that prohibits inline comments in
Rust source files under src/**/*.rs.

In `@src/transaction/mod.rs`:
- Around line 1237-1250: Remove all the inline explanatory comments in the test
module around the constant definitions. Specifically, delete the comment lines
preceding the MINIMAL_POL_HASH constant definition, the MINIMAL_POL_COMPACT
constant definition, and the BerachainTxEnvelope compress_to_buf() output
comment section. Keep only the actual constant declarations and their
assignments, as the repository coding guidelines prohibit explanatory comments
in src/**/*.rs files unless explicitly requested.

In `@src/transaction/pol.rs`:
- Around line 260-263: Remove the entire multi-line comment block that describes
the self-generated snapshot and references compress_to_buf output and
test_pol_transaction_hash_regression. This comment violates the repository's
coding guideline that prohibits comments in Rust source files (src/**/*.rs)
unless explicitly requested. Delete all lines containing the snapshot
explanation and cargo test instruction.
- Line 242: The magic numbers `10` and `1000` are hardcoded in multiple test
calls to `create_pol_transaction` on lines 242 and 271, which violates the
coding guideline to extract magic numbers into documented constants. Define
named constants at the module level with descriptive names that explain what
these values represent (e.g., their role in the test fixture), then replace all
hardcoded occurrences of `10` and `1000` in both `create_pol_transaction`
invocations with these constants to ensure consistency and maintainability
across the test suite.

In `@src/transaction/txtype.rs`:
- Around line 196-197: Replace the magic number literals in the assert_eq calls
with named constants. Extract 3usize (the compact extended identifier flag) and
0x7e (POL_TX_TYPE) into properly documented constant definitions, then use these
constants in place of the raw literals in the assertion statements within the
test function. This aligns with the coding guideline to extract magic numbers
into documented constants for improved code clarity and maintainability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b64ba9c0-2d3b-4bf9-910c-076871c1019a

📥 Commits

Reviewing files that changed from the base of the PR and between 9352f11 and 6fc5bf3.

📒 Files selected for processing (7)
  • src/chainspec/mod.rs
  • src/primitives/header.rs
  • src/test_utils.rs
  • src/test_utils/regression_fixtures.rs
  • src/transaction/mod.rs
  • src/transaction/pol.rs
  • src/transaction/txtype.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds deterministic regression tests to pin expected hash and compact-encoding outputs for Berachain-specific primitives (headers, PoL transactions, tx type encoding, and genesis hashes), so any upstream/internal encoding or hashing changes will surface as test failures instead of silently changing compatibility.

Changes:

  • Introduces shared deterministic regression fixtures plus an ignored “snapshot generator” test for regenerating pinned values.
  • Adds regression tests for header compact/hash (including Berachain extension fields) and PoL transaction hash/compact/envelope-compact.
  • Adds regression tests for Bepolia and mainnet genesis hash values.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/transaction/txtype.rs Adds a regression test pinning Berachain tx type compact encoding output.
src/transaction/pol.rs Adds PoL transaction hash and envelope compact encoding regression tests.
src/transaction/mod.rs Adds regression tests for minimal PoL tx hash/compact and envelope compact encoding.
src/test_utils/regression_fixtures.rs Adds deterministic fixtures and an ignored generator for printing/pinning regression values.
src/test_utils.rs Exposes the regression fixtures module for tests.
src/primitives/header.rs Adds header compact/hash regression tests, including Berachain extension fields, and roundtrip checks.
src/chainspec/mod.rs Adds regression tests pinning Bepolia and mainnet genesis hashes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
@NikhilSharmaWe

Copy link
Copy Markdown
Author

@calbera PTAL, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: regression tests for hash and compress calculations

2 participants