@@ -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)
6840forge 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
8246npm run test:all # Sets up chain, deploys contracts, runs all tests
@@ -86,60 +50,71 @@ npm run test:all:foundry # Also includes Foundry tests
8650npm run test:setup # Start Anvil and deploy contracts
8751npm run test:run # Run tests against deployed contracts
8852npm 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
11564forge script script/Deploy.s.sol:DeployScript --broadcast --rpc-url http://localhost:8545
11665
11766# Deploy to other networks
11867forge 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
136111Set 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
145120npm run dev
@@ -151,27 +126,7 @@ npm run build && npm start
151126npm 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
184139anvil
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/
0 commit comments