Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions crates/core/src/driver/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! The test driver handles the compilation and execution of the test cases.

use alloy::json_abi::JsonAbi;
use alloy::primitives::Bytes;
use alloy::network::TransactionBuilder;
use alloy::rpc::types::TransactionReceipt;
use alloy::rpc::types::trace::geth::GethTrace;
use alloy::rpc::types::{TransactionInput, TransactionReceipt};
use alloy::{
primitives::{Address, TxKind, map::HashMap},
primitives::{Address, map::HashMap},
rpc::types::{
TransactionRequest,
trace::geth::{AccountState, DiffMode},
Expand Down Expand Up @@ -135,21 +135,17 @@ where
std::any::type_name::<T>()
);

let tx = match input.legacy_transaction(
self.config.network_id,
nonce,
&self.deployed_contracts,
&self.deployed_abis,
) {
Ok(tx) => {
tracing::debug!("Legacy transaction data: {tx:#?}");
tx
}
Err(err) => {
tracing::error!("Failed to construct legacy transaction: {err:?}");
return Err(err);
}
};
let tx =
match input.legacy_transaction(nonce, &self.deployed_contracts, &self.deployed_abis) {
Ok(tx) => {
tracing::debug!("Legacy transaction data: {tx:#?}");
tx
}
Err(err) => {
tracing::error!("Failed to construct legacy transaction: {err:?}");
return Err(err);
}
};

tracing::trace!("Executing transaction for input: {input:?}");

Expand Down Expand Up @@ -201,6 +197,9 @@ where

for contracts in contract_map.values() {
for (contract_name, contract) in contracts {
let tracing_span = tracing::info_span!("Deploying contract", contract_name);
let _guard = tracing_span.enter();

tracing::debug!(
"Contract name is: {:?} and the input name is: {:?}",
&contract_name,
Expand Down Expand Up @@ -228,16 +227,14 @@ where
std::any::type_name::<T>()
);

let tx = TransactionRequest {
from: Some(input.caller),
to: Some(TxKind::Create),
gas_price: Some(5_000_000),
gas: Some(5_000_000),
chain_id: Some(self.config.network_id),
nonce: Some(nonce),
input: TransactionInput::new(Bytes::from(code.into_bytes())),
..Default::default()
};
// We are using alloy for building and submitting the transactions and it will
// automatically fill in all of the missing fields from the provider that we
// are using.
let code = alloy::hex::decode(&code)?;
let tx = TransactionRequest::default()
.nonce(nonce)
.from(input.caller)
.with_deploy_code(code);

let receipt = match node.execute_transaction(tx) {
Ok(receipt) => receipt,
Expand Down
31 changes: 10 additions & 21 deletions crates/format/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::collections::HashMap;
use alloy::{
hex,
json_abi::{Function, JsonAbi},
primitives::{Address, Bytes, TxKind},
rpc::types::{TransactionInput, TransactionRequest},
network::TransactionBuilder,
primitives::{Address, Bytes},
rpc::types::TransactionRequest,
};
use alloy_primitives::U256;
use alloy_sol_types::SolValue;
Expand Down Expand Up @@ -220,30 +221,18 @@ impl Input {
/// Parse this input into a legacy transaction.
pub fn legacy_transaction(
&self,
chain_id: u64,
nonce: u64,
deployed_contracts: &HashMap<String, Address>,
deployed_abis: &HashMap<String, JsonAbi>,
) -> anyhow::Result<TransactionRequest> {
let to = match self.method {
Method::Deployer => Some(TxKind::Create),
_ => Some(TxKind::Call(
self.instance_to_address(&self.instance, deployed_contracts)?,
)),
};

let input_data = self.encoded_input(deployed_abis, deployed_contracts)?;

Ok(TransactionRequest {
from: Some(self.caller),
to,
nonce: Some(nonce),
chain_id: Some(chain_id),
gas_price: Some(5_000_000),
gas: Some(5_000_000),
input: TransactionInput::new(input_data),
..Default::default()
})
let transaction_request = TransactionRequest::default().nonce(nonce);
match self.method {
Method::Deployer => Ok(transaction_request.with_deploy_code(input_data)),
_ => Ok(transaction_request
.to(self.instance_to_address(&self.instance, deployed_contracts)?)
.input(input_data.into())),
}
}
}

Expand Down