From 5a7cd15e946aed47b0929c5b52080765d023e5ff Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com> Date: Mon, 24 Mar 2025 13:46:55 +0000 Subject: [PATCH] test(trie): fix cursor mocks (#15242) --- crates/trie/trie/src/hashed_cursor/mock.rs | 7 ++----- crates/trie/trie/src/trie_cursor/mock.rs | 8 +++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/trie/trie/src/hashed_cursor/mock.rs b/crates/trie/trie/src/hashed_cursor/mock.rs index 42816f4e44..895bf852a2 100644 --- a/crates/trie/trie/src/hashed_cursor/mock.rs +++ b/crates/trie/trie/src/hashed_cursor/mock.rs @@ -103,11 +103,8 @@ impl HashedCursor for MockHashedCursor { #[instrument(level = "trace", skip(self), ret)] fn seek(&mut self, key: B256) -> Result, 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); } diff --git a/crates/trie/trie/src/trie_cursor/mock.rs b/crates/trie/trie/src/trie_cursor/mock.rs index 06cd459f82..4c7d20defb 100644 --- a/crates/trie/trie/src/trie_cursor/mock.rs +++ b/crates/trie/trie/src/trie_cursor/mock.rs @@ -123,11 +123,9 @@ impl TrieCursor for MockTrieCursor { &mut self, key: Nibbles, ) -> Result, 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()); }