use mega_evm::revm::primitives::{B256, U256};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum TestError {
#[error("unable to recover sender from fixture secretKey (key redacted)")]
UnknownPrivateKey(B256),
#[error("invalid transaction type")]
InvalidTransactionType,
#[error("transaction part index {index} out of bounds for `{part}` (len {len})")]
PartIndexOutOfBounds {
part: &'static str,
index: usize,
len: usize,
},
#[error("transaction `{field}` value {value} exceeds the supported range")]
ValueOutOfRange {
field: &'static str,
value: U256,
},
#[error("unexpected exception: got {got_exception:?}, expected {expected_exception:?}")]
UnexpectedException {
expected_exception: Option<String>,
got_exception: Option<String>,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn unknown_private_key_display_redacts_key_material() {
let key = B256::repeat_byte(0xab);
let msg = TestError::UnknownPrivateKey(key).to_string();
assert!(!msg.contains("abab"), "display leaks key material: {msg}");
assert!(!msg.contains(&format!("{key:?}")), "display leaks key material: {msg}");
assert!(msg.contains("redacted"), "display should say redacted: {msg}");
}
#[test]
fn value_out_of_range_display_names_field_and_value() {
let msg = TestError::ValueOutOfRange { field: "nonce", value: U256::MAX }.to_string();
assert!(msg.contains("nonce"), "missing field name: {msg}");
assert!(msg.contains(&U256::MAX.to_string()), "missing value: {msg}");
}
}