Merge pull request #905 from Yunusabdul38/feat/gas-optimization #1
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 Contracts CI/CD | |
| on: | |
| pull_request: | |
| paths: | |
| - "soroban/**" | |
| - "contracts/**" | |
| - ".github/workflows/contracts-ci.yml" | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| - master | |
| paths: | |
| - "soroban/**" | |
| - "contracts/**" | |
| - ".github/workflows/contracts-ci.yml" | |
| jobs: | |
| contracts-ci: | |
| name: Format, Build, Test, and Stellar Build Check | |
| runs-on: macos-latest | |
| defaults: | |
| run: | |
| working-directory: contracts/bounty_escrow | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Rust (with Soroban targets) | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: wasm32v1-none, wasm32-unknown-unknown | |
| - name: Install Stellar CLI | |
| run: | | |
| VERSION="22.5.0" | |
| ARCH="$(uname -m)" | |
| case "$ARCH" in | |
| arm64|aarch64) TARGET="aarch64-apple-darwin" ;; | |
| x86_64) TARGET="x86_64-apple-darwin" ;; | |
| *) echo "Unsupported macOS architecture: $ARCH" && exit 1 ;; | |
| esac | |
| URL="https://github.com/stellar/stellar-cli/releases/download/v${VERSION}/stellar-cli-${VERSION}-${TARGET}.tar.gz" | |
| curl -fL "$URL" -o stellar-cli.tar.gz | |
| tar -xzf stellar-cli.tar.gz | |
| mkdir -p "$HOME/.local/bin" | |
| mv stellar "$HOME/.local/bin/stellar" | |
| chmod +x "$HOME/.local/bin/stellar" | |
| echo "$HOME/.local/bin" >> "$GITHUB_PATH" | |
| "$HOME/.local/bin/stellar" --version | |
| - name: Cache Cargo dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| contracts/bounty_escrow/target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('contracts/bounty_escrow/**/Cargo.lock', 'contracts/bounty_escrow/contracts/escrow/src/**', 'contracts/grainlify-core/src/**') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Check code formatting | |
| run: | | |
| source $HOME/.cargo/env | |
| cd contracts/escrow | |
| cargo fmt --check --all | |
| - name: Build contracts | |
| run: | | |
| source $HOME/.cargo/env | |
| cd contracts/escrow | |
| cargo build --release --target wasm32v1-none | |
| - name: Run tests | |
| run: | | |
| source $HOME/.cargo/env | |
| cd contracts/escrow | |
| cargo check --verbose --lib | |
| - name: Run invariant checker tests | |
| run: | | |
| source $HOME/.cargo/env | |
| cd contracts/escrow | |
| cargo check --verbose --lib | |
| - name: Build Soroban contract | |
| run: | | |
| source $HOME/.cargo/env | |
| cd contracts/escrow | |
| stellar contract build --verbose | |
| - name: Stellar build check | |
| run: | | |
| source $HOME/.cargo/env | |
| # Cargo puts target/ at the workspace root (contracts/bounty_escrow), not in contracts/escrow | |
| wasm_file="target/wasm32v1-none/release/bounty_escrow.wasm" | |
| echo "Checking for generated WASM files..." | |
| if [ ! -f "$wasm_file" ]; then | |
| echo "Error: WASM file not found" | |
| echo "Expected: $wasm_file" | |
| echo "Available files in target directory:" | |
| find . -name "*.wasm" -type f 2>/dev/null || echo "No WASM files found" | |
| exit 1 | |
| fi | |
| echo "✓ Found WASM file" | |
| if [ ! -s "$wasm_file" ]; then | |
| echo "Error: WASM file is empty" | |
| exit 1 | |
| fi | |
| echo "Contract built successfully for Stellar/Soroban deployment" | |
| - name: Set up Stellar identity for tests | |
| run: | | |
| source $HOME/.cargo/env | |
| # Create the grainlify-deployer identity needed by script tests | |
| echo "Creating grainlify-deployer identity for tests..." | |
| stellar keys generate grainlify-deployer || echo "Identity already exists" | |
| stellar keys ls | grep grainlify-deployer || echo "Identity setup complete" | |
| - name: Run script tests | |
| run: | | |
| # From working-directory contracts/bounty_escrow, scripts live at ../scripts | |
| chmod +x ../scripts/test_deploy_failures.sh | |
| chmod +x ../scripts/test_upgrade_failures.sh | |
| chmod +x ../scripts/test_all_script_failures.sh | |
| echo "Running individual script tests..." | |
| ../scripts/test_deploy_failures.sh | |
| ../scripts/test_upgrade_failures.sh | |
| echo "Running comprehensive script failure test suite..." | |
| ../scripts/test_all_script_failures.sh | |
| sdk-smoke-tests: | |
| name: SDK Smoke Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: | | |
| cd contracts/sdk | |
| npm install | |
| - name: Run smoke tests | |
| run: | | |
| cd contracts/sdk | |
| npm run test:smoke |