From b46adb6363faa0e267f89f872ab5eac3eace1249 Mon Sep 17 00:00:00 2001 From: Alice Carroll Date: Fri, 1 Dec 2023 17:49:39 +0100 Subject: [PATCH] refactor(tests): Always use `debug` in tests (#3542) --- pallets/gear/Cargo.toml | 13 ++--- pallets/gear/src/tests.rs | 101 ++++++++++++-------------------------- 2 files changed, 39 insertions(+), 75 deletions(-) diff --git a/pallets/gear/Cargo.toml b/pallets/gear/Cargo.toml index a70eaf7fe1c..ec2507f87bb 100644 --- a/pallets/gear/Cargo.toml +++ b/pallets/gear/Cargo.toml @@ -66,15 +66,16 @@ demo-constructor = { workspace = true, optional = true } demo-waiter = { workspace = true, optional = true } demo-init-wait = { workspace = true, optional = true } +# Some of tests require `debug` feature enabled [dev-dependencies] wabt.workspace = true hex.workspace = true blake2-rfc.workspace = true -gstd = { workspace = true, features = ["debug"] } +gstd.workspace = true demo-async.workspace = true demo-async-init.workspace = true demo-async-recursion.workspace = true -demo-async-tester.workspace = true +demo-async-tester = { workspace = true, features = ["debug"] } demo-delayed-sender.workspace = true demo-distributor.workspace = true demo-init-fail-sender.workspace = true @@ -95,10 +96,10 @@ demo-calc-hash.workspace = true demo-calc-hash-over-blocks.workspace = true demo-calc-hash-in-one-block.workspace = true demo-compose.workspace = true -demo-constructor.workspace = true +demo-constructor = { workspace = true, features = ["debug"] } demo-mul-by-const.workspace = true demo-wait.workspace = true -demo-waiter = { workspace = true, features = ["debug"] } # The 'debug' feature is required for some assertion in tests +demo-waiter = { workspace = true, features = ["debug"] } demo-wait-timeout.workspace = true demo-wait-wake.workspace = true demo-reserve-gas.workspace = true @@ -114,8 +115,8 @@ demo-out-of-memory.workspace = true demo-ping.workspace = true demo-sync-duplicate.workspace = true demo-custom.workspace = true -demo-delayed-reservation-sender.workspace = true -test-syscalls.workspace = true +demo-delayed-reservation-sender = { workspace = true, features = ["debug"] } +test-syscalls = { workspace = true, features = ["debug"] } page_size.workspace = true frame-support-test = { workspace = true, features = ["std"] } common = { workspace = true, features = ["std"] } diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index 5d0e7578a87..2bbb59d5f83 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -337,16 +337,12 @@ fn delayed_reservations_sending_validation() { run_to_next_block(None); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - format!( - "{SENDING_EXPECT}: {:?}", - GstdError::Core( - ExtError::Message(MessageError::InsufficientGasForDelayedSending).into() - ) + let error_text = format!( + "{SENDING_EXPECT}: {:?}", + GstdError::Core( + ExtError::Message(MessageError::InsufficientGasForDelayedSending).into() ) - } else { - String::from("no info") - }; + ); assert_failed( mid, @@ -377,16 +373,12 @@ fn delayed_reservations_sending_validation() { run_for_blocks(wait_for + 1, None); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - format!( - "{SENDING_EXPECT}: {:?}", - GstdError::Core( - ExtError::Message(MessageError::InsufficientGasForDelayedSending).into() - ) + let error_text = format!( + "{SENDING_EXPECT}: {:?}", + GstdError::Core( + ExtError::Message(MessageError::InsufficientGasForDelayedSending).into() ) - } else { - String::from("no info") - }; + ); assert_failed( mid, @@ -492,14 +484,10 @@ fn default_wait_lock_timeout() { run_to_block(expiration_block, None); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - format!( - "ran into error-reply: {:?}", - GstdError::Timeout(expiration_block, expiration_block) - ) - } else { - String::from("no info") - }; + let error_text = format!( + "ran into error-reply: {:?}", + GstdError::Timeout(expiration_block, expiration_block) + ); assert_failed( mid, @@ -7402,14 +7390,10 @@ fn pay_program_rent_syscall_works() { run_to_next_block(None); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - format!( - "{PAY_PROGRAM_RENT_EXPECT}: {:?}", - GstdError::Core(ExtError::Execution(ExecutionError::NotEnoughValue).into()) - ) - } else { - String::from("no info") - }; + let error_text = format!( + "{PAY_PROGRAM_RENT_EXPECT}: {:?}", + GstdError::Core(ExtError::Execution(ExecutionError::NotEnoughValue).into()) + ); assert_failed( message_id, @@ -7448,16 +7432,10 @@ fn pay_program_rent_syscall_works() { run_to_next_block(None); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - format!( - "{PAY_PROGRAM_RENT_EXPECT}: {:?}", - GstdError::Core( - ExtError::ProgramRent(ProgramRentError::MaximumBlockCountPaid).into() - ) - ) - } else { - String::from("no info") - }; + let error_text = format!( + "{PAY_PROGRAM_RENT_EXPECT}: {:?}", + GstdError::Core(ExtError::ProgramRent(ProgramRentError::MaximumBlockCountPaid).into()) + ); assert_failed( message_id, ActorExecutionErrorReplyReason::Trap(TrapExplanation::Panic(error_text.into())), @@ -8585,14 +8563,10 @@ fn test_create_program_with_value_lt_ed() { // to send init message with value in invalid range. assert_total_dequeued(1); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - format!( - "Failed to create program: {:?}", - GstdError::Core(ExtError::Message(MessageError::InsufficientValue).into()) - ) - } else { - String::from("no info") - }; + let error_text = format!( + "Failed to create program: {:?}", + GstdError::Core(ExtError::Message(MessageError::InsufficientValue).into()) + ); assert_failed( msg_id, @@ -8639,15 +8613,10 @@ fn test_create_program_with_exceeding_value() { // to send init message with value in invalid range. assert_total_dequeued(1); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - format!( - "Failed to create program: {:?}", - GstdError::Core(ExtError::Execution(ExecutionError::NotEnoughValue).into()) - ) - } else { - String::from("no info") - }; - + let error_text = format!( + "Failed to create program: {:?}", + GstdError::Core(ExtError::Execution(ExecutionError::NotEnoughValue).into()) + ); assert_failed( msg_id, ActorExecutionErrorReplyReason::Trap(TrapExplanation::Panic(error_text.into())), @@ -8731,17 +8700,11 @@ fn demo_constructor_works() { run_to_next_block(None); - let error_text = if cfg!(any(feature = "debug", debug_assertions)) { - "I just panic every time" - } else { - "no info" - }; + let error_text = "I just panic every time".to_owned(); assert_failed( message_id, - ActorExecutionErrorReplyReason::Trap(TrapExplanation::Panic( - error_text.to_string().into(), - )), + ActorExecutionErrorReplyReason::Trap(TrapExplanation::Panic(error_text.into())), ); let reply = maybe_any_last_message().expect("Should be");