From 035ea9cbd5825695f340b13a31602685be31572b Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 15 Mar 2023 13:42:46 -0400 Subject: [PATCH] chore: rebase on main --- soroban-env-common/src/env.rs | 1 - soroban-env-host/src/events/internal.rs | 2 +- soroban-env-host/src/host.rs | 20 +++++++------------ .../src/host/diagnostics_helper.rs | 6 ++---- soroban-env-host/src/host/error.rs | 6 +++--- soroban-env-host/src/test/event.rs | 2 +- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/soroban-env-common/src/env.rs b/soroban-env-common/src/env.rs index 381ce8bea..887d31905 100644 --- a/soroban-env-common/src/env.rs +++ b/soroban-env-common/src/env.rs @@ -46,7 +46,6 @@ pub trait EnvBase: Sized + Clone { /// Used to check two environments are the same, trapping if not. fn check_same_env(&self, other: &Self); - /// Used to clone an environment deeply, not just a handle to it. #[allow(clippy::return_self_not_must_use)] fn deep_clone(&self) -> Self; diff --git a/soroban-env-host/src/events/internal.rs b/soroban-env-host/src/events/internal.rs index 0ef8cf578..306f2b130 100644 --- a/soroban-env-host/src/events/internal.rs +++ b/soroban-env-host/src/events/internal.rs @@ -84,7 +84,7 @@ impl InternalEventsBuffer { pub fn dump_to_debug_log(&self) { use log::debug; debug!("=======Start of events======="); - for e in self.vec.iter() { + for e in &self.vec { match &e.0 { InternalEvent::Contract(c) => debug!("Contract event: {:?}", c), InternalEvent::Debug(d) => debug!("Debug event: {}", d), diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs index a75020139..b733d5070 100644 --- a/soroban-env-host/src/host.rs +++ b/soroban-env-host/src/host.rs @@ -142,18 +142,13 @@ pub struct LedgerInfo { pub base_reserve: u32, } -#[derive(Clone)] +#[derive(Clone, Default)] pub enum DiagnosticLevel { + #[default] None, Debug, } -impl Default for DiagnosticLevel { - fn default() -> Self { - DiagnosticLevel::None - } -} - #[derive(Clone, Default)] pub(crate) struct HostImpl { source_account: RefCell>, @@ -1026,7 +1021,7 @@ impl Host { } } - self.fn_call_diagnostics(&id, &func, args)?; + self.fn_call_diagnostics(id, &func, args)?; // "testutils" is not covered by budget metering. #[cfg(any(test, feature = "testutils"))] @@ -1110,14 +1105,13 @@ impl Host { } } - let res = self.call_contract_fn(&id, &func, args); + let res = self.call_contract_fn(id, &func, args); - match &res { - Ok(res) => self.fn_return_diagnostics(id, &func, &res)?, - Err(err) => {} + if let Ok(res) = &res { + self.fn_return_diagnostics(id, &func, res)?; } - return res; + res } // Notes on metering: covered by the called components. diff --git a/soroban-env-host/src/host/diagnostics_helper.rs b/soroban-env-host/src/host/diagnostics_helper.rs index 87432430f..59a3f17af 100644 --- a/soroban-env-host/src/host/diagnostics_helper.rs +++ b/soroban-env-host/src/host/diagnostics_helper.rs @@ -76,8 +76,7 @@ impl Host { self.record_system_debug_contract_event( ContractEventType::Diagnostic, calling_contract, - self.add_host_object(HostVec::from_vec(topics)?)? - .try_into()?, + self.add_host_object(HostVec::from_vec(topics)?)?, self.vec_new_from_slice(args)?.into(), ) }) @@ -102,8 +101,7 @@ impl Host { self.record_system_debug_contract_event( ContractEventType::Diagnostic, Some(self.hash_to_bytesobj(contract_id)?), - self.add_host_object(HostVec::from_vec(topics)?)? - .try_into()?, + self.add_host_object(HostVec::from_vec(topics)?)?, *res, ) }) diff --git a/soroban-env-host/src/host/error.rs b/soroban-env-host/src/host/error.rs index 602810ed5..d8ef4d5bc 100644 --- a/soroban-env-host/src/host/error.rs +++ b/soroban-env-host/src/host/error.rs @@ -66,9 +66,9 @@ impl Debug for HostError { ev.0.iter() .rev() .filter_map(|ev| match ev.event.clone() { - Event::Debug(e) => Some(format!("Debug {:}", e)), - Event::StructuredDebug(e) => Some(format!("StructuredDebug {:?}", e)), - _ => None, + Event::Debug(e) => Some(format!("Debug {e:}")), + Event::StructuredDebug(e) => Some(format!("StructuredDebug {e:?}")), + Event::Contract(_) => None, }) .take(MAX_DEBUG_EVENTS) .enumerate() diff --git a/soroban-env-host/src/test/event.rs b/soroban-env-host/src/test/event.rs index 816ba1bde..e57844095 100644 --- a/soroban-env-host/src/test/event.rs +++ b/soroban-env-host/src/test/event.rs @@ -98,7 +98,7 @@ fn test_event_rollback() -> Result<(), HostError> { let args = host.test_vec_obj::(&[1, 2])?; host.register_test_contract(id, test_contract)?; assert_eq!( - host.call(id, sym.into(), args.into())?.get_payload(), + host.call(id, sym, args)?.get_payload(), RawVal::from_void().to_raw().get_payload() ); host.0.events.borrow_mut().rollback(1)?;