diff --git a/Cargo.lock b/Cargo.lock index fde0c6326e50..337c5f061a59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1356,6 +1356,7 @@ dependencies = [ "time", "tokio", "tracing", + "tracing-subscriber", "vergen", "yansi 0.5.1", ] diff --git a/crates/chisel/Cargo.toml b/crates/chisel/Cargo.toml index 4a6364af66f2..22d78e64e611 100644 --- a/crates/chisel/Cargo.toml +++ b/crates/chisel/Cargo.toml @@ -54,6 +54,7 @@ tracing.workspace = true criterion = { version = "0.5", features = ["async_tokio"] } once_cell = "1" serial_test = "2" +tracing-subscriber.workspace = true [features] default = ["rustls"] diff --git a/crates/chisel/src/executor.rs b/crates/chisel/src/executor.rs index f3dcb40f3781..1a425d3f2e8f 100644 --- a/crates/chisel/src/executor.rs +++ b/crates/chisel/src/executor.rs @@ -861,10 +861,7 @@ impl Type { "name" => Some(DynSolType::String), "creationCode" | "runtimeCode" => Some(DynSolType::Bytes), "interfaceId" => Some(DynSolType::FixedBytes(4)), - "min" | "max" => { - let arg = args.unwrap().pop().flatten().unwrap(); - Some(arg.into_builtin().unwrap()) - } + "min" | "max" => Some(DynSolType::Uint(256)), _ => None, }, "string" => match access { @@ -1570,6 +1567,8 @@ mod tests { #[test] fn test_global_vars() { + init_tracing(); + // https://docs.soliditylang.org/en/latest/cheatsheet.html#global-variables let global_variables = { use DynSolType::*; @@ -1649,9 +1648,11 @@ mod tests { ("type(C).runtimeCode", Bytes), ("type(I).interfaceId", FixedBytes(4)), ("type(uint256).min", Uint(256)), - ("type(int256).min", Int(256)), + ("type(int256).min", Uint(256)), ("type(uint256).max", Uint(256)), - ("type(int256).max", Int(256)), + ("type(int256).max", Uint(256)), + ("type(Enum1).min", Uint(256)), + ("type(Enum1).max", Uint(256)), // function ("this.run.address", Address), ("this.run.selector", FixedBytes(4)), @@ -1712,14 +1713,16 @@ mod tests { s.drain_global_code(); } - let input = input.trim_end().trim_end_matches(';').to_string() + ";"; + *s = s.clone_with_new_line("enum Enum1 { A }".into()).unwrap().0; + + let input = format!("{};", input.trim_end().trim_end_matches(';')); let (mut _s, _) = s.clone_with_new_line(input).unwrap(); *s = _s.clone(); let s = &mut _s; if let Err(e) = s.parse() { for err in e { - eprintln!("{} @ {}:{}", err.message, err.loc.start(), err.loc.end()); + eprintln!("{}:{}: {}", err.loc.start(), err.loc.end(), err.message); } let source = s.to_repl_source(); panic!("could not parse input:\n{source}") @@ -1750,7 +1753,6 @@ mod tests { ty.and_then(|ty| ty.try_as_ethabi(Some(&intermediate))) } - #[track_caller] fn generic_type_test<'a, T, I>(s: &mut SessionSource, input: I) where T: AsRef + std::fmt::Display + 'a, @@ -1762,4 +1764,13 @@ mod tests { assert_eq!(ty.as_ref(), Some(expected), "\n{input}"); } } + + fn init_tracing() { + if std::env::var_os("RUST_LOG").is_none() { + std::env::set_var("RUST_LOG", "debug"); + } + let _ = tracing_subscriber::FmtSubscriber::builder() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .try_init(); + } } diff --git a/crates/chisel/src/session_source.rs b/crates/chisel/src/session_source.rs index 36fb5cf1c167..c827454e97c4 100644 --- a/crates/chisel/src/session_source.rs +++ b/crates/chisel/src/session_source.rs @@ -14,7 +14,7 @@ use foundry_config::{Config, SolcReq}; use foundry_evm::{backend::Backend, opts::EvmOpts}; use semver::Version; use serde::{Deserialize, Serialize}; -use solang_parser::pt; +use solang_parser::{diagnostics::Diagnostic, pt}; use std::{collections::HashMap, fs, path::PathBuf}; use yansi::Paint; @@ -665,16 +665,26 @@ pub fn parse_fragment( match base.clone().with_run_code(buffer).parse() { Ok(_) => return Some(ParseTreeFragment::Function), - Err(e) => tracing::debug!(?e), + Err(e) => debug_errors(&e), } match base.clone().with_top_level_code(buffer).parse() { Ok(_) => return Some(ParseTreeFragment::Contract), - Err(e) => tracing::debug!(?e), + Err(e) => debug_errors(&e), } match base.with_global_code(buffer).parse() { Ok(_) => return Some(ParseTreeFragment::Source), - Err(e) => tracing::debug!(?e), + Err(e) => debug_errors(&e), } None } + +fn debug_errors(errors: &[Diagnostic]) { + if !tracing::enabled!(tracing::Level::DEBUG) { + return; + } + + for error in errors { + tracing::debug!("error: {}", error.message); + } +} diff --git a/crates/forge/bin/cmd/verify/mod.rs b/crates/forge/bin/cmd/verify/mod.rs index 404ed2251b12..4590c46a3efe 100644 --- a/crates/forge/bin/cmd/verify/mod.rs +++ b/crates/forge/bin/cmd/verify/mod.rs @@ -99,6 +99,10 @@ pub struct VerifyArgs { #[clap(long, conflicts_with = "flatten")] pub show_standard_json_input: bool, + /// Use the Yul intermediate representation compilation pipeline. + #[clap(long)] + pub via_ir: bool, + #[clap(flatten)] pub etherscan: EtherscanOpts, @@ -107,10 +111,6 @@ pub struct VerifyArgs { #[clap(flatten)] pub verifier: VerifierArgs, - - /// Use the Yul intermediate representation compilation pipeline. - #[clap(long)] - pub via_ir: bool, } impl_figment_convert!(VerifyArgs); @@ -119,6 +119,7 @@ impl figment::Provider for VerifyArgs { fn metadata(&self) -> figment::Metadata { figment::Metadata::named("Verify Provider") } + fn data( &self, ) -> Result, figment::Error> {