8000 feat: generic snapshots by jeluard · Pull Request #233 · pragma-org/amaru · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: generic snapshots #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

feat: generic snapshots #233

wants to merge 15 commits into from

Conversation

jeluard
Copy link
Contributor
@jeluard jeluard commented May 28, 2025

Make sure snapshots tests (run via make test-e2e) are network agnostic. Also generate the test_case annotation based on snap files. This paves the way to having tests run pick up all generated files.

Summary by CodeRabbit

  • New Features

    • Enabled snapshot testing across multiple networks and epochs, allowing for more comprehensive test coverage.
    • Introduced automated generation of network-specific snapshot test cases.
  • Bug Fixes

    • Added explicit error handling for missing snapshot source files to improve reliability.
  • Tests

    • Generalized test functions to support various networks and epochs.
    • Incorporated dynamically generated test cases for improved flexibility and organization.

jeluard added 3 commits May 28, 2025 16:01
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Copy link
Contributor
coderabbitai bot commented May 28, 2025

Walkthrough

Alrighty, here's the lowdown: The snapshot test framework got a solid tune-up, now supporting multiple networks and epochs instead of just Preprod. There's a new script to auto-generate Rust test cases based on available snapshots, and error handling is beefed up for missing files. Some trait implementations and dependencies got sorted too.

Changes

File(s) Change Summary
conformance-tests/scripts/generate.mjs Updated snapshot source path, added file existence check, and error handling for missing files.
crates/amaru-kernel/src/network.rs Added From<NetworkName> for pallas_addresses::Network trait implementation.
crates/amaru/Cargo.toml Added amaru-kernel as a build dependency in the workspace.
crates/amaru/tests/summary.rs Generalized test functions for multi-network/epoch, dynamic snapshot paths, refactored protocol version logic.
crates/amaru/tests/generated_compare_snapshot_test_cases.incl Introduced generated test cases for Preprod epochs, new test function for dynamic cases.
scripts/generate-snapshot-test-cases New 8000 Bash script to auto-generate Rust test cases from snapshot files and networks.

Sequence Diagram(s)

sequenceDiagram
    participant Script as Bash Script
    participant FS as File System
    participant RustIncl as generated_compare_snapshot_test_cases.incl
    participant TestRunner as Rust Test Runner

    Script->>FS: Scan snapshots directory for network folders
    Script->>FS: Find all summary__rewards_summary_<epoch>.snap files
    Script->>RustIncl: Write test cases for each (network, epoch)
    TestRunner->>RustIncl: Run generated test cases
    RustIncl->>TestRunner: Call compare_snapshot(network, epoch)
Loading

Poem

Snapshots gathered, networks wide,
Aussie code with Irish pride.
Scripts now roam, epochs in tow,
Rusty tests put on a show.
If a file goes missing, don’t you fear—
Error handling’s now top-tier!
So grab a flat white, mate, and cheer! ☕🍀

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
codecov bot commented May 29, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/amaru-kernel/src/network.rs 0.00% 5 Missing ⚠️
Files with missing lines Coverage Δ
crates/amaru-kernel/src/network.rs 82.94% <0.00%> (-1.24%) ⬇️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: jeluard <jeluard@users.noreply.github.com>
@jeluard jeluard force-pushed the jeluard/generic-snapshots branch from a0186df to 48a820d Compare May 29, 2025 07:42
jeluard added 4 commits June 2, 2025 15:54
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
@jeluard jeluard marked this pull request as ready for review June 2, 2025 16:31
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 579299b and 91886bf.

