Skip to content
15 changes: 14 additions & 1 deletion crates/precompiles/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ pub fn add_errors_to_registry<T: SolInterface>(
let converter = Arc::new(converter);
for selector in T::selectors() {
let converter = Arc::clone(&converter);
registry.insert(

let old_selector = registry.insert(
selector.into(),
Box::new(move |data: &[u8]| {
T::abi_decode(data)
Expand All @@ -106,6 +107,7 @@ pub fn add_errors_to_registry<T: SolInterface>(
})
}),
);
debug_assert!(old_selector.is_none(), "Duplicate selector {selector:x?}");
}
}

Expand Down Expand Up @@ -254,3 +256,14 @@ impl<T> IntoPrecompileResult<T> for TempoPrecompileError {
Ok(PrecompileOutput::new_reverted(gas, bytes))
}
}

#[cfg(test)]
mod tests {
use crate::error::error_decoder_registry;

// Test that initializes the error decoder registry and fails if there are any duplicates.
#[test]
fn test_error_decoder_registry_init() {
error_decoder_registry();
}
}
Loading