Last active
June 19, 2024 11:22
-
-
Save drgorillamd/1035272d6e1df8ef2ff39997e0814944 to your computer and use it in GitHub Desktop.
contract nonce if revert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.25; | |
import {Test} from 'forge-std/Test.sol'; | |
contract DeployRevert { | |
constructor() { | |
revert("DeployRevert"); | |
} | |
} | |
contract DeployNotRevert { | |
uint256 public constant foo = 123; | |
} | |
contract Deployer { | |
constructor() {} | |
function deployRevert() public { | |
new DeployNotRevert(); | |
new DeployNotRevert(); | |
try new DeployRevert() {} catch {} | |
} | |
function deployNotRevert() public { | |
new DeployNotRevert(); | |
new DeployNotRevert(); | |
new DeployNotRevert(); | |
} | |
} | |
contract ForTestOpUSDCBridgeAdapter is Test { | |
function test_deployRevertNonce() public { | |
// Pre condition | |
Deployer deployer = new Deployer(); | |
uint256 _nonceBefore = vm.getNonce(address(deployer)); | |
// Sanity check (we're all mad here) | |
deployer.deployNotRevert(); | |
assertEq(vm.getNonce(address(deployer)), _nonceBefore + 3, "Nonce should increase by 3"); | |
_nonceBefore = vm.getNonce(address(deployer)); | |
// Action | |
try deployer.deployRevert() {} catch {} // 2 deploys, 1 revert | |
// Post condition | |
assertEq(vm.getNonce(address(deployer)), _nonceBefore + 3, "Nonce should increase by 3"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment