From 1e6d11342d2ff2d08390c0b4c236ce9e3b6fb540 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 16 Sep 2024 17:42:21 +0200 Subject: [PATCH] additional imports --- src/cheatcodes/parse-json.md | 2 +- src/cheatcodes/parse-toml.md | 2 +- src/config/vscode.md | 2 +- src/faq.md | 2 +- src/forge/differential-ffi-testing.md | 2 +- src/forge/forge-std.md | 6 +++--- src/projects/dependencies.md | 2 +- src/reference/config/solidity-compiler.md | 4 ++-- src/reference/forge-std/console-log.md | 2 +- src/tutorials/solidity-scripting.md | 16 ++++++++-------- src/tutorials/solmate-nft.md | 18 +++++++++--------- 11 files changed, 29 insertions(+), 29 deletions(-) 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 b38deed09..6420e61fb 100644 --- a/src/forge/differential-ffi-testing.md +++ b/src/forge/differential-ffi-testing.md @@ -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 0b724032d..2c0b360ff 100644 --- a/src/forge/forge-std.md +++ b/src/forge/forge-std.md @@ -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 302abfe2e..507e1a9cb 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/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/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 7f9625449..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; @@ -196,7 +196,7 @@ Within your test folder rename the current `Contract.t.sol` test file to `NFT.t. pragma solidity 0.8.10; import {Test} from "forge-std/Test.sol"; -import "../src/NFT.sol"; +import {NFT} from "../src/NFT.sol"; contract NFTTest is Test { using stdStorage for StdStorage;