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

feat(cheatcodes): add vm.getFoundryVersion() #8036

Closed
PatrickAlphaC opened this issue Jun 2, 2024 · 11 comments · Fixed by #8530
Closed

feat(cheatcodes): add vm.getFoundryVersion() #8036

PatrickAlphaC opened this issue Jun 2, 2024 · 11 comments · Fixed by #8530
Assignees
Labels
A-cheatcodes Area: cheatcodes first issue A good way to start contributing T-feature Type: feature
Milestone

Comments

@PatrickAlphaC
Copy link

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 PatrickAlphaC added the T-feature Type: feature label Jun 2, 2024
@PatrickAlphaC
Copy link
Author

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

@DaniPopes DaniPopes added first issue A good way to start contributing A-cheatcodes Area: cheatcodes labels Jun 7, 2024
@LukePereyra
Copy link

Hello! I want to take this Issue !

@mattsse
Copy link
Member

mattsse commented Jun 10, 2024

assigned,
lmk if you need need pointers

@LukePereyra
Copy link

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
Copy link
Member

mattsse commented Jun 11, 2024

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
Copy link
Collaborator

mds1 commented Jun 11, 2024

@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:

  • Start with 0.2.0+0001 and increment with each build
  • Use the UTC timestamp of build, e.g. 0.2.0+202406111234

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
Copy link
Member

mattsse commented Jun 11, 2024

makes sense

@zerosnacks
Copy link
Member

Hi @LukePereyra, any updates on this ticket? Would be great to get this in

Let me know if you are running into anything or need any pointers

@zerosnacks zerosnacks changed the title vm.getFoundryVersion() feat(cheatcodes): add vm.getFoundryVersion() Jul 16, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@leovct
Copy link
Contributor

leovct commented Jul 26, 2024

Hi @zerosnacks, I'd like to take over if possible.

@zerosnacks
Copy link
Member

Re-assigning to @leovct

@zerosnacks
Copy link
Member

zerosnacks commented Jan 16, 2025

Hi @PatrickAlphaC

There will be a breaking change introduced in #9683 that changes the format of vm.getFoundryVersion() to use a UNIX timestamp and the parsing of the version format is slightly different.

forge --version will output a UNIX timestamp alongside a human readable version

We will also start versioning our releases more actively allowing you to more easily match on the Cargo version number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes first issue A good way to start contributing T-feature Type: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants