• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ergoplatform / sigma-rust / 15667516698

15 Jun 2025 09:22PM UTC coverage: 77.672% (-0.6%) from 78.291%
15667516698

Pull #832

github

web-flow
Merge 39c40f47b into 6f12ef8f2
Pull Request #832: Soft Fork support

298 of 462 new or added lines in 72 files covered. (64.5%)

53 existing lines in 22 files now uncovered.

11765 of 15147 relevant lines covered (77.67%)

2.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/ergotree-ir/src/mir/bool_to_sigma.rs
1
//! Embedding of Boolean values to SigmaProp
2
use alloc::boxed::Box;
3

4
use crate::has_opcode::HasStaticOpCode;
5
use crate::mir::unary_op::OneArgOp;
6
use crate::mir::unary_op::OneArgOpTryBuild;
7
use crate::serialization::op_code::OpCode;
8
use crate::types::stype::SType;
9

10
use super::expr::Expr;
11
use super::expr::InvalidArgumentError;
12

13
/** Embedding of Boolean values to SigmaProp values. As an example, this operation allows boolean experesions
14
 * to be used as arguments of `atLeast(..., sigmaProp(boolExpr), ...)` operation.
15
 * During execution results to either `TrueProp` or `FalseProp` values of SigmaProp type.
16
 */
17
#[derive(PartialEq, Eq, Debug, Clone)]
18
pub struct BoolToSigmaProp {
19
    /// Expr of type SBoolean
20
    pub input: Box<Expr>,
21
}
22

23
impl BoolToSigmaProp {
24
    /// Type
25
    pub fn tpe(&self) -> SType {
6✔
26
        SType::SSigmaProp
4✔
27
    }
28
}
29

30
impl HasStaticOpCode for BoolToSigmaProp {
31
    const OP_CODE: OpCode = OpCode::BOOL_TO_SIGMA_PROP;
32
}
33

34
impl OneArgOp for BoolToSigmaProp {
35
    fn input(&self) -> &Expr {
7✔
36
        &self.input
7✔
37
    }
38
    fn input_mut(&mut self) -> &mut Expr {
2✔
39
        &mut self.input
2✔
40
    }
41
}
42

43
impl OneArgOpTryBuild for BoolToSigmaProp {
UNCOV
44
    fn try_build(input: Expr) -> Result<Self, InvalidArgumentError> {
×
45
        // Input TPE is not checked here as old versions of interpreter (v4.0) accepted SigmaProp as argument to BoolToSigmaProp
NEW
46
        Ok(Self::build_unchecked(input))
×
47
    }
48

49
    fn build_unchecked(input: Expr) -> Self {
4✔
50
        Self {
51
            input: input.into(),
6✔
52
        }
53
    }
54
}
55

56
/// Arbitrary impl
57
#[cfg(feature = "arbitrary")]
58
mod arbitrary {
59
    use crate::mir::expr::arbitrary::ArbExprParams;
60

61
    use super::*;
62
    use proptest::prelude::*;
63

64
    impl Arbitrary for BoolToSigmaProp {
65
        type Strategy = BoxedStrategy<Self>;
66
        type Parameters = usize;
67

68
        fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
1✔
69
            any_with::<Expr>(ArbExprParams {
1✔
70
                tpe: SType::SBoolean,
1✔
71
                depth: args,
72
            })
73
            .prop_map(|input| Self {
1✔
74
                input: input.into(),
1✔
75
            })
76
            .boxed()
77
        }
78
    }
79
}
80

81
#[cfg(test)]
82
#[cfg(feature = "arbitrary")]
83
#[allow(clippy::panic)]
84
mod tests {
85

86
    use crate::mir::expr::Expr;
87
    use crate::serialization::sigma_serialize_roundtrip;
88

89
    use super::*;
90

91
    use proptest::prelude::*;
92

93
    proptest! {
94

95
        #[test]
96
        fn ser_roundtrip(v in any::<BoolToSigmaProp>()) {
97
            let expr: Expr = v.into();
98
            prop_assert_eq![sigma_serialize_roundtrip(&expr), expr];
99
        }
100

101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc