forked from Cookie-Jar-DAO/cookie-jar-v3
-
-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (143 loc) · 4.8 KB
/
contract-tests.yml
File metadata and controls
171 lines (143 loc) · 4.8 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Smart Contract Tests
on:
push:
paths:
- 'contracts/**'
- 'lib/**'
- '.github/workflows/contract-tests.yml'
pull_request:
paths:
- 'contracts/**'
- 'lib/**'
- '.github/workflows/contract-tests.yml'
workflow_dispatch:
jobs:
contract-tests:
name: Foundry Tests & Analysis
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
# Skip all bun/Node.js dependencies - contracts tests don't need them
- name: Create OZ v5 compatibility shims
run: ./scripts/oz-compat.sh
- name: Build contracts
run: |
echo "🔧 Building contracts..."
cd contracts
# Use dev profile (matches local package.json scripts)
export FOUNDRY_PROFILE=dev
# Build contracts with size reporting
forge build --sizes
if [ $? -ne 0 ]; then
echo "❌ Contract compilation failed"
exit 1
fi
echo "✅ Contracts compiled successfully"
echo ""
echo "📊 Contract sizes:"
forge build --sizes | tail -20 # Show size information
- name: Run contract tests
run: |
echo "🧪 Running Foundry test suite..."
cd contracts
# Use dev profile (matches local package.json scripts)
export FOUNDRY_PROFILE=dev
# Run tests with detailed output and gas reporting
forge test -vvv --gas-report
if [ $? -eq 0 ]; then
echo ""
echo "✅ All contract tests passed!"
else
echo ""
echo "❌ Some contract tests failed"
echo "💡 Check test output above for details"
exit 1
fi
- name: Generate and upload coverage report
run: |
echo "📊 Generating coverage report..."
cd contracts
# Use dev profile (matches local package.json scripts)
export FOUNDRY_PROFILE=dev
# Generate coverage in lcov format for better tooling support
forge coverage --report lcov
if [ -f lcov.info ]; then
echo "✅ Coverage report generated"
echo ""
echo "📈 Coverage summary:"
# Show basic coverage info if lcov tools are available
if command -v lcov &> /dev/null; then
lcov --summary lcov.info
else
echo "📄 Coverage data saved to lcov.info"
fi
else
echo "⚠️ Coverage report not generated"
fi
continue-on-error: true # Don't fail build if coverage fails
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: always()
with:
files: ./contracts/lcov.info
flags: contract-tests
name: contract-coverage
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
- name: Contract security analysis
run: |
echo "🔍 Running basic security analysis..."
cd contracts
export FOUNDRY_PROFILE=dev
echo "📋 Checking compilation warnings:"
forge build 2>&1 | tee build-warnings.log
if grep -E "(Warning|Error):" build-warnings.log; then
echo "⚠️ Found compilation warnings/errors"
else
echo "✅ No compilation warnings found"
fi
echo ""
echo "📋 Contract complexity analysis:"
find src -name "*.sol" -exec wc -l {} + | sort -n | tail -10
echo ""
echo "💡 For comprehensive security analysis, consider:"
echo " • Slither static analysis"
echo " • Mythril symbolic execution"
echo " • Manual audit for mainnet deployment"
continue-on-error: true
- name: Archive test artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: contract-test-artifacts
path: |
contracts/out/
contracts/lcov.info
contracts/cache/
contracts/build-warnings.log
retention-days: 7
- name: Test Summary
if: always()
run: |
echo ""
echo "🏗️ CONTRACT TESTS COMPLETED"
echo "==========================="
if [ "${{ job.status }}" = "success" ]; then
echo "✅ All contract tests passed!"
echo "📊 Coverage reports generated"
echo "🔧 Contracts compiled successfully"
echo "🎉 Smart contracts are ready for deployment"
else
echo "❌ Contract tests failed"
echo "💡 Check output above for details"
echo "🔧 Fix issues before deployment"
fi