Skip to content

Commit

Permalink
test: check version before running Solc (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Nov 21, 2023
1 parent 2809e8b commit fdf8a5e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
24 changes: 22 additions & 2 deletions crates/json-abi/tests/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,28 @@ fn normalize_newlines(s: &str) -> String {
}

fn run_solc() -> bool {
let Ok(status) = Command::new("solc").arg("--version").status() else {
let Some(v) = get_solc_version() else {
return false;
};
status.success()
// UDVTs: https://soliditylang.org/blog/2021/09/27/user-defined-value-types/
v >= (0, 8, 8)
}

fn get_solc_version() -> Option<(u16, u16, u16)> {
let output = Command::new("solc").arg("--version").output().ok()?;
if !output.status.success() {
return None;
}
let stdout = String::from_utf8(output.stdout).ok()?;

let start = stdout.find(": 0.")?;
let version = &stdout[start + 2..];
let end = version.find('+')?;
let version = &version[..end];

let mut iter = version.split('.').map(|s| s.parse::<u16>().expect("bad solc version"));
let major = iter.next().unwrap();
let minor = iter.next().unwrap();
let patch = iter.next().unwrap();
Some((major, minor, patch))
}
29 changes: 24 additions & 5 deletions crates/syn-solidity/src/item/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,12 @@ mod tests {
#[test]
#[cfg_attr(miri, ignore = "takes too long")]
fn getters() {
let run_solc = run_solc();

macro_rules! test_getters {
($($var:literal => $f:literal),* $(,)?) => {
let vars: &[&str] = &[$($var),*];
let fns: &[&str] = &[$($f),*];
let run_solc = run_solc();
for (var, f) in std::iter::zip(vars, fns) {
test_getter(var, f, run_solc);
}
Expand Down Expand Up @@ -484,10 +485,28 @@ mod tests {
}

fn run_solc() -> bool {
let Ok(status) = Command::new("solc").arg("--version").status() else {
return false;
};
status.success()
let Some(v) = get_solc_version() else { return false };
// Named keys in mappings: https://soliditylang.org/blog/2023/02/01/solidity-0.8.18-release-announcement/
v >= (0, 8, 18)
}

fn get_solc_version() -> Option<(u16, u16, u16)> {
let output = Command::new("solc").arg("--version").output().ok()?;
if !output.status.success() {
return None;
}
let stdout = String::from_utf8(output.stdout).ok()?;

let start = stdout.find(": 0.")?;
let version = &stdout[start + 2..];
let end = version.find('+')?;
let version = &version[..end];

let mut iter = version.split('.').map(|s| s.parse::<u16>().expect("bad solc version"));
let major = iter.next().unwrap();
let minor = iter.next().unwrap();
let patch = iter.next().unwrap();
Some((major, minor, patch))
}

fn wrap_and_compile(s: &str, var: bool) -> std::result::Result<String, Box<dyn Error>> {
Expand Down

0 comments on commit fdf8a5e

Please sign in to comment.