From c7d30667d01b667cac0bb1d020028e9af1209bf3 Mon Sep 17 00:00:00 2001 From: Tomasz Polaczyk Date: Thu, 9 Jan 2020 18:23:11 +0100 Subject: [PATCH] feat(rad): add NoReveals error --- rad/src/error.rs | 3 +++ rad/src/lib.rs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/rad/src/error.rs b/rad/src/error.rs index 4fe594163..29b7f869b 100644 --- a/rad/src/error.rs +++ b/rad/src/error.rs @@ -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 diff --git a/rad/src/lib.rs b/rad/src/lib.rs index 681c8a58d..b71e30847 100644 --- a/rad/src/lib.rs +++ b/rad/src/lib.rs @@ -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) @@ -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)); + } }