forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeployCode.t.sol
More file actions
122 lines (95 loc) · 4.07 KB
/
DeployCode.t.sol
File metadata and controls
122 lines (95 loc) · 4.07 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.18;
import "ds-test/test.sol";
import "cheats/Vm.sol";
contract TestContract {}
contract TestContractWithArgs {
uint256 public a;
uint256 public b;
constructor(uint256 _a, uint256 _b) {
a = _a;
b = _b;
}
}
contract TestPayableContract {
uint256 public a;
constructor() payable {
a = msg.value;
}
}
contract TestPayableContractWithArgs {
uint256 public a;
uint256 public b;
uint256 public c;
constructor(uint256 _a, uint256 _b) payable {
a = _a;
b = _b;
c = msg.value;
}
}
contract DeployCodeTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);
address public constant overrideAddress = 0x0000000000000000000000000000000000000064;
event Payload(address sender, address target, bytes data);
function testDeployCode() public {
address addrDefault = address(new TestContract());
address addrDeployCode = vm.deployCode("cheats/DeployCode.t.sol:TestContract");
assertEq(addrDefault.code, addrDeployCode.code);
}
function testDeployCodeWithArgs() public {
address withNew = address(new TestContractWithArgs(1, 2));
TestContractWithArgs withDeployCode =
TestContractWithArgs(vm.deployCode("cheats/DeployCode.t.sol:TestContractWithArgs", abi.encode(3, 4)));
assertEq(withNew.code, address(withDeployCode).code);
assertEq(withDeployCode.a(), 3);
assertEq(withDeployCode.b(), 4);
}
function testDeployCodeWithPayableConstructorAndArgs() public {
address withNew = address(new TestPayableContractWithArgs(1, 2));
TestPayableContractWithArgs withDeployCode = TestPayableContractWithArgs(
vm.deployCode("cheats/DeployCode.t.sol:TestPayableContractWithArgs", abi.encode(3, 4), 101)
);
assertEq(withNew.code, address(withDeployCode).code);
assertEq(withDeployCode.a(), 3);
assertEq(withDeployCode.b(), 4);
assertEq(withDeployCode.c(), 101);
}
function testDeployCodeWithPayableConstructor() public {
address withNew = address(new TestPayableContract());
TestPayableContract withDeployCode =
TestPayableContract(vm.deployCode("cheats/DeployCode.t.sol:TestPayableContract", 111));
assertEq(withNew.code, address(withDeployCode).code);
assertEq(withDeployCode.a(), 111);
}
function testDeployCodeWithSalt() public {
address addrDefault = address(new TestContract());
address addrDeployCode = vm.deployCode("cheats/DeployCode.t.sol:TestContract", bytes32("salt"));
assertEq(addrDefault.code, addrDeployCode.code);
}
function testDeployCodeWithArgsAndSalt() public {
address withNew = address(new TestContractWithArgs(1, 2));
TestContractWithArgs withDeployCode = TestContractWithArgs(
vm.deployCode("cheats/DeployCode.t.sol:TestContractWithArgs", abi.encode(3, 4), bytes32("salt"))
);
assertEq(withNew.code, address(withDeployCode).code);
assertEq(withDeployCode.a(), 3);
assertEq(withDeployCode.b(), 4);
}
function testDeployCodeWithPayableConstructorAndSalt() public {
address withNew = address(new TestPayableContract());
TestPayableContract withDeployCode =
TestPayableContract(vm.deployCode("cheats/DeployCode.t.sol:TestPayableContract", 111, bytes32("salt")));
assertEq(withNew.code, address(withDeployCode).code);
assertEq(withDeployCode.a(), 111);
}
function testDeployCodeWithPayableConstructorAndArgsAndSalt() public {
address withNew = address(new TestPayableContractWithArgs(1, 2));
TestPayableContractWithArgs withDeployCode = TestPayableContractWithArgs(
vm.deployCode("cheats/DeployCode.t.sol:TestPayableContractWithArgs", abi.encode(3, 4), 101, bytes32("salt"))
);
assertEq(withNew.code, address(withDeployCode).code);
assertEq(withDeployCode.a(), 3);
assertEq(withDeployCode.b(), 4);
assertEq(withDeployCode.c(), 101);
}
}