Skip to content

Instantly share code, notes, and snippets.

@janewang
Created October 31, 2025 04:21
Show Gist options
  • Select an option

  • Save janewang/b3e6c2edac0ed8676c06e038df636507 to your computer and use it in GitHub Desktop.

Select an option

Save janewang/b3e6c2edac0ed8676c06e038df636507 to your computer and use it in GitHub Desktop.
Forge
# Download foundry installer `foundryup`
> curl -L https://foundry.paradigm.xyz | bash
# Install forge, cast, anvil, chisel
> foundryup
> forge init counter
> cd counter
> forge build
[⠊] Compiling...
[⠒] Compiling 23 files with Solc 0.8.30
[⠘] Installing Solc version 0.8.30
[⠆] Successfully installed Solc 0.8.30
[⠔] Solc 0.8.30 finished in 18.69s
Compiler run successful!
> forge test
[⠊] Compiling...
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 28978, ~: 29289)
[PASS] test_Increment() (gas: 28783)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 8.07ms (4.87ms CPU time)
Ran 1 test suite in 134.50ms (8.07ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
> forge test -vv
[⠊] Compiling...
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 29211, ~: 29289)
[PASS] test_Increment() (gas: 28783)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 9.19ms (6.06ms CPU time)
Ran 1 test suite in 136.58ms (9.19ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
> forge test -vvvv
[⠊] Compiling...
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 28900, ~: 29289)
Traces:
[29289] CounterTest::testFuzz_SetNumber(1068876234 [1.068e9])
├─ [22492] Counter::setNumber(1068876234 [1.068e9])
│ └─ ← [Stop]
├─ [424] Counter::number() [staticcall]
│ └─ ← [Return] 1068876234 [1.068e9]
└─ ← [Stop]
[PASS] test_Increment() (gas: 28783)
Traces:
[28783] CounterTest::test_Increment()
├─ [22418] Counter::increment()
│ └─ ← [Stop]
├─ [424] Counter::number() [staticcall]
│ └─ ← [Return] 1
└─ ← [Stop]
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 4.23ms (4.02ms CPU time)
Ran 1 test suite in 133.90ms (4.23ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
// update the test to fail
> forge test -vvv
[⠊] Compiling...
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 29133, ~: 29289)
[FAIL: assertion failed: 1 != 2] test_Increment() (gas: 31867)
Traces:
[31867] CounterTest::test_Increment()
├─ [22418] Counter::increment()
│ └─ ← [Stop]
├─ [424] Counter::number() [staticcall]
│ └─ ← [Return] 1
├─ [0] VM::assertEq(1, 2) [staticcall]
│ └─ ← [Revert] assertion failed: 1 != 2
└─ ← [Revert] assertion failed: 1 != 2
Backtrace:
at VM.assertEq
at CounterTest.test_Increment
Suite result: FAILED. 1 passed; 1 failed; 0 skipped; finished in 4.69ms (3.69ms CPU time)
Ran 1 test suite in 133.04ms (4.69ms CPU time): 1 tests passed, 1 failed, 0 skipped (2 total tests)
Failing tests:
Encountered 1 failing test in test/Counter.t.sol:CounterTest
[FAIL: assertion failed: 1 != 2] test_Increment() (gas: 31867)
Encountered a total of 1 failing tests, 1 tests succeeded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment