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

tari-project / tari / 18097567115

29 Sep 2025 12:50PM UTC coverage: 58.554% (-2.3%) from 60.88%
18097567115

push

github

web-flow
chore(ci): switch rust toolchain to stable (#7524)

Description
switch rust toolchain to stable

Motivation and Context
use stable rust toolchain


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Standardized Rust toolchain on stable across CI workflows for more
predictable builds.
* Streamlined setup by removing unnecessary components and aligning
toolchain configuration with environment variables.
  * Enabled an environment flag to improve rustup behavior during CI.
* Improved coverage workflow consistency with dynamic toolchain
selection.

* **Tests**
* Removed nightly-only requirements, simplifying test commands and
improving compatibility.
* Expanded CI triggers to include ci-* branches for better pre-merge
validation.
* Maintained existing job logic while improving reliability and
maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

66336 of 113291 relevant lines covered (58.55%)

551641.45 hits per line

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

66.67
/base_layer/transaction_components/src/tari_proof_of_work/proof_of_work_algorithm.rs
1
// Copyright 2020. The Tari Project
2
//
3
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
// following conditions are met:
5
//
6
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
// disclaimer.
8
//
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
// following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
// products derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
use std::{
23
    convert::TryFrom,
24
    fmt::{Display, Formatter},
25
    str::FromStr,
26
};
27

28
use borsh::{BorshDeserialize, BorshSerialize};
29
use serde::{Deserialize, Serialize};
30

31
/// Indicates the algorithm used to mine a block
32
#[repr(u8)]
33
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Hash, Eq, BorshSerialize, BorshDeserialize)]
×
34
#[borsh(use_discriminant = true)]
35
pub enum PowAlgorithm {
36
    RandomXM = 0,
37
    Sha3x = 1,
38
    RandomXT = 2,
39
    Cuckaroo = 3,
40
}
41

42
impl PowAlgorithm {
43
    /// Returns true if the PoW algorithm is merged mined monero RandomX
44
    pub fn is_merged_mined_randomx(&self) -> bool {
×
45
        matches!(self, Self::RandomXM)
×
46
    }
×
47

48
    /// Returns true if the PoW algorithm is solo tari RandomX
49
    pub fn is_tari_randomx(&self) -> bool {
×
50
        matches!(self, Self::RandomXT)
×
51
    }
×
52

53
    /// Returns true if the PoW algorithm is Sha3
54
    pub fn is_sha3(&self) -> bool {
×
55
        matches!(self, Self::Sha3x)
×
56
    }
×
57

58
    /// A convenience functions that returns the PoW algorithm as a u64
59
    pub fn as_u64(&self) -> u64 {
×
60
        *self as u64
×
61
    }
×
62
}
63

64
impl TryFrom<u64> for PowAlgorithm {
65
    type Error = String;
66

67
    fn try_from(v: u64) -> Result<Self, Self::Error> {
×
68
        match v {
×
69
            0 => Ok(PowAlgorithm::RandomXM),
×
70
            1 => Ok(PowAlgorithm::Sha3x),
×
71
            2 => Ok(PowAlgorithm::RandomXT),
×
72
            3 => Ok(PowAlgorithm::Cuckaroo),
×
73
            _ => Err("Invalid PoWAlgorithm".into()),
×
74
        }
75
    }
×
76
}
77

78
impl FromStr for PowAlgorithm {
79
    type Err = anyhow::Error;
80

81
    fn from_str(s: &str) -> Result<Self, Self::Err> {
21✔
82
        let s_trimmed = s.replace("\"", "").replace("\'", "").replace(" ", "").to_uppercase();
21✔
83
        match s_trimmed.as_str() {
21✔
84
            "RANDOMXM" | "RANDOM_XM" | "MONERO_RANDOM_X" | "RANDOMX" | "RANDOM_X" | "RANDOMXMONERO" => {
21✔
85
                Ok(Self::RandomXM)
7✔
86
            },
87
            "SHA" | "SHA3" | "SHA3X" => Ok(Self::Sha3x),
14✔
88
            "RANDOMXT" | "RANDOM_XT" | "TARI_RANDOM_X" | "RANDOMXTARI" => Ok(Self::RandomXT),
4✔
89
            "CUCKAROO" | "CUCKAROO29" | "C29" => Ok(Self::Cuckaroo),
×
90
            _ => Err(anyhow::Error::msg(format!("Unknown pow algorithm type: {s}"))),
×
91
        }
92
    }
21✔
93
}
94

95
impl Display for PowAlgorithm {
96
    fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
2✔
97
        let algo = match self {
2✔
98
            PowAlgorithm::RandomXM => "RandomXMonero",
×
99
            PowAlgorithm::Sha3x => "Sha3",
1✔
100
            PowAlgorithm::RandomXT => "RandomXTari",
1✔
101
            PowAlgorithm::Cuckaroo => "Cuckaroo",
×
102
        };
103
        fmt.write_str(algo)
2✔
104
    }
2✔
105
}
106

107
#[cfg(test)]
108
mod tests {
109
    use serde_json;
110

111
    use super::*;
112

113
    #[test]
114
    fn test_pow_algorithm_from_str_variants() {
1✔
115
        // Test valid variants for RandomXM
116
        let randomxm_variants = vec![
1✔
117
            "RandomXM",
118
            "RandomX",
1✔
119
            "randomx",
1✔
120
            "random_x",
1✔
121
            "randomxm",
1✔
122
            "RANDOM_XM",
1✔
123
            "monero_random_x",
1✔
124
        ];
125
        for variant in randomxm_variants {
8✔
126
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse RandomXM variant");
7✔
127
            assert_eq!(algo, PowAlgorithm::RandomXM);
7✔
128
        }
129

130
        // Test valid variants for Sha3x
131
        let sha3x_variants = vec![
1✔
132
            "Sha3x",
133
            "\"Sha3x\"",
1✔
134
            "\'Sha3x\'",
1✔
135
            "Sha 3 x",
1✔
136
            "sha",
1✔
137
            "sha3",
1✔
138
            "SHA3",
1✔
139
            "sha3X",
1✔
140
            "Sha3X",
1✔
141
            "SHA3X",
1✔
142
        ];
143
        for variant in sha3x_variants {
11✔
144
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse Sha3x variant");
10✔
145
            assert_eq!(algo, PowAlgorithm::Sha3x);
10✔
146
        }
147

148
        // Test valid variants for RandomXT
149
        let randomxt_variants = vec!["RandomXT", "randomxt", "tari_random_x", "RANDOM_XT"];
1✔
150
        for variant in randomxt_variants {
5✔
151
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse RandomXT variant");
4✔
152
            assert_eq!(algo, PowAlgorithm::RandomXT);
4✔
153
        }
154
    }
1✔
155

156
    #[test]
157
    fn test_pow_algorithm_serialization() {
1✔
158
        for algo in [PowAlgorithm::Sha3x, PowAlgorithm::RandomXM, PowAlgorithm::RandomXT] {
3✔
159
            let serialized = serde_json::to_string(&algo).expect("Failed to serialize PowAlgorithm");
3✔
160
            let deserialized: PowAlgorithm =
3✔
161
                serde_json::from_str(&serialized).expect("Failed to deserialize PowAlgorithm");
3✔
162
            assert_eq!(deserialized, algo);
3✔
163
        }
164
    }
1✔
165
}
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

© 2026 Coveralls, Inc