Skip to content

Commit

Permalink
Merge pull request #50 from PaulRBerg/refactor/remove-prb-test
Browse files Browse the repository at this point in the history
refactor: use Test instead of PRBTest
  • Loading branch information
PaulRBerg authored Apr 16, 2024
2 parents d9554ea + a46a5b6 commit 77f8e8d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ A Foundry-based template for developing Solidity smart contracts, with sensible

- [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, format, and deploy smart
contracts
- [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and cheatcodes for testing
- [PRBTest](https://github.com/PaulRBerg/prb-test): modern collection of testing assertions and logging utilities
- [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and utilities for testing
- [Prettier](https://github.com/prettier/prettier): code formatter for non-Solidity files
- [Solhint](https://github.com/protofire/solhint): linter for Solidity code

Expand Down Expand Up @@ -92,10 +91,10 @@ Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an

## Writing Tests

To write a new test contract, you start by importing [PRBTest](https://github.com/PaulRBerg/prb-test) and inherit from
it in your test contract. PRBTest comes with a pre-instantiated [cheatcodes](https://book.getfoundry.sh/cheatcodes/)
environment accessible via the `vm` property. If you would like to view the logs in the terminal output you can add the
`-vvv` flag and use [console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog).
To write a new test contract, you start by importing `Test` from `forge-std`, and then you inherit it in your test
contract. Forge Std comes with a pre-instantiated [cheatcodes](https://book.getfoundry.sh/cheatcodes/) environment
accessible via the `vm` property. If you would like to view the logs in the terminal output, you can add the `-vvv` flag
and use [console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog).

This template comes with an example test contract [Foo.t.sol](./test/Foo.t.sol)

Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"@openzeppelin/contracts": "^5.0.1"
},
"devDependencies": {
"@prb/test": "^0.6.4",
"forge-std": "github:foundry-rs/forge-std#v1.7.5",
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
"prettier": "^3.0.0",
"solhint": "^3.6.2"
},
Expand Down
1 change: 0 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
@prb/test/=node_modules/@prb/test/
forge-std/=node_modules/forge-std/
9 changes: 4 additions & 5 deletions test/Foo.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;

import { PRBTest } from "@prb/test/src/PRBTest.sol";
import { Test } from "forge-std/src/Test.sol";
import { console2 } from "forge-std/src/console2.sol";
import { StdCheats } from "forge-std/src/StdCheats.sol";

import { Foo } from "../src/Foo.sol";

Expand All @@ -13,7 +12,7 @@ interface IERC20 {

/// @dev If this is your first time with Forge, read this tutorial in the Foundry Book:
/// https://book.getfoundry.sh/forge/writing-tests
contract FooTest is PRBTest, StdCheats {
contract FooTest is Test {
Foo internal foo;

/// @dev A function invoked before each test case is run.
Expand All @@ -23,7 +22,7 @@ contract FooTest is PRBTest, StdCheats {
}

/// @dev Basic test. Run it with `forge test -vvv` to see the console log.
function test_Example() external {
function test_Example() external view {
console2.log("Hello World");
uint256 x = 42;
assertEq(foo.id(x), x, "value mismatch");
Expand All @@ -32,7 +31,7 @@ contract FooTest is PRBTest, StdCheats {
/// @dev Fuzz test that provides random values for an unsigned integer, but which rejects zero as an input.
/// If you need more sophisticated input validation, you should use the `bound` utility instead.
/// See https://twitter.com/PaulRBerg/status/1622558791685242880
function testFuzz_Example(uint256 x) external {
function testFuzz_Example(uint256 x) external view {
vm.assume(x != 0); // or x = bound(x, 1, 100)
assertEq(foo.id(x), x, "value mismatch");
}
Expand Down

0 comments on commit 77f8e8d

Please sign in to comment.