Skip to content

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Nov 7, 2024
1 parent c93abc6 commit 2dbb68e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 67 deletions.
51 changes: 26 additions & 25 deletions crates/pop-drink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ pub mod testnet {
/// ```rs
/// #[drink::test(sandbox = Pop)]
/// fn test_constructor_works(mut session: Session) {
/// let bundle = BundleProvider::local().unwrap();
/// let bundle = BundleProvider::local().unwrap();
///
/// // Deploy contract.
/// //
/// // `ContractError` is the error type used by the contract.
/// assert_ok!(deploy<Pop, ContractError>(&mut session, bundle, "new", input, salt, init_value));
/// // Deploy contract.
/// //
/// // `ContractError` is the error type used by the contract.
/// assert_ok!(deploy<Pop, ContractError>(&mut session, bundle, "new", input, salt, init_value));
/// }
/// ```
pub fn deploy<S, E>(
Expand Down Expand Up @@ -151,19 +151,19 @@ where
/// ```rs
/// #[drink::test(sandbox = Pop)]
/// fn call_works(mut session: Session) {
/// let bundle = BundleProvider::local().unwrap();
/// assert_ok!(deploy<Pop, ContractError>(&mut session, bundle, "new", input, salt, init_value));
/// let bundle = BundleProvider::local().unwrap();
/// assert_ok!(deploy<Pop, ContractError>(&mut session, bundle, "new", input, salt, init_value));
///
/// // Call contract.
/// //
/// // `()` is the successful result type used by the contract.
/// // `ContractError` is the error type used by the contract.
/// call::<Pop, (), ContractError>(
/// session,
/// "transfer",
/// input,
/// init_value,
/// )
/// // Call contract.
/// //
/// // `()` is the successful result type used by the contract.
/// // `ContractError` is the error type used by the contract.
/// call::<Pop, (), ContractError>(
/// session,
/// "transfer",
/// input,
/// init_value,
/// )
/// }
/// ```
pub fn call<S, O, E>(
Expand All @@ -180,8 +180,9 @@ where
{
match session.call::<String, ()>(func_name, &input, endowment) {
// If the call is reverted, decode the error into the specified error type.
Err(SessionError::CallReverted(error)) =>
Err(E::decode(&mut &error[2..]).expect("Decoding failed")),
Err(SessionError::CallReverted(error)) => {
Err(E::decode(&mut &error[2..]).expect("Decoding failed"))
},
// If the call is successful, decode the last returned value.
Ok(_) => Ok(session
.record()
Expand All @@ -206,12 +207,12 @@ where
/// use drink::last_contract_event;
///
/// assert_eq!(
/// last_contract_event::<Pop>(&session).unwrap(),
/// ContractEvent {
/// value: 42,
/// }
/// .encode()
/// .as_slice()
/// last_contract_event::<Pop>(&session).unwrap(),
/// ContractEvent {
/// value: 42,
/// }
/// .encode()
/// .as_slice()
/// );
/// ```
pub fn last_contract_event<S>(session: &Session<S>) -> Option<Vec<u8>>
Expand Down
84 changes: 42 additions & 42 deletions crates/pop-drink/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use crate::last_contract_event;
///
/// ```rs
/// use drink::devnet::{
/// Assets,
/// AssetsError::BalanceLow,
/// v0::{
/// Arithmetic,
/// ArithmeticError::Overflow,
/// BadOrigin
/// },
/// Assets,
/// AssetsError::BalanceLow,
/// v0::{
/// Arithmetic,
/// ArithmeticError::Overflow,
/// BadOrigin
/// },
/// };
/// ```
///
Expand Down Expand Up @@ -51,50 +51,50 @@ use crate::last_contract_event;
///
/// /// Custom error in contract.
/// pub enum CustomError {
/// ...,
/// /// Error with status code.
/// StatusCode(u32),
/// ...,
/// /// Error with status code.
/// StatusCode(u32),
/// }
///
/// impl From<StatusCode> for CustomError {
/// /// Converts a `StatusCode` (returned by the api) to a `CustomError`.
/// fn from(value: StatusCode) -> Self {
/// match value {
/// ...,
/// _ => CustomError::StatusCode(value.0),
/// }
/// }
/// /// Converts a `StatusCode` (returned by the api) to a `CustomError`.
/// fn from(value: StatusCode) -> Self {
/// match value {
/// ...,
/// _ => CustomError::StatusCode(value.0),
/// }
/// }
/// }
///
/// impl From<CustomError> for u32 {
/// /// Converts a `CustomError to a `u32`.
/// //
/// // Required for the `assert_err` macro to assert to `Error`.
/// fn from(value: CustomError) -> Self {
/// match value {
/// ...,
/// CustomError::StatusCode(status_code) => status_code,
/// }
/// }
/// /// Converts a `CustomError to a `u32`.
/// //
/// // Required for the `assert_err` macro to assert to `Error`.
/// fn from(value: CustomError) -> Self {
/// match value {
/// ...,
/// CustomError::StatusCode(status_code) => status_code,
/// }
/// }
/// }
///
/// - Use `assert_err` in a test.
///
/// #[drink::test(sandbox = Pop)]
/// fn test_custom_error(mut session: Session) {
/// ...
/// ...
///
/// // Call a contract method that returns a `Result<(), CustomError>`.
/// let result = call::<Pop, (), CustomError>(session, "hello_world", vec![], None);
/// // Call a contract method that returns a `Result<(), CustomError>`.
/// let result = call::<Pop, (), CustomError>(session, "hello_world", vec![], None);
///
/// // Assert the result to the expected error.
/// assert_err!(result, Error::Raw(BadOrigin)));
/// // Assert the result to the expected error.
/// assert_err!(result, Error::Raw(BadOrigin)));
///
/// // Other assertions:
/// ...
/// assert_err!(result, Error::Raw(Arithmetic(Overflow)));
/// ...
/// assert_err!(result, Error::Module(Assets(BalanceLow)));
/// // Other assertions:
/// ...
/// assert_err!(result, Error::Raw(Arithmetic(Overflow)));
/// ...
/// assert_err!(result, Error::Module(Assets(BalanceLow)));
/// }
/// ```
///
Expand Down Expand Up @@ -135,12 +135,12 @@ where
///
/// ```rs
/// assert_last_contract_event!(
/// &session,
/// Transfer {
/// from: Some(account_id_from_slice(&contract)),
/// to: Some(account_id_from_slice(&BOB)),
/// value,
/// }
/// &session,
/// Transfer {
/// from: Some(account_id_from_slice(&contract)),
/// to: Some(account_id_from_slice(&BOB)),
/// value,
/// }
/// );
/// ```
///
Expand Down

0 comments on commit 2dbb68e

Please sign in to comment.