Skip to content

Commit

Permalink
Add some tests for non-zero msg.value passed to proxy constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
k06a committed Jan 17, 2024
1 parent b7e9b82 commit 05c7819
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ExampleCloneFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ contract ExampleCloneFactory {
uint256 param2,
uint64 param3,
uint8 param4
) external returns (ExampleClone clone) {
) external payable returns (ExampleClone clone) {
bytes memory data = abi.encodePacked(param1, param2, param3, param4);
clone = ExampleClone(address(implementation).clone(data));
clone = ExampleClone(address(implementation).clone(data, msg.value));
}

function createClone2(
address param1,
uint256 param2,
uint64 param3,
uint8 param4
) external returns (ExampleClone clone) {
) external payable returns (ExampleClone clone) {
bytes memory data = abi.encodePacked(param1, param2, param3, param4);
clone = ExampleClone(address(implementation).clone2(data));
clone = ExampleClone(address(implementation).clone2(data, msg.value));
}

function addressOfClone2(
Expand All @@ -49,9 +49,9 @@ contract ExampleCloneFactory {
uint64 param3,
uint8 param4,
bytes32 salt
) external returns (ExampleClone clone) {
) external payable returns (ExampleClone clone) {
bytes memory data = abi.encodePacked(param1, param2, param3, param4);
clone = ExampleClone(address(implementation).clone3(data, salt));
clone = ExampleClone(address(implementation).clone3(data, salt, msg.value));
}

function addressOfClone3(bytes32 salt) external view returns (address) {
Expand Down
57 changes: 57 additions & 0 deletions src/test/ExampleCloneFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ contract ExampleCloneFactoryTest is DSTest {
assertEq(clone.param4(), param4);
}

function testCorrectness_clone_value(
address param1,
uint256 param2,
uint64 param3,
uint8 param4
) public {
ExampleClone clone = factory.createClone{ value: 1 wei }(
param1,
param2,
param3,
param4
);
assertEq(clone.param1(), param1);
assertEq(clone.param2(), param2);
assertEq(clone.param3(), param3);
assertEq(clone.param4(), param4);
}

function testCorrectness_clone2(
address param1,
uint256 param2,
Expand All @@ -80,6 +98,24 @@ contract ExampleCloneFactoryTest is DSTest {
assertEq(clone.param4(), param4);
}

function testCorrectness_clone2_value(
address param1,
uint256 param2,
uint64 param3,
uint8 param4
) public {
ExampleClone clone = factory.createClone2{ value: 1 wei }(
param1,
param2,
param3,
param4
);
assertEq(clone.param1(), param1);
assertEq(clone.param2(), param2);
assertEq(clone.param3(), param3);
assertEq(clone.param4(), param4);
}

function testCorrectness_clone3(
address param1,
uint256 param2,
Expand All @@ -101,6 +137,27 @@ contract ExampleCloneFactoryTest is DSTest {
assertEq(address(clone), factory.addressOfClone3(salt));
}

function testCorrectness_clone3_value(
address param1,
uint256 param2,
uint64 param3,
uint8 param4,
bytes32 salt
) public {
ExampleClone clone = factory.createClone3{ value: 1 wei }(
param1,
param2,
param3,
param4,
salt
);
assertEq(clone.param1(), param1);
assertEq(clone.param2(), param2);
assertEq(clone.param3(), param3);
assertEq(clone.param4(), param4);
assertEq(address(clone), factory.addressOfClone3(salt));
}

function testCorrectness_addressOfClone2(
address param1,
uint256 param2,
Expand Down

0 comments on commit 05c7819

Please sign in to comment.