Marginally simplify `TestStore`
What changed, and why it matters
This is a small code cleanup inside a test-only helper. It removes a special case that used a different key format when the secondary namespace was empty, replacing it with one consistent format. It also avoids an unnecessary copy of a byte buffer. The change only affects internal test utilities and does not alter production code or real user data handling.
No security action needed. Review as normal test refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors TestStore in lightning/src/util/test_utils.rs. Previously, key prefixes were primary_namespace when secondary_namespace was empty, otherwise primary_namespace/secondary_namespace. The patch always uses format!("{primary_namespace}/{secondary_namespace}"). It also replaces a manual Vec::new() + write_all clone with direct insertion of the owned buf parameter. TestStore is a mock/test implementation, so this is a simplification with no production security impact.
Changed components
lightning/src/util/test_utils.rsTestStore mock storage helperInspect captured patch +5 / −23
diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs
index 769c2a3..8bb5fd7 100644
--- a/lightning/src/util/test_utils.rs
+++ b/lightning/src/util/test_utils.rs
@@ -871,11 +871,7 @@ impl TestStore {
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> io::Result<Vec<u8>> {
let persisted_lock = self.persisted_bytes.lock().unwrap();
- let prefixed = if secondary_namespace.is_empty() {
- primary_namespace.to_string()
- } else {
- format!("{}/{}", primary_namespace, secondary_namespace)
- };
+ let prefixed = format!("{primary_namespace}/{secondary_namespace}");
if let Some(outer_ref) = persisted_lock.get(&prefixed) {
if let Some(inner_ref) = outer_ref.get(key) {
@@ -900,15 +896,9 @@ impl TestStore {
}
let mut persisted_lock = self.persisted_bytes.lock().unwrap();
- let prefixed = if secondary_namespace.is_empty() {
- primary_namespace.to_string()
- } else {
- format!("{}/{}", primary_namespace, secondary_namespace)
- };
+ let prefixed = format!("{primary_namespace}/{secondary_namespace}");
let outer_e = persisted_lock.entry(prefixed).or_insert(new_hash_map());
- let mut bytes = Vec::new();
- bytes.write_all(&buf)?;
- outer_e.insert(key.to_string(), bytes);
+ outer_e.insert(key.to_string(), buf);
Ok(())
}
@@ -924,11 +914,7 @@ impl TestStore {
let mut persisted_lock = self.persisted_bytes.lock().unwrap();
- let prefixed = if secondary_namespace.is_empty() {
- primary_namespace.to_string()
- } else {
- format!("{}/{}", primary_namespace, secondary_namespace)
- };
+ let prefixed = format!("{primary_namespace}/{secondary_namespace}");
if let Some(outer_ref) = persisted_lock.get_mut(&prefixed) {
outer_ref.remove(&key.to_string());
}
@@ -941,11 +927,7 @@ impl TestStore {
) -> io::Result<Vec<String>> {
let mut persisted_lock = self.persisted_bytes.lock().unwrap();
- let prefixed = if secondary_namespace.is_empty() {
- primary_namespace.to_string()
- } else {
- format!("{}/{}", primary_namespace, secondary_namespace)
- };
+ let prefixed = format!("{primary_namespace}/{secondary_namespace}");
match persisted_lock.entry(prefixed) {
hash_map::Entry::Occupied(e) => Ok(e.get().keys().cloned().collect()),
hash_map::Entry::Vacant(_) => Ok(Vec::new()),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.