Skip to content

Commit

Permalink
Add sandbox err message
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones committed Apr 23, 2024
1 parent d9ed700 commit cf1b94f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
16 changes: 13 additions & 3 deletions crates/e2e/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,26 @@ where

/// Dummy error type for sandbox_client
#[derive(Debug, thiserror::Error)]
pub struct SandboxErr;
pub struct SandboxErr {
msg: String,
}

impl SandboxErr {
pub fn new(msg: String) -> Self {
Self { msg }
}
}

impl fmt::Display for SandboxErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SandboxErr")
write!(f, "SandboxErr: {}", self.msg)
}
}

impl<Balance> From<ContractExecResult<Balance, ()>> for SandboxErr {
fn from(_value: ContractExecResult<Balance, ()>) -> Self {
Self {}
Self {
msg: "ContractExecResult".to_string(),
}
}
}
20 changes: 8 additions & 12 deletions crates/e2e/src/sandbox_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ where

// Encode the call object.
let call = subxt::dynamic::tx(pallet_name, call_name, call_data);
let encoded_call = call
.encode_call_data(&metadata.into())
.map_err(|_| SandboxErr)?;
let encoded_call = call.encode_call_data(&metadata.into()).map_err(|err| {
SandboxErr::new(format!("runtime_call: Error encoding call: {err:?}"))
})?;

// Decode the call object.
// Panic on error - we just encoded a validated call object, so it should be
Expand All @@ -197,7 +197,7 @@ where
decoded_call,
S::convert_account_to_origin(keypair_to_account(origin)),
)
.map_err(|_| SandboxErr)?;
.map_err(|_| SandboxErr::new(format!("runtime_call: execution error")))?;

Ok(())
}
Expand Down Expand Up @@ -244,7 +244,7 @@ where
let account_id_raw = match &result.result {
Err(err) => {
log_error(&format!("Instantiation failed: {err:?}"));
return Err(SandboxErr);
return Err(SandboxErr::new(format!("bare_instantiate: {err:?}")));
}
Ok(res) => *res.account_id.as_ref(),
};
Expand Down Expand Up @@ -319,7 +319,7 @@ where
Ok(result) => result,
Err(err) => {
log_error(&format!("Upload failed: {err:?}"));
return Err(SandboxErr);
return Err(SandboxErr::new(format!("bare_upload: {err:?}")))
}
};

Expand Down Expand Up @@ -362,8 +362,7 @@ where
let exec_input = Encode::encode(message.clone().params().exec_input());
let account_id = (*account_id.as_ref()).into();

if self
.sandbox
self.sandbox
.call_contract(
account_id,
value,
Expand All @@ -374,10 +373,7 @@ where
pallet_contracts::Determinism::Enforced,
)
.result
.is_err()
{
return Err(SandboxErr);
}
.map_err(|err| SandboxErr::new(format!("bare_call: {err:?}")))?;

Ok(())
}
Expand Down

0 comments on commit cf1b94f

Please sign in to comment.