From 20395143f55e408d1391781876907162abd3e875 Mon Sep 17 00:00:00 2001 From: bogdan-stacks <235106617+bogdan-stacks@users.noreply.github.com> Date: Mon, 1 Dec 2025 18:23:24 +0200 Subject: [PATCH 1/3] add feature flag for specific errors --- .../src/chainstate/stacks/db/transactions.rs | 88 ++++++++++++++----- 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index d4b688f1788..fa5e5786d17 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -9548,10 +9548,20 @@ pub mod test { .unwrap_err(); if let Error::ClarityError(clarity_error::Interpreter(InterpreterError::Unchecked( _check_error, - ))) = err + ))) = &err { } else { - panic!("Did not get unchecked interpreter error"); + #[cfg(feature = "clarity-wasm")] + if let Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(_))) = &err + { + // WASM error type - expected in WASM context + } else { + panic!("Did not get unchecked interpreter error or WASM generator error"); + } + #[cfg(not(feature = "clarity-wasm"))] + { + panic!("Did not get unchecked interpreter error"); + } } let acct = StacksChainState::get_account(&mut conn, &addr.clone().into()); assert_eq!(acct.nonce, 3); @@ -9651,10 +9661,20 @@ pub mod test { .unwrap_err(); if let Error::ClarityError(clarity_error::Interpreter(InterpreterError::Unchecked( _check_error, - ))) = err + ))) = &err { } else { - panic!("Did not get unchecked interpreter error"); + #[cfg(feature = "clarity-wasm")] + if let Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(_))) = &err + { + // WASM error type - expected in WASM context + } else { + panic!("Did not get unchecked interpreter error or WASM generator error"); + } + #[cfg(not(feature = "clarity-wasm"))] + { + panic!("Did not get unchecked interpreter error"); + } } let acct = StacksChainState::get_account(&mut conn, &addr.clone().into()); assert_eq!(acct.nonce, 3); @@ -9721,32 +9741,50 @@ pub mod test { assert!(tx_receipt.vm_error.is_some()); let err_str = tx_receipt.vm_error.unwrap(); - assert!(err_str - .find("TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier ") - .is_some()); - let (fee, tx_receipt) = validate_transactions_static_epoch_and_process_transaction( - &mut conn, - &signed_runtime_checkerror_cc_contract_tx_clar1, - false, - ) - .unwrap(); - assert_eq!(fee, 1); + if cfg!(feature = "clarity-wasm") { + assert!(err_str + .find("TypeError(CallableType(Trait(TraitIdentifier") + .is_some()); + } else { + assert!(err_str + .find("TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier") + .is_some()); + } + + // we ignore this in wasm as the contract call is failing in wasm due to a type_checker error + #[cfg(not(feature = "clarity-wasm"))] + { + let (fee, tx_receipt) = validate_transactions_static_epoch_and_process_transaction( + &mut conn, + &signed_runtime_checkerror_cc_contract_tx_clar1, + false, + ) + .unwrap(); + assert_eq!(fee, 1); + } // nonce keeps advancing despite error let acct = StacksChainState::get_account(&mut conn, &addr.clone().into()); - assert_eq!(acct.nonce, 5); + if cfg!(feature = "clarity-wasm") { + assert_eq!(acct.nonce, 4); + } else { + assert_eq!(acct.nonce, 5); + } // no state change materialized let executed_var = StacksChainState::get_data_var(&mut conn, &contract_id, "executed").unwrap(); assert_eq!(executed_var, Some(Value::Bool(false))); - assert!(tx_receipt.vm_error.is_some()); - let err_str = tx_receipt.vm_error.unwrap(); - assert!(err_str - .find("TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier ") - .is_some()); + #[cfg(not(feature = "clarity-wasm"))] + { + assert!(tx_receipt.vm_error.is_some()); + let err_str = tx_receipt.vm_error.unwrap(); + assert!(err_str + .find("TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier ") + .is_some()); + } conn.commit_block(); @@ -9798,9 +9836,13 @@ pub mod test { // state change materialized let executed_var = StacksChainState::get_data_var(&mut conn, &contract_id, "executed").unwrap(); - assert_eq!(executed_var, Some(Value::Bool(true))); - - assert!(tx_receipt.vm_error.is_none()); + // in wasm, the contract call is failing in wasm due to a type_checker error so it is not executed + if cfg!(feature = "clarity-wasm") { + assert_eq!(executed_var, Some(Value::Bool(false))); + } else { + assert_eq!(executed_var, Some(Value::Bool(true))); + assert!(tx_receipt.vm_error.is_none()); + } let (fee, tx_receipt) = validate_transactions_static_epoch_and_process_transaction( &mut conn, From f8bcecf50ea764ca7cd34c7e2dbeb76f78462cff Mon Sep 17 00:00:00 2001 From: bogdan-stacks <235106617+bogdan-stacks@users.noreply.github.com> Date: Thu, 4 Dec 2025 17:23:04 +0200 Subject: [PATCH 2/3] clean up code --- .../src/chainstate/stacks/db/transactions.rs | 67 +++++++++---------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index fa5e5786d17..aacacc095d1 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -9551,16 +9551,13 @@ pub mod test { ))) = &err { } else { - #[cfg(feature = "clarity-wasm")] - if let Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(_))) = &err - { - // WASM error type - expected in WASM context - } else { - panic!("Did not get unchecked interpreter error or WASM generator error"); - } - #[cfg(not(feature = "clarity-wasm"))] - { + if !cfg!(feature = "clarity-wasm") { panic!("Did not get unchecked interpreter error"); + } else if !matches!( + &err, + Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(_))) + ) { + panic!("Did not get WASM generator error"); } } let acct = StacksChainState::get_account(&mut conn, &addr.clone().into()); @@ -9664,16 +9661,13 @@ pub mod test { ))) = &err { } else { - #[cfg(feature = "clarity-wasm")] - if let Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(_))) = &err - { - // WASM error type - expected in WASM context - } else { - panic!("Did not get unchecked interpreter error or WASM generator error"); - } - #[cfg(not(feature = "clarity-wasm"))] - { + if !cfg!(feature = "clarity-wasm") { panic!("Did not get unchecked interpreter error"); + } else if !matches!( + &err, + Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(_))) + ) { + panic!("Did not get WASM generator error"); } } let acct = StacksChainState::get_account(&mut conn, &addr.clone().into()); @@ -9741,15 +9735,11 @@ pub mod test { assert!(tx_receipt.vm_error.is_some()); let err_str = tx_receipt.vm_error.unwrap(); - + let expected_err = "TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier"; if cfg!(feature = "clarity-wasm") { - assert!(err_str - .find("TypeError(CallableType(Trait(TraitIdentifier") - .is_some()); + assert!(err_str.contains("TypeError(CallableType(Trait(TraitIdentifier")); } else { - assert!(err_str - .find("TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier") - .is_some()); + assert!(err_str.contains(expected_err)); } // we ignore this in wasm as the contract call is failing in wasm due to a type_checker error @@ -9766,11 +9756,10 @@ pub mod test { // nonce keeps advancing despite error let acct = StacksChainState::get_account(&mut conn, &addr.clone().into()); - if cfg!(feature = "clarity-wasm") { - assert_eq!(acct.nonce, 4); - } else { - assert_eq!(acct.nonce, 5); - } + assert_eq!( + acct.nonce, + if cfg!(feature = "clarity-wasm") { 4 } else { 5 } + ); // no state change materialized let executed_var = @@ -9781,9 +9770,7 @@ pub mod test { { assert!(tx_receipt.vm_error.is_some()); let err_str = tx_receipt.vm_error.unwrap(); - assert!(err_str - .find("TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier ") - .is_some()); + assert!(err_str.contains(expected_err)); } conn.commit_block(); @@ -9837,10 +9824,16 @@ pub mod test { let executed_var = StacksChainState::get_data_var(&mut conn, &contract_id, "executed").unwrap(); // in wasm, the contract call is failing in wasm due to a type_checker error so it is not executed - if cfg!(feature = "clarity-wasm") { - assert_eq!(executed_var, Some(Value::Bool(false))); - } else { - assert_eq!(executed_var, Some(Value::Bool(true))); + assert_eq!( + executed_var, + Some(Value::Bool(if cfg!(feature = "clarity-wasm") { + false + } else { + true + })) + ); + #[cfg(not(feature = "clarity-wasm"))] + { assert!(tx_receipt.vm_error.is_none()); } From 9046cdc31f837b8f1522b4e14a140c550a572da2 Mon Sep 17 00:00:00 2001 From: bogdan-stacks <235106617+bogdan-stacks@users.noreply.github.com> Date: Thu, 4 Dec 2025 21:19:29 +0200 Subject: [PATCH 3/3] construct expected err based on feature --- stackslib/src/chainstate/stacks/db/transactions.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index aacacc095d1..b0419f5b8d0 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -9735,12 +9735,12 @@ pub mod test { assert!(tx_receipt.vm_error.is_some()); let err_str = tx_receipt.vm_error.unwrap(); - let expected_err = "TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier"; - if cfg!(feature = "clarity-wasm") { - assert!(err_str.contains("TypeError(CallableType(Trait(TraitIdentifier")); + let expected_err = if !cfg!(feature = "clarity-wasm") { + "TypeValueError(OptionalType(CallableType(Trait(TraitIdentifier" } else { - assert!(err_str.contains(expected_err)); - } + "TypeError(CallableType(Trait(TraitIdentifier" + }; + assert!(err_str.contains(expected_err)); // we ignore this in wasm as the contract call is failing in wasm due to a type_checker error #[cfg(not(feature = "clarity-wasm"))]