-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use super::prelude::*; | ||
|
||
pub(crate) fn block_depth_doesnt_skip_numbers(state: &State) -> Outcome { | ||
match (&state.previous_block, &state.current_block) { | ||
(Some(prev), Some(curr)) => Outcome::from((curr.number - prev.number) == 1), | ||
_ => Outcome::Unknown, | ||
} | ||
} | ||
|
||
pub(crate) fn block_slot_increases(state: &State) -> Outcome { | ||
match (&state.previous_block, &state.current_block) { | ||
(Some(prev), Some(curr)) => Outcome::from(prev.slot < curr.slot), | ||
_ => Outcome::Unknown, | ||
} | ||
} | ||
|
||
pub(crate) fn event_timestamp_increases(state: &State) -> Outcome { | ||
match (&state.previous_event, &state.current_event) { | ||
(Some(prev), Some(curr)) => match (prev.context.timestamp, curr.context.timestamp) { | ||
(Some(prev), Some(curr)) => Outcome::from(prev <= curr), | ||
_ => Outcome::Unknown, | ||
}, | ||
_ => Outcome::Unknown, | ||
} | ||
} | ||
|
||
pub(crate) fn block_previous_hash_matches(state: &State) -> Outcome { | ||
match (&state.previous_block, &state.current_block) { | ||
(Some(prev), Some(curr)) => Outcome::from(curr.previous_hash == prev.hash), | ||
_ => Outcome::Unknown, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod checks; | ||
mod prelude; | ||
mod run; | ||
mod setup; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::model::{BlockRecord, Event}; | ||
|
||
#[derive(Default, Debug)] | ||
pub(crate) struct State { | ||
pub current_event: Option<Event>, | ||
pub previous_event: Option<Event>, | ||
pub current_block: Option<BlockRecord>, | ||
pub previous_block: Option<BlockRecord>, | ||
} | ||
|
||
pub(crate) enum Outcome { | ||
Pass, | ||
Fail, | ||
Unknown, | ||
} | ||
|
||
impl From<bool> for Outcome { | ||
fn from(other: bool) -> Self { | ||
match other { | ||
true => Outcome::Pass, | ||
false => Outcome::Fail, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters