Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Created February 12, 2023 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulRBerg/9d9b2d6f88c265336b72357024af3d60 to your computer and use it in GitHub Desktop.
Save PaulRBerg/9d9b2d6f88c265336b72357024af3d60 to your computer and use it in GitHub Desktop.
Simple Solidity test tree
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.18;
import { PRBTest } from "@prb/test/PRBTest.sol";
contract Foo is PRBTest {
function test_RevertWhen_CallerNotOwner() external {
vm.expectRevert();
// ...
}
modifier callerOwner() {
_;
}
function test_RevertWhen_DepositZero() external callerOwner {
vm.expectRevert();
// ...
}
modifier depositNotZero() {
_;
}
function test_MyFunc() external callerOwner depositNotZero {
// ...
}
}
foo.t.sol
├── when the caller is not the owner
│ └── it should revert
└── when the caller is the owner
├── when the deposit is zero
│ └── it should revert
└── when the deposit is not zero
└── it should work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment