forked from lambdaclass/ethrex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add error handling to evm module (lambdaclass#142)
**Motivation** Add error handling to `execute_tx` and remove unwrap <!-- Why does this pull request exist? What are its goals? --> **Description** Add `EvmError` Map revm's `EVMError` to `EvmError` Add error handling to `execute_tx` <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 --> Closes None
- Loading branch information
Showing
3 changed files
with
36 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::fmt::Display; | ||
|
||
use revm::primitives::result::EVMError as RevmError; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum EvmError { | ||
#[error("Invalid Transaction: {0}")] | ||
Transaction(String), | ||
#[error("Invalid Header: {0}")] | ||
Header(String), | ||
#[error("DB error: {0}")] | ||
DB(String), | ||
#[error("{0}")] | ||
Custom(String), | ||
#[error("{0}")] | ||
Precompile(String), | ||
} | ||
|
||
impl<T: Display> From<RevmError<T>> for EvmError { | ||
fn from(value: RevmError<T>) -> Self { | ||
match value { | ||
RevmError::Transaction(err) => EvmError::Transaction(err.to_string()), | ||
RevmError::Header(err) => EvmError::Header(err.to_string()), | ||
RevmError::Database(err) => EvmError::DB(err.to_string()), | ||
RevmError::Custom(err) => EvmError::Custom(err), | ||
RevmError::Precompile(err) => EvmError::Precompile(err), | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -35,6 +35,7 @@ fn execute_test(test: &TestUnit) { | |
&pre, | ||
SpecId::CANCUN, | ||
) | ||
.unwrap() | ||
.is_success()); | ||
} | ||
|
||
|