Skip to content

Commit

Permalink
✅ test ghost_add() and ghostAddResult
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Apr 4, 2024
1 parent 7afe188 commit 984876f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
27 changes: 11 additions & 16 deletions test/invariant/Overflow.t.sol
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
pragma solidity >=0.8.19;

import {DSTest} from "forge-std/Test.sol";
import "forge-std/InvariantTest.sol";
import {Handler, BaseInt128Handler} from "./handlers/Handler.sol";
import {Test} from "forge-std/Test.sol";
import {Handler, BaseInt128Handler, BaseInt128} from "./handlers/Handler.sol";

contract OverflowInvariant is DSTest {
contract OverflowInvariant is Test {
BaseInt128Handler public baseInt128Handler;
Handler public handler;

function setUp() public {
baseInt128Handler = new BaseInt128Handler();
handler = new Handler({_baseInt128Handler: baseInt128Handler});

// bytes4[] memory selectors = new bytes4[](6);
// selectors[0] = Handler.deposit.selector;
// selectors[1] = Handler.withdraw.selector;
// selectors[2] = Handler.sendFallback.selector;
// selectors[3] = Handler.approve.selector;
// selectors[4] = Handler.transfer.selector;
// selectors[5] = Handler.transferFrom.selector;
// //selectors[6] = Handler.forcePush.selector;
bytes4[] memory selectors = new bytes4[](1);
selectors[0] = Handler.ghost_add.selector;
//selectors[n] = Handler.forcePush.selector;

// targetSelector(
// FuzzSelector({addr: address(handler), selectors: selectors})
// );
targetSelector(
FuzzSelector({addr: address(handler), selectors: selectors})
);

targetContract(address(handler));
}

function invariant_Int128_BaseInt128_Interactions() public {
assertEq(true, true);
BaseInt128 result = baseInt128Handler.ghostAddResult();
assertGe(result.unwrap(), 0);
}
}
13 changes: 6 additions & 7 deletions test/invariant/handlers/Handler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {
contract BaseInt128Handler is Test {
using InteractionsBaseInt128 for BaseInt128;

function add(BaseInt128 x, BaseInt128 y) public view returns (BaseInt128) {
return x + y;
BaseInt128 public ghostAddResult;

function add(BaseInt128 x) public view {
ghostAddResult + x;
}

function to256(BaseInt128 value) public view returns (BaseInt256) {
Expand Down Expand Up @@ -68,11 +70,8 @@ contract Handler is Test {
baseInt128Handler = _baseInt128Handler;
}

function add(uint256 actorSeed, int128 x, int128 y)
public
countCall("add")
{
baseInt128Handler.add(BaseInt128.wrap(x), BaseInt128.wrap(y));
function ghost_add(int128 x) public countCall("add") {
baseInt128Handler.add(BaseInt128.wrap(x));
}

function callSummary() external view {
Expand Down

0 comments on commit 984876f

Please sign in to comment.