From 182f6ee541efd564c8c1ec43e50ab988451a29cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Wed, 27 Sep 2023 14:56:26 +0100 Subject: [PATCH] Change type of the error message to String Since this is for testing it doesn't need to be optimised unnecessarily --- .../support/src/storage/storage_noop_guard.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/substrate/frame/support/src/storage/storage_noop_guard.rs b/substrate/frame/support/src/storage/storage_noop_guard.rs index 485c41d01078..1278f1f64cdd 100644 --- a/substrate/frame/support/src/storage/storage_noop_guard.rs +++ b/substrate/frame/support/src/storage/storage_noop_guard.rs @@ -39,14 +39,14 @@ #[must_use] pub struct StorageNoopGuard { storage_root: sp_std::vec::Vec, - error_message: &'static str, + error_message: String, } impl Default for StorageNoopGuard { fn default() -> Self { Self { storage_root: sp_io::storage::root(sp_runtime::StateVersion::V1), - error_message: "`StorageNoopGuard` detected an attempted storage change.", + error_message: String::from("`StorageNoopGuard` detected an attempted storage change."), } } } @@ -58,12 +58,12 @@ impl StorageNoopGuard { } /// Creates a new [`StorageNoopGuard`] with a custom error message. - pub fn from_error_message(error_message: &'static str) -> Self { + pub fn from_error_message(error_message: String) -> Self { Self { storage_root: sp_io::storage::root(sp_runtime::StateVersion::V1), error_message } } /// Sets a custom error message for a [`StorageNoopGuard`]. - pub fn set_error_message(&mut self, error_message: &'static str) { + pub fn set_error_message(&mut self, error_message: String) { self.error_message = error_message; } } @@ -140,9 +140,9 @@ mod tests { #[should_panic(expected = "`StorageNoopGuard` found unexpected storage changes.")] fn storage_noop_guard_panics_created_from_error_message() { TestExternalities::default().execute_with(|| { - let _guard = StorageNoopGuard::from_error_message( + let _guard = StorageNoopGuard::from_error_message(String::from( "`StorageNoopGuard` found unexpected storage changes.", - ); + )); frame_support::storage::unhashed::put(b"key", b"value"); }); } @@ -152,7 +152,9 @@ mod tests { fn storage_noop_guard_panics_with_set_error_message() { TestExternalities::default().execute_with(|| { let mut guard = StorageNoopGuard::default(); - guard.set_error_message("`StorageNoopGuard` found unexpected storage changes."); + guard.set_error_message(String::from( + "`StorageNoopGuard` found unexpected storage changes.", + )); frame_support::storage::unhashed::put(b"key", b"value"); }); }