Skip to content

Commit

Permalink
chore: prefer named imports over default imports (#1298)
Browse files Browse the repository at this point in the history
* prefer named imports

* fix formatting diff

* additional imports
  • Loading branch information
zerosnacks authored Sep 16, 2024
1 parent 5999bd0 commit 9be7241
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions projects/cheatcodes/test/BlastMock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ANCHOR: all
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

// Firstly, we implement a mock emulating the actual precompile behavior
contract YieldMock {
Expand Down Expand Up @@ -38,4 +38,4 @@ contract SomeBlastTest is Test {
function testSomething() public {
// Now we can interact with Blast contracts without reverts
}
}
}
2 changes: 1 addition & 1 deletion projects/cheatcodes/test/EmitContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ANCHOR: all
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

contract EmitContractTest is Test {
event Transfer(address indexed from, address indexed to, uint256 amount);
Expand Down
2 changes: 1 addition & 1 deletion projects/cheatcodes/test/OwnerUpOnly.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ANCHOR: prelude
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

error Unauthorized();
// ANCHOR_END: prelude
Expand Down
2 changes: 1 addition & 1 deletion projects/fuzz_testing/test/Safe.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ANCHOR: all
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

contract Safe {
receive() external payable {}
Expand Down
2 changes: 1 addition & 1 deletion projects/fuzz_testing/test/Safe.t.sol.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ANCHOR: all
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

contract Safe {
receive() external payable {}
Expand Down
2 changes: 1 addition & 1 deletion projects/fuzz_testing/test/Safe.t.sol.2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ANCHOR: all
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

contract Safe {
receive() external payable {}
Expand Down
2 changes: 1 addition & 1 deletion projects/fuzz_testing/test/Safe.t.sol.3
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ANCHOR: all
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

contract Safe {
receive() external payable {}
Expand Down
2 changes: 1 addition & 1 deletion projects/test_filters/test/ComplicatedContract.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

contract ComplicatedContractTest is Test {
function test_DepositERC20() public pure {
Expand Down
2 changes: 1 addition & 1 deletion projects/test_filters/test/ContractB.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";

contract ContractBTest is Test {
function testExample() public {
Expand Down
2 changes: 1 addition & 1 deletion projects/writing_tests/test/Basic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity 0.8.10;

// ANCHOR: import
import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";
// ANCHOR_END: import

contract ContractBTest is Test {
Expand Down
2 changes: 1 addition & 1 deletion projects/writing_tests/test/Basic2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity 0.8.10;

// ANCHOR: import
import "forge-std/Test.sol";
import {Test, stdError} from "forge-std/Test.sol";
// ANCHOR_END: import

contract ContractBTest is Test {
Expand Down
2 changes: 1 addition & 1 deletion src/cheatcodes/parse-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ If your JSON object has `hex numbers`, they will be encoded as bytes. The way to

### How to use StdJson

1. Import the library `import "../StdJson.sol";`
1. Import the library `import {stdJson} from "forge-std/StdJson.sol";`
2. Define its usage with `string`: `using stdJson for string;`
3. If you want to parse simple values (numbers, address, etc.) use the helper functions
4. If you want to parse entire JSON objects:
Expand Down
2 changes: 1 addition & 1 deletion src/cheatcodes/parse-toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ for (uint256 i = 0; i < fruitstall.apples.length; i++) {

### How to use StdToml

1. Import the library `import "../StdToml.sol";`
1. Import the library `import {stdToml} from "forge-std/StdToml.sol";`
2. Define its usage with `string`: `using stdToml for string;`
3. If you want to parse simple values (numbers, address, etc.) use the helper functions
4. If you want to parse entire TOML tables:
Expand Down
2 changes: 1 addition & 1 deletion src/config/vscode.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ Add line to `.vscode/settings.json` file (solidity extension settings):
Now all contracts from the OpenZeppelin documentation can be used.

```javascript
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
```
2 changes: 1 addition & 1 deletion src/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Alternatively, you can use [Forge Std][forge-std] which comes bundled with `cons
you have to import it:

```solidity
import "forge-std/console.sol";
import {console} from "forge-std/console.sol";
```

### How do I run specific tests?
Expand Down
4 changes: 2 additions & 2 deletions src/forge/differential-ffi-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Below are some examples of how Forge is used for differential testing.
[`ffi`](../cheatcodes/ffi.md) allows you to execute an arbitrary shell command and capture the output. Here's a mock example:

```solidity
import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";
contract TestContract is Test {
Expand Down Expand Up @@ -90,7 +90,7 @@ Finally, the test asserts that the both roots are exactly equal. If they are not
You may want to use differential testing against another Solidity implementation. In that case, `ffi` is not needed. Instead, the reference implementation is imported directly into the test.

```solidity
import "openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol";
import {MerkleProof} from "openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol";
//...
function testCompatibilityOpenZeppelinProver(bytes32[] memory _data, uint256 node) public {
vm.assume(_data.length > 1);
Expand Down
8 changes: 4 additions & 4 deletions src/forge/forge-std.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It provides all the essential functionality you need to get started writing test
Simply import `Test.sol` and inherit from `Test` in your test contract:

```solidity
import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";
contract ContractTest is Test { ...
```
Expand All @@ -38,17 +38,17 @@ deal(address(dai), alice, 10000e18);
To import the `Vm` interface or the `console` library individually:

```solidity
import "forge-std/Vm.sol";
import {Vm} from "forge-std/Vm.sol";
```

```solidity
import "forge-std/console.sol";
import {console} from "forge-std/console.sol";
```

**Note:** `console2.sol` contains patches to `console.sol` that allows Forge to decode traces for calls to the console, but it is not compatible with Hardhat.

```solidity
import "forge-std/console2.sol";
import {console2} from "forge-std/console2.sol";
```

### Standard libraries
Expand Down
2 changes: 1 addition & 1 deletion src/projects/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ remappings = [
Now we can import any of the contracts in `src/utils` of the solmate repository like so:

```solidity
import "@solmate-utils/LibString.sol";
import {LibString} from "@solmate-utils/LibString.sol";
```

### Updating dependencies
Expand Down
4 changes: 2 additions & 2 deletions src/reference/config/solidity-compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ A remapping _remaps_ Solidity imports to different directories. For example, the
with an import like

```solidity
import "@openzeppelin/contracts/utils/Context.sol";
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
```

becomes

```solidity
import "node_modules/@openzeppelin/openzeppelin-contracts/contracts/utils/Context.sol";
import {Context} from "node_modules/@openzeppelin/openzeppelin-contracts/contracts/utils/Context.sol";
```

##### `auto_detect_remappings`
Expand Down
2 changes: 1 addition & 1 deletion src/reference/ds-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Dappsys Test (DSTest for short) provides basic logging and assertion functionali
To get access to the functions, import `forge-std/Test.sol` and inherit from `Test` in your test contract:

```solidity
import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";
contract ContractTest is Test {
// ... tests ...
Expand Down
12 changes: 6 additions & 6 deletions src/reference/forge-std/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ What's included:
- `Vm.sol`: Up-to-date [cheatcodes interface](../../cheatcodes/#cheatcodes-interface)

```solidity
import "forge-std/Vm.sol";
import {Vm} from "forge-std/Vm.sol";
```

- [`console.sol`](./console-log.md) and `console2.sol`: Hardhat-style logging functionality

```solidity
import "forge-std/console.sol";
import {console} from "forge-std/console.sol";
```

**Note:** `console2.sol` contains patches to `console.sol` that allow Forge to decode traces for calls to the console, but it is not compatible with Hardhat.

```solidity
import "forge-std/console2.sol";
import {console2} from "forge-std/console2.sol";
```

- `Script.sol`: Basic utilities for [Solidity scripting](../../tutorials/solidity-scripting.md)

```solidity
import "forge-std/Script.sol";
import {Script} from "forge-std/Script.sol";
```

- `Test.sol`: The complete Forge Std experience (more details [below](#forge-stds-test))

```solidity
import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";
```

### Forge Std's `Test`
Expand All @@ -43,7 +43,7 @@ The `Test` contract in `Test.sol` provides all the essential functionality you n
Simply import `Test.sol` and inherit from `Test` in your test contract:

```solidity
import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";
contract ContractTest is Test { ...
```
Expand Down
2 changes: 1 addition & 1 deletion src/reference/forge-std/console-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- You can use it in calls and transactions. It also works with view and pure functions.
- It always works, regardless of the call or transaction failing or being successful.
- To use it you need import it:
- `import "forge-std/console.sol";`
- `import {console} from "forge-std/console.sol";`
- You can call console.log with up to 4 parameters in any order of following types:
- `uint`
- `string`
Expand Down
2 changes: 1 addition & 1 deletion src/tutorials/create2-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Initialize a contract named `Create2Test` like this:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "forge-std/Test.sol";
import {Test} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";
import {Create2} from "../src/Create2.sol";
Expand Down
16 changes: 8 additions & 8 deletions src/tutorials/solidity-scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ Once that’s done, you should open up your preferred code editor and copy the c
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.10;
import "solmate/tokens/ERC721.sol";
import "openzeppelin-contracts/contracts/utils/Strings.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";
import {ERC721} from "solmate/tokens/ERC721.sol";
import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
error MintPriceNotPaid();
error MaxSupply();
error NonExistentTokenURI();
error WithdrawTransfer();
contract NFT is ERC721, Ownable {
using Strings for uint256;
string public baseURI;
uint256 public currentTokenId;
uint256 public constant TOTAL_SUPPLY = 10_000;
Expand Down Expand Up @@ -163,8 +163,8 @@ The contents of `NFT.s.sol` should look like this:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Script.sol";
import "../src/NFT.sol";
import {Script} from "forge-std/Script.sol";
import {NFT} from "../src/NFT.sol";
contract MyScript is Script {
function run() external {
Expand All @@ -188,8 +188,8 @@ pragma solidity ^0.8.13;
Remember even if it’s a script it still works like a smart contract, but is never deployed, so just like any other smart contract written in Solidity the `pragma version` has to be specified.

```solidity
import "forge-std/Script.sol";
import "../src/NFT.sol";
import {Script} from "forge-std/Script.sol";
import {NFT} from "../src/NFT.sol";
```

Just like we may import Forge Std to get testing utilities when writing tests, Forge Std also provides some scripting utilities that we import here.
Expand Down
20 changes: 10 additions & 10 deletions src/tutorials/solmate-nft.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ We are then going to rename the boilerplate contract in `src/Contract.sol` to `s
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;
import "solmate/tokens/ERC721.sol";
import "openzeppelin-contracts/contracts/utils/Strings.sol";
import {ERC721} from "solmate/tokens/ERC721.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
contract NFT is ERC721 {
uint256 public currentTokenId;
Expand Down Expand Up @@ -61,8 +61,8 @@ Compiler run failed
error[6275]: ParserError: Source "lib/openzeppelin-contracts/contracts/contracts/utils/Strings.sol" not found: File not found. Searched the following locations: "/PATH/TO/REPO".
--> src/NFT.sol:5:1:
|
5 | import "openzeppelin-contracts/contracts/utils/Strings.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

this can be fixed by setting up the correct remapping. Create a file `remappings.txt` in your project and add the line
Expand Down Expand Up @@ -115,18 +115,18 @@ Let's extend our NFT by adding metadata to represent the content of our NFTs, as
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.10;
import "solmate/tokens/ERC721.sol";
import "openzeppelin-contracts/contracts/utils/Strings.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";
import {ERC721} from "solmate/tokens/ERC721.sol";
import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
error MintPriceNotPaid();
error MaxSupply();
error NonExistentTokenURI();
error WithdrawTransfer();
contract NFT is ERC721, Ownable {
using Strings for uint256;
string public baseURI;
uint256 public currentTokenId;
uint256 public constant TOTAL_SUPPLY = 10_000;
Expand Down Expand Up @@ -195,8 +195,8 @@ Within your test folder rename the current `Contract.t.sol` test file to `NFT.t.
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;
import "forge-std/Test.sol";
import "../src/NFT.sol";
import {Test} from "forge-std/Test.sol";
import {NFT} from "../src/NFT.sol";
contract NFTTest is Test {
using stdStorage for StdStorage;
Expand Down

0 comments on commit 9be7241

Please sign in to comment.