Skip to content

Commit

Permalink
feat(rad): add NoReveals error
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Jan 10, 2020
1 parent 20f48ba commit c7d3066
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rad/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ pub enum RadError {
value
)]
InvalidScript { value: SerdeCborValue },
/// No reveals received
#[fail(display = "No reveals received")]
NoReveals,
}

/// Satisfy the `ErrorLike` trait that ensures generic compatibility of `witnet_rad` and
Expand Down
22 changes: 22 additions & 0 deletions rad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ pub fn run_tally_report(
let reducer = consensus.reducer;
let radon_script = create_radon_script_from_filters_and_reducer(filters, reducer)?;

if radon_types_vec.is_empty() {
return RadonReport::from_result(Err(RadError::NoReveals), context);
}

let items_to_tally = RadonTypes::from(RadonArray::from(radon_types_vec));

execute_radon_script(items_to_tally, &radon_script, context)
Expand Down Expand Up @@ -705,4 +709,22 @@ mod tests {
}
);
}

#[test]
fn test_result_no_reveals() {
// Trying to create a tally with no reveals will return a RadError result
let reveals = vec![];
let report = run_tally_report(
reveals,
&RADTally {
filters: vec![],
reducer: RadonReducers::AverageMean as u32,
},
None,
)
.unwrap();

let output_tally = report.into_inner();
assert_eq!(output_tally, Err(RadError::NoReveals));
}
}

0 comments on commit c7d3066

Please sign in to comment.