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

Refactor all tests to use named import syntax never import full files #11170

Open
arthurgousset opened this issue Jul 22, 2024 · 0 comments
Open

Comments

@arthurgousset
Copy link
Contributor

arthurgousset commented Jul 22, 2024

(House keeping)

Always use named import syntax, don’t import full files. This restricts what is being imported to just the named items, not everything in the file. Importing full files can result in solc complaining about duplicate definitions and slither erroring, especially as repos grow and have more dependencies with overlapping names.

Good: import {MyContract} from "src/MyContract.sol" to only import MyContract.
Bad: import "src/MyContract.sol" imports everything in MyContract.sol. (Importing forge-std/Test or Script can be an exception here, so you get the console library, etc).

Source: Foundry > Best Practices

For example:

This:

import { Test } from "celo-foundry/Test.sol";

Instead of this:

Not only is this better from a bug prevention perspective, but it also make it explicit where contracts are defined when they are inherited.

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

1 participant