From 85584ae6243ea7f9317b379c2bdff1503e4b064b Mon Sep 17 00:00:00 2001 From: Daejun Park Date: Mon, 24 Jul 2023 17:37:40 -0700 Subject: [PATCH] add code reverting case --- tests/expected/all.json | 8 ++++++++ tests/test/Revert.t.sol | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/expected/all.json b/tests/expected/all.json index eadb7430..02cd1f4c 100644 --- a/tests/expected/all.json +++ b/tests/expected/all.json @@ -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": [ diff --git a/tests/test/Revert.t.sol b/tests/test/Revert.t.sol index 7b40f317..f72f3e1a 100644 --- a/tests/test/Revert.t.sol +++ b/tests/test/Revert.t.sol @@ -5,6 +5,8 @@ pragma solidity >=0.8.0 <0.9.0; import "forge-std/Test.sol"; +contract A { } + contract C { uint256 public num; @@ -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 { @@ -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); + } + } }