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

Forge script crashes when two script contracts have the same name. #3177

Closed
2 tasks done
Willyham opened this issue Sep 12, 2022 · 3 comments
Closed
2 tasks done

Forge script crashes when two script contracts have the same name. #3177

Willyham opened this issue Sep 12, 2022 · 3 comments
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug T-to-reproduce Type: requires reproduction
Milestone

Comments

@Willyham
Copy link

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (63c71b4 2022-09-12T00:05:14.033477Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

When two 'script contracts' have the same name, and forge script is run for any function in the contract, forge crashes with this error:

➜  contracts git:(script-test) ✗ forge script src/deploy/Deploy.t.sol --sig "deploy()"--private-key <>
[⠰] Compiling...
[⠒] Compiling 1 files with 0.8.10
[⠘] Solc 0.8.10 finished in 1.13s
Compiler run successful
The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: cli/src/cmd/forge/script/executor.rs:36

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
[1]    6716 abort      forge script src/deploy/Deploy.t.sol --sig "deploy()" --rpc-url  --private-ke

It is likely that having two contracts with the same name in different files is not ideal (or possibly not valid, they compiled fine). However, if that is the case then forge should detect this and print a friendly error.

Thanks!

@Willyham Willyham added the T-bug Type: bug label Sep 12, 2022
@gakonst gakonst added this to Foundry Sep 12, 2022
@gakonst gakonst moved this to Todo in Foundry Sep 12, 2022
@rkrasiuk rkrasiuk added C-forge Command: forge Cmd-forge-script Command: forge script labels Sep 12, 2022
@mattsse
Copy link
Member

mattsse commented Sep 12, 2022

are both contracts actually contracts or is one an interface?

@aewing
Copy link

aewing commented Jan 10, 2023

I ran into this today. Basically what I did was clone a script (Deploy.s.sol) and renamed it (to Mint.s.sol), changed the content, but forgot to change the name of the new contract from DeployScript -- leading to the above error and no hint as to why I was seeing it.

Renaming the contract in Mint.s.sol (and eliminating the duplicated script contract name) resolved the issue.

@zerosnacks
Copy link
Member

Optimistically marking as resolved

Recreating a setup with a duplicate CounterScript now returns:

Error: 
Multiple contracts found with the name `CounterScript`

Running against a direct path forge script script/Counter2.s.sol yields no errors

@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug T-to-reproduce Type: requires reproduction
Projects
Archived in project
Development

No branches or pull requests

5 participants