Unverified Commit 1f184b61 authored by Michael Müller's avatar Michael Müller Committed by GitHub
Browse files

Migrate to `panic_any` (#763)

* Migrate to `panic_any`

* Clean up unnecessary `std`-cfg's in off-chain env
parent 828352e3
Pipeline #134611 passed with stages
in 55 minutes and 48 seconds
...@@ -278,7 +278,7 @@ impl EnvInstance { ...@@ -278,7 +278,7 @@ impl EnvInstance {
beneficiary, beneficiary,
transferred: all, transferred: all,
}; };
panic!("{:?}", scale::Encode::encode(&res)); std::panic::panic_any(scale::Encode::encode(&res));
} }
} }
......
...@@ -31,7 +31,7 @@ use crate::{ ...@@ -31,7 +31,7 @@ use crate::{
Result, Result,
}; };
use ink_prelude::string::String; use ink_prelude::string::String;
use std::str::FromStr; use std::panic::UnwindSafe;
/// Pushes a contract execution context. /// Pushes a contract execution context.
/// ///
...@@ -390,9 +390,6 @@ where ...@@ -390,9 +390,6 @@ where
pub transferred: <E as Environment>::Balance, pub transferred: <E as Environment>::Balance,
} }
#[cfg(feature = "std")]
use std::panic::UnwindSafe;
/// Tests if a contract terminates successfully after `self.env().terminate()` /// Tests if a contract terminates successfully after `self.env().terminate()`
/// has been called. /// has been called.
/// ///
...@@ -408,7 +405,6 @@ use std::panic::UnwindSafe; ...@@ -408,7 +405,6 @@ use std::panic::UnwindSafe;
/// ``` /// ```
/// ///
/// See `examples/contract-terminate` for a complete usage example. /// See `examples/contract-terminate` for a complete usage example.
#[cfg(feature = "std")]
pub fn assert_contract_termination<T, F>( pub fn assert_contract_termination<T, F>(
should_terminate: F, should_terminate: F,
expected_beneficiary: T::AccountId, expected_beneficiary: T::AccountId,
...@@ -422,17 +418,10 @@ pub fn assert_contract_termination<T, F>( ...@@ -422,17 +418,10 @@ pub fn assert_contract_termination<T, F>(
let value_any = ::std::panic::catch_unwind(should_terminate) let value_any = ::std::panic::catch_unwind(should_terminate)
.expect_err("contract did not terminate"); .expect_err("contract did not terminate");
let encoded_input = value_any let encoded_input = value_any
.downcast_ref::<String>() .downcast_ref::<Vec<u8>>()
.expect("panic object can not be cast"); .expect("panic object can not be cast");
let deserialized_vec = encoded_input
.replace("[", "")
.replace("]", "")
.split(", ")
.map(|s| u8::from_str(s).expect("u8 cannot be extracted from str"))
.collect::<Vec<u8>>();
let res: ContractTerminationResult<T> = let res: ContractTerminationResult<T> =
scale::Decode::decode(&mut &deserialized_vec[..]) scale::Decode::decode(&mut &encoded_input[..]).expect("input can not be decoded");
.expect("input can not be decoded");
assert_eq!(res.beneficiary, expected_beneficiary); assert_eq!(res.beneficiary, expected_beneficiary);
assert_eq!(res.transferred, expected_balance); assert_eq!(res.transferred, expected_balance);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment