26 lines
855 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
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-23 17:46:53 -07:00
let input: Vec<u8> = make_input("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
let expected = U256::from("0xb0e20b6e3116640286ed3a87a5713079b21f5189");
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-23 13:48:11 -07:00
let output: U256 = run_with_kernel(&kernel, label, stack_input)?.stack()[0];
2022-09-23 13:28:47 -07:00
assert_eq!(output, expected);
2022-09-19 18:38:43 -07:00
Ok(())
}