Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chisel): enum min and max #7173

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/chisel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
29 changes: 20 additions & 9 deletions crates/chisel/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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<str> + std::fmt::Display + 'a,
Expand All @@ -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();
}
}
18 changes: 14 additions & 4 deletions crates/chisel/src/session_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
9 changes: 5 additions & 4 deletions crates/forge/bin/cmd/verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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);
Expand All @@ -119,6 +119,7 @@ impl figment::Provider for VerifyArgs {
fn metadata(&self) -> figment::Metadata {
figment::Metadata::named("Verify Provider")
}

fn data(
&self,
) -> Result<figment::value::Map<figment::Profile, figment::value::Dict>, figment::Error> {
Expand Down
Loading