|
| 1 | +# Test Scripts |
| 2 | + |
| 3 | +This directory contains automated test scripts for the DStack KMS Ethereum backend. |
| 4 | + |
| 5 | +## Scripts Overview |
| 6 | + |
| 7 | +### 🚀 setup-local-chain.sh |
| 8 | +Sets up a local Anvil blockchain and deploys the DStack contracts. |
| 9 | +- Starts Anvil on port 8545 |
| 10 | +- Deploys DstackKms and DstackApp contracts |
| 11 | +- Saves configuration to `.env.test` |
| 12 | + |
| 13 | +```bash |
| 14 | +npm run test:setup |
| 15 | +# or |
| 16 | +./scripts/setup-local-chain.sh |
| 17 | +``` |
| 18 | + |
| 19 | +### 🧪 run-tests.sh |
| 20 | +Runs all tests against the deployed contracts on the local chain. |
| 21 | +- Requires local chain to be already set up |
| 22 | +- Runs Jest unit tests |
| 23 | +- Runs integration tests |
| 24 | +- Optionally runs Foundry tests |
| 25 | + |
| 26 | +```bash |
| 27 | +npm run test:run # Run JS/TS tests only |
| 28 | +npm run test:run:foundry # Include Foundry tests |
| 29 | +# or |
| 30 | +./scripts/run-tests.sh |
| 31 | +./scripts/run-tests.sh --with-foundry |
| 32 | +``` |
| 33 | + |
| 34 | +### 🎯 test-all.sh |
| 35 | +Complete test suite - sets up chain and runs all tests. |
| 36 | +- Combines setup-local-chain.sh and run-tests.sh |
| 37 | +- Perfect for CI/CD or fresh test runs |
| 38 | + |
| 39 | +```bash |
| 40 | +npm run test:all # Complete test suite |
| 41 | +npm run test:all:foundry # Include Foundry tests |
| 42 | +# or |
| 43 | +./scripts/test-all.sh |
| 44 | +./scripts/test-all.sh --with-foundry |
| 45 | +``` |
| 46 | + |
| 47 | +### 🧹 cleanup.sh |
| 48 | +Cleans up all test processes and temporary files. |
| 49 | +- Stops Anvil and API server |
| 50 | +- Removes temporary files and logs |
| 51 | + |
| 52 | +```bash |
| 53 | +npm run test:cleanup |
| 54 | +# or |
| 55 | +./scripts/cleanup.sh |
| 56 | +``` |
| 57 | + |
| 58 | +## Typical Workflows |
| 59 | + |
| 60 | +### One-time Setup, Multiple Test Runs |
| 61 | +```bash |
| 62 | +# Set up once |
| 63 | +npm run test:setup |
| 64 | + |
| 65 | +# Run tests multiple times |
| 66 | +npm run test:run |
| 67 | +npm run test:run |
| 68 | +npm run test:run |
| 69 | + |
| 70 | +# Clean up when done |
| 71 | +npm run test:cleanup |
| 72 | +``` |
| 73 | + |
| 74 | +### Complete Test Run |
| 75 | +```bash |
| 76 | +# Run everything in one go |
| 77 | +npm run test:all |
| 78 | + |
| 79 | +# Or with Foundry tests |
| 80 | +npm run test:all:foundry |
| 81 | +``` |
| 82 | + |
| 83 | +### Development Workflow |
| 84 | +```bash |
| 85 | +# Set up chain |
| 86 | +npm run test:setup |
| 87 | + |
| 88 | +# Keep chain running, develop and test |
| 89 | +npm run test:run |
| 90 | +# ... make changes ... |
| 91 | +npm run test:run |
| 92 | +# ... make more changes ... |
| 93 | +npm run test:run |
| 94 | + |
| 95 | +# Clean up when done |
| 96 | +npm run test:cleanup |
| 97 | +``` |
| 98 | + |
| 99 | +## Environment Variables |
| 100 | + |
| 101 | +After running `setup-local-chain.sh`, the following environment variables are saved to `.env.test`: |
| 102 | + |
| 103 | +- `ANVIL_PID` - Process ID of the Anvil instance |
| 104 | +- `ETH_RPC_URL` - RPC endpoint (http://127.0.0.1:8545) |
| 105 | +- `CHAIN_ID` - Chain ID (31337) |
| 106 | +- `KMS_CONTRACT_ADDR` - Deployed KMS proxy contract address |
| 107 | +- `APP_IMPLEMENTATION` - DstackApp implementation address |
| 108 | +- `KMS_IMPLEMENTATION` - DstackKms implementation address |
| 109 | +- `DEPLOYER_ADDRESS` - Address that deployed the contracts |
| 110 | +- `DEPLOYER_PRIVATE_KEY` - Private key of the deployer |
| 111 | + |
| 112 | +## Logs |
| 113 | + |
| 114 | +The scripts generate the following log files: |
| 115 | + |
| 116 | +- `anvil.log` - Anvil blockchain logs |
| 117 | +- `deploy.log` - Contract deployment logs |
| 118 | +- `server-test.log` - API server logs during tests |
| 119 | + |
| 120 | +## Requirements |
| 121 | + |
| 122 | +- Node.js and npm |
| 123 | +- Foundry (forge, anvil) |
| 124 | +- All npm dependencies installed (`npm install`) |
| 125 | + |
0 commit comments