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

Unable to find artifact when contract name is different from file name #6

Open
beeb opened this issue Dec 21, 2023 · 2 comments
Open

Comments

@beeb
Copy link

beeb commented Dec 21, 2023

The portion of code below looks for the artifact file in the out directory and uses the contract name for both the folder and json filename.

However, if a contract has a different name from the solidity file that contains it, this fails:

Assume the file is named SomeFile.sol

Error: ENOENT: no such file or directory, open '/home/myproject/out/MyContract.sol/MyContract.json'

The path should be /home/myproject/out/SomeFile.sol/MyContract.json

The culprit:

const filePath = path.join(__dirname, `../../out/${contractName}.sol/${contractName}.json`);

@ZeroEkkusu
Copy link
Member

Hey, @beeb!

Currently, Forge returns null when there are multiple contracts with the same name.

For example, if you make two contracts with the same name, deploy them using forge script, and look at the broadcast file, some data will be null.

We had to work around this, and assume that all contract will have unique names.

As for the the file name, the idea is that the file name should reflect the name of the main contract inside it. If there is more that one 'main' contract in the file, they should be moved to their separate files.

You are correct that this is not indicated, and we should add it to the readme.

@beeb
Copy link
Author

beeb commented Jan 11, 2024

Thanks for the feedback on this. I agree that having multiple contracts with the same name should not be a supported use case, since foundry doesn't itself populate the broadcast files accordingly. However, having a contract with a different name from the source filename should in my opinion be supported. Likewise, having multiple contracts in the same file should be supported. Forge chronicles could probably be smart about it and try to find the source file containing a given contract, if its name is unique accross the project.

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

No branches or pull requests

2 participants