Skip to content

Allow script ephimeral addresses - or allow detection of test or script env #10437

@kevupton

Description

@kevupton

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

nightly-33cb8d2faf6787ddecde2af7343ee472bdf829ee

What version of Foundryup are you on?

.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit ╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development ╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust. .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx Repo : https://github.com/foundry-rs/ Book : https://book.getfoundry.sh/ Chat : https://t.me/foundry_rs/ Support : https://t.me/foundry_support/ Contribute : Foundry .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx foundryup: installing foundry (version , tag ) foundryup: downloading latest forge, cast, anvil, and chisel ############################################################################### 100.0% tar: Error opening archive: Unrecognized archive format foundryup: downloading manpages ############################################################################### 100.0% tar: Error opening archive: Unrecognized archive format foundryup: installed - forge Version: 1.1.0-v1.1.0 Commit SHA: d484a00 Build Timestamp: 2025-04-28T08:22:18.429906000Z (1745828538) Build Profile: maxperf foundryup: installed - cast Version: 1.1.0-v1.1.0 Commit SHA: d484a00 Build Timestamp: 2025-04-28T08:22:18.429906000Z (1745828538) Build Profile: maxperf foundryup: installed - anvil Version: 1.1.0-v1.1.0 Commit SHA: d484a00 Build Timestamp: 2025-04-28T08:22:18.429906000Z (1745828538) Build Profile: maxperf foundryup: installed - chisel Version: 1.1.0-v1.1.0 Commit SHA: d484a00 Build Timestamp: 2025-04-28T08:22:18.429906000Z (1745828538) Build Profile: maxperf foundryup: done

What command(s) is the bug in?

No response

Operating System

None

Describe the bug

Right now i am using this method as part of my base script to determine if the file is a test or script. I am using this:

    function isTest() public view returns (bool) {
        try Test(address(this)).IS_TEST() returns (bool result) {
            return result;
        } catch {
            return false;
        }
    }

In the latest version of foundry , you guys have prevented calling a script contract.

Error: Usage of address(this) detected in script contract. Script contracts are ephemeral and their addresses should not be relied upon.

It would be good to have a way to identify if its running in a test environment or not. If you want to add the above error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-bugType: bugT-needs-triageType: this issue needs to be labelled

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions