#[macro_export]
macro_rules! sqladdress {
($s:expr) => {
$crate::SqlAddress::new_from_address($crate::alloy::primitives::address!($s))
};
}
#[macro_export]
macro_rules! sqlhash {
($n:literal, $s:literal) => {{
$crate::SqlFixedBytes::<$n>::from_bytes($crate::alloy::primitives::fixed_bytes!($s))
}};
}
#[macro_export]
macro_rules! sqlu256 {
($val:literal) => {{
const _: () = assert!($val >= 0, "SqlU256 cannot be negative at compile time");
$crate::SqlU256::from($val as u128)
}};
}
#[cfg(test)]
mod tests {
use crate::SqlHash;
use alloy::primitives::hex;
#[test]
fn test_sqlhash_const_and_runtime() {
const TRANSFER_EVENT_SIGNATURE: SqlHash = sqlhash!(
32,
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
);
let runtime_hash: SqlHash = sqlhash!(
32,
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
);
assert_eq!(TRANSFER_EVENT_SIGNATURE, runtime_hash);
let expected =
hex::decode("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
assert_eq!(TRANSFER_EVENT_SIGNATURE.as_slice(), expected.as_slice());
const SHORT: crate::SqlFixedBytes<4> = sqlhash!(4, "0x095ea7b3");
let short_expected = hex::decode("095ea7b3").unwrap();
assert_eq!(SHORT.as_slice(), short_expected.as_slice());
}
#[test]
fn test_sqlu256_runtime() {
let runtime_amount: crate::SqlU256 = sqlu256!(12345678901234567890u128);
use alloy::primitives::U256;
let expected = U256::from(12345678901234567890u128);
assert_eq!(*runtime_amount, expected);
}
}