Skip to content

Commit

Permalink
test: add balance reverting case
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark committed Jul 24, 2023
1 parent ed0b130 commit ca84082
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tests/expected/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,14 @@
"num_paths": null,
"time": null,
"num_bounded_loops": null
},
{
"name": "check_RevertBalance(bool,uint256)",
"exitcode": 0,
"num_models": 0,
"num_paths": null,
"time": null,
"num_bounded_loops": null
}
],
"test/Send.t.sol:SendTest": [
Expand Down Expand Up @@ -1081,4 +1089,4 @@
}
]
}
}
}
25 changes: 24 additions & 1 deletion tests/test/Revert.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity >=0.8.0 <0.9.0;

// from https://github.com/a16z/halmos/issues/109

import "forge-std/Test.sol";

contract C {
uint256 public num;

Expand All @@ -15,9 +17,13 @@ contract C {
revert("blah");
num = x;
}

function deposit(bool paused) public payable {
if (paused) revert("paused");
}
}

contract CTest {
contract CTest is Test {
C c;

function setUp() public {
Expand All @@ -37,4 +43,21 @@ contract CTest {
assert(!result);
assert(c.num() != x);
}

function check_RevertBalance(bool paused, uint256 amount) public {
vm.deal(address(this), amount);
vm.deal(address(c), 0);

(bool result,) = address(c).call{value: amount}(abi.encodeWithSignature("deposit(bool)", paused));

if (result) {
assert(!paused);
assert(address(this).balance == 0);
assert(address(c).balance == amount);
} else {
assert(paused);
assert(address(this).balance == amount);
assert(address(c).balance == 0);
}
}
}

0 comments on commit ca84082

Please sign in to comment.