-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into expectCreate
- Loading branch information
Showing
13 changed files
with
221 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ mod config; | |
|
||
mod crypto; | ||
|
||
mod version; | ||
|
||
mod env; | ||
pub use env::set_execution_context; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; | ||
use alloy_sol_types::SolValue; | ||
use foundry_common::version::SEMVER_VERSION; | ||
use semver::Version; | ||
use std::cmp::Ordering; | ||
|
||
impl Cheatcode for foundryVersionCmpCall { | ||
fn apply(&self, _state: &mut Cheatcodes) -> Result { | ||
let Self { version } = self; | ||
foundry_version_cmp(version).map(|cmp| (cmp as i8).abi_encode()) | ||
} | ||
} | ||
|
||
impl Cheatcode for foundryVersionAtLeastCall { | ||
fn apply(&self, _state: &mut Cheatcodes) -> Result { | ||
let Self { version } = self; | ||
foundry_version_cmp(version).map(|cmp| cmp.is_ge().abi_encode()) | ||
} | ||
} | ||
|
||
fn foundry_version_cmp(version: &str) -> Result<Ordering> { | ||
version_cmp(SEMVER_VERSION.split('-').next().unwrap(), version) | ||
} | ||
|
||
fn version_cmp(version_a: &str, version_b: &str) -> Result<Ordering> { | ||
let version_a = parse_version(version_a)?; | ||
let version_b = parse_version(version_b)?; | ||
Ok(version_a.cmp(&version_b)) | ||
} | ||
|
||
fn parse_version(version: &str) -> Result<Version> { | ||
let version = | ||
Version::parse(version).map_err(|e| fmt_err!("invalid version `{version}`: {e}"))?; | ||
if !version.pre.is_empty() { | ||
return Err(fmt_err!("invalid version `{version}`: pre-release versions are not supported")); | ||
} | ||
if !version.build.is_empty() { | ||
return Err(fmt_err!("invalid version `{version}`: build metadata is not supported")); | ||
} | ||
Ok(version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters