Skip to content

Commit

Permalink
prefer named imports
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Sep 16, 2024
1 parent 963dfa0 commit f1de98a
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 28 deletions.
17 changes: 12 additions & 5 deletions projects/cheatcodes/test/BlastMock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
// 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 {
address private constant blastContract = 0x4300000000000000000000000000000000000002;
address private constant blastContract =
0x4300000000000000000000000000000000000002;

mapping(address => uint8) public getConfiguration;

function configure(address contractAddress, uint8 flags) external returns (uint256) {
function configure(
address contractAddress,
uint8 flags
) external returns (uint256) {
require(msg.sender == blastContract);

getConfiguration[contractAddress] = flags;
Expand All @@ -32,10 +36,13 @@ contract SomeBlastTest is Test {
// Deploy mock of the precompile
YieldMock yieldMock = new YieldMock();
// Set mock bytecode to the expected precompile address
vm.etch(0x0000000000000000000000000000000000000100, address(yieldMock).code);
vm.etch(
0x0000000000000000000000000000000000000100,
address(yieldMock).code
);
}

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
4 changes: 2 additions & 2 deletions 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 All @@ -30,7 +30,7 @@ contract OwnerUpOnly {
// ANCHOR: contract_prelude
contract OwnerUpOnlyTest is Test {
OwnerUpOnly upOnly;
// ANCHOR_END: contract_prelude
// ANCHOR_END: contract_prelude

// ANCHOR: simple_test
function setUp() public {
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -25,7 +25,7 @@ contract SafeTest is Test {

// ANCHOR: signature
function testFuzz_Withdraw(uint96 amount) public {
// ANCHOR_END: signature
// ANCHOR_END: signature
payable(address(safe)).transfer(amount);
uint256 preBalance = address(this).balance;
safe.withdraw();
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/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
2 changes: 1 addition & 1 deletion 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 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/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
2 changes: 1 addition & 1 deletion src/tutorials/solmate-nft.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ 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 {Test} from "forge-std/Test.sol";
import "../src/NFT.sol";
contract NFTTest is Test {
Expand Down

0 comments on commit f1de98a

Please sign in to comment.