Implement Contract Rollback Testing Framework FIXED#435
Open
Mitch5000 wants to merge 1 commit into
Open
Conversation
|
@Mitch5000 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a dedicated testing framework for contract rollbacks so StarForge users can validate that contract upgrades can be safely reverted without data loss. The new rollback harness compares previous and upgraded WASM artifacts, executes deterministic rollback scenarios against a mock state model, verifies state preservation, runs data integrity checks, and enforces rollback performance budgets.
Closes #373
Type of Change
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Documentation update
Changes Made
Added a new rollback testing module, src/utils/rollback_testing.rs, with rollback scenarios, state mutation modeling, state preservation checks, integrity checks, performance budget checks, and JSON/HTML report generation.
Extended starforge test with rollback-specific flags: --rollback, --previous-wasm, repeatable --rollback-scenario, and --rollback-performance-budget-ms.
Added integration tests in tests/contract_rollback_testing.rs covering the default harness, state-loss failure detection, and custom rollback scenario loading.
Registered the rollback testing module in src/utils/mod.rs.
Added rollback testing documentation in ROLLBACK_TESTING.md and linked it from README.md.
Testing
How has this been tested?
The following commands were run locally:
Bash
cargo check
cargo test --test contract_rollback_testing
cargo test rollback_testing
cargo build
A manual CLI smoke test was also performed with temporary previous/upgraded WASM files:
Bash
./target/debug/starforge --quiet test
--wasm /tmp/.../v2.wasm
--rollback
--previous-wasm /tmp/.../v1.wasm
--rollback-performance-budget-ms 1000
Result: rollback safety checks passed.
Unit tests added/updated
Integration tests added/updated
Manual testing performed
Test Coverage
Describe what scenarios have been tested:
Happy path: default rollback scenario passes when preserved balances, admin keys, and total supply remain intact after rollback.
Edge cases: custom scenario arrays load correctly; rollback mutations can restore schema/counter state; checksum and expected-state checks validate final rollback state.
Error handling: the harness fails when a preserved key is deleted or lost during upgrade/rollback; invalid or missing WASM/scenario files are surfaced as errors through existing path validation and harness validation.
Code Quality Checklist
My code follows the style guidelines of this project (rustfmt was run on changed Rust files)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation
My changes generate no new warnings (cargo clippy -- -D warnings) — not run locally
I have added tests that prove my fix is effective or that my feature works
New and existing targeted unit tests pass locally with my changes
The CI checks pass (format, clippy, tests) — pending CI
Breaking Changes
This PR introduces breaking changes
If checked, describe the breaking changes and migration path:
No breaking changes. The rollback framework is additive and only runs when starforge test --rollback is explicitly used.
Documentation
README.md updated
DEVELOPER_GUIDE.md updated (if applicable)
API_REFERENCE.md updated (if applicable)
No documentation changes needed
Additional documentation added:
ROLLBACK_TESTING.md added with scenario schema, integrity check reference, usage examples, and CI guidance.
Screenshots (if applicable)
Not applicable. This PR adds CLI/testing functionality and documentation; no UI changes were made.
Additional Context
The rollback harness uses a deterministic mock state model so rollback checks can run quickly and reliably in local development and CI. It is intended to complement final integration or testnet rollback drills before production upgrades.
The actual issue number was not provided in the task context, so Closes # should be replaced with the correct issue number before opening the PR.Description
This PR adds a dedicated testing framework for contract rollbacks so StarForge users can validate that contract upgrades can be safely reverted without data loss. The new rollback harness compares previous and upgraded WASM artifacts, executes deterministic rollback scenarios against a mock state model, verifies state preservation, runs data integrity checks, and enforces rollback performance budgets.
Closes #
Type of Change
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Documentation update
Changes Made
Added a new rollback testing module, src/utils/rollback_testing.rs, with rollback scenarios, state mutation modeling, state preservation checks, integrity checks, performance budget checks, and JSON/HTML report generation.
Extended starforge test with rollback-specific flags: --rollback, --previous-wasm, repeatable --rollback-scenario, and --rollback-performance-budget-ms.
Added integration tests in tests/contract_rollback_testing.rs covering the default harness, state-loss failure detection, and custom rollback scenario loading.
Registered the rollback testing module in src/utils/mod.rs.
Added rollback testing documentation in ROLLBACK_TESTING.md and linked it from README.md.
Testing
How has this been tested?
The following commands were run locally:
Bash
cargo check
cargo test --test contract_rollback_testing
cargo test rollback_testing
cargo build
A manual CLI smoke test was also performed with temporary previous/upgraded WASM files:
Bash
./target/debug/starforge --quiet test
--wasm /tmp/.../v2.wasm
--rollback
--previous-wasm /tmp/.../v1.wasm
--rollback-performance-budget-ms 1000
Result: rollback safety checks passed.
Unit tests added/updated
Integration tests added/updated
Manual testing performed
Test Coverage
Describe what scenarios have been tested:
Happy path: default rollback scenario passes when preserved balances, admin keys, and total supply remain intact after rollback.
Edge cases: custom scenario arrays load correctly; rollback mutations can restore schema/counter state; checksum and expected-state checks validate final rollback state.
Error handling: the harness fails when a preserved key is deleted or lost during upgrade/rollback; invalid or missing WASM/scenario files are surfaced as errors through existing path validation and harness validation.
Code Quality Checklist
My code follows the style guidelines of this project (rustfmt was run on changed Rust files)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation
My changes generate no new warnings (cargo clippy -- -D warnings) — not run locally
I have added tests that prove my fix is effective or that my feature works
New and existing targeted unit tests pass locally with my changes
The CI checks pass (format, clippy, tests) — pending CI
Breaking Changes
This PR introduces breaking changes
If checked, describe the breaking changes and migration path:
No breaking changes. The rollback framework is additive and only runs when starforge test --rollback is explicitly used.
Documentation
README.md updated
DEVELOPER_GUIDE.md updated (if applicable)
API_REFERENCE.md updated (if applicable)
No documentation changes needed
Additional documentation added:
ROLLBACK_TESTING.md added with scenario schema, integrity check reference, usage examples, and CI guidance.
Screenshots (if applicable)
Not applicable. This PR adds CLI/testing functionality and documentation; no UI changes were made.
Additional Context
The rollback harness uses a deterministic mock state model so rollback checks can run quickly and reliably in local development and CI. It is intended to complement final integration or testnet rollback drills before production upgrades.
The actual issue number was not provided in the task context, so Closes # should be replaced with the correct issue number before opening the PR.
Closes #373