Skip to content

Commit

Permalink
Add TryFrom<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianBland committed Aug 26, 2024
1 parent 7df4f78 commit 70afc00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion crates/op-test-vectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ alloy-consensus.workspace = true
op-alloy-rpc-types.workspace = true
op-alloy-consensus.workspace = true

# Kona
kona-primitives.workspace = true

[dev-dependencies]
serde_json.workspace = true
kona-primitives.workspace = true
26 changes: 23 additions & 3 deletions crates/op-test-vectors/src/faultproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256};
use hashbrown::HashMap;
use kona_derive::types::RollupConfig;
use kona_primitives::RollupConfig;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

Expand Down Expand Up @@ -54,9 +54,29 @@ pub enum FaultProofStatus {
Unknown,
}

impl TryFrom<u8> for FaultProofStatus {
type Error = String;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(FaultProofStatus::Valid),
1 => Ok(FaultProofStatus::Invalid),
2 => Ok(FaultProofStatus::Panic),
3 => Ok(FaultProofStatus::Unfinished),
_ => Ok(FaultProofStatus::Unknown),
}
}
}

impl From<FaultProofStatus> for u8 {
fn from(status: FaultProofStatus) -> u8 {
status as u8
}
}

#[cfg(test)]
mod tests {
use kona_derive::types::BASE_MAINNET_CONFIG;
use kona_primitives::BASE_MAINNET_CONFIG;

use super::*;

Expand Down Expand Up @@ -112,7 +132,7 @@ mod tests {
rollup_config: BASE_MAINNET_CONFIG,
},
expected_status: FaultProofStatus::Valid,
witness_data: witness_data,
witness_data,
};

let serialized_fixture =
Expand Down

0 comments on commit 70afc00

Please sign in to comment.