feat: Handle correct probing of genesis block (#57)

This commit is contained in:
Santiago Carmuega 2022-02-24 11:45:37 -03:00 committed by GitHub
parent f09047482e
commit 5784ee6c4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

File diff suppressed because one or more lines are too long

View file

@ -7,6 +7,7 @@ use crate::Era;
#[derive(Debug)]
pub enum Outcome {
Matched(Era),
GenesisBlock,
Inconclusive,
}
@ -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),
@ -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");