29 lines
897 B
Rust
Raw Normal View History

2022-09-19 18:38:43 -07:00
use anyhow::Result;
2022-09-19 19:06:48 -07:00
use ethereum_types::U256;
2022-09-19 18:38:43 -07:00
use crate::cpu::kernel::aggregator::combined_kernel;
2022-09-22 09:27:11 -07:00
use crate::cpu::kernel::interpreter::run_with_kernel;
2022-09-19 18:38:43 -07:00
#[test]
fn test_ripemd() -> Result<()> {
2022-09-23 08:05:14 -07:00
let input: Vec<u32> = vec![
2022-09-23 10:52:05 -07:00
26, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
2022-09-23 08:05:14 -07:00
];
2022-09-22 09:27:11 -07:00
2022-09-22 10:34:32 -07:00
let kernel = combined_kernel();
let stack_input: Vec<U256> = input.iter().map(|&x| U256::from(x as u32)).rev().collect();
2022-09-23 08:05:14 -07:00
let stack_output = run_with_kernel(&kernel, kernel.global_labels["ripemd_alt"], stack_input)?;
2022-09-23 10:52:05 -07:00
let actual: String = stack_output
2022-09-23 08:05:14 -07:00
.stack()
.iter()
2022-09-23 10:39:49 -07:00
.map(|&x| format!("{:x}", x))
2022-09-23 08:05:14 -07:00
.rev()
.collect();
2022-09-23 10:52:05 -07:00
let expected = "f71c27109c692c1b56bbdceb5b9d2865b3708dbc";
assert_eq!(expected, actual);
2022-09-19 18:38:43 -07:00
Ok(())
}