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() #8530

Merged

Conversation

leovct
Copy link
Contributor

@leovct leovct commented Jul 26, 2024

Motivation

Closes #8036

Implement a new cheatcode to get the foundry version: vm.getFoundryVersion.

Solution

The current versioning scheme incorporates the cargo version, the git SHA and the UTC timestamp of the build to simplify differentiating by version number until v1 is released.

The version format follows this structure: <cargo_version>+<git_sha>+<build_timestamp>.

For example, a typical version might look like this: 0.2.0+faa94c384+202407110019.

Test

Install forge locally.

cargo install --path ./crates/forge --profile release --force --locked
alias forgedev="$(pwd)/target/release/forge" 

Run GetFoundryVersion test.

$ pushd testdata
$ forgedev test --match-contract GetFoundryVersion
[⠊] Compiling...
[⠢] Compiling 1 files with Solc 0.8.18
[⠆] Solc 0.8.18 finished in 101.72ms
Compiler run successful!

Ran 1 test for default/cheats/GetFoundryVersion.t.sol:GetFoundryVersionTest
[PASS] testGetFoundryVersion() (gas: 12955)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 425.29µs (111.42µs CPU time)

Ran 1 test suite in 148.77ms (425.29µs CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, this should work because the vergen env var is set when the forge binary is compiled

doc nit

@leovct leovct force-pushed the feat/add-vm-cheatcode-getfoundryversion branch from 68e9f49 to cc7b2b4 Compare July 26, 2024 16:23
@leovct leovct force-pushed the feat/add-vm-cheatcode-getfoundryversion branch from cc7b2b4 to 20d04fb Compare July 26, 2024 16:34
@leovct leovct marked this pull request as ready for review July 26, 2024 16:42
@mds1
Copy link
Collaborator

mds1 commented Jul 26, 2024

Do linux/mac/windows binaries all have the same UTC timestamp? I think they are built separately in CI and so likely will have the same date but different timestamps.

The failure mode here is I see my foundry version is 202407110019 and assert >= 202407110019, but the linux version is 202407110018 and fails that check. I think it's ok if we just document this and suggest only comparing against >= YYYYMMDD0000, i.e. just zero out the timestamps

@leovct
Copy link
Contributor Author

leovct commented Jul 26, 2024

Do linux/mac/windows binaries all have the same UTC timestamp? I think they are built separately in CI and so likely will have the same date but different timestamps.

The failure mode here is I see my foundry version is 202407110019 and assert >= 202407110019, but the linux version is 202407110018 and fails that check. I think it's ok if we just document this and suggest only comparing against >= YYYYMMDD0000, i.e. just zero out the timestamps

We can also format the build timestamp to %Y%M%D (e.g. 20240711)?

@mds1
Copy link
Collaborator

mds1 commented Jul 26, 2024

I thought about this but sometimes two releases are put out in a day, e.g. when there is an import or urgent fix. I think the current approach is fine as long as we document it. Thanks for this PR! :)

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, pending @DaniPopes re vergen dep

@leovct do you want to submit the new cheatcode to forge-std? foundry-rs/forge-std#589 nvm this is updated automatically

Comment on lines +17 to +22
[build-dependencies]
vergen = { workspace = true, default-features = false, features = [
"build",
"git",
"gitcl",
] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is fine, given that we also use this in other crates and the build overhead should be minimal

@mattsse mattsse merged commit a416c10 into foundry-rs:master Jul 27, 2024
21 checks passed
@leovct leovct deleted the feat/add-vm-cheatcode-getfoundryversion branch July 29, 2024 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(cheatcodes): add vm.getFoundryVersion()
5 participants