36 lines
1.2 KiB
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
2022-09-23 17:56:28 -07:00
2022-09-23 13:28:47 -07:00
fn make_input(word: &str) -> Vec<u8> {
2022-09-23 13:48:11 -07:00
let mut bytes: Vec<u8> = vec![word.len().try_into().unwrap()];
bytes.append(&mut word.as_bytes().to_vec());
bytes
2022-09-23 13:28:47 -07:00
}
2022-09-19 18:38:43 -07:00
#[test]
fn test_ripemd() -> Result<()> {
2022-09-26 07:34:57 -07:00
// let input: Vec<u8> = make_input("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
// let expected = U256::from("0x9b752e45573d4b39f4dbd3323cab82bf63326bfb");
2022-09-26 10:32:54 -07:00
let input: Vec<u8> = make_input("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
let expected = U256::from("0xb0e20b6e3116640286ed3a87a5713079b21f5189");
2022-09-26 07:34:57 -07:00
2022-09-22 09:27:11 -07:00
2022-09-22 10:34:32 -07:00
let kernel = combined_kernel();
2022-09-23 13:28:47 -07:00
let label = kernel.global_labels["ripemd_alt"];
let stack_input: Vec<U256> = input.iter().map(|&x| U256::from(x as u8)).rev().collect();
2022-09-26 07:34:57 -07:00
let stack_output: Vec<U256> = run_with_kernel(&kernel, label, stack_input)?.stack().to_vec();
let read_out: Vec<String> = stack_output.iter().map(|x| format!("{:x}", x)).rev().collect();
println!("{:x?}", read_out);
let actual = stack_output[0];
assert_eq!(actual, expected);
2022-09-19 18:38:43 -07:00
Ok(())
}