Skip to content

Commit

Permalink
add code reverting case
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark committed Jul 25, 2023
1 parent 988de19 commit 85584ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/expected/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,14 @@
"num_paths": null,
"time": null,
"num_bounded_loops": null
},
{
"name": "check_RevertCode(address)",
"exitcode": 0,
"num_models": 0,
"num_paths": null,
"time": null,
"num_bounded_loops": null
}
],
"test/Send.t.sol:SendTest": [
Expand Down
22 changes: 22 additions & 0 deletions tests/test/Revert.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pragma solidity >=0.8.0 <0.9.0;

import "forge-std/Test.sol";

contract A { }

contract C {
uint256 public num;

Expand All @@ -21,6 +23,11 @@ contract C {
function deposit(bool paused) public payable {
if (paused) revert("paused");
}

function create() public {
A a = new A();
revert(string(abi.encode(a)));
}
}

contract CTest is Test {
Expand Down Expand Up @@ -60,4 +67,19 @@ contract CTest is Test {
assert(address(c).balance == 0);
}
}

function codesize(address x) internal view returns (uint256 size) {
assembly { size := extcodesize(x) }
}

function check_RevertCode(address x) public {
uint256 oldSize = codesize(x);
try c.create() {
} catch Error(string memory s) {
address a = abi.decode(bytes(s), (address));
uint256 size = codesize(a);
vm.assume(a == x);
assert(size == oldSize);
}
}
}

0 comments on commit 85584ae

Please sign in to comment.