-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(op-test-vectors): Update ExecutionFixture
to use op-alloy-consensus
types
#73
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c898315
update execution fixtures to use alloy types
0xKitsune 57feb44
remove anvil from test-vectors lib
0xKitsune 9242317
add conversion from transaction receipt to op transaction receipt
0xKitsune f3b9872
convert anvil typed tx to op typed tx
0xKitsune 1375753
construct execution environment from block
0xKitsune eb2ec93
update comment
0xKitsune eb6cdc6
clippy
0xKitsune a515401
updating test
0xKitsune 2bfcbb2
fix tests
0xKitsune 3e2d5fa
Merge branch 'main' into 0xkitsune/alloy
0xKitsune File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,10 +2,9 @@ | |
|
||
use alloy_primitives::{Address, Bloom, B256, U256}; | ||
use alloy_rpc_types::trace::geth::AccountState; | ||
use alloy_rpc_types::{Log, TransactionReceipt}; | ||
use anvil_core::eth::block::Block; | ||
use anvil_core::eth::transaction::{TypedReceipt, TypedTransaction}; | ||
use color_eyre::eyre; | ||
|
||
use op_alloy_consensus::OpTypedTransaction; | ||
use op_alloy_rpc_types::OpTransactionReceipt; | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashMap; | ||
|
||
|
@@ -24,7 +23,7 @@ pub struct ExecutionFixture { | |
pub out_alloc: HashMap<Address, AccountState>, | ||
/// Transactions to execute. | ||
#[serde(rename = "txs")] | ||
pub transactions: Vec<TypedTransaction>, | ||
pub transactions: Vec<OpTypedTransaction>, | ||
/// The expected result after executing transactions. | ||
pub result: ExecutionResult, | ||
} | ||
|
@@ -51,20 +50,6 @@ pub struct ExecutionEnvironment { | |
pub block_hashes: Option<HashMap<U256, B256>>, | ||
} | ||
|
||
impl From<Block> for ExecutionEnvironment { | ||
fn from(block: Block) -> Self { | ||
Self { | ||
current_coinbase: block.header.beneficiary, | ||
current_difficulty: block.header.difficulty, | ||
current_gas_limit: U256::from(block.header.gas_limit), | ||
previous_hash: block.header.parent_hash, | ||
current_number: U256::from(block.header.number), | ||
current_timestamp: U256::from(block.header.timestamp), | ||
block_hashes: None, | ||
} | ||
} | ||
} | ||
|
||
/// The execution result is the expected result after running the transactions | ||
/// in the execution environment over the pre-state. | ||
#[derive(Serialize, Deserialize, Debug, Default)] | ||
|
@@ -79,53 +64,7 @@ pub struct ExecutionResult { | |
/// The logs bloom. | ||
pub logs_bloom: Bloom, | ||
/// A list of execution receipts for each executed transaction. | ||
pub receipts: Vec<ExecutionReceipt>, | ||
} | ||
|
||
/// An execution receipt is the result of running a transaction in the execution environment. | ||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ExecutionReceipt { | ||
/// The state root. | ||
pub root: B256, | ||
/// The hash of the transaction. | ||
pub transaction_hash: B256, | ||
/// The contract address that the transaction created. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub contract_address: Option<Address>, | ||
/// The gas used by the transaction. | ||
pub gas_used: U256, | ||
/// The block hash. | ||
pub block_hash: B256, | ||
/// The transaction index. | ||
pub transaction_index: U256, | ||
/// The inner log receipt. | ||
#[serde(flatten)] | ||
pub inner: TypedReceipt<Log>, | ||
} | ||
|
||
impl TryFrom<TransactionReceipt<TypedReceipt<Log>>> for ExecutionReceipt { | ||
type Error = eyre::Error; | ||
|
||
fn try_from(receipt: TransactionReceipt<TypedReceipt<Log>>) -> eyre::Result<Self> { | ||
Ok(Self { | ||
transaction_hash: receipt.transaction_hash, | ||
root: receipt | ||
.state_root | ||
.ok_or_else(|| eyre::eyre!("missing state root"))?, | ||
contract_address: receipt.contract_address, | ||
gas_used: U256::from(receipt.gas_used), | ||
block_hash: receipt | ||
.block_hash | ||
.ok_or_else(|| eyre::eyre!("missing block hash"))?, | ||
transaction_index: U256::from( | ||
receipt | ||
.transaction_index | ||
.ok_or_else(|| eyre::eyre!("missing transaction index"))?, | ||
), | ||
inner: receipt.inner, | ||
}) | ||
} | ||
pub receipts: Vec<OpTransactionReceipt>, | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -159,53 +98,4 @@ mod tests { | |
.expect("failed to parse expected result"); | ||
assert_eq!(serialized_value, expected_value); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test/tests here for deserializing the op types? |
||
#[test] | ||
fn test_exec_receipt_try_from_tx_receipt() { | ||
let tx_receipt_str = include_str!("./testdata/tx_receipt.json"); | ||
let tx_receipt: TransactionReceipt<TypedReceipt<Log>> = | ||
serde_json::from_str(tx_receipt_str).expect("failed to parse tx receipt"); | ||
let exec_receipt = ExecutionReceipt::try_from(tx_receipt.clone()) | ||
.expect("failed to convert tx receipt to exec receipt"); | ||
assert_eq!(exec_receipt.transaction_hash, tx_receipt.transaction_hash); | ||
assert_eq!(exec_receipt.root, tx_receipt.state_root.unwrap()); | ||
assert_eq!(exec_receipt.contract_address, tx_receipt.contract_address); | ||
assert_eq!(exec_receipt.gas_used, U256::from(tx_receipt.gas_used)); | ||
assert_eq!(exec_receipt.block_hash, tx_receipt.block_hash.unwrap()); | ||
assert_eq!( | ||
exec_receipt.transaction_index, | ||
U256::from(tx_receipt.transaction_index.unwrap()) | ||
); | ||
assert_eq!(exec_receipt.inner, tx_receipt.inner); | ||
} | ||
|
||
#[test] | ||
fn test_exec_receipt_try_from_missing_root() { | ||
let tx_receipt_str = include_str!("./testdata/tx_receipt.json"); | ||
let mut tx_receipt: TransactionReceipt<TypedReceipt<Log>> = | ||
serde_json::from_str(tx_receipt_str).expect("failed to parse tx receipt"); | ||
tx_receipt.state_root = None; | ||
let exec_receipt = ExecutionReceipt::try_from(tx_receipt); | ||
assert!(exec_receipt.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_exec_receipt_try_from_missing_block_hash() { | ||
let tx_receipt_str = include_str!("./testdata/tx_receipt.json"); | ||
let mut tx_receipt: TransactionReceipt<TypedReceipt<Log>> = | ||
serde_json::from_str(tx_receipt_str).expect("failed to parse tx receipt"); | ||
tx_receipt.block_hash = None; | ||
let exec_receipt = ExecutionReceipt::try_from(tx_receipt); | ||
assert!(exec_receipt.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_exec_receipt_try_from_missing_tx_index() { | ||
let tx_receipt_str = include_str!("./testdata/tx_receipt.json"); | ||
let mut tx_receipt: TransactionReceipt<TypedReceipt<Log>> = | ||
serde_json::from_str(tx_receipt_str).expect("failed to parse tx receipt"); | ||
tx_receipt.transaction_index = None; | ||
let exec_receipt = ExecutionReceipt::try_from(tx_receipt); | ||
assert!(exec_receipt.is_err()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree - I will add issues in op-alloy for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I can open a PR for these issues on
op-alloy
later today/tomorrow.