foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
7.89k stars 1.59k forks source link

vm.getFoundryVersion() #8036

Open PatrickAlphaC opened 1 month ago

PatrickAlphaC commented 1 month ago

Component

Forge

Describe the feature you would like

It would be great if there was a way to get the foundry version in our scripts. I can make sure a script with ffi, but it would be cool if there was an API like:

vm.getFoundryVersion();

To let people know that some tests will only work on certain editions of foundry.

Additional context

No response

PatrickAlphaC commented 1 month ago

(IMO this is super low priority, and probably a good first issue?)

LukePereyra commented 1 month ago

Hello! I want to take this Issue !

mattsse commented 1 month ago

assigned, lmk if you need need pointers

LukePereyra commented 4 weeks ago

assigned, lmk if you need need pointers

oh perfect! I was taking a look into the code, and there is a file (crates/cheatcodes/spec/src/vm.rs) that is the interface with the EVM. can I add the method getFoundryVersion there? (and then implement it with a Cheatcode) btw, the foundryVersion is the one that its in Cargo.toml in the section [workspace.package] or that one it's outdate?

mattsse commented 4 weeks ago

can I add the method getFoundryVersion there? (and then implement it with a Cheatcode)

exactly,

you can get the version by duplicating this in the cheatcodes crate

https://github.com/foundry-rs/foundry/blob/master/crates/forge/bin/opts.rs#L12-L19

mds1 commented 4 weeks ago

@mattsse what do you think about also appending a build identifier to versions, to simplify differentiating by version number until v1 is released? Currently everything is 0.2.0 with different commits, so getFoundryVersion() isn't super useful as you can't easily enforce "this version or later". Could either:

Then you can do:

function assertMinFoundryVersion() internal view {
  string memory version = vm.getFoundryVersion();
  uint256 buildId = vm.parseUint(vm.split(version, "+")[1]);
  require(buildId >= 202406111234, "too old");
mattsse commented 4 weeks ago

makes sense