⛔ Files ignored due to path filters (34)
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_163.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_164.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_165.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_166.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_167.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_168.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_169.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_170.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_171.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_172.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_173.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_174.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_175.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_176.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_177.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_178.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__rewards_summary_179.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_163.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_164.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_165.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_166.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_167.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_168.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_169.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_170.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_171.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_172.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_173.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_174.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_175.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_176.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_177.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_178.snap is excluded by !**/*.snap
  • crates/amaru/tests/snapshots/preprod/summary__stake_distribution_179.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • conformance-tests/scripts/generate.mjs (1 hunks)
  • crates/amaru-kernel/src/network.rs (2 hunks)
  • crates/amaru/Cargo.toml (1 hunks)
  • crates/amaru/build.rs (1 hunks)
  • crates/amaru/tests/summary.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Build on ubuntu-24.04 with target aarch64-unknown-linux-musl
  • GitHub Check: Build on ubuntu-latest with target x86_64-unknown-linux-gnu
  • GitHub Check: Build on ubuntu-latest with target riscv32im-risc0-zkvm-elf
  • GitHub Check: Build on windows-latest with target x86_64-pc-windows-msvc
  • GitHub Check: Build on macos-latest with target aarch64-apple-darwin
  • GitHub Check: Coverage
  • GitHub Check: Snapshots (preprod, 10.1.4)
  • GitHub Check: Simulation
  • GitHub Check: Build on ubuntu-latest with target riscv32im-risc0-zkvm-elf
  • GitHub Check: Build on windows-latest with target x86_64-pc-windows-msvc
  • GitHub Check: Build on ubuntu-24.04 with target aarch64-unknown-linux-musl
  • GitHub Check: Build on macos-latest with target aarch64-apple-darwin
  • GitHub Check: Build on ubuntu-latest with target x86_64-unknown-linux-gnu
🔇 Additional comments (13)
crates/amaru/Cargo.toml (1)

59-59: Fair dinkum, good addition mate!

Adding amaru-kernel as a build dependency makes perfect sense for the build script to access NetworkName types when generating those test cases. It's like giving your build script the right tools for the job - no point trying to hammer a nail with a screwdriver, eh?

crates/amaru-kernel/src/network.rs (2)

17-17: Spot on with the import!

Adding the pallas_addresses::Network import to support the conversion trait - clean as a whistle!


237-245: Crikey, that's a neat conversion implementation!

The From<NetworkName> for Network trait is bang on - mapping Mainnet to Mainnet and everything else to Testnet makes perfect sense since pallas_addresses only has those two variants. It's like choosing between Neo's red pill or blue pill - there's only two options in the Matrix, mate!

conformance-tests/scripts/generate.mjs (2)

109-109: Path update looks bonzer!

The source path update from "crates/amaru/src/ledger/rewards.rs" to "crates/amaru-ledger/src/summary/rewards.rs" aligns with the code reorganization. It's like updating your GPS when they change the street names - gotta keep up with the times!


110-114: Bloody brilliant defensive programming!

Adding the file existence check with proper error handling is top-notch! Rather than letting the script fail mysteriously later, you're catching the problem early and giving a clear error message. It's like checking if your keys are in your pocket before you lock the door - saves you a world of trouble later, mate!

crates/amaru/tests/summary.rs (4)

68-71: Ace automation with the generated test cases!

Including the generated test cases from the build script is like having a robot butler that automatically sets up all your tests - pure genius! No more manually adding test cases when new snapshots appear.


74-74: Function signature makeover looks mint!

Generalizing from compare_preprod_snapshot to compare_snapshot with a NetworkName parameter is the right move for network-agnostic testing. It's like upgrading from a one-trick pony to a Swiss Army knife!


95-102: Dynamic snapshot paths - you beauty!

Using insta::with_settings! to set the snapshot path dynamically based on the network name is brilliant organization. Each network gets its own snapshot folder - tidy as a cricket pitch!


116-123: Consistent snapshot handling - top shelf!

Same dynamic snapshot path approach for the rewards summary - consistency is key, like having matching socks!

crates/amaru/build.rs (4)

15-22: G'day! Nice clean imports, mate!

The import additions look spot on - you've got all the essential bits for file operations and the NetworkName enum. Clean as a whistle!


88-88: Don't forget to handle the Result, mate!

Since we're suggesting the function return a Result, you'll need to handle it in main() too.

-    generated_compare_snapshot_test_cases();
+    if let Err(e) = generated_compare_snapshot_test_cases() {
+        panic!("Failed to generate snapshot test cases: {}", e);
+    }

55-62: The string parsing logic is solid as a rock, legend!

Love how you're using strip_prefix and strip_suffix - that's some proper Rust idiomatic code right there! The pattern matching for extracting epoch numbers is clean and handles edge cases nicely. This bit's tighter than a drum!


24-31:

✅ Verification successful

Solid enum conversion, but mind the gap!

This helper function is clean as a fresh Foster's, but I'm wondering if we're covering all the NetworkName variants here. Like making sure we didn't miss any characters in our ensemble cast, you know?

Let me check if all NetworkName variants are handled:


🏁 Script executed:

#!/bin/bash
# Description: Check if all NetworkName enum variants are covered in the conversion function
# Expected: All enum variants should be handled in the match statement

ast-grep --pattern $'enum NetworkName {
  $$$
}'

Length of output: 49


Ah, let’s give our enum a proper once-over—time to crack open the code and see every NetworkName variant in action.


🏁 Script executed:

#!/bin/bash
# Locate the NetworkName enum and list its variants
rg -n -A 5 "enum NetworkName" .

Length of output: 361


All NetworkName variants covered—looks shipshape!

I checked crates/amaru-kernel/src/network.rs and saw exactly these variants:

  • Mainnet
  • Preprod
  • Preview
  • Testnet(u32)

Your network_name_to_string match handles each one. No gaps here—good on ya!

jeluard added 3 commits June 2, 2025 19:04
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
@jeluard jeluard requested review from abailly and KtorZ June 2, 2025 19:04
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
jeluard added 2 commits June 4, 2025 15:25
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
@jeluard jeluard requested a review from KtorZ June 5, 2025 11:00
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
scripts/generate-snapshot-test-cases (2)

18-43: Network name mapping is top-notch, but consider some edge cases!

The network_name_to_string function handles the main suspects beautifully - mainnet, preprod, preview, and even testnet variants with magic numbers. Though like any good RPG character build, you might want to consider what happens with unexpected inputs.

Consider adding some logging for unknown network names to help with debugging:

        *)
            # Fallback: capitalize first letter
+           echo "Warning: Unknown network '$network', using fallback capitalization" >&2
            echo "${network^}"
            ;;

66-80: File operations are safe but consider atomic writes!

The approach of truncating and writing is fine for a generated file, but if this script might run concurrently (like in a CI pipeline), you might want to consider atomic writes to avoid race conditions.

Consider using a temporary file for atomic writes:

-# Create/truncate the output file
-> "$DEST_PATH"
+# Create temporary file for atomic write
+TEMP_FILE=$(mktemp)
+trap 'rm -f "$TEMP_FILE"' EXIT

 # Write test cases to file
 for TEST_CASE in "${TEST_CASES[@]}"; do
     NETWORK="${TEST_CASE%:*}"
     EPOCH="${TEST_CASE#*:}"
     
     NETWORK_ENUM=$(network_name_to_string "$NETWORK")
-    echo "#[test_case(NetworkName::$NETWORK_ENUM, $EPOCH)]" >> "$DEST_PATH"
+    echo "#[test_case(NetworkName::$NETWORK_ENUM, $EPOCH)]" >> "$TEMP_FILE"
 done

 # Append the test function content
-cat >> "$DEST_PATH" << 'EOF'
+cat >> "$TEMP_FILE" << 'EOF'
 #[ignore]
 pub fn compare_snapshot_test_case(network_name: NetworkName, epoch: u64) {
     let epoch = Epoch::from(epoch);
     compare_snapshot(network_name, epoch)
 }
 EOF
+
+# Atomic move
+mv "$TEMP_FILE" "$DEST_PATH"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 006a605 and bda215f.

📒 Files selected for processing (3)
  • crates/amaru/tests/generated_compare_snapshot_test_cases.incl (1 hunks)
  • crates/amaru/tests/summary.rs (3 hunks)
  • scripts/generate-snapshot-test-cases (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/amaru/tests/summary.rs
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Simulation
  • GitHub Check: Coverage
  • GitHub Check: Build on macos-latest with target aarch64-apple-darwin
  • GitHub Check: Build on ubuntu-latest with target x86_64-unknown-linux-gnu
  • GitHub Check: Build on ubuntu-latest with target aarch64-unknown-linux-musl
  • GitHub Check: Build on windows-latest with target x86_64-pc-windows-msvc
  • GitHub Check: Snapshots (preprod, 10.1.4)
  • GitHub Check: Sanity
🔇 Additional comments (5)
crates/amaru/tests/generated_compare_snapshot_test_cases.incl (2)

1-18: G'day mate! All tests are on the bench - is this the plan?

Fair dinkum, every single test case is marked with #[ignore], which means they'll be sitting on the sidelines like a substitute player in FIFA. Just want to double-check this is intentional for your e2e test strategy, yeah?


19-22: Clean as a whistle, this function!

The test function implementation is spot on - simple conversion from u64 to Epoch and delegating to compare_snapshot. It's like a perfect assist in a footy match - does exactly what it needs to do without any fancy footwork.

scripts/generate-snapshot-test-cases (3)

1-16: Solid defensive play with the error checking!

Love the upfront validation - checking both the destination file and snapshots directory exist before diving in. It's like checking your equipment before a big game, proper preparation prevents poor performance!


56-60: Regex pattern matching is chef's kiss!

The pattern ^summary__rewards_summary_([0-9]+)\.snap$ is bang on for extracting epoch numbers. Clean capture group usage that would make even the most pedantic code reviewer happy as Larry.


82-91: Script finale is clean as a new pair of boots!

The heredoc approach for appending the test function is textbook perfect - readable, maintainable, and does exactly what it says on the tin. The confirmation message at the end is a nice touch too!

@jeluard jeluard requested a review from abailly June 13, 2025 19:08
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.

3 participants
0