Skip to content

Commit

Permalink
Change type of the error message to String
Browse files Browse the repository at this point in the history
Since this is for testing it doesn't need to be optimised unnecessarily
  • Loading branch information
seadanda committed Sep 27, 2023
1 parent 7bc5b61 commit 182f6ee
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions substrate/frame/support/src/storage/storage_noop_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
#[must_use]
pub struct StorageNoopGuard {
storage_root: sp_std::vec::Vec<u8>,
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."),
}
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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");
});
}
Expand All @@ -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");
});
}
Expand Down

0 comments on commit 182f6ee

Please sign in to comment.