Skip to content

Conversation

@JoseSK999
Copy link
Contributor

What is the purpose of this pull request?

  • Bug fix
  • Documentation update
  • New feature
  • Test
  • Other:

Which crates are being modified?

  • floresta-chain
  • floresta-cli
  • floresta-common
  • floresta-compact-filters
  • floresta-electrum
  • floresta-watch-only
  • floresta-wire
  • floresta
  • florestad
  • Other:

Description

We have a couple of assert!(result.is_ok()) and assert!(result.is_err()) in our tests. These are very readable but whenever they fail they don't debug the Result value. We have recently seen this lack of debugging in some electrum tests CI fails:

  ---- electrum_protocol::test::test_blockchain_headers stdout ----
  thread 'electrum_protocol::test::test_blockchain_headers' panicked at crates/floresta-electrum/src/electrum_protocol.rs:1221:9:
  assertion failed: send_request(batch_req, port).await.is_ok()
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

We could fix this with result.unwrap() or result.unwrap_err(), but it worsens readability. I find it nicer to use these new assert_ok and assert_err macros. Added a few unit and doc tests for them.

Notes to the reviewers

There's a clippy lint for this but it's on restriction mode because of the readability loss of using unwraps, which we solve with these macros. But the clippy lint doesn't catch all cases for some reason. I also saw there's an std::assert_matches macro but it's unstable.

@Davidson-Souza Davidson-Souza added chore Cleaning, refactoring, reducing complexity code quality Generally improves code readability and maintainability labels May 7, 2025
@jaoleal
Copy link
Collaborator

jaoleal commented May 8, 2025

LGTM. a0b54e7

Copy link
Contributor

@lucad70 lucad70 left a comment

Choose a reason for hiding this comment

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

ACK a0b54e7

@JoseSK999 JoseSK999 force-pushed the debug-errors-in-tests branch from a0b54e7 to b9420a6 Compare May 9, 2025 16:05
@Davidson-Souza
Copy link
Member

ACK b9420a6

@Davidson-Souza Davidson-Souza requested a review from lucad70 May 9, 2025 16:09
We have a couple of `assert!(result.is_ok())` and `assert!(result.is_err())` in our tests. These are very readable but whenever they fail they don't debug the `Result` value. We have recently seen this lack of debugging in some electrum tests CI fails.

We could fix this with `result.unwrap()` or `result.unwrap_err()`, but it worsens readability. I find it nicer to use these `assert_ok` and `assert_err` macros. Added a few unit and doc tests for them.
@JoseSK999 JoseSK999 force-pushed the debug-errors-in-tests branch from b9420a6 to eacbc61 Compare May 9, 2025 18:48
@JoseSK999
Copy link
Contributor Author

Rebased to resolve a conflict

@Davidson-Souza
Copy link
Member

re-ack eacbc61

@Davidson-Souza Davidson-Souza merged commit 9bb3a7e into vinteumorg:master May 9, 2025
10 checks passed
@JoseSK999 JoseSK999 deleted the debug-errors-in-tests branch May 9, 2025 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Cleaning, refactoring, reducing complexity code quality Generally improves code readability and maintainability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants