Skip to content

Commit a8cde6f

Browse files
committed
deploy contracts
1 parent 547563e commit a8cde6f

File tree

2 files changed

+90
-17
lines changed

2 files changed

+90
-17
lines changed

crates/core/src/driver/mod.rs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//! The test driver handles the compilation and execution of the test cases.
22
33
use alloy::{
4-
primitives::{Address, map::HashMap},
5-
rpc::types::trace::geth::{AccountState, DiffMode, GethTrace},
4+
network::TransactionBuilder,
5+
primitives::{Address, bytes::Bytes, map::HashMap},
6+
rpc::types::{
7+
TransactionRequest,
8+
trace::geth::{AccountState, DiffMode, GethTrace},
9+
},
610
};
711
use revive_dt_compiler::{Compiler, CompilerInput, SolidityCompiler};
812
use revive_dt_config::Arguments;
@@ -109,6 +113,56 @@ where
109113

110114
Ok((trace, diff))
111115
}
116+
117+
pub fn deploy_contracts(&mut self, input: &Input, node: &T::Blockchain) -> anyhow::Result<()> {
118+
for output in self.contracts.values() {
119+
let Some(contract_map) = &output.contracts else {
120+
log::debug!("No contracts in output — skipping deployment for this input.");
121+
continue;
122+
};
123+
124+
for contracts in contract_map.values() {
125+
for (contract_name, contract) in contracts {
126+
if contract_name != &input.instance {
127+
continue;
128+
}
129+
130+
let bytecode = contract
131+
.evm
132+
.as_ref()
133+
.and_then(|evm| evm.bytecode.as_ref())
134+
.map(|b| b.object.clone());
135+
136+
let Some(code) = bytecode else {
137+
anyhow::bail!("no bytecode for contract `{}`", contract_name);
138+
};
139+
140+
let tx = TransactionRequest::default()
141+
.with_from(input.caller)
142+
.with_to(Address::ZERO)
143+
.with_input(Bytes::from(code.clone()))
144+
.with_gas_price(20_000_000_000)
145+
.with_gas_limit(20_000_000_000)
146+
.with_chain_id(self.config.network_id)
147+
.with_nonce(0);
148+
149+
let receipt = node.execute_transaction(tx)?;
150+
let Some(address) = receipt.contract_address else {
151+
anyhow::bail!(
152+
"contract `{}` deployment did not return an address",
153+
contract_name
154+
);
155+
};
156+
157+
self.deployed_contracts
158+
.insert(contract_name.clone(), address);
159+
log::info!("deployed contract `{}` at {:?}", contract_name, address);
160+
}
161+
}
162+
}
163+
164+
Ok(())
165+
}
112166
}
113167

114168
pub struct Driver<'a, Leader: Platform, Follower: Platform> {
@@ -173,6 +227,9 @@ where
173227

174228
for case in &self.metadata.cases {
175229
for input in &case.inputs {
230+
leader_state.deploy_contracts(input, self.leader_node)?;
231+
follower_state.deploy_contracts(input, self.follower_node)?;
232+
176233
let (_, leader_diff) = leader_state.execute_input(input, self.leader_node)?;
177234
let (_, follower_diff) =
178235
follower_state.execute_input(input, self.follower_node)?;

crates/core/src/main.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rayon::{ThreadPoolBuilder, prelude::*};
55

66
use revive_dt_config::*;
77
use revive_dt_core::{
8-
Geth, Kitchensink,
8+
Geth, Kitchensink, Platform,
99
driver::{Driver, State},
1010
};
1111
use revive_dt_format::{corpus::Corpus, metadata::Metadata};
@@ -74,28 +74,30 @@ fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<Metad
7474
Ok(corpora)
7575
}
7676

77-
fn execute_corpus(args: &Arguments, tests: &[Metadata], span: Span) -> anyhow::Result<()> {
78-
let leader_nodes = NodePool::new(args)?;
79-
let follower_nodes = NodePool::new(args)?;
77+
fn run_driver<L, F>(args: &Arguments, tests: &[Metadata], span: Span) -> anyhow::Result<()>
78+
where
79+
L: Platform,
80+
F: Platform,
81+
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
82+
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
83+
{
84+
let leader_nodes = NodePool::<L::Blockchain>::new(args)?;
85+
let follower_nodes = NodePool::<F::Blockchain>::new(args)?;
8086

8187
tests.par_iter().for_each(|metadata| {
82-
let mut driver = match (&args.leader, &args.follower) {
83-
(TestingPlatform::Geth, TestingPlatform::Kitchensink) => Driver::<Geth, Geth>::new(
84-
metadata,
85-
args,
86-
leader_nodes.round_robbin(),
87-
follower_nodes.round_robbin(),
88-
),
89-
_ => unimplemented!(),
90-
};
88+
let mut driver = Driver::<L, F>::new(
89+
metadata,
90+
args,
91+
leader_nodes.round_robbin(),
92+
follower_nodes.round_robbin(),
93+
);
9194

9295
match driver.execute(span) {
93-
Ok(build) => {
96+
Ok(_) => {
9497
log::info!(
9598
"metadata {} success",
9699
metadata.directory().as_ref().unwrap().display()
97100
);
98-
build
99101
}
100102
Err(error) => {
101103
log::warn!(
@@ -109,6 +111,20 @@ fn execute_corpus(args: &Arguments, tests: &[Metadata], span: Span) -> anyhow::R
109111
Ok(())
110112
}
111113

114+
fn execute_corpus(args: &Arguments, tests: &[Metadata], span: Span) -> anyhow::Result<()> {
115+
match (&args.leader, &args.follower) {
116+
(TestingPlatform::Geth, TestingPlatform::Kitchensink) => {
117+
run_driver::<Geth, Kitchensink>(args, tests, span)?
118+
}
119+
(TestingPlatform::Geth, TestingPlatform::Geth) => {
120+
run_driver::<Geth, Geth>(args, tests, span)?
121+
}
122+
_ => unimplemented!(),
123+
}
124+
125+
Ok(())
126+
}
127+
112128
fn compile_corpus(config: &Arguments, tests: &[Metadata], platform: &TestingPlatform, span: Span) {
113129
tests.par_iter().for_each(|metadata| {
114130
for mode in &metadata.solc_modes() {

0 commit comments

Comments
 (0)