Skip to content

Note lifecycle assertion macros#2833

Open
marijamijailovic wants to merge 2 commits into0xMiden:nextfrom
walnuthq:pr/note-assertion-helpers
Open

Note lifecycle assertion macros#2833
marijamijailovic wants to merge 2 commits into0xMiden:nextfrom
walnuthq:pr/note-assertion-helpers

Conversation

@marijamijailovic
Copy link
Copy Markdown

@marijamijailovic marijamijailovic commented Apr 27, 2026

This PRs closes #2805

Copy link
Copy Markdown
Contributor

@partylikeits1983 partylikeits1983 left a comment

Choose a reason for hiding this comment

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

Thank you for this! Looks good to me!

Process note for next time: please add a short PR description and link a tracking issue. For a 441-line addition introducing a new public module + five macros, that context speeds up review and leaves a design rationale to point back to later.

Approving once CI is green and the rename is in.

Comment thread crates/miden-testing/tests/asserts.rs Outdated
use miden_protocol::account::AccountId;
use miden_protocol::account::auth::AuthScheme;
use miden_protocol::asset::{Asset, FungibleAsset};
use miden_protocol::Word;
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.

rustfmt is failing on this import block. The miden_protocol::* uses should be merged into a single use miden_protocol::{...} with Word reordered. make format from the repo root fixes it.


/// Asserts the tx consumed the given note (checks `tx.input_notes()`).
///
/// Tx-level counterpart to [`assert_note_consumed!`].
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.

cargo doc -D warnings is failing on three unresolved intra-doc links here and on the other macros (assert_note_created, assert_note_consumed_by, assert_note_consumed). Inside #[macro_export] macro_rules! blocks, rustdoc can't resolve bare macro names. Fully-qualify them ([`crate::assert_note_consumed!`]) or drop the link syntax.

/// );
/// ```
#[macro_export]
macro_rules! assert_note_created {
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.

Could you please rename the macros to make the naming less ambiguous? Right now assert_note_consumed_by! (tx-level) and assert_note_consumed! (chain-level) share a prefix and the _by does all the disambiguation work, which is too easy to misread. Prefix every macro with the scope:

  • assert_note_created! -> assert_tx_created!
  • assert_note_consumed_by! -> assert_tx_consumed!
  • assert_note_committed! -> assert_chain_committed!
  • assert_note_unspent! -> assert_chain_unspent!
  • assert_note_consumed! -> assert_chain_consumed!

@marijamijailovic
Copy link
Copy Markdown
Author

Thanks for the review @partylikeits1983, and apologies for skipping the PR description and issue link earlier - that was my mistake. I’ve now linked the tracking issue(#2805).

I’ll also fix the remaining lint failures.

For the chain-level note lifecycle checks, I’d lean toward following @PhilippGackstatter's suggestion and adding helpers on ‎MockChain instead of keeping the chain-level macros as-is, since that should give us clearer errors and a nicer DevX at the call sites. I’m happy to adjust this PR in that direction, but would love to hear if you have any concerns with that approach.

Address comments from the issuse 0xMiden#2805, drop the 4 macros in favor of plain helper methods.
 - `assert_note_committed!`  -> `MockChain::is_note_committed`
 - `assert_note_unspent!`    -> `MockChain::is_note_unspent`
 - `assert_note_consumed!`   -> `MockChain::is_note_consumed`
 - `assert_note_consumed_by!` -> `ExecutedTransaction::consumes_note`

Keep `assert_note_created!` since it does spec matching with optional fields.
@marijamijailovic marijamijailovic force-pushed the pr/note-assertion-helpers branch from 8cb73d5 to c1888d2 Compare May 4, 2026 07:18
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.

miden-testing: note lifecycle assertion macros

2 participants