Skip to content

test: define state_compute tests in a yaml file#6574

Merged
hanabi1224 merged 1 commit intomainfrom
hm/define-state-compute-tests-in-file
Feb 10, 2026
Merged

test: define state_compute tests in a yaml file#6574
hanabi1224 merged 1 commit intomainfrom
hm/define-state-compute-tests-in-file

Conversation

@hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Feb 10, 2026

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Tests

    • Refactored state compute tests to be data-driven and generated at build time, replacing many hard-coded per-epoch test functions.
    • Added a YAML-based test manifest covering mainnet and calibnet scenarios to enable parameterized per-network/per-epoch test runs.
  • Chores

    • Consolidated serde, serde_yaml, and ahash under workspace-managed dependencies.
    • Enhanced the build process to generate test code from the manifest for improved maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

Walkthrough

Adds workspace-managed serde/serde_yaml/ahash deps, a build-time generator that parses a YAML manifest to emit per-chain/epoch state_compute test functions, and refactors hard-coded per-epoch tests to include and run those generated tests via a shared runner.

Changes

Cohort / File(s) Summary
Workspace / Cargo
Cargo.toml
Added workspace-scoped dependencies (ahash, serde with derive, serde_yaml) and switched crates to reference workspace-managed deps (workspace = true) for consistent dependency resolution.
Build-time generator
build.rs
Added state_compute_tests_gen() that reads src/state_manager/state_compute_tests.yaml, deserializes into StateComputeTests, and writes generated Rust test functions (__state_compute_tests_gen.rs) into OUT_DIR; integrated into main build script.
Test manifest
src/state_manager/state_compute_tests.yaml
New YAML file listing per-chain state_compute test epochs (mainnet, calibnet) including named state migrations and epoch IDs.
Test runner / inclusion
src/state_manager/utils.rs
Removed many hard-coded per-epoch test functions; added include!(concat!(env!("OUT_DIR"), "/__state_compute_tests_gen.rs")) and a private helper state_compute_test_run(chain, epoch) to centralize snapshot preparation and state_compute invocation.

Sequence Diagram(s)

sequenceDiagram
  participant Build as Build Script (build.rs)
  participant FS as Filesystem (src/state_manager/state_compute_tests.yaml)
  participant Generator as Generated Tests (OUT_DIR/__state_compute_tests_gen.rs)
  participant TestRunner as Test code (utils.rs)
  participant Cargo as Cargo Test Harness

  Build->>FS: read state_compute_tests.yaml
  Build->>Build: deserialize YAML -> StateComputeTests
  Build->>Generator: write generated test functions
  Note right of Generator: emitted cargo_test_state_compute_{chain}_{epoch}()
  TestRunner->>Generator: include! generated file at compile time
  Cargo->>TestRunner: run tests (cargo test)
  TestRunner->>TestRunner: call state_compute_test_run(chain, epoch)
  TestRunner->>FS: (runtime) obtain snapshot / state data
  TestRunner->>Cargo: report test results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • LesnyRumcajs
  • sudo-shashank
  • akaladarshi
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: define state_compute tests in a yaml file' directly and clearly summarizes the main change: moving state_compute tests from hardcoded definitions to a YAML-driven data file approach.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hm/define-state-compute-tests-in-file

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
build.rs (2)

100-123: Consider sanitizing chain names for valid Rust identifiers.

The rpc_regression_tests_gen function (lines 78-83) sanitizes test names by replacing non-alphanumeric characters with underscores, but state_compute_tests_gen directly interpolates {chain} into the function name. If a chain name ever contains characters like - or ., the generated code will fail to compile.

♻️ Suggested fix to sanitize chain names
 fn state_compute_tests_gen() {
     println!("cargo:rerun-if-changed=src/state_manager/state_compute_tests.yaml");
     let StateComputeTests { tests } =
         serde_yaml::from_str(include_str!("src/state_manager/state_compute_tests.yaml")).unwrap();
     let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
     let out_path = out_dir.join("__state_compute_tests_gen.rs");
     let mut w = BufWriter::new(File::create(&out_path).unwrap());
     for (chain, epochs) in tests {
+        let chain_ident = chain
+            .chars()
+            .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' })
+            .collect::<String>();
         for epoch in epochs {
             writeln!(
                 w,
                 r#"
                     #[cfg(feature = "cargo-test")]
                     #[tokio::test(flavor = "multi_thread")]
                     #[fickle::fickle]
-                    async fn cargo_test_state_compute_{chain}_{epoch}() {{
+                    async fn cargo_test_state_compute_{chain_ident}_{epoch}() {{
                         state_compute_test_run("{chain}".parse().unwrap(), {epoch}).await
                     }}
                 "#,
             )
             .unwrap();
         }
     }
 }

125-128: Serialize derive is unused.

The StateComputeTests struct only needs Deserialize since it's read from YAML, not written. Consider removing Serialize to avoid unused code.

♻️ Optional: Remove unused derive
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Deserialize)]
 struct StateComputeTests {
     tests: HashMap<String, Vec<i64>>,
 }

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

@hanabi1224 hanabi1224 marked this pull request as ready for review February 10, 2026 06:49
@hanabi1224 hanabi1224 requested a review from a team as a code owner February 10, 2026 06:49
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and removed request for a team February 10, 2026 06:49
@hanabi1224 hanabi1224 force-pushed the hm/define-state-compute-tests-in-file branch from 17ed8b8 to 6350790 Compare February 10, 2026 07:11
@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.35%. Comparing base (99d1f28) to head (6350790).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
src/state_manager/utils.rs 79.56% <100.00%> (-2.22%) ⬇️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99d1f28...6350790. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Feb 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2026
@hanabi1224 hanabi1224 added this pull request to the merge queue Feb 10, 2026
Merged via the queue into main with commit fa7add4 Feb 10, 2026
35 checks passed
@hanabi1224 hanabi1224 deleted the hm/define-state-compute-tests-in-file branch February 10, 2026 09:26
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.

2 participants