-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (112 loc) · 4.74 KB
/
ci.yml
File metadata and controls
133 lines (112 loc) · 4.74 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.13
- name: Install dependencies
run: uv sync --all-extras
- name: Run linter
run: |
uv run ruff format --check .
uv run ruff check .
- name: Run type checker
run: uv run pyright
- name: Run automated tests
run: uv run pytest tests/ -v
- name: Start server
run: |
APP_PORT=8080 APP_BASE_URL=http://localhost:8080 uv run uvicorn main:app --host 0.0.0.0 --port 8080 &
sleep 3
- name: "Test 1: Health Check"
run: |
RESPONSE=$(curl -s http://localhost:8080/)
echo "$RESPONSE" | head -5
echo "$RESPONSE" | grep -q 'Payment Link Service'
- name: "Test 2: Create Payment Link"
run: |
TEST_RECEIVER="0x1234567890abcdef1234567890abcdef12345678"
RESPONSE=$(curl -s "http://localhost:8080/create-payment-link?amount=0.05&receiver=$TEST_RECEIVER")
echo "$RESPONSE"
PAYMENT_ID=$(echo "$RESPONSE" | jq -r '.payment_id')
echo "PAYMENT_ID=$PAYMENT_ID" >> $GITHUB_ENV
echo "$RESPONSE" | jq -e '.payment_id' > /dev/null
echo "$RESPONSE" | jq -e '.payment_url' > /dev/null
echo "$RESPONSE" | jq -e '.amount' > /dev/null
echo "$RESPONSE" | jq -e '.receiver' > /dev/null
- name: "Test 2b: Verify Database Record"
run: |
uv run python -c "
import sqlite3
conn = sqlite3.connect('payments.db')
conn.row_factory = sqlite3.Row
cur = conn.cursor()
cur.execute('SELECT payment_id, amount, receiver, status, tx_hash FROM payments WHERE payment_id=?', ('${{ env.PAYMENT_ID }}',))
row = cur.fetchone()
assert row is not None, 'Record not found in database'
assert row['amount'] == 0.05, f'Amount mismatch: {row[\"amount\"]}'
assert row['receiver'] == '0x1234567890abcdef1234567890abcdef12345678', f'Receiver mismatch: {row[\"receiver\"]}'
assert row['status'] == 'pending', f'Status mismatch: {row[\"status\"]}'
assert row['tx_hash'] is None, f'tx_hash should be None: {row[\"tx_hash\"]}'
print('Database record verified successfully')
print(f' payment_id: {row[\"payment_id\"]}')
print(f' amount: {row[\"amount\"]}')
print(f' receiver: {row[\"receiver\"]}')
print(f' status: {row[\"status\"]}')
print(f' tx_hash: {row[\"tx_hash\"]}')
conn.close()
"
- name: "Test 3: Invalid Amount"
run: |
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8080/create-payment-link?amount=-5")
echo "HTTP Status: $HTTP_CODE"
[ "$HTTP_CODE" -eq 422 ]
- name: "Test 4: Missing Amount"
run: |
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8080/create-payment-link")
echo "HTTP Status: $HTTP_CODE"
[ "$HTTP_CODE" -eq 422 ]
- name: "Test 5: Check Payment Status (Pending)"
run: |
RESPONSE=$(curl -s "http://localhost:8080/status/${{ env.PAYMENT_ID }}")
echo "$RESPONSE"
echo "$RESPONSE" | jq -e '.paid == false' > /dev/null
echo "$RESPONSE" | jq -e '.tx == null' > /dev/null
- name: "Test 6: Status Not Found"
run: |
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8080/status/nonexistent-id")
echo "HTTP Status: $HTTP_CODE"
[ "$HTTP_CODE" -eq 404 ]
- name: "Test 7: Payment Endpoint (No Header) - Returns 402"
run: |
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8080/pay/${{ env.PAYMENT_ID }}")
echo "HTTP Status: $HTTP_CODE"
[ "$HTTP_CODE" -eq 402 ]
- name: "Test 8: Payment Not Found"
run: |
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8080/pay/nonexistent-id")
echo "HTTP Status: $HTTP_CODE"
[ "$HTTP_CODE" -eq 404 ]
- name: "Test 9: Browser Request Returns HTML"
run: |
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Accept: text/html" \
-H "User-Agent: Mozilla/5.0" \
"http://localhost:8080/pay/${{ env.PAYMENT_ID }}")
echo "HTTP Status: $HTTP_CODE"
[ "$HTTP_CODE" -eq 400 ]
- name: Stop server
if: always()
run: pkill -f "uvicorn main:app" || true