-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add expectCreate and expectCreate2 cheatcodes * add tests * apply clippy fixes * apply clippy fixes * fix failing test * fix failing test * fix failing test * fix failing test: use line wildcards * add requested changes * move nested creates to single test * Fix test --------- Co-authored-by: zerosnacks <[email protected]> Co-authored-by: grandizzy <[email protected]> Co-authored-by: grandizzy <[email protected]>
- Loading branch information
1 parent
3afcab4
commit f3130a5
Showing
8 changed files
with
296 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Note Used in forge-cli tests to assert failures. | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.18; | ||
|
||
import "./test.sol"; | ||
import "./Vm.sol"; | ||
|
||
contract Contract { | ||
function add(uint256 a, uint256 b) public pure returns (uint256) { | ||
return a + b; | ||
} | ||
} | ||
|
||
contract OtherContract { | ||
function sub(uint256 a, uint256 b) public pure returns (uint256) { | ||
return a - b; | ||
} | ||
} | ||
|
||
contract ExpectCreateFailureTest is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
bytes contractBytecode = | ||
vm.getDeployedCode("ExpectCreateFailures.t.sol:Contract"); | ||
|
||
function testShouldFailExpectCreate() public { | ||
vm.expectCreate(contractBytecode, address(this)); | ||
} | ||
|
||
function testShouldFailExpectCreate2() public { | ||
vm.expectCreate2(contractBytecode, address(this)); | ||
} | ||
|
||
function testShouldFailExpectCreateWrongBytecode() public { | ||
vm.expectCreate(contractBytecode, address(this)); | ||
new OtherContract(); | ||
} | ||
|
||
function testShouldFailExpectCreate2WrongBytecode() public { | ||
vm.expectCreate2(contractBytecode, address(this)); | ||
new OtherContract{salt: "foobar"}(); | ||
} | ||
|
||
function testShouldFailExpectCreateWrongDeployer() public { | ||
vm.expectCreate(contractBytecode, address(0)); | ||
new Contract(); | ||
} | ||
|
||
function testShouldFailExpectCreate2WrongDeployer() public { | ||
vm.expectCreate2(contractBytecode, address(0)); | ||
new Contract(); | ||
} | ||
|
||
function testShouldFailExpectCreateWrongScheme() public { | ||
vm.expectCreate(contractBytecode, address(this)); | ||
new Contract{salt: "foobar"}(); | ||
} | ||
|
||
function testShouldFailExpectCreate2WrongScheme() public { | ||
vm.expectCreate2(contractBytecode, address(this)); | ||
new Contract(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.