diff --git a/unit-tests/tests/utils/errors.rs b/unit-tests/tests/utils/errors.rs index fb9d86c1..0b6710ab 100644 --- a/unit-tests/tests/utils/errors.rs +++ b/unit-tests/tests/utils/errors.rs @@ -1,6 +1,7 @@ +#![allow(dead_code)] + use scrypto_test::prelude::*; -#[allow(dead_code)] pub fn is_wasm_panic(result: &Result) -> bool { matches!( result, @@ -9,3 +10,64 @@ pub fn is_wasm_panic(result: &Result) -> bool { )) ) } + +pub fn is_wasm_panic_error_contains( + result: &Result, + str: &str, +) -> bool { + matches!( + result, + Err(RuntimeError::ApplicationError( + ApplicationError::PanicMessage(error) + )) + if error.contains(str) + ) +} + +macro_rules! define_error_functions { + ( + $( + $func_name: ident => $string: expr; + )* + ) => { + $( + paste::paste! { + pub fn $func_name(result: &Result) -> bool + where + T: Debug + { + is_wasm_panic_error_contains(result, $string) + } + + pub fn [< assert_ $func_name >]( + result: &Result + ) + where + T: Debug + { + assert!( + $func_name(result), + "Running \"{}\" failed for result: {:#?}", + stringify!($func_name), + result + ) + } + } + )* + }; +} + +define_error_functions! { + is_open_liquidity_position_opening_disabled_error + => "Opening liquidity positions is not allowed at this time."; + is_open_liquidity_position_pool_not_allowed_error + => "is not found in the list of allowed pools"; + is_open_liquidity_position_not_a_valid_lockup_period_error + => "No reward percentage associated with lockup period."; + is_open_liquidity_position_no_adapter_error + => "No adapter found for liquidity pool"; + is_open_liquidity_position_price_difference_too_large_error + => "when the maximum allowed is:"; + is_add_allowed_pool_no_adapter_found_for_pool + => "No adapter found for component"; +}