Skip to content

Commit

Permalink
Feature flags and add one test
Browse files Browse the repository at this point in the history
  • Loading branch information
anikaraghu committed Nov 16, 2023
1 parent c994ad1 commit 68d2857
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vergen = { version = "8", default-features = false, features = ["build", "git",

[dependencies]
# foundry internal
anvil-core = { path = "core", features = ["fastrlp", "serde", "impersonated-tx"] }
anvil-core = { path = "core", features = ["fastrlp", "serde", "impersonated-tx", "optimism"] }
anvil-rpc = { path = "rpc" }
anvil-server = { path = "server" }
foundry-common.workspace = true
Expand Down
10 changes: 7 additions & 3 deletions crates/anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ foundry-utils.workspace = true
revm = { workspace = true, default-features = false, features = ["std", "serde", "memory_limit"] }

alloy-primitives = { workspace = true, features = ["serde"] }
ethers-core.workspace = true
ethers-core = { workspace = true, features = ["optimism"], optional = true }
ethers-contract = { workspace = true, features = ["optimism"], optional = true }
ethers-providers = { workspace = true, features = ["optimism"], optional = true }
ethers-middleware = { workspace = true, features = ["optimism"], optional = true }
serde = { workspace = true, optional = true }
serde_json.workspace = true
bytes = { version = "1.4" }
Expand All @@ -30,10 +33,11 @@ reference-trie = { version = "0.25" }
keccak-hasher = { version = "0.15" }

[dev-dependencies]
serde.workspace = true
anvil-core = { path = ".", features = ["serde"] }

[features]
default = []
default = ["serde","optimism"]
impersonated-tx = []
fastrlp = ["dep:open-fastrlp"]
serde = ["dep:serde"]
optimism = ["dep:ethers-core", "dep:ethers-contract", "dep:ethers-providers", "dep:ethers-middleware"]
53 changes: 38 additions & 15 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ impl Encodable for EIP1559TransactionRequest {

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DepositTransactionRequest {
pub source_hash: H256,
pub from: Address,
pub source_hash: H256,
pub kind: TransactionKind,
pub mint: U256,
pub value: U256,
Expand All @@ -465,8 +465,8 @@ impl DepositTransactionRequest {
impl From<DepositTransaction> for DepositTransactionRequest {
fn from(tx: DepositTransaction) -> Self {
Self {
source_hash: tx.source_hash,
from: tx.from,
source_hash: tx.source_hash,
kind: tx.kind,
mint: tx.mint,
value: tx.value,
Expand All @@ -480,8 +480,8 @@ impl From<DepositTransaction> for DepositTransactionRequest {
impl Encodable for DepositTransactionRequest {
fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(8);
s.append(&self.source_hash);
s.append(&self.from);
s.append(&self.source_hash);
s.append(&self.kind);
s.append(&self.mint);
s.append(&self.value);
Expand Down Expand Up @@ -1281,7 +1281,8 @@ impl DepositTransaction {

impl Encodable for DepositTransaction {
fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(8);
s.begin_list(9);
s.append(&self.nonce);
s.append(&self.source_hash);
s.append(&self.from);
s.append(&self.kind);
Expand All @@ -1295,20 +1296,20 @@ impl Encodable for DepositTransaction {

impl Decodable for DepositTransaction {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
if rlp.item_count()? != 8 {
if rlp.item_count()? != 9 {
return Err(DecoderError::RlpIncorrectListLen)
}

Ok(Self {
source_hash: rlp.val_at(0)?,
from: rlp.val_at(1)?,
kind: rlp.val_at(2)?,
mint: rlp.val_at(3)?,
value: rlp.val_at(4)?,
gas_limit: rlp.val_at(5)?,
is_system_tx: rlp.val_at(6)?,
input: rlp.val_at::<Vec<u8>>(7)?.into(),
nonce: U256::from(0),
nonce: rlp.val_at(0)?,
source_hash: rlp.val_at(1)?,
from: rlp.val_at(2)?,
kind: rlp.val_at(3)?,
mint: rlp.val_at(4)?,
value: rlp.val_at(5)?,
gas_limit: rlp.val_at(6)?,
is_system_tx: rlp.val_at(7)?,
input: rlp.val_at::<Vec<u8>>(8)?.into(),
})
}
}
Expand Down Expand Up @@ -1535,7 +1536,7 @@ impl TransactionInfo {
#[cfg(test)]
mod tests {
use super::*;
use ethers_core::utils::hex;
use ethers_core::{types::H160, utils::hex};

#[test]
fn can_recover_sender() {
Expand Down Expand Up @@ -1781,6 +1782,28 @@ mod tests {
expected,
<TypedTransaction as open_fastrlp::Decodable>::decode(bytes_fifth).unwrap()
);

let bytes_sixth = &mut &hex::decode("b8587ef85507a0000000000000000000000000000000000000000000000000000000000000000094cf7f9e66af820a19257a2108375b180b0ec491679461815774383099e24810ab832a5b2a5425c154d5808230398287fb0180").unwrap()[..];
let expected: TypedTransaction = TypedTransaction::Deposit(DepositTransaction {
nonce: 7u64.into(),
source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
from: H160::from_str("cf7f9e66af820a19257a2108375b180b0ec49167").unwrap(),
kind: TransactionKind::Call(Address::from_slice(
&hex::decode("61815774383099e24810ab832a5b2a5425c154d5").unwrap()[..],
)),
mint: U256::zero(),
value: 12345u64.into(),
gas_limit: 34811u64.into(),
input: Bytes::default(),
is_system_tx: true,
});
let rlpbytes = expected.rlp_bytes();
let bytes = rlpbytes.as_ref();
println!("{}", hex::encode(bytes));
assert_eq!(
expected,
<TypedTransaction as open_fastrlp::Decodable>::decode(bytes_sixth).unwrap()
);
}

// <https://github.com/gakonst/ethers-rs/issues/1732>
Expand Down
1 change: 1 addition & 0 deletions crates/evm/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub fn halt_to_instruction_result(halt: Halt) -> InstructionResult {
Halt::CallNotAllowedInsideStatic => InstructionResult::CallNotAllowedInsideStatic,
Halt::OutOfFund => InstructionResult::OutOfFund,
Halt::CallTooDeep => InstructionResult::CallTooDeep,
Halt::FailedDeposit => todo!(),
}
}

Expand Down

0 comments on commit 68d2857

Please sign in to comment.