diff --git a/projects/cheatcodes/test/BlastMock.t.sol b/projects/cheatcodes/test/BlastMock.t.sol index 62b6bf8ca..ca1869298 100644 --- a/projects/cheatcodes/test/BlastMock.t.sol +++ b/projects/cheatcodes/test/BlastMock.t.sol @@ -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 { @@ -38,4 +38,4 @@ contract SomeBlastTest is Test { function testSomething() public { // Now we can interact with Blast contracts without reverts } -} \ No newline at end of file +} diff --git a/projects/cheatcodes/test/EmitContract.t.sol b/projects/cheatcodes/test/EmitContract.t.sol index 9b7439456..7756324d5 100644 --- a/projects/cheatcodes/test/EmitContract.t.sol +++ b/projects/cheatcodes/test/EmitContract.t.sol @@ -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); diff --git a/projects/cheatcodes/test/OwnerUpOnly.t.sol b/projects/cheatcodes/test/OwnerUpOnly.t.sol index 9b43bea18..79cd3dbff 100644 --- a/projects/cheatcodes/test/OwnerUpOnly.t.sol +++ b/projects/cheatcodes/test/OwnerUpOnly.t.sol @@ -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 diff --git a/projects/fuzz_testing/test/Safe.t.sol b/projects/fuzz_testing/test/Safe.t.sol index c1cd8de9b..a059d39c6 100644 --- a/projects/fuzz_testing/test/Safe.t.sol +++ b/projects/fuzz_testing/test/Safe.t.sol @@ -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 {} diff --git a/projects/fuzz_testing/test/Safe.t.sol.1 b/projects/fuzz_testing/test/Safe.t.sol.1 index 42cbad3ad..4df224ba6 100644 --- a/projects/fuzz_testing/test/Safe.t.sol.1 +++ b/projects/fuzz_testing/test/Safe.t.sol.1 @@ -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 {} diff --git a/projects/fuzz_testing/test/Safe.t.sol.2 b/projects/fuzz_testing/test/Safe.t.sol.2 index 0d724b4ab..b6d3b8976 100644 --- a/projects/fuzz_testing/test/Safe.t.sol.2 +++ b/projects/fuzz_testing/test/Safe.t.sol.2 @@ -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 {} diff --git a/projects/fuzz_testing/test/Safe.t.sol.3 b/projects/fuzz_testing/test/Safe.t.sol.3 index c1cd8de9b..a059d39c6 100644 --- a/projects/fuzz_testing/test/Safe.t.sol.3 +++ b/projects/fuzz_testing/test/Safe.t.sol.3 @@ -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 {} diff --git a/projects/test_filters/test/ComplicatedContract.t.sol b/projects/test_filters/test/ComplicatedContract.t.sol index 7e3977ad1..e68a7d85d 100644 --- a/projects/test_filters/test/ComplicatedContract.t.sol +++ b/projects/test_filters/test/ComplicatedContract.t.sol @@ -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 { diff --git a/projects/test_filters/test/ContractB.t.sol b/projects/test_filters/test/ContractB.t.sol index 2aa12c16e..379f4e135 100644 --- a/projects/test_filters/test/ContractB.t.sol +++ b/projects/test_filters/test/ContractB.t.sol @@ -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 { diff --git a/projects/writing_tests/test/Basic.t.sol b/projects/writing_tests/test/Basic.t.sol index 45df22a7a..837da365a 100644 --- a/projects/writing_tests/test/Basic.t.sol +++ b/projects/writing_tests/test/Basic.t.sol @@ -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 { diff --git a/projects/writing_tests/test/Basic2.t.sol b/projects/writing_tests/test/Basic2.t.sol index dde81d4f1..bf4e78e7e 100644 --- a/projects/writing_tests/test/Basic2.t.sol +++ b/projects/writing_tests/test/Basic2.t.sol @@ -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 { diff --git a/src/cheatcodes/parse-json.md b/src/cheatcodes/parse-json.md index 698143074..cf66cbeba 100644 --- a/src/cheatcodes/parse-json.md +++ b/src/cheatcodes/parse-json.md @@ -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: diff --git a/src/cheatcodes/parse-toml.md b/src/cheatcodes/parse-toml.md index 205f38e41..2352654c1 100644 --- a/src/cheatcodes/parse-toml.md +++ b/src/cheatcodes/parse-toml.md @@ -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: diff --git a/src/config/vscode.md b/src/config/vscode.md index 184b1b027..5e388c879 100644 --- a/src/config/vscode.md +++ b/src/config/vscode.md @@ -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"; ``` diff --git a/src/faq.md b/src/faq.md index 48c7f07ae..b26b0ff92 100644 --- a/src/faq.md +++ b/src/faq.md @@ -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? diff --git a/src/forge/differential-ffi-testing.md b/src/forge/differential-ffi-testing.md index ad056f2c4..6420e61fb 100644 --- a/src/forge/differential-ffi-testing.md +++ b/src/forge/differential-ffi-testing.md @@ -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 { @@ -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); diff --git a/src/forge/forge-std.md b/src/forge/forge-std.md index 0413db230..2c0b360ff 100644 --- a/src/forge/forge-std.md +++ b/src/forge/forge-std.md @@ -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 { ... ``` @@ -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 diff --git a/src/projects/dependencies.md b/src/projects/dependencies.md index f0dee0f13..7030cf0cc 100644 --- a/src/projects/dependencies.md +++ b/src/projects/dependencies.md @@ -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 diff --git a/src/reference/config/solidity-compiler.md b/src/reference/config/solidity-compiler.md index cb85b98db..1d5e00555 100644 --- a/src/reference/config/solidity-compiler.md +++ b/src/reference/config/solidity-compiler.md @@ -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` diff --git a/src/reference/ds-test.md b/src/reference/ds-test.md index a45180497..14c4a91bf 100644 --- a/src/reference/ds-test.md +++ b/src/reference/ds-test.md @@ -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 ... diff --git a/src/reference/forge-std/README.md b/src/reference/forge-std/README.md index e52e41b06..a877062c8 100644 --- a/src/reference/forge-std/README.md +++ b/src/reference/forge-std/README.md @@ -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` @@ -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 { ... ``` diff --git a/src/reference/forge-std/console-log.md b/src/reference/forge-std/console-log.md index 9cc7e22c4..268e278f7 100644 --- a/src/reference/forge-std/console-log.md +++ b/src/reference/forge-std/console-log.md @@ -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` diff --git a/src/tutorials/create2-tutorial.md b/src/tutorials/create2-tutorial.md index 509a8bf27..f31e0ee1e 100644 --- a/src/tutorials/create2-tutorial.md +++ b/src/tutorials/create2-tutorial.md @@ -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"; diff --git a/src/tutorials/solidity-scripting.md b/src/tutorials/solidity-scripting.md index 05fa93842..3dd2fd176 100644 --- a/src/tutorials/solidity-scripting.md +++ b/src/tutorials/solidity-scripting.md @@ -49,9 +49,9 @@ 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(); @@ -59,8 +59,8 @@ 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; @@ -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 { @@ -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. diff --git a/src/tutorials/solmate-nft.md b/src/tutorials/solmate-nft.md index ba6842fad..43e3c9fb2 100644 --- a/src/tutorials/solmate-nft.md +++ b/src/tutorials/solmate-nft.md @@ -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; @@ -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 @@ -115,9 +115,9 @@ 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(); @@ -125,8 +125,8 @@ 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; @@ -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;