test(trie): fix cursor mocks (#15242)

This commit is contained in:
Alexey Shekhirin
2025-03-24 13:46:55 +00:00
committed by GitHub
parent 0200ad6ee0
commit 5a7cd15e94
2 changed files with 5 additions and 10 deletions

View File

@@ -103,11 +103,8 @@ impl<T: Debug + Clone> HashedCursor for MockHashedCursor<T> {
#[instrument(level = "trace", skip(self), ret)]
fn seek(&mut self, key: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
// Find the first key that has a prefix of the given key.
let entry = self
.values
.iter()
.find_map(|(k, v)| k.starts_with(key.as_slice()).then(|| (*k, v.clone())));
// Find the first key that is greater than or equal to the given key.
let entry = self.values.iter().find_map(|(k, v)| (k >= &key).then(|| (*k, v.clone())));
if let Some((key, _)) = &entry {
self.current_key = Some(*key);
}

View File

@@ -123,11 +123,9 @@ impl TrieCursor for MockTrieCursor {
&mut self,
key: Nibbles,
) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError> {
// Find the first key that has a prefix of the given key.
let entry = self
.trie_nodes
.iter()
.find_map(|(k, v)| k.starts_with(&key).then(|| (k.clone(), v.clone())));
// Find the first key that is greater than or equal to the given key.
let entry =
self.trie_nodes.iter().find_map(|(k, v)| (k >= &key).then(|| (k.clone(), v.clone())));
if let Some((key, _)) = &entry {
self.current_key = Some(key.clone());
}