assert as U256

This commit is contained in:
Dmitry Vagner 2022-09-23 13:48:11 -07:00
parent 36c4b48017
commit abcb93d0a8

View File

@ -5,26 +5,20 @@ use crate::cpu::kernel::aggregator::combined_kernel;
use crate::cpu::kernel::interpreter::run_with_kernel;
fn make_input(word: &str) -> Vec<u8> {
let mut bytes: Vec<u8> = vec![word.len().try_into().unwrap()];
bytes.append(&mut word.as_bytes().to_vec());
bytes
let mut bytes: Vec<u8> = vec![word.len().try_into().unwrap()];
bytes.append(&mut word.as_bytes().to_vec());
bytes
}
#[test]
fn test_ripemd() -> Result<()> {
let input: Vec<u8> = make_input("abcdefghijklmnopqrstuvwxyz");
let expected = "f71c27109c692c1b56bbdceb5b9d2865b3708dbc";
let input: Vec<u8> = make_input("a");
let expected = U256::from("0x0bdc9d2d256b3ee9daae347be6f4dc835a467ffe");
let kernel = combined_kernel();
let label = kernel.global_labels["ripemd_alt"];
let stack_input: Vec<U256> = input.iter().map(|&x| U256::from(x as u8)).rev().collect();
let output: String = run_with_kernel(&kernel, label, stack_input)?
.stack()
.iter()
.map(|&x| format!("{:x}", x))
.rev()
.collect();
let output: U256 = run_with_kernel(&kernel, label, stack_input)?.stack()[0];
assert_eq!(output, expected);
Ok(())