• 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

83.33
/ergotree-ir/src/mir/global_vars.rs
1
//! Global variables
2

3
use alloc::sync::Arc;
4
use core::fmt::Display;
5

6
use crate::has_opcode::HasOpCode;
7
use crate::serialization::op_code::OpCode;
8
use crate::traversable::impl_traversable_expr;
9
use crate::types::stype::SType;
10

11
use super::expr::Expr;
12

13
#[derive(PartialEq, Eq, Debug, Clone)]
14
/// Predefined global variables
15
pub enum GlobalVars {
16
    /// Tx inputs
17
    Inputs,
18
    /// Tx outputs
19
    Outputs,
20
    /// Current blockchain height
21
    Height,
22
    /// ErgoBox instance, which script is being evaluated
23
    SelfBox,
24
    /// When interpreted evaluates to a ByteArrayConstant built from Context.minerPubkey
25
    MinerPubKey,
26
    /// GroupElement (EcPoint) generator
27
    GroupGenerator,
28
}
29

30
impl GlobalVars {
31
    /// Type
32
    pub fn tpe(&self) -> SType {
6✔
33
        match self {
7✔
34
            GlobalVars::Inputs => SType::SColl(Arc::new(SType::SBox)),
3✔
35
            GlobalVars::Outputs => SType::SColl(Arc::new(SType::SBox)),
5✔
36
            GlobalVars::Height => SType::SInt,
4✔
37
            GlobalVars::SelfBox => SType::SBox,
4✔
UNCOV
38
            GlobalVars::MinerPubKey => SType::SColl(Arc::new(SType::SByte)),
×
39
            GlobalVars::GroupGenerator => SType::SGroupElement,
×
40
        }
41
    }
42
}
43

44
impl HasOpCode for GlobalVars {
45
    /// Op code (serialization)
46
    fn op_code(&self) -> OpCode {
5✔
47
        match self {
5✔
48
            GlobalVars::SelfBox => OpCode::SELF_BOX,
6✔
49
            GlobalVars::Inputs => OpCode::INPUTS,
2✔
50
            GlobalVars::Outputs => OpCode::OUTPUTS,
4✔
51
            GlobalVars::Height => OpCode::HEIGHT,
3✔
52
            GlobalVars::MinerPubKey => OpCode::MINER_PUBKEY,
2✔
53
            GlobalVars::GroupGenerator => OpCode::GROUP_GENERATOR,
1✔
54
        }
55
    }
56
}
57

58
impl Display for GlobalVars {
59
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2✔
60
        match self {
2✔
61
            GlobalVars::SelfBox => write!(f, "SELF"),
1✔
62
            GlobalVars::Inputs => write!(f, "INPUTS"),
1✔
63
            GlobalVars::Outputs => write!(f, "OUTPUTS"),
2✔
64
            GlobalVars::Height => write!(f, "HEIGHT"),
1✔
65
            GlobalVars::MinerPubKey => write!(f, "MINER_PUBKEY"),
×
66
            GlobalVars::GroupGenerator => write!(f, "GROUP_GENERATOR"),
×
67
        }
68
    }
69
}
70

71
impl_traversable_expr!(GlobalVars);
72

73
#[cfg(test)]
74
#[cfg(feature = "arbitrary")]
75
mod tests {
76
    use super::*;
77
    use proptest::prelude::*;
78

79
    impl Arbitrary for GlobalVars {
80
        type Parameters = ();
81
        type Strategy = BoxedStrategy<Self>;
82

83
        fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
84
            use GlobalVars::*;
85
            prop_oneof![
86
                Just(Inputs),
87
                Just(Outputs),
88
                Just(Height),
89
                Just(SelfBox),
90
                Just(MinerPubKey),
91
                Just(GroupGenerator)
92
            ]
93
            .boxed()
94
        }
95
    }
96
}
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