From 63389ef199e8823ad77c61b73212ed3a37aaadf7 Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Mon, 25 Aug 2025 13:52:09 +0300 Subject: [PATCH] Add information on the deployed contracts --- crates/core/src/driver/mod.rs | 8 ++ crates/core/src/main.rs | 2 + crates/report/src/aggregator.rs | 13 ++++ crates/report/src/common.rs | 8 +- crates/report/src/runner_event.rs | 123 ++++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+), 1 deletion(-) diff --git a/crates/core/src/driver/mod.rs b/crates/core/src/driver/mod.rs index 4912b9a..d06ea52 100644 --- a/crates/core/src/driver/mod.rs +++ b/crates/core/src/driver/mod.rs @@ -22,6 +22,7 @@ use anyhow::Context; use futures::TryStreamExt; use indexmap::IndexMap; use revive_dt_format::traits::{ResolutionContext, ResolverApi}; +use revive_dt_report::ExecutionSpecificReporter; use semver::Version; use revive_dt_format::case::Case; @@ -51,6 +52,9 @@ pub struct CaseState { /// Stores the version used for the current case. compiler_version: Version, + /// The execution reporter. + execution_reporter: ExecutionSpecificReporter, + phantom: PhantomData, } @@ -62,12 +66,14 @@ where compiler_version: Version, compiled_contracts: HashMap>, deployed_contracts: HashMap, + execution_reporter: ExecutionSpecificReporter, ) -> Self { Self { compiled_contracts, deployed_contracts, variables: Default::default(), compiler_version, + execution_reporter, phantom: PhantomData, } } @@ -718,6 +724,8 @@ where instance_address = ?address, "Deployed contract" ); + self.execution_reporter + .report_contract_deployed_event(contract_instance.clone(), address)?; self.deployed_contracts.insert( contract_instance.clone(), diff --git a/crates/core/src/main.rs b/crates/core/src/main.rs index f24e7dc..43ae3be 100644 --- a/crates/core/src/main.rs +++ b/crates/core/src/main.rs @@ -888,11 +888,13 @@ where leader_compiler_version, leader_post_link_contracts, leader_deployed_libraries.unwrap_or_default(), + leader_reporter, ); let follower_state = CaseState::::new( follower_compiler_version, follower_post_link_contracts, follower_deployed_libraries.unwrap_or_default(), + follower_reporter, ); let mut driver = CaseDriver::::new( diff --git a/crates/report/src/aggregator.rs b/crates/report/src/aggregator.rs index bcca409..1f7af7e 100644 --- a/crates/report/src/aggregator.rs +++ b/crates/report/src/aggregator.rs @@ -105,6 +105,9 @@ impl ReportAggregator { RunnerEvent::LibrariesDeployed(event) => { self.handle_libraries_deployed_event(*event); } + RunnerEvent::ContractDeployed(event) => { + self.handle_contract_deployed_event(*event); + } } } debug!("Report aggregation completed"); @@ -371,6 +374,13 @@ impl ReportAggregator { .deployed_libraries = Some(event.libraries); } + fn handle_contract_deployed_event(&mut self, event: ContractDeployedEvent) { + self.execution_information(&event.execution_specifier) + .deployed_contracts + .get_or_insert_default() + .insert(event.contract_instance, event.address); + } + fn test_case_report(&mut self, specifier: &TestSpecifier) -> &mut TestCaseReport { self.report .test_case_information @@ -494,6 +504,9 @@ pub struct ExecutionInformation { /// Information on the deployed libraries. #[serde(skip_serializing_if = "Option::is_none")] pub deployed_libraries: Option>, + /// Information on the deployed contracts. + #[serde(skip_serializing_if = "Option::is_none")] + pub deployed_contracts: Option>, } /// Information related to compilation diff --git a/crates/report/src/common.rs b/crates/report/src/common.rs index 550a5a9..5b6e3f1 100644 --- a/crates/report/src/common.rs +++ b/crates/report/src/common.rs @@ -4,7 +4,7 @@ use std::{path::PathBuf, sync::Arc}; use revive_dt_common::define_wrapper_type; use revive_dt_compiler::Mode; -use revive_dt_format::case::CaseIdx; +use revive_dt_format::{case::CaseIdx, input::StepIdx}; use serde::{Deserialize, Serialize}; define_wrapper_type!( @@ -35,3 +35,9 @@ pub enum NodeDesignation { Leader, Follower, } + +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct StepExecutionSpecifier { + pub execution_specifier: Arc, + pub step_idx: StepIdx, +} diff --git a/crates/report/src/runner_event.rs b/crates/report/src/runner_event.rs index 7a915b1..ddb67f9 100644 --- a/crates/report/src/runner_event.rs +++ b/crates/report/src/runner_event.rs @@ -204,6 +204,101 @@ macro_rules! __report_gen_for_variant_exec { }; } +macro_rules! __report_gen_emit_step_execution_specific { + ( + $ident:ident, + $variant_ident:ident, + $skip_field:ident; + $( $bname:ident : $bty:ty, )* + ; + $( $aname:ident : $aty:ty, )* + ) => { + paste::paste! { + pub fn [< report_ $variant_ident:snake _event >]( + &self + $(, $bname: impl Into<$bty> )* + $(, $aname: impl Into<$aty> )* + ) -> anyhow::Result<()> { + self.report([< $variant_ident Event >] { + $skip_field: self.step_specifier.clone() + $(, $bname: $bname.into() )* + $(, $aname: $aname.into() )* + }) + } + } + }; +} + +macro_rules! __report_gen_emit_step_execution_specific_by_parse { + ( + $ident:ident, + $variant_ident:ident, + $skip_field:ident; + $( $bname:ident : $bty:ty, )* ; $( $aname:ident : $aty:ty, )* + ) => { + __report_gen_emit_step_execution_specific!( + $ident, $variant_ident, $skip_field; + $( $bname : $bty, )* ; $( $aname : $aty, )* + ); + }; +} + +macro_rules! __report_gen_scan_before_step { + ( + $ident:ident, $variant_ident:ident; + $( $before:ident : $bty:ty, )* + ; + step_specifier : $skip_ty:ty, + $( $after:ident : $aty:ty, )* + ; + ) => { + __report_gen_emit_step_execution_specific_by_parse!( + $ident, $variant_ident, step_specifier; + $( $before : $bty, )* ; $( $after : $aty, )* + ); + }; + ( + $ident:ident, $variant_ident:ident; + $( $before:ident : $bty:ty, )* + ; + $name:ident : $ty:ty, $( $after:ident : $aty:ty, )* + ; + ) => { + __report_gen_scan_before_step!( + $ident, $variant_ident; + $( $before : $bty, )* $name : $ty, + ; + $( $after : $aty, )* + ; + ); + }; + ( + $ident:ident, $variant_ident:ident; + $( $before:ident : $bty:ty, )* + ; + ; + ) => {}; +} + +macro_rules! __report_gen_for_variant_step { + ( + $ident:ident, + $variant_ident:ident; + ) => {}; + ( + $ident:ident, + $variant_ident:ident; + $( $field_ident:ident : $field_ty:ty ),+ $(,)? + ) => { + __report_gen_scan_before_step!( + $ident, $variant_ident; + ; + $( $field_ident : $field_ty, )* + ; + ); + }; +} + /// Defines the runner-event which is sent from the test runners to the report aggregator. /// /// This macro defines a number of things related to the reporting infrastructure and the interface @@ -349,10 +444,28 @@ macro_rules! define_event { fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> { self.reporter.report(event) } + $( __report_gen_for_variant_exec! { $ident, $variant_ident; $( $field_ident : $field_ty ),* } )* } + + /// A reporter that's tied to a specific step execution + #[derive(Clone, Debug)] + pub struct [< $ident StepExecutionSpecificReporter >] { + $vis reporter: [< $ident Reporter >], + $vis step_specifier: std::sync::Arc<$crate::common::StepExecutionSpecifier>, + } + + impl [< $ident StepExecutionSpecificReporter >] { + fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> { + self.reporter.report(event) + } + + $( + __report_gen_for_variant_step! { $ident, $variant_ident; $( $field_ident : $field_ty ),* } + )* + } } }; } @@ -494,12 +607,22 @@ define_event! { /// The failure reason. reason: String, }, + /// An event emitted by the runners when a library has been deployed. LibrariesDeployed { /// A specifier for the execution that's taking place. execution_specifier: Arc, /// The addresses of the libraries that were deployed. libraries: BTreeMap }, + /// An event emitted by the runners when they've deployed a new contract. + ContractDeployed { + /// A specifier for the execution that's taking place. + execution_specifier: Arc, + /// The instance name of the contract. + contract_instance: ContractInstance, + /// The address of the contract. + address: Address + }, } }