Skip to content

refactor: replace panic-based test error handling with Result (#319) - #321

Merged
MaryammAli merged 2 commits into
BlockDash-Studios:mainfrom
portableDD:feat/result-based-test-errors
Jul 21, 2026
Merged

refactor: replace panic-based test error handling with Result (#319)#321
MaryammAli merged 2 commits into
BlockDash-Studios:mainfrom
portableDD:feat/result-based-test-errors

Conversation

@portableDD

Copy link
Copy Markdown
Contributor

Summary

Replaces panic-based error handling in test files with explicit Result handling and descriptive failure messages.

Changes

app/contract/contracts/Folder/build.rs

  • Replaced .unwrap() on OUT_DIR with .expect() describing the missing env var
  • Replaced .unwrap() on fs::write with .expect() describing the write failure
  • Replaced .unwrap_or_else(|_| panic!(...)) on git rev-parse with .expect() with descriptive message

app/contract/contracts/Folder/src/test.rs

  • Replaced panic!() in match arms of test_emergency_mode_blocks_risky_entry_points_and_allows_safe_paths with assert!() macros with descriptive messages
  • Improved assert_contract_error helper: all match arms now produce descriptive assertions instead of a generic panic!()
  • Improved latest_contract_event: .unwrap() to .expect(), panic message made more descriptive
  • Improved event_data_map: .unwrap() to .expect() with conversion error context

app/contract/contracts/Folder/src/role_test.rs

  • Replaced panic!("Expected InsufficientRole error") in test_insufficient_role_error with assert!() including the actual error in the message

Testing

All 317 tests pass (cargo test).

Closes #319

portableDD and others added 2 commits July 20, 2026 16:14
…ash-Studios#319)

- Replace panic!() calls in test match arms with descriptive assert! macros
- Replace bare .unwrap() calls with .expect() containing descriptive messages
- Improve assert_contract_error to provide detailed failure context
- Update latest_contract_event to use descriptive expect/panic messages
- Convert event_data_map to use .expect() instead of .unwrap()

Closes BlockDash-Studios#319

@MaryammAli MaryammAli 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.

LGTM

@MaryammAli
MaryammAli merged commit b1341e5 into BlockDash-Studios:main Jul 21, 2026
2 checks passed
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.

replace panic-based test error handling with Result and descriptive failures

2 participants