forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExpectCreate.t.sol
44 lines (36 loc) · 1.1 KB
/
ExpectCreate.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.18;
import "ds-test/test.sol";
import "cheats/Vm.sol";
contract Contract {
function add(uint256 a, uint256 b) public pure returns (uint256) {
return a + b;
}
}
contract ContractDeployer {
function deployContract() public {
new Contract();
}
function deployContractCreate2() public {
new Contract{salt: "foo"}();
}
}
contract ExpectCreateTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);
bytes bytecode = vm.getDeployedCode("cheats/ExpectCreate.t.sol:Contract");
function testExpectCreate() public {
vm.expectCreate(bytecode, address(this));
new Contract();
}
function testExpectCreate2() public {
vm.expectCreate2(bytecode, address(this));
new Contract{salt: "foo"}();
}
function testExpectNestedCreate() public {
ContractDeployer foo = new ContractDeployer();
vm.expectCreate(bytecode, address(foo));
vm.expectCreate2(bytecode, address(foo));
foo.deployContract();
foo.deployContractCreate2();
}
}