-
Notifications
You must be signed in to change notification settings - Fork 26
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
11 changed files
with
421 additions
and
157 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
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
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
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,115 @@ | ||
use solana_banks_client::BanksClientError; | ||
use solana_sdk::pubkey::Pubkey; | ||
use std::fmt::{Debug, Display}; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum FuzzClientError { | ||
#[error("Custom fuzzing error: {0}")] | ||
Custom(u32), | ||
#[error("Not able to initialize client")] | ||
ClientInitError, | ||
#[error("Obtained Banks Client Error: {0}")] | ||
BanksError(#[from] BanksClientError), | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum FuzzingError { | ||
#[error("Custom fuzzing error: {0}\n")] | ||
Custom(u32), | ||
#[error("Not able to deserialize account: {0}\n")] | ||
DeserializeError(String), | ||
#[error("Not Able To Obtain AccountInfos\n")] | ||
NotAbleToObtainAccountInfos, | ||
#[error("Balance Mismatch\n")] | ||
BalanceMismatch, | ||
#[error("Data Mismatch example message xyz\n")] | ||
DataMismatch, | ||
#[error("Unable to obtain Data\n")] | ||
UnableToObtainData, | ||
} | ||
#[derive(Debug, Clone)] | ||
pub enum Origin { | ||
Instruction(String), | ||
Account(Pubkey), | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Context { | ||
Pre, | ||
Post, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct FuzzClientErrorWithOrigin { | ||
pub client_error: FuzzClientError, | ||
pub origin: Option<Origin>, | ||
pub context: Option<Context>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct FuzzingErrorWithOrigin { | ||
pub fuzzing_error: FuzzingError, | ||
pub origin: Option<Origin>, | ||
pub context: Option<Context>, | ||
} | ||
|
||
impl From<FuzzClientError> for FuzzClientErrorWithOrigin { | ||
fn from(client_error: FuzzClientError) -> Self { | ||
Self { | ||
client_error, | ||
origin: None, | ||
context: None, | ||
} | ||
} | ||
} | ||
|
||
impl From<FuzzingError> for FuzzingErrorWithOrigin { | ||
fn from(fuzzing_error: FuzzingError) -> Self { | ||
Self { | ||
fuzzing_error, | ||
origin: None, | ||
context: None, | ||
} | ||
} | ||
} | ||
|
||
// \x1b[93m ... \x1b[0m provides some text color in the terminal | ||
// this can help to increase readability of the debug output | ||
impl Display for FuzzClientErrorWithOrigin { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
Display::fmt(&self.client_error, f)?; | ||
writeln!(f, "\x1b[93mOrigin:\x1b[0m {:#?}", &self.origin)?; | ||
writeln!(f, "\x1b[93mContext:\x1b[0m {:#?}", &self.context)?; | ||
Ok(()) | ||
} | ||
} | ||
impl Display for FuzzingErrorWithOrigin { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
Display::fmt(&self.fuzzing_error, f)?; | ||
writeln!(f, "\x1b[93mOrigin:\x1b[0m {:#?}", &self.origin)?; | ||
writeln!(f, "\x1b[93mContext:\x1b[0m {:#?}", &self.context)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl FuzzClientErrorWithOrigin { | ||
pub fn with_origin(mut self, origin: Origin) -> Self { | ||
self.origin = Some(origin); | ||
self | ||
} | ||
pub fn with_context(mut self, context: Context) -> Self { | ||
self.context = Some(context); | ||
self | ||
} | ||
} | ||
impl FuzzingErrorWithOrigin { | ||
pub fn with_origin(mut self, origin: Origin) -> Self { | ||
self.origin = Some(origin); | ||
self | ||
} | ||
pub fn with_context(mut self, context: Context) -> Self { | ||
self.context = Some(context); | ||
self | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,3 +7,5 @@ pub mod snapshot; | |
pub mod snapshot_generator; | ||
|
||
pub type AccountId = u8; | ||
|
||
pub mod error; |
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
Oops, something went wrong.