Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Handle correct probing of genesis block #57

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pallas-primitives/src/byron/test_data/genesis.block

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions pallas-primitives/src/probing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::Era;
#[derive(Debug)]
pub enum Outcome {
Matched(Era),
GenesisBlock,
Inconclusive,
}

Expand All @@ -22,6 +23,7 @@ pub fn probe_block_cbor_era(cbor: &[u8]) -> Outcome {

match tokenizer.next() {
Some(Ok(Token::U8(variant))) => match variant {
0 => Outcome::GenesisBlock,
1 => Outcome::Matched(Era::Byron),
2 => Outcome::Matched(Era::Shelley),
3 => Outcome::Matched(Era::Allegra),
Expand All @@ -37,6 +39,16 @@ pub fn probe_block_cbor_era(cbor: &[u8]) -> Outcome {
mod tests {
use super::*;

#[test]
fn genesis_block_detected() {
let block_str = include_str!("byron/test_data/genesis.block");
let bytes = hex::decode(block_str).unwrap();

let inference = probe_block_cbor_era(bytes.as_slice());

assert!(matches!(inference, Outcome::GenesisBlock));
}

#[test]
fn byron_block_detected() {
let block_str = include_str!("byron/test_data/test1.block");
Expand Down