Skip to content

Commit

Permalink
refactor(tests): Always use debug in tests (#3542)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecaralice authored Dec 1, 2023
1 parent 9e8d87d commit b46adb6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 75 deletions.
13 changes: 7 additions & 6 deletions pallets/gear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"] }
Expand Down
101 changes: 32 additions & 69 deletions pallets/gear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())),
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b46adb6

Please sign in to comment.