mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-05-01 05:17:58 +00:00
Cleanup implementation
This commit is contained in:
@@ -22,10 +22,8 @@ use indexmap::IndexMap;
|
||||
use revive_dt_compiler::{Compiler, SolidityCompiler};
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_dt_format::case::CaseIdx;
|
||||
use revive_dt_format::input::{Calldata, Expected, ExpectedOutput, Method, default_caller};
|
||||
use revive_dt_format::metadata::{
|
||||
AddressReplacementMap, ContractInstance, ContractPathAndIdentifier,
|
||||
};
|
||||
use revive_dt_format::input::{Calldata, Expected, ExpectedOutput, Method};
|
||||
use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdentifier};
|
||||
use revive_dt_format::{input::Input, metadata::Metadata, mode::SolcMode};
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
use revive_dt_report::reporter::{CompilationTask, Report, Span};
|
||||
@@ -147,17 +145,11 @@ where
|
||||
case_idx: CaseIdx,
|
||||
input: &Input,
|
||||
node: &T::Blockchain,
|
||||
address_replacement: &AddressReplacementMap,
|
||||
) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> {
|
||||
let deployment_receipts =
|
||||
self.handle_contract_deployment(metadata, case_idx, input, node, address_replacement)?;
|
||||
let execution_receipt = self.handle_input_execution(
|
||||
case_idx,
|
||||
input,
|
||||
deployment_receipts,
|
||||
node,
|
||||
address_replacement,
|
||||
)?;
|
||||
self.handle_contract_deployment(metadata, case_idx, input, node)?;
|
||||
let execution_receipt =
|
||||
self.handle_input_execution(case_idx, input, deployment_receipts, node)?;
|
||||
self.handle_input_expectations(case_idx, input, &execution_receipt, node)?;
|
||||
self.handle_input_diff(case_idx, execution_receipt, node)
|
||||
}
|
||||
@@ -169,7 +161,6 @@ where
|
||||
case_idx: CaseIdx,
|
||||
input: &Input,
|
||||
node: &T::Blockchain,
|
||||
address_replacement: &AddressReplacementMap,
|
||||
) -> anyhow::Result<HashMap<ContractInstance, TransactionReceipt>> {
|
||||
let span = tracing::debug_span!(
|
||||
"Handling contract deployment",
|
||||
@@ -261,16 +252,7 @@ where
|
||||
TransactionBuilder::<Ethereum>::with_deploy_code(tx, code)
|
||||
};
|
||||
|
||||
let receipt = match node.execute_transaction(
|
||||
tx,
|
||||
Some(
|
||||
address_replacement
|
||||
.as_ref()
|
||||
.values()
|
||||
.map(|(sk, _)| sk)
|
||||
.map(Clone::clone),
|
||||
),
|
||||
) {
|
||||
let receipt = match node.execute_transaction(tx) {
|
||||
Ok(receipt) => receipt,
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
@@ -334,7 +316,6 @@ where
|
||||
input: &Input,
|
||||
mut deployment_receipts: HashMap<ContractInstance, TransactionReceipt>,
|
||||
node: &T::Blockchain,
|
||||
address_replacement: &AddressReplacementMap,
|
||||
) -> anyhow::Result<TransactionReceipt> {
|
||||
match input.method {
|
||||
// This input was already executed when `handle_input` was called. We just need to
|
||||
@@ -358,16 +339,7 @@ where
|
||||
|
||||
tracing::trace!("Executing transaction for input: {input:?}");
|
||||
|
||||
match node.execute_transaction(
|
||||
tx,
|
||||
Some(
|
||||
address_replacement
|
||||
.as_ref()
|
||||
.values()
|
||||
.map(|(sk, _)| sk)
|
||||
.map(Clone::clone),
|
||||
),
|
||||
) {
|
||||
match node.execute_transaction(tx) {
|
||||
Ok(receipt) => Ok(receipt),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
@@ -599,7 +571,7 @@ where
|
||||
}
|
||||
|
||||
pub struct Driver<'a, Leader: Platform, Follower: Platform> {
|
||||
metadata: &'a mut Metadata,
|
||||
metadata: &'a Metadata,
|
||||
config: &'a Arguments,
|
||||
leader_node: &'a Leader::Blockchain,
|
||||
follower_node: &'a Follower::Blockchain,
|
||||
@@ -611,7 +583,7 @@ where
|
||||
F: Platform,
|
||||
{
|
||||
pub fn new(
|
||||
metadata: &'a mut Metadata,
|
||||
metadata: &'a Metadata,
|
||||
config: &'a Arguments,
|
||||
leader_node: &'a L::Blockchain,
|
||||
follower_node: &'a F::Blockchain,
|
||||
@@ -722,44 +694,6 @@ where
|
||||
|
||||
// For cases if one of the inputs fail then we move on to the next case and we do NOT
|
||||
// bail out of the whole thing.
|
||||
let replacement_maps = self
|
||||
.metadata
|
||||
.cases
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.map(|(case_id, case)| (CaseIdx::new(case_id), case))
|
||||
.fold(HashMap::new(), |mut map, (case_idx, case)| {
|
||||
let mut replacement_map = AddressReplacementMap::default();
|
||||
case.inputs
|
||||
.iter()
|
||||
.filter_map(|input| {
|
||||
if input.caller == default_caller() {
|
||||
None
|
||||
} else {
|
||||
Some(input.caller)
|
||||
}
|
||||
})
|
||||
.for_each(|caller| {
|
||||
replacement_map.get(caller);
|
||||
});
|
||||
if let Err(error) = case.handle_address_replacement(&mut replacement_map) {
|
||||
tracing::error!(
|
||||
target = ?Target::Leader,
|
||||
?error,
|
||||
"Case address replacement failed"
|
||||
);
|
||||
execution_result.add_failed_case(
|
||||
Target::Leader,
|
||||
mode.clone(),
|
||||
case.name.as_deref().unwrap_or("no case name").to_owned(),
|
||||
case_idx,
|
||||
0,
|
||||
anyhow::Error::msg(format!("{error}")),
|
||||
);
|
||||
}
|
||||
map.insert(case_idx, replacement_map);
|
||||
map
|
||||
});
|
||||
|
||||
'case_loop: for (case_idx, case) in self.metadata.cases.iter().enumerate() {
|
||||
let tracing_span = tracing::info_span!(
|
||||
@@ -770,7 +704,6 @@ where
|
||||
let _guard = tracing_span.enter();
|
||||
|
||||
let case_idx = CaseIdx::new_from(case_idx);
|
||||
let replacement_map = replacement_maps.get(&case_idx).cloned().unwrap_or_default();
|
||||
|
||||
// For inputs if one of the inputs fail we move on to the next case (we do not move
|
||||
// on to the next input as it doesn't make sense. It depends on the previous one).
|
||||
@@ -782,13 +715,8 @@ where
|
||||
tracing::info_span!("Executing input", contract_name = ?input.instance)
|
||||
.in_scope(|| {
|
||||
let (leader_receipt, _, leader_diff) = match leader_state
|
||||
.handle_input(
|
||||
self.metadata,
|
||||
case_idx,
|
||||
&input,
|
||||
self.leader_node,
|
||||
&replacement_map,
|
||||
) {
|
||||
.handle_input(self.metadata, case_idx, &input, self.leader_node)
|
||||
{
|
||||
Ok(result) => result,
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
@@ -817,7 +745,6 @@ where
|
||||
case_idx,
|
||||
&input,
|
||||
self.follower_node,
|
||||
&replacement_map,
|
||||
) {
|
||||
Ok(result) => result,
|
||||
Err(error) => {
|
||||
|
||||
+77
-11
@@ -1,5 +1,13 @@
|
||||
use std::{collections::HashMap, sync::LazyLock};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use alloy::{
|
||||
network::TxSigner,
|
||||
primitives::FixedBytes,
|
||||
signers::{Signature, local::PrivateKeySigner},
|
||||
};
|
||||
use clap::Parser;
|
||||
use rayon::{ThreadPoolBuilder, prelude::*};
|
||||
|
||||
@@ -8,7 +16,11 @@ use revive_dt_core::{
|
||||
Geth, Kitchensink, Platform,
|
||||
driver::{Driver, State},
|
||||
};
|
||||
use revive_dt_format::{corpus::Corpus, metadata::MetadataFile};
|
||||
use revive_dt_format::{
|
||||
corpus::Corpus,
|
||||
input::default_caller,
|
||||
metadata::{AddressReplacementMap, MetadataFile},
|
||||
};
|
||||
use revive_dt_node::pool::NodePool;
|
||||
use revive_dt_report::reporter::{Report, Span};
|
||||
use temp_dir::TempDir;
|
||||
@@ -20,12 +32,48 @@ static TEMP_DIR: LazyLock<TempDir> = LazyLock::new(|| TempDir::new().unwrap());
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let args = init_cli()?;
|
||||
|
||||
for (corpus, mut tests) in collect_corpora(&args)? {
|
||||
let mut corpora = collect_corpora(&args)?;
|
||||
let mut replacement_private_keys = HashSet::<FixedBytes<32>>::new();
|
||||
for case in corpora
|
||||
.values_mut()
|
||||
.flat_map(|metadata| metadata.iter_mut())
|
||||
.flat_map(|metadata| metadata.content.cases.iter_mut())
|
||||
{
|
||||
let mut replacement_map = AddressReplacementMap::new();
|
||||
for address in case.inputs.iter().filter_map(|input| {
|
||||
if input.caller != default_caller() {
|
||||
Some(input.caller)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
replacement_map.get(address);
|
||||
}
|
||||
case.handle_address_replacement(&mut replacement_map)?;
|
||||
replacement_private_keys.extend(
|
||||
replacement_map
|
||||
.into_inner()
|
||||
.into_values()
|
||||
.map(|(sk, _)| sk)
|
||||
.map(|sk| sk.to_bytes()),
|
||||
);
|
||||
}
|
||||
|
||||
for (corpus, tests) in collect_corpora(&args)? {
|
||||
let span = Span::new(corpus, args.clone())?;
|
||||
|
||||
match &args.compile_only {
|
||||
Some(platform) => compile_corpus(&args, &tests, platform, span),
|
||||
None => execute_corpus(&args, &mut tests, span)?,
|
||||
None => execute_corpus(
|
||||
&args,
|
||||
&tests,
|
||||
replacement_private_keys
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|bytes| PrivateKeySigner::from_bytes(&bytes).expect("Can't fail"))
|
||||
.collect::<Vec<_>>(),
|
||||
span,
|
||||
)?,
|
||||
}
|
||||
|
||||
Report::save()?;
|
||||
@@ -83,17 +131,26 @@ fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<Metad
|
||||
Ok(corpora)
|
||||
}
|
||||
|
||||
fn run_driver<L, F>(args: &Arguments, tests: &mut [MetadataFile], span: Span) -> anyhow::Result<()>
|
||||
fn run_driver<L, F>(
|
||||
args: &Arguments,
|
||||
tests: &[MetadataFile],
|
||||
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>
|
||||
+ Clone
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
span: Span,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
L: Platform,
|
||||
F: Platform,
|
||||
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
{
|
||||
let leader_nodes = NodePool::<L::Blockchain>::new(args)?;
|
||||
let follower_nodes = NodePool::<F::Blockchain>::new(args)?;
|
||||
let leader_nodes = NodePool::<L::Blockchain>::new(args, additional_signers.clone())?;
|
||||
let follower_nodes = NodePool::<F::Blockchain>::new(args, additional_signers)?;
|
||||
|
||||
tests.par_iter_mut().for_each(
|
||||
tests.par_iter().for_each(
|
||||
|MetadataFile {
|
||||
content: metadata,
|
||||
path: metadata_file_path,
|
||||
@@ -141,13 +198,22 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn execute_corpus(args: &Arguments, tests: &mut [MetadataFile], span: Span) -> anyhow::Result<()> {
|
||||
fn execute_corpus(
|
||||
args: &Arguments,
|
||||
tests: &[MetadataFile],
|
||||
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>
|
||||
+ Clone
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
span: Span,
|
||||
) -> anyhow::Result<()> {
|
||||
match (&args.leader, &args.follower) {
|
||||
(TestingPlatform::Geth, TestingPlatform::Kitchensink) => {
|
||||
run_driver::<Geth, Kitchensink>(args, tests, span)?
|
||||
run_driver::<Geth, Kitchensink>(args, tests, additional_signers, span)?
|
||||
}
|
||||
(TestingPlatform::Geth, TestingPlatform::Geth) => {
|
||||
run_driver::<Geth, Geth>(args, tests, span)?
|
||||
run_driver::<Geth, Geth>(args, tests, additional_signers, span)?
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user