assert_eq!(hash.len(), 40);
"0x"
.chars()
.chain(address.chars().zip(hash.chars()).map(|(a, h)| match h {
'0'..='7' => a,
'8'..='9' | 'a'..='f' => a.to_ascii_uppercase(),
_ => unreachable!(),
}))
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_eth_checksum_generation() {
// test addresses from https://eips.ethereum.org/EIPS/eip-55
for addr in &[
"0x27b1fdb04752bbc536007a920d24acb045561c26",
"0x52908400098527886E0F7030069857D2E4169EE7",
"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
"0x8617E340B3D01FA5F11F306F4090FD50E238070D",
"0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
"0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB",
"0xde709f2102306220921060314715629080e2fb77",
"0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359",
] {
let lowercased = String::from(&addr[2..]).to_ascii_lowercase();
assert_eq!(addr.to_string(), create_address_with_checksum(&lowercased));
}
}
#[test]
fn test_inscription_id_to_teleburn_address() {