Move `TestStore` logic to `_internal` methods
What changed, and why it matters
This commit is a simple internal code cleanup in the project's test utilities. It takes the existing logic of a test-only key-value store and splits it into private helper methods, then has the public trait methods call those helpers. There is no change to behavior, no fix for a bug, and no security relevance.
No action needed. This is a non-security refactoring change in test-only code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors TestStore in lightning/src/util/test_utils.rs. The existing KVStoreSync trait implementation methods (read, write, remove, list) are renamed to read_internal, write_internal, remove_internal, and list_internal, and moved into the impl TestStore block. New public KVStoreSync trait methods are added that simply delegate to these _internal methods. The logic, locking behavior, error handling, and read_only checks are identical before and after. This is purely a refactor to allow other trait implementations or test code to reuse the same logic.
Changed components
lightning/src/util/test_utils.rsInspect captured patch +30 / −6
diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs
index d28d0ab..840b0a5 100644
--- a/lightning/src/util/test_utils.rs
+++ b/lightning/src/util/test_utils.rs
@@ -863,10 +863,8 @@ impl TestStore {
let persisted_bytes = Mutex::new(new_hash_map());
Self { persisted_bytes, read_only }
}
-}
-impl KVStoreSync for TestStore {
- fn read(
+ fn read_internal(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> io::Result<Vec<u8>> {
let persisted_lock = self.persisted_bytes.lock().unwrap();
@@ -888,7 +886,7 @@ impl KVStoreSync for TestStore {
}
}
- fn write(
+ fn write_internal(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
) -> io::Result<()> {
if self.read_only {
@@ -911,7 +909,7 @@ impl KVStoreSync for TestStore {
Ok(())
}
- fn remove(
+ fn remove_internal(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool,
) -> io::Result<()> {
if self.read_only {
@@ -935,7 +933,9 @@ impl KVStoreSync for TestStore {
Ok(())
}
- fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
+ fn list_internal(
+ &self, primary_namespace: &str, secondary_namespace: &str,
+ ) -> io::Result<Vec<String>> {
let mut persisted_lock = self.persisted_bytes.lock().unwrap();
let prefixed = if secondary_namespace.is_empty() {
@@ -950,6 +950,30 @@ impl KVStoreSync for TestStore {
}
}
+impl KVStoreSync for TestStore {
+ fn read(
+ &self, primary_namespace: &str, secondary_namespace: &str, key: &str,
+ ) -> io::Result<Vec<u8>> {
+ self.read_internal(primary_namespace, secondary_namespace, key)
+ }
+
+ fn write(
+ &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
+ ) -> io::Result<()> {
+ self.write_internal(primary_namespace, secondary_namespace, key, buf)
+ }
+
+ fn remove(
+ &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
+ ) -> io::Result<()> {
+ self.remove_internal(primary_namespace, secondary_namespace, key, lazy)
+ }
+
+ fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
+ self.list_internal(primary_namespace, secondary_namespace)
+ }
+}
+
unsafe impl Sync for TestStore {}
unsafe impl Send for TestStore {}
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.