ergotree_interpreter/eval/
sigma_prop_bytes.rs1use ergotree_ir::mir::sigma_prop_bytes::SigmaPropBytes;
2use ergotree_ir::mir::value::Value;
3
4use crate::eval::env::Env;
5use crate::eval::Context;
6use crate::eval::EvalError;
7use crate::eval::Evaluable;
8
9impl Evaluable for SigmaPropBytes {
10 fn eval<'ctx>(
11 &self,
12 env: &mut Env<'ctx>,
13 ctx: &Context<'ctx>,
14 ) -> Result<Value<'ctx>, EvalError> {
15 let input_v = self.input.eval(env, ctx)?;
16 match input_v {
17 Value::SigmaProp(sigma_prop) => Ok(sigma_prop.prop_bytes()?.into()),
18 _ => Err(EvalError::UnexpectedValue(format!(
19 "Expected SigmaPropBytes input to be Value::SigmaProp, got {0:?}",
20 input_v
21 ))),
22 }
23 }
24}
25
26#[cfg(feature = "arbitrary")]
27#[cfg(test)]
28#[allow(clippy::unwrap_used)]
29#[allow(clippy::panic)]
30mod tests {
31 use super::*;
32 use crate::eval::tests::eval_out_wo_ctx;
33 use ergotree_ir::mir::constant::Constant;
34 use ergotree_ir::mir::expr::Expr;
35 use ergotree_ir::sigma_protocol::sigma_boolean::SigmaProp;
36 use proptest::prelude::*;
37
38 proptest! {
39
40 #![proptest_config(ProptestConfig::with_cases(8))]
41
42 #[test]
43 fn eval(v in any::<SigmaProp>()) {
44 let expected_bytes = v.prop_bytes().unwrap();
45 let input: Constant = v.into();
46 let e: Expr = SigmaPropBytes {
47 input: Box::new(input.into()),
48 }
49 .into();
50 prop_assert_eq!(eval_out_wo_ctx::<Vec<u8>>(&e), expected_bytes);
51 }
52 }
53}