Skip to content

Commit 9374a1b

Browse files
h4x3rotabclaude
andcommitted
Clean up documentation and remove script overlaps
- Replace foundry-cast-cheatsheet.md with migration notice - Remove duplicate Interact.s.sol file - Remove duplicate ShowKmsInfo from Manage.s.sol - Streamline README.md, TESTING.md to focus on essentials - Update script/README.md to remove development notes - All Cast operations now covered by type-safe Foundry scripts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent db22f66 commit 9374a1b

File tree

8 files changed

+997
-760
lines changed

8 files changed

+997
-760
lines changed

kms/auth-eth/README.md

Lines changed: 40 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,12 @@ npm run build
3535

3636
## Testing
3737

38-
The project uses Foundry for testing with proper separation between core functionality and upgrade testing.
39-
40-
### Core Functionality Tests
41-
42-
Test the basic features of the contracts without upgrade-related functionality:
43-
44-
```bash
45-
# Test DstackApp core functionality (11 tests)
46-
forge test --ffi --match-path "test/DstackApp.t.sol"
47-
48-
# Test DstackKms core functionality (16 tests)
49-
forge test --ffi --match-path "test/DstackKms.t.sol"
50-
51-
# Run both core functionality test suites
52-
forge test --ffi --match-path "test/DstackApp.t.sol" && forge test --ffi --match-path "test/DstackKms.t.sol"
53-
```
54-
55-
### Upgrade Tests
56-
57-
Test upgrade functionality and contract migration scenarios using OpenZeppelin Foundry Upgrades plugin:
58-
59-
```bash
60-
# Test comprehensive upgrade scenarios with plugin
61-
forge test --ffi --match-path "test/UpgradesWithPlugin.t.sol"
62-
```
63-
6438
### Run All Tests
65-
6639
```bash
67-
# Run all tests (36 tests total)
6840
forge test --ffi
69-
70-
# Or run specific test suites
71-
forge test --ffi --match-path "test/DstackApp.t.sol" && \
72-
forge test --ffi --match-path "test/DstackKms.t.sol" && \
73-
forge test --ffi --match-path "test/UpgradesWithPlugin.t.sol"
7441
```
7542

7643
### Local Integration Testing
77-
78-
The project includes automated scripts for testing against a local Anvil blockchain:
79-
8044
```bash
8145
# Quick test workflow
8246
npm run test:all # Sets up chain, deploys contracts, runs all tests
@@ -86,60 +50,71 @@ npm run test:all:foundry # Also includes Foundry tests
8650
npm run test:setup # Start Anvil and deploy contracts
8751
npm run test:run # Run tests against deployed contracts
8852
npm run test:cleanup # Stop all test processes
89-
90-
# Available NPM scripts for testing
91-
npm test # Run Jest unit tests
92-
npm run test:foundry # Run Foundry tests with FFI
9353
```
9454

95-
### Test Coverage Summary
96-
97-
-**DstackApp.t.sol**: 11/11 tests PASS - Core app functionality
98-
-**DstackKms.t.sol**: 16/16 tests PASS - Core KMS functionality
99-
-**UpgradesWithPlugin.t.sol**: 9/9 tests PASS - Comprehensive upgrade scenarios
100-
10155
**Total: 36/36 tests PASSING (100% success rate)**
10256

103-
## Important Notes
104-
105-
- **FFI Flag Required**: Tests use the `--ffi` flag because they rely on the OpenZeppelin Foundry Upgrades plugin
106-
- **Clean Builds**: If you encounter OpenZeppelin validation errors, run `forge clean && forge build` before testing
107-
- **Test Organization**: Basic functionality tests use OpenZeppelin plugin for deployment (production-like) but don't test upgrading. All upgrade testing is isolated in dedicated test files.
57+
## Contract Management
10858

109-
## Contract Deployment
110-
111-
The contracts are designed to be deployed as UUPS proxies. The project includes deployment scripts:
59+
Use Foundry scripts for all contract operations instead of Cast commands:
11260

61+
### Deployment
11362
```bash
114-
# Deploy to local Anvil
63+
# Deploy both contracts
11564
forge script script/Deploy.s.sol:DeployScript --broadcast --rpc-url http://localhost:8545
11665

11766
# Deploy to other networks
11867
forge script script/Deploy.s.sol:DeployScript --broadcast --rpc-url <RPC_URL> --private-key <PRIVATE_KEY>
11968
```
12069

121-
Available deployment scripts:
122-
- `DeployScript` - Deploys both DstackKms and DstackApp
123-
- `DeployKmsOnly` - Deploys only DstackKms (requires APP_IMPLEMENTATION env var)
124-
- `DeployAppOnly` - Deploys only DstackApp implementation
70+
### Management Operations
71+
```bash
72+
# Add KMS aggregated MR
73+
KMS_CONTRACT_ADDR=0x... MR_AGGREGATED=0x1234... \
74+
forge script script/Manage.s.sol:AddKmsAggregatedMr --broadcast --rpc-url $RPC_URL
75+
76+
# Deploy new app via factory
77+
KMS_CONTRACT_ADDR=0x... APP_OWNER=0x... \
78+
forge script script/Manage.s.sol:DeployApp --broadcast --rpc-url $RPC_URL
79+
```
80+
81+
### Query Operations
82+
```bash
83+
# Get KMS settings
84+
KMS_CONTRACT_ADDR=0x... \
85+
forge script script/Query.s.sol:GetKmsSettings --rpc-url $RPC_URL
86+
87+
# Check if device is allowed
88+
APP_CONTRACT_ADDR=0x... DEVICE_ID=0x1234... \
89+
forge script script/Query.s.sol:CheckAppDevice --rpc-url $RPC_URL
90+
```
91+
92+
### Safe Upgrades
93+
```bash
94+
# Upgrade KMS to V2
95+
KMS_CONTRACT_ADDR=0x... \
96+
forge script script/Upgrade.s.sol:UpgradeKmsToV2 --broadcast --rpc-url $RPC_URL --ffi
97+
```
98+
99+
See `script/README.md` for complete documentation of all available scripts.
125100

