-
Notifications
You must be signed in to change notification settings - Fork 124
Labels
good first issueGood for newcomersGood for newcomerstestsImprovements to testingImprovements to testing
Milestone
Description
As a small quality of life improvement for debugging, I think we should crate a newtype wrapper around the VM's ExecutionError that overrides the Display impl:
#[derive(Debug, thiserror::Error)]
pub struct ExecError(pub ExecutionError);
impl Display for ExecError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(&PrintDiagnostic::new(&self.0).to_string())
}
}This allows us to always use anyhow::Result<()> in tests instead of a mix between that and miette::Result. The latter is only needed because ExecutionError does not turn into a nice report by default. E.g. if we do tx_context.execute_code(code).await? in a test with anyhow::Result, we'd get:
one or more warnings were emitted
Error: assertion failed at clock cycle 1889 with error message: get_balance can only be called on a fungible asset
Using ExecError + anyhow::Result instead, we get:
stderr ───
one or more warnings were emitted
Error: x assertion failed at clock cycle 1889 with error message: get_balance can only be called on a fungible asset
,-[~/git/miden-base/target/test-dev/build/miden-lib-f0afd6e1413cd388/out/asm/kernels/transaction/lib/asset_vault.masm:62:5]
61 | dup exec.account_id::is_fungible_faucet
62 | assert.err=ERR_VAULT_GET_BALANCE_CAN_ONLY_BE_CALLED_ON_FUNGIBLE_ASSET
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63 | # => [faucet_id_prefix, faucet_id_suffix, vault_root_ptr]
`----
So the task here is to:
- Introduce the above error type in
crates/miden-testing/src/tx_context/errors.rs. - Change
TransactionContext::execute_codeto returnResult<ExecutionOutput, ExecError>. - Replace all
miette::Resultinmiden-testingwithanyhow::Result. This means we also need to get rid of a bunch ofinto_diagnosticcalls. - Make adjustments to the
assert_execution_error!macro to handle matching onExecError(error).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomerstestsImprovements to testingImprovements to testing