Skip to content

test: add failed operation state rollback tests - #573

Open
ghg001 wants to merge 10 commits into
Axionvera:mainfrom
ghg001:fix/issue-167-add-tests-for-failed-operation-state-rollback
Open

test: add failed operation state rollback tests#573
ghg001 wants to merge 10 commits into
Axionvera:mainfrom
ghg001:fix/issue-167-add-tests-for-failed-operation-state-rollback

Conversation

@ghg001

@ghg001 ghg001 commented Aug 30, 2026

Copy link
Copy Markdown

Overview

This PR adds a focused suite of negative-path tests for the savings vault, proving that failed vault operations do not leave partial or inconsistent state changes. Each test records the full vault state before a failed deposit, lock, or withdrawal, invokes the failing operation, and asserts that balances, lock metadata, and accounting invariants remain unchanged. This closes the rollback coverage gap and prepares the contract for token-backed transfers.

Related Issue

Closes #

Changes

🧪 Failed Operation Rollback Tests

  • [ADD] contracts/savings_vault/src/test/negative_paths.rs

    • Covers failed withdrawal and invalid amount scenarios; snapshots balances and total locked before each call and asserts no mutations after failure.
  • [ADD] contracts/savings_vault/src/test/token_transfer_rollback.rs

    • Simulates token transfer failures after validation and verifies the vault does not apply partial accounting updates.
  • [ADD] contracts/savings_vault/src/test/balance_conservation.rs

    • Asserts vault balance and total supply conservation before and after failed operations.
  • [ADD] contracts/savings_vault/src/test/multi_lock_invariants.rs

    • Ensures multi-lock accounting invariants remain consistent after failed lock attempts.
  • [ADD] contracts/savings_vault/src/test/lock_atomicity.rs

    • Verifies lock operations are atomic: failed locks do not mutate lock lists, timestamps, or lock counts.

🔒 State Snapshot Assertions

  • [ADD] Shared snapshot helper in test utilities that records balances, lock counts, and lock metadata before a failed call and compares them after the call.
  • [MODIFY] Existing failure tests to use the same snapshot assertions, making rollback expectations explicit and easier to extend.

Verification Results

cargo test -p savings-vault --lib
✅ 45/45 passed

Live acceptance check:
✅ Failed withdrawal rollback verified — balances and locks unchanged
✅ Failed lock rollback verified — lock list/timestamps unchanged
✅ Invalid amount rollback verified — no state mutation
✅ State before/after failed calls verified — snapshot assertions pass
✅ Tests clear and extendable — shared helper + named scenarios
Acceptance Criteria Status
Tests cover failed withdrawal rollback ✅ Negative path and token transfer rollback tests assert unchanged balances/locks
Tests cover failed lock rollback ✅ Lock atomicity and multi-lock invariant tests assert no partial lock mutations
Tests cover invalid amount rollback ✅ Invalid deposit/withdrawal amounts leave state fully unchanged
Tests verify state before and after failed calls ✅ Snapshot helper records and compares state around every failed call
Tests are clear enough for future contributors to extend ✅ Scenario names and shared helper document intended rollback behavior

Closes #167

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.

Add tests for failed operation state rollback

1 participant