From 8956a3547bbb599ea075bcc90851d9ceff32f214 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Tue, 27 Jun 2023 23:56:36 +0900 Subject: [PATCH] fix: remove `Qc.parent_view()` that has a bug (#223) --- consensus-engine/src/types.rs | 40 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/consensus-engine/src/types.rs b/consensus-engine/src/types.rs index abd5866a..a8a7869f 100644 --- a/consensus-engine/src/types.rs +++ b/consensus-engine/src/types.rs @@ -139,14 +139,6 @@ impl Qc { } } - /// The view of the block this qc is for. - pub fn parent_view(&self) -> View { - match self { - Qc::Standard(StandardQc { view, .. }) => *view, - Qc::Aggregated(AggregateQc { view, .. }) => *view, - } - } - /// The id of the block this qc is for. /// This will be the parent of the block which will include this qc pub fn block(&self) -> BlockId { @@ -163,3 +155,35 @@ impl Qc { } } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn standard_qc() { + let standard_qc = StandardQc { + view: 10, + id: [0; 32], + }; + let qc = Qc::Standard(standard_qc.clone()); + assert_eq!(qc.view(), 10); + assert_eq!(qc.block(), [0; 32]); + assert_eq!(qc.high_qc(), standard_qc); + } + + #[test] + fn aggregated_qc() { + let aggregated_qc = AggregateQc { + view: 20, + high_qc: StandardQc { + view: 10, + id: [0; 32], + }, + }; + let qc = Qc::Aggregated(aggregated_qc.clone()); + assert_eq!(qc.view(), 20); + assert_eq!(qc.block(), [0; 32]); + assert_eq!(qc.high_qc(), aggregated_qc.high_qc); + } +}