From 93a407b560bd2a24d238bda1ff44e3d08079014a Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com> Date: Mon, 23 Jun 2025 14:21:27 +0100 Subject: [PATCH] test: special case for nibbles implementations of `Compact` (#17006) --- crates/cli/commands/src/test_vectors/compact.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/cli/commands/src/test_vectors/compact.rs b/crates/cli/commands/src/test_vectors/compact.rs index abd3635e4f..d7a22838c5 100644 --- a/crates/cli/commands/src/test_vectors/compact.rs +++ b/crates/cli/commands/src/test_vectors/compact.rs @@ -222,6 +222,23 @@ where }; let res = obj.to_compact(&mut compact_buffer); + // `Compact` for `StoredNibbles` and `StoredNibblesSubKey` is implemented as converting to + // an array of nybbles, with each byte representing one nibble. This also matches the + // internal representation of `nybbles::Nibbles`: each nibble is stored in a separate byte, + // with high nibble set to zero. + // + // Unfortunately, the `Arbitrary` implementation for `nybbles::Nibbles` doesn't generate + // valid nibbles, as it sets the high nibble to a non-zero value. + // + // This hack sets the high nibble to zero. + // + // TODO: remove this, see https://github.com/paradigmxyz/reth/pull/17006 + if type_name == "StoredNibbles" || type_name == "StoredNibblesSubKey" { + for byte in &mut compact_buffer { + *byte &= 0x0F; + } + } + if IDENTIFIER_TYPE.contains(&type_name) { compact_buffer.push(res as u8); }