feat: Implement circuit-breaker for database write-load during mass u… #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Smart Contract Tests | |
| on: | |
| push: | |
| branches: [ "main", "develop", "feature/*" ] | |
| pull_request: | |
| branches: [ "main", "develop" ] | |
| jobs: | |
| smart-contract-tests: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| target: wasm32-unknown-unknown | |
| override: true | |
| - name: Cache Rust dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| contracts/target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Install Stellar CLI | |
| run: | | |
| if ! command -v stellar &> /dev/null; then | |
| sudo apt-get update && sudo apt-get install -y libdbus-1-dev pkg-config libudev-dev | |
| cargo install --locked stellar-cli | |
| fi | |
| echo "$HOME/.cargo/bin" >> $GITHUB_PATH | |
| # Ensure stellar is the name used if the script installs it as stellar | |
| sudo cp $HOME/.cargo/bin/stellar /usr/local/bin/soroban || true | |
| sudo cp $HOME/.cargo/bin/stellar /usr/local/bin/stellar || true | |
| - name: Build smart contracts | |
| run: | | |
| cd contracts | |
| cargo build --target wasm32-unknown-unknown --release | |
| - name: Run smart contract tests | |
| run: | | |
| cd contracts | |
| cargo test --workspace | |
| - name: Run reentrancy tests specifically | |
| run: | | |
| cd contracts/reentrancy-tests | |
| cargo test -- --nocapture | |
| - name: Verify contract examples | |
| run: | | |
| cd contracts | |
| for contract in vesting-vault malicious-contract reentrancy-tests; do | |
| echo "Testing $contract contract..." | |
| cd $contract | |
| cargo test | |
| cd .. | |
| done | |
| backend-tests: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_PASSWORD: password | |
| POSTGRES_USER: postgres | |
| POSTGRES_DB: vesting_vault_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: backend/package-lock.json | |
| - name: Install dependencies | |
| working-directory: ./backend | |
| run: npm ci | |
| - name: Create environment file | |
| working-directory: ./backend | |
| run: cp .env.example .env | |
| - name: Create data directory | |
| working-directory: ./backend | |
| run: mkdir -p data | |
| - name: Run backend tests | |
| working-directory: ./backend | |
| run: npm test | |
| - name: Generate coverage report | |
| working-directory: ./backend | |
| run: npm run test:coverage | |
| integration-tests: | |
| runs-on: ubuntu-latest | |
| needs: [smart-contract-tests, backend-tests] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: backend/package-lock.json | |
| - name: Install Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| target: wasm32-unknown-unknown | |
| override: true | |
| - name: Install Stellar CLI | |
| working-directory: ./backend | |
| run: | | |
| if ! command -v stellar &> /dev/null; then | |
| sudo apt-get update && sudo apt-get install -y libdbus-1-dev pkg-config libudev-dev | |
| cargo install --locked stellar-cli | |
| fi | |
| sudo cp $HOME/.cargo/bin/stellar /usr/local/bin/soroban || true | |
| sudo cp $HOME/.cargo/bin/stellar /usr/local/bin/stellar || true | |
| - name: Build contracts | |
| run: | | |
| cd contracts | |
| cargo build --target wasm32-unknown-unknown --release | |
| - name: Start backend server | |
| working-directory: ./backend | |
| run: | | |
| cp .env.example .env | |
| mkdir -p data | |
| export NODE_ENV=test | |
| export DB_HOST=localhost | |
| export DB_PORT=5432 | |
| export DB_NAME=vesting_vault_test | |
| export DB_USER=postgres | |
| export DB_PASSWORD=password | |
| npm start & | |
| sleep 15 | |
| - name: Run integration tests | |
| run: | | |
| echo "Testing backend API with smart contracts..." | |
| curl -f http://localhost:4000/ || exit 1 | |
| curl -f http://localhost:4000/api/audit/verify || exit 1 | |
| - name: Test reentrancy protection | |
| run: | | |
| cd contracts/reentrancy-tests | |
| cargo test test_comprehensive_reentrancy_protection -- --nocapture |