forked from RareSkills/huff-puzzles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create.t.sol
48 lines (40 loc) · 1.45 KB
/
Create.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
45
46
47
48
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import {HuffDeployer} from "foundry-huff/HuffDeployer.sol";
import {NonMatchingSelectorHelper} from "./test-utils/NonMatchingSelectorHelper.sol";
interface Create {
function makeContract() external returns (address);
}
contract CreateTest is Test, NonMatchingSelectorHelper {
Create public create;
function setUp() public {
create = Create(HuffDeployer.config().deploy("Create"));
}
function testCreate() external {
address newContract = create.makeContract();
assertEq(
newContract != address(0),
true,
"new contract cannot be address 0"
);
(bool success, bytes memory data) = newContract.call("");
require(success, "check return of new contract failed");
assertEq(
abi.decode(data, (bytes32)),
0x00000000000000000000000000000000000000000000000000000000000caffe,
"expected new contract call to return 0xcaffe"
);
}
/// @notice Test that a non-matching selector reverts
function testNonMatchingSelector(bytes32 callData) public {
bytes4[] memory func_selectors = new bytes4[](1);
func_selectors[0] = Create.makeContract.selector;
bool success = nonMatchingSelectorHelper(
func_selectors,
callData,
address(create)
);
assert(!success);
}
}