Skip to content

Commit

Permalink
📚 add generic example
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Apr 4, 2024
1 parent bb01477 commit 2f62829
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/invariant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
example

```solidity
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.13;
import {Test} from "forge-std/Test.sol";
contract ExampleTypeHandler is Test {
function canResultInOverflow(bytes memory x) public pure {
// logic that can result in overflow given x
}
function canResultInUnderflow(bytes memory x) public pure {
// logic that can result in underflow given x
}
}
contract ExampleHandler is Test {
ExampleTypeHandler public exampleTypeHandler;
constructor(ExampleTypeHandler _exampleTypeHandler) {
exampleTypeHandler = _exampleTypeHandler;
}
function ghost_overflow(bytes memory x) public view {
exampleTypeHandler.canResultInOverflow(x);
}
function ghost_underflow(bytes memory x) public view {
exampleTypeHandler.canResultInUnderflow(x);
}
}
contract ExampleInvariantOverflow is Test {
ExampleHandler public exampleHandler;
constructor(ExampleHandler _exampleHandler) {
exampleHandler = _exampleHandler;
}
function invariant_overflow() public view {
bytes memory x;
exampleHandler.ghost_overflow(x);
}
}
contract ExampleInvariantUnderflow is Test {
ExampleHandler public exampleHandler;
constructor(ExampleHandler _exampleHandler) {
exampleHandler = _exampleHandler;
}
function invariant_underflow() public view {
bytes memory x;
exampleHandler.ghost_underflow(x);
}
}
```

0 comments on commit 2f62829

Please sign in to comment.