Paul Berg
Spearbit seminar: Sep 28, 2023
function test_Foo() external {
uint256 x = 42;
assertEq(contract.foo(x), x, "value mismatch");
}
function test_Foo_1() external {
// --- snip ---
}
function test_Foo_2() external {
// --- snip ---
}
function test_Foo_3(uint256 arg0) external {
// --- snip ---
}
function test_Foo_4(uint256 arg0, uint256 arg1) external {
// --- snip ---
}
Technique | Barrier to entry | Effectiveness |
---|---|---|
Braching Tree Technique | Entry-level | Moderately effective |
Cucumber Gherkin | Medium-level | Moderately effective |
Certora, K Framework, TLA+ | Senior-level | Highly effective |
whenBranch.tree
WhenBranchTest
├── when x is false
│ └── it should revert
└── when x is true
└── it should return x
simpleWhen.t.sol
contract SimpleWhenTest {
function test_RevertWhen_XIsFalse() external {
// it should revert
}
function test_WhenXIsTrue() external {
// it should return x
}
}
simpleWhen.t.sol
contract SimpleWhenTest {
function test_RevertWhen_XIsFalse() external {
vm.expectRevert("x must not be false");
foo.simpleWhen({ x: false });
}
function test_WhenXIsTrue() external {
bool result = foo.simpleWhen({ x: true });
assertTrue(result);
}
}
Scenario | Answer |
---|---|
Is it a contract state that is prepared in advance? | Given |
Is it a mode of execution, e.g. call vs delegatecall? | When |
Is it a function parameter that the user is in control when calling the function? | When |