Skip to content

Commit 3be6787

Browse files
committed
feat: handle NoReveals in tally_precondition_clause
And add conversion between NoReveals RadError and RadonError
1 parent c7d3066 commit 3be6787

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

data_structures/src/radon_error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub enum RadonErrors {
3737
Overflow = 0x41,
3838
/// Tried to divide by zero.
3939
DivisionByZero = 0x42,
40+
// Other errors
41+
/// Received zero reveals
42+
NoReveals = 0x50,
4043
}
4144

4245
/// Use `RadonErrors::Unknown` as the default value of `RadonErrors`.

rad/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ impl ErrorLike for RadError {
244244
Some(error),
245245
vec![CborValue::U8(status_code as u8)],
246246
),
247+
RadError::NoReveals => RadonError::new(RadonErrors::NoReveals, Some(error), vec![]),
247248
other => RadonError::from(other),
248249
}),
249250
result => result.map_err(RadonError::from),

rad/src/types/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ impl TryFrom<&cbor::value::Value> for RadonTypes {
296296
}
297297
}
298298
}
299+
RadonErrors::NoReveals => {
300+
return Err(RadError::NoReveals);
301+
}
302+
RadonErrors::Unknown => {
303+
return Err(RadError::Unknown);
304+
}
299305
_ => {
300306
log::warn!(
301307
"RadonError not implemented in TryFrom CBOR value"

validations/src/validations.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ pub fn evaluate_tally_precondition_clause(
219219
reveals: Vec<RadonReport<RadonTypes>>,
220220
non_error_min: f64,
221221
) -> Result<(Vec<RadonTypes>, Vec<bool>), RadError> {
222+
if reveals.is_empty() {
223+
return Err(RadError::NoReveals);
224+
}
225+
222226
let reveals_len = reveals.len() as f64;
223227

224228
let mut counter = Counter::new(RadonTypes::num_types());
@@ -1613,4 +1617,13 @@ mod tests {
16131617

16141618
assert_eq!(out, RadError::default());
16151619
}
1620+
1621+
#[test]
1622+
fn test_tally_precondition_clause_no_reveals() {
1623+
let v = vec![];
1624+
1625+
let out = evaluate_tally_precondition_clause(v, 0.51).unwrap_err();
1626+
1627+
assert_eq!(out, RadError::NoReveals);
1628+
}
16161629
}

0 commit comments

Comments
 (0)