126101
## BootAuth Server
127102

128-
The project includes a Fastify-based HTTP server that provides TEE boot validation services:
103+
The project includes a Fastify-based HTTP server for TEE boot validation:
129104

130-
### Server Endpoints:
105+
### Endpoints
131106
- **`GET /`** - Health check and contract information
132107
- **`POST /bootAuth/app`** - Validate application boot information
133108
- **`POST /bootAuth/kms`** - Validate KMS boot information
134109

135-
### Configuration:
110+
### Configuration
136111
Set these environment variables:
137112
- **`ETH_RPC_URL`** - Ethereum RPC endpoint (default: `http://localhost:8545`)
138113
- **`KMS_CONTRACT_ADDR`** - Deployed DstackKms contract address
139114
- **`PORT`** - Server port (default: `8000`)
140115
- **`HOST`** - Server host (default: `127.0.0.1`)
141116

142-
### Running the Server:
117+
### Running the Server
143118
```bash
144119
# Development mode
145120
npm run dev
@@ -151,27 +126,7 @@ npm run build && npm start
151126
npm test
152127
```
153128

154-
## Migration Status
155-
156-
This project has been successfully migrated from Hardhat to Foundry while maintaining:
157-
- Complete test coverage of core functionality
158-
- Proper separation between basic functionality and upgrade testing
159-
- Production-like deployment patterns using OpenZeppelin upgrades
160-
- All essential contract features and security properties
161-
162-
---
163-
164-
## Foundry Reference
165-
166-
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
167-
168-
Foundry consists of:
169-
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
170-
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
171-
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
172-
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
173-
174-
### Additional Foundry Commands
129+
## Additional Commands
175130

176131
```bash
177132
# Format code
@@ -182,14 +137,6 @@ forge snapshot
182137

183138
# Start local node
184139
anvil
185-
186-
# Deploy contracts
187-
forge script script/Deploy.s.sol --rpc-url <your_rpc_url> --private-key <your_private_key>
188-
189-
# Help
190-
forge --help
191-
anvil --help
192-
cast --help
193140
```
194141

195-
Documentation: https://book.getfoundry.sh/
142+
Documentation: https://book.getfoundry.sh/

kms/auth-eth/TESTING.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
# Testing Guide for DStack KMS Auth
1+
# Testing Guide
22

3-
Complete testing with **Foundry only** - no Hardhat dependencies.
4-
5-
## 🏗️ Smart Contract Testing
3+
## Smart Contract Testing
64

75
```bash
8-
npm run test:foundry:all # All smart contract tests (36 tests)
6+
# Run all tests (36 tests total)
7+
forge test --ffi
98
```
109

11-
Covers: Core logic, upgrades, authorization, gas optimization
12-
13-
## 🌐 API Server Testing
10+
## API Server Testing
1411

15-
### Unit Tests (Fast)
12+
### Unit Tests
1613
```bash
1714
npm test # Jest with mocked blockchain (4 tests)
1815
```
1916

20-
### Integration Tests (Real Blockchain)
17+
### Integration Tests
2118
```bash
22-
npm run test:full # Complete: Anvil + Deploy + API tests + Cleanup
19+
npm run test:all # Complete: Anvil + Deploy + API tests + Cleanup
2320
```
2421

2522
This automatically:
@@ -29,25 +26,23 @@ This automatically:
2926
4. Tests all endpoints
3027
5. Cleans up
3128

32-
## 🔧 Manual Testing
29+
## Manual Testing
3330

3431
### Start Services
3532
```bash
36-
npm run test:full:keep # Keep Anvil + API server running
33+
npm run test:setup # Start Anvil and deploy contracts
34+
npm run dev # Start API server in development mode
3735
```
3836

3937
### Test Endpoints
4038
```bash
4139
curl http://127.0.0.1:8000/ # Health check
4240
curl -X POST http://127.0.0.1:8000/bootAuth/app \
4341
-H "Content-Type: application/json" \
44-
-d '{"tcbStatus":"UpToDate","advisoryIds":[],"mrAggregated":"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef","osImageHash":"0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd","mrSystem":"0x9012901290129012901290129012901290129012901290129012901290129012","appId":"0x9012345678901234567890123456789012345678","composeHash":"0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","instanceId":"0x3456789012345678901234567890123456789012","deviceId":"0xef12ef12ef12ef12ef12ef12ef12ef12ef12ef12ef12ef12ef12ef12ef12ef12"}'
42+
-d '{"tcbStatus":"UpToDate","advisoryIds":[],"mrAggregated":"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef","osImageHash":"0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd"}'
4543
```
4644

47-
## 🚀 CI/CD Pipeline
48-
45+
### Cleanup
4946
```bash
50-
npm test # Fast unit tests
51-
npm run test:foundry:all # Complete contract tests
52-
npm run build # Build check
47+
npm run test:cleanup # Stop all test processes
5348
```

0 commit comments

Comments
 (0)