-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathSumArray.t.sol
More file actions
39 lines (31 loc) · 1.21 KB
/
SumArray.t.sol
File metadata and controls
39 lines (31 loc) · 1.21 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
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import {HuffDeployer} from "foundry-huff/HuffDeployer.sol";
import {NonMatchingSelectorHelper} from "./test-utils/NonMatchingSelectorHelper.sol";
interface SumArray {
function sumArray(uint256[] calldata nums) external pure returns (uint256);
}
contract SumArrayTest is Test, NonMatchingSelectorHelper {
SumArray public sumArray;
function setUp() public {
sumArray = SumArray(HuffDeployer.config().deploy("SumArray"));
}
function testSumArray(uint256[] memory array) external {
uint256 expected;
for (uint256 i; i < array.length; ++i) {
unchecked {
expected += array[i];
}
}
uint256 sum = sumArray.sumArray(array);
assertEq(sum, expected, "Wrong sum of array");
}
/// @notice Test that a non-matching selector reverts
function testNonMatchingSelector(bytes32 callData) public {
bytes4[] memory func_selectors = new bytes4[](1);
func_selectors[0] = SumArray.sumArray.selector;
bool success = nonMatchingSelectorHelper(func_selectors, callData, address(sumArray));
assert(!success);
}
}