Skip to content

Commit 7670833

Browse files
committed
chore: added coverage fix, and sorting imports
1 parent 604187b commit 7670833

File tree

2 files changed

+108
-19
lines changed

2 files changed

+108
-19
lines changed

script/coverage.sh

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,106 @@ cd ..
77
folder_path="coverage"
88

99
if [ ! -d "$folder_path" ]; then
10-
# If not, create the folder
1110
mkdir -p "$folder_path"
1211
echo "Folder created at: $folder_path"
1312
else
1413
echo "Folder already exists at: $folder_path"
1514
fi
1615

16+
# Configuration: Define test files for different EVM versions
17+
declare -a SHANGHAI_TESTS=(
18+
# "test/helpers/LiquidStaking.t.sol"
19+
test/helpers/PooledStaking.t.sol
20+
# Add more shanghai tests here in the future
21+
# "test/helpers/AnotherShanghaiTest.t.sol"
22+
)
1723

24+
declare -a CANCUN_TESTS=(
25+
# Add cancun tests here when needed
26+
# "test/helpers/CancunTest.t.sol"
27+
)
1828

19-
# Generates lcov.info
20-
forge coverage --report lcov --skip scripts --report-file "$folder_path/lcov.info"
29+
# Function to build match patterns for forge coverage
30+
build_match_patterns() {
31+
local tests=("$@")
32+
local patterns=""
33+
34+
for test in "${tests[@]}"; do
35+
if [[ -n "$patterns" ]]; then
36+
patterns="$patterns --match-path *$(basename "$test")"
37+
else
38+
patterns="--match-path *$(basename "$test")"
39+
fi
40+
done
41+
42+
echo "$patterns"
43+
}
44+
45+
# Function to build no-match patterns for forge coverage
46+
build_no_match_patterns() {
47+
local tests=("$@")
48+
local patterns=""
49+
50+
for test in "${tests[@]}"; do
51+
if [[ -n "$patterns" ]]; then
52+
patterns="$patterns --no-match-path *$(basename "$test")"
53+
else
54+
patterns="--no-match-path *$(basename "$test")"
55+
fi
56+
done
57+
58+
echo "$patterns"
59+
}
60+
61+
echo "Running coverage with inline EVM version flags..."
62+
echo "-----------------------------------------------"
63+
64+
# Build list of all special EVM tests to exclude from default London run
65+
ALL_SPECIAL_EVM_TESTS=("${SHANGHAI_TESTS[@]}" "${CANCUN_TESTS[@]}")
66+
LONDON_NO_MATCH_PATTERNS=$(build_no_match_patterns "${ALL_SPECIAL_EVM_TESTS[@]}")
67+
68+
# Generate coverage for London EVM (default) - exclude special EVM tests
69+
if [[ -n "$LONDON_NO_MATCH_PATTERNS" ]]; then
70+
echo "Running coverage for London EVM..."
71+
echo "Excluding: ${ALL_SPECIAL_EVM_TESTS[*]}"
72+
forge coverage --evm-version london --report lcov --skip scripts $LONDON_NO_MATCH_PATTERNS --report-file "$folder_path/lcov-london.info"
73+
else
74+
echo "Running coverage for London EVM - no exclusions..."
75+
forge coverage --evm-version london --report lcov --skip scripts --report-file "$folder_path/lcov-london.info"
76+
fi
77+
78+
# Generate coverage for Shanghai EVM tests if any exist
79+
if [ ${#SHANGHAI_TESTS[@]} -gt 0 ]; then
80+
echo "Running coverage for Shanghai EVM..."
81+
echo "Including: ${SHANGHAI_TESTS[*]}"
82+
SHANGHAI_MATCH_PATTERNS=$(build_match_patterns "${SHANGHAI_TESTS[@]}")
83+
forge coverage --evm-version shanghai --report lcov --skip scripts $SHANGHAI_MATCH_PATTERNS --report-file "$folder_path/lcov-shanghai.info"
84+
fi
85+
86+
# Generate coverage for Cancun EVM tests if any exist
87+
if [ ${#CANCUN_TESTS[@]} -gt 0 ]; then
88+
echo "Running coverage for Cancun EVM..."
89+
echo "Including: ${CANCUN_TESTS[*]}"
90+
CANCUN_MATCH_PATTERNS=$(build_match_patterns "${CANCUN_TESTS[@]}")
91+
forge coverage --evm-version cancun --report lcov --skip scripts $CANCUN_MATCH_PATTERNS --report-file "$folder_path/lcov-cancun.info"
92+
fi
93+
94+
# Build the list of coverage files to merge
95+
COVERAGE_FILES=("$folder_path/lcov-london.info")
96+
if [ ${#SHANGHAI_TESTS[@]} -gt 0 ]; then
97+
COVERAGE_FILES+=("$folder_path/lcov-shanghai.info")
98+
fi
99+
if [ ${#CANCUN_TESTS[@]} -gt 0 ]; then
100+
COVERAGE_FILES+=("$folder_path/lcov-cancun.info")
101+
fi
102+
103+
# Merge the lcov files
104+
echo "Merging coverage reports..."
105+
echo "Files to merge: ${COVERAGE_FILES[*]}"
106+
lcov \
107+
--rc branch_coverage=1 \
108+
$(printf -- "--add-tracefile %s " "${COVERAGE_FILES[@]}") \
109+
--output-file "$folder_path/lcov.info"
21110

22111
# Filter out test, mock, and script files
23112
lcov \
@@ -39,4 +128,4 @@ then
39128
--output-directory "$folder_path" \
40129
"$folder_path/filtered-lcov.info"
41130
open "$folder_path/index.html"
42-
fi
131+
fi

test/helpers/PooledStaking.t.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
pragma solidity 0.8.23;
33

44
import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
5+
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
56

67
import { BaseTest } from "../utils/BaseTest.t.sol";
7-
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
88
import { EncoderLib } from "../../src/libraries/EncoderLib.sol";
99
import { Implementation, SignatureType } from "../utils/Types.t.sol";
1010
import { Execution, Delegation, Caveat, ModeCode } from "../../src/utils/Types.sol";
@@ -398,43 +398,43 @@ contract PooledStakingTest is BaseTest {
398398

399399
// Group 0: Deposit operations
400400
{
401-
Caveat[] memory depositCaveats = new Caveat[](2);
402-
depositCaveats[0] =
401+
Caveat[] memory depositCaveats_ = new Caveat[](2);
402+
depositCaveats_[0] =
403403
Caveat({ args: hex"", enforcer: address(allowedTargetsEnforcer), terms: abi.encodePacked(address(VAULT)) });
404-
depositCaveats[1] = Caveat({
404+
depositCaveats_[1] = Caveat({
405405
args: hex"",
406406
enforcer: address(exactCalldataEnforcer),
407407
terms: abi.encodeWithSelector(IVaultEthStaking.deposit.selector, _delegator, address(0))
408408
});
409-
groups[0] = LogicalOrWrapperEnforcer.CaveatGroup({ caveats: depositCaveats });
409+
groups[0] = LogicalOrWrapperEnforcer.CaveatGroup({ caveats: depositCaveats_ });
410410
}
411411

412412
// Group 1: Enter exit queue operations
413413
{
414-
Caveat[] memory exitQueueCaveats = new Caveat[](3);
415-
exitQueueCaveats[0] =
414+
Caveat[] memory exitQueueCaveats_ = new Caveat[](3);
415+
exitQueueCaveats_[0] =
416416
Caveat({ args: hex"", enforcer: address(allowedTargetsEnforcer), terms: abi.encodePacked(address(VAULT)) });
417-
exitQueueCaveats[1] = Caveat({ args: hex"", enforcer: address(valueLteEnforcer), terms: abi.encode(uint256(0)) });
418-
exitQueueCaveats[2] = Caveat({
417+
exitQueueCaveats_[1] = Caveat({ args: hex"", enforcer: address(valueLteEnforcer), terms: abi.encode(uint256(0)) });
418+
exitQueueCaveats_[2] = Caveat({
419419
args: hex"",
420420
enforcer: address(allowedMethodsEnforcer),
421421
terms: abi.encodePacked(IVaultEnterExit.enterExitQueue.selector)
422422
});
423-
groups[1] = LogicalOrWrapperEnforcer.CaveatGroup({ caveats: exitQueueCaveats });
423+
groups[1] = LogicalOrWrapperEnforcer.CaveatGroup({ caveats: exitQueueCaveats_ });
424424
}
425425

426426
// Group 2: Claim exited assets operations
427427
{
428-
Caveat[] memory claimCaveats = new Caveat[](3);
429-
claimCaveats[0] =
428+
Caveat[] memory claimCaveats_ = new Caveat[](3);
429+
claimCaveats_[0] =
430430
Caveat({ args: hex"", enforcer: address(allowedTargetsEnforcer), terms: abi.encodePacked(address(VAULT)) });
431-
claimCaveats[1] = Caveat({ args: hex"", enforcer: address(valueLteEnforcer), terms: abi.encode(uint256(0)) });
432-
claimCaveats[2] = Caveat({
431+
claimCaveats_[1] = Caveat({ args: hex"", enforcer: address(valueLteEnforcer), terms: abi.encode(uint256(0)) });
432+
claimCaveats_[2] = Caveat({
433433
args: hex"",
434434
enforcer: address(allowedMethodsEnforcer),
435435
terms: abi.encodePacked(IVaultEnterExit.claimExitedAssets.selector)
436436
});
437-
groups[2] = LogicalOrWrapperEnforcer.CaveatGroup({ caveats: claimCaveats });
437+
groups[2] = LogicalOrWrapperEnforcer.CaveatGroup({ caveats: claimCaveats_ });
438438
}
439439
}
440440
}

0 commit comments

Comments
 (0)