feat: Handle correct probing of genesis block (#57)
This commit is contained in:
parent
cd85e2dae1
commit
8ccc9d48f7
2 changed files with 13 additions and 0 deletions
1
pallas-primitives/src/byron/test_data/genesis.block
Normal file
1
pallas-primitives/src/byron/test_data/genesis.block
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,7 @@ use crate::Era;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Outcome {
|
pub enum Outcome {
|
||||||
Matched(Era),
|
Matched(Era),
|
||||||
|
GenesisBlock,
|
||||||
Inconclusive,
|
Inconclusive,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,6 +23,7 @@ pub fn probe_block_cbor_era(cbor: &[u8]) -> Outcome {
|
||||||
|
|
||||||
match tokenizer.next() {
|
match tokenizer.next() {
|
||||||
Some(Ok(Token::U8(variant))) => match variant {
|
Some(Ok(Token::U8(variant))) => match variant {
|
||||||
|
0 => Outcome::GenesisBlock,
|
||||||
1 => Outcome::Matched(Era::Byron),
|
1 => Outcome::Matched(Era::Byron),
|
||||||
2 => Outcome::Matched(Era::Shelley),
|
2 => Outcome::Matched(Era::Shelley),
|
||||||
3 => Outcome::Matched(Era::Allegra),
|
3 => Outcome::Matched(Era::Allegra),
|
||||||
|
|
@ -37,6 +39,16 @@ pub fn probe_block_cbor_era(cbor: &[u8]) -> Outcome {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
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]
|
#[test]
|
||||||
fn byron_block_detected() {
|
fn byron_block_detected() {
|
||||||
let block_str = include_str!("byron/test_data/test1.block");
|
let block_str = include_str!("byron/test_data/test1.block");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue