kind: pipeline
type: docker
name: fuzz-nightly

when:
  event: cron

steps:
  - name: bootstrap-deps
    image: registry.niovi.voyage/harb/node-ci:latest
    commands:
      - |
        bash -c '
          set -euo pipefail
          git submodule update --init --recursive
          yarn --cwd onchain/lib/uni-v3-lib install --frozen-lockfile
        '

  - name: fuzz
    image: registry.niovi.voyage/harb/node-ci:latest
    commands:
      - |
        bash -c '
          set -euo pipefail
          if ! command -v bc >/dev/null 2>&1; then
            apt-get update
            apt-get install -y bc
          fi
          cd onchain
          export PATH=/root/.foundry/bin:$PATH
          forge --version
          ./analysis/run-fuzzing.sh BullMarketOptimizer runs=75
        '

  - name: package-results
    image: alpine:3.20
    when:
      status:
        - success
        - failure
    commands:
      - set -e
      - apk add --no-cache tar
      - mkdir -p artifacts
      - if [ -d onchain/analysis ]; then tar -czf artifacts/fuzz-results.tgz onchain/analysis; fi
