Compare commits

...

2 Commits

Author SHA1 Message Date
Omar Abdulla eacff46624 Make metadata serializable 2025-08-11 00:32:42 +03:00
Omar 64d63ef999 Remove the provider cache (#121)
* Remove the provider cache

* Add timing information to the CLI report
2025-08-07 03:55:24 +00:00
7 changed files with 37 additions and 19 deletions
+7 -1
View File
@@ -2,6 +2,7 @@ use std::{
collections::HashMap,
path::Path,
sync::{Arc, LazyLock},
time::Instant,
};
use alloy::{
@@ -189,6 +190,7 @@ where
)));
let status_reporter_task = {
let metadata_case_status = metadata_case_status.clone();
let start = Instant::now();
async move {
const GREEN: &str = "\x1B[32m";
const RED: &str = "\x1B[31m";
@@ -281,8 +283,12 @@ where
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
}
let elapsed = start.elapsed();
eprintln!(
"{GREEN}{number_of_successes}{RESET} cases succeeded, {RED}{number_of_failures}{RESET} cases failed"
"{GREEN}{}{RESET} cases succeeded, {RED}{}{RESET} cases failed in {} seconds",
number_of_successes,
number_of_failures,
elapsed.as_secs()
);
}
};
+2 -2
View File
@@ -1,4 +1,4 @@
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use revive_dt_common::macros::define_wrapper_type;
@@ -7,7 +7,7 @@ use crate::{
mode::Mode,
};
#[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct Case {
pub name: Option<String>,
pub comment: Option<String>,
+9 -9
View File
@@ -17,7 +17,7 @@ use revive_dt_common::macros::define_wrapper_type;
use crate::traits::ResolverApi;
use crate::{metadata::ContractInstance, traits::ResolutionContext};
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
pub struct Input {
#[serde(default = "Input::default_caller")]
pub caller: Address,
@@ -33,7 +33,7 @@ pub struct Input {
pub variable_assignments: Option<VariableAssignments>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[serde(untagged)]
pub enum Expected {
Calldata(Calldata),
@@ -41,7 +41,7 @@ pub enum Expected {
ExpectedMany(Vec<ExpectedOutput>),
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
pub struct ExpectedOutput {
pub compiler_version: Option<VersionReq>,
pub return_data: Option<Calldata>,
@@ -50,7 +50,7 @@ pub struct ExpectedOutput {
pub exception: bool,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
pub struct Event {
pub address: Option<String>,
pub topics: Vec<String>,
@@ -108,7 +108,7 @@ pub struct Event {
/// [`Single`]: Calldata::Single
/// [`Compound`]: Calldata::Compound
/// [reverse polish notation]: https://en.wikipedia.org/wiki/Reverse_Polish_notation
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[serde(untagged)]
pub enum Calldata {
Single(Bytes),
@@ -142,7 +142,7 @@ enum Operation {
}
/// Specify how the contract is called.
#[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub enum Method {
/// Initiate a deploy transaction, calling contracts constructor.
///
@@ -167,7 +167,7 @@ define_wrapper_type!(
pub struct EtherValue(U256);
);
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
pub struct VariableAssignments {
/// A vector of the variable names to assign to the return data.
///
@@ -599,7 +599,7 @@ impl<T: AsRef<str>> CalldataToken<T> {
Some(block_number) => *block_number,
None => resolver.last_block_number().await?,
};
let desired_block_number = current_block_number - offset;
let desired_block_number = current_block_number.saturating_sub(offset);
let block_hash = resolver.block_hash(desired_block_number.into()).await?;
@@ -612,7 +612,7 @@ impl<T: AsRef<str>> CalldataToken<T> {
Ok(U256::from(current_block_number))
} else if item == Self::BLOCK_TIMESTAMP_VARIABLE {
resolver
.block_timestamp(BlockNumberOrTag::Latest)
.block_timestamp(context.resolve_block_number(BlockNumberOrTag::Latest))
.await
.map(U256::from)
} else if let Some(variable_name) = item.strip_prefix(Self::VARIABLE_PREFIX) {
+1 -2
View File
@@ -43,12 +43,11 @@ impl Deref for MetadataFile {
}
}
#[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct Metadata {
pub targets: Option<Vec<String>>,
pub cases: Vec<Case>,
pub contracts: Option<BTreeMap<ContractInstance, ContractPathAndIdent>>,
// TODO: Convert into wrapper types for clarity.
pub libraries: Option<BTreeMap<PathBuf, BTreeMap<ContractIdent, ContractInstance>>>,
pub ignore: Option<bool>,
pub modes: Option<Vec<Mode>>,
+18 -1
View File
@@ -16,6 +16,7 @@ pub struct SolcMode {
pub solc_version: Option<semver::VersionReq>,
solc_optimize: Option<bool>,
pub llvm_optimizer_settings: Vec<String>,
mode_string: String,
}
impl SolcMode {
@@ -29,7 +30,10 @@ impl SolcMode {
/// - A solc `SemVer version requirement` string
/// - One or more `-OX` where X is a supposed to be an LLVM opt mode
pub fn parse_from_mode_string(mode_string: &str) -> Option<Self> {
let mut result = Self::default();
let mut result = Self {
mode_string: mode_string.to_string(),
..Default::default()
};
let mut parts = mode_string.trim().split(" ");
@@ -104,3 +108,16 @@ impl<'de> Deserialize<'de> for Mode {
Ok(Self::Unknown(mode_string))
}
}
impl Serialize for Mode {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let string = match self {
Mode::Solidity(solc_mode) => &solc_mode.mode_string,
Mode::Unknown(string) => string,
};
string.serialize(serializer)
}
}
-2
View File
@@ -22,7 +22,6 @@ use alloy::{
Provider, ProviderBuilder,
ext::DebugApi,
fillers::{CachedNonceManager, ChainIdFiller, FillProvider, NonceFiller, TxFiller},
layers::CacheLayer,
},
rpc::types::{
TransactionReceipt, TransactionRequest,
@@ -258,7 +257,6 @@ impl GethNode {
.filler(FallbackGasFiller::new(500_000_000, 500_000_000, 1))
.filler(ChainIdFiller::default())
.filler(NonceFiller::new(nonce_manager))
.layer(CacheLayer::new(10_000))
.wallet(wallet)
.connect(&connection_string)
.await
-2
View File
@@ -23,7 +23,6 @@ use alloy::{
Provider, ProviderBuilder,
ext::DebugApi,
fillers::{CachedNonceManager, ChainIdFiller, FillProvider, NonceFiller, TxFiller},
layers::CacheLayer,
},
rpc::types::{
TransactionReceipt,
@@ -373,7 +372,6 @@ impl KitchensinkNode {
))
.filler(ChainIdFiller::default())
.filler(NonceFiller::new(nonce_manager))
.layer(CacheLayer::new(10_000))
.wallet(wallet)
.connect(&connection_string)
.await