diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 2420470c..03e3dca4 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -1,7 +1,7 @@ name: Bug Report description: File a bug report title: "[BUG] " -labels: [ "bug" ] +labels: ["bug"] body: - type: textarea id: what-happened @@ -62,5 +62,4 @@ body: label: Is there an existing issue for this? options: - label: I have searched the existing issues and verified no issue exits for this problem. - # Thanks to https://github.com/MarketingPipeline/Awesome-Repo-Template diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index af1d6d12..bfe241da 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -8,5 +8,4 @@ body: description: Describe the feature(s) you would like to be added. validations: required: true - # Thanks to https://github.com/MarketingPipeline/Awesome-Repo-Template diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 0e7cc096..636027eb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,18 +2,15 @@ Closes # - ## Introduced changes -<!-- A brief description of the changes --> - -- -- +<!-- A brief description of the changes --> +- +- ## - [ ] This PR contains breaking changes <!-- List of all breaking changes --> - diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index d6e69b17..d09f1dda 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,93 +1,59 @@ --- - name: Task - Build & Push Docker Image - - on: - workflow_dispatch: - workflow_call: - - env: - PYTHON_VERSION: 3.12.4 - DOCKER_REGISTRY: ghcr.io/${{ github.repository }} +name: Task - Build & Push Docker Image - jobs: - build_containers: - strategy: - matrix: - package: [pragma-sdk, price-pusher, vrf-listener, checkpointer, merkle-maker] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to GHCR - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} +on: + workflow_dispatch: + workflow_call: - - name: Extract package version - run: | - export PACKAGE_VERSION=$(grep 'version = "' ./${{ matrix.package }}/pyproject.toml | grep -m 1 -e '[0-9][0-9a-zA-Z]*[-.a-z0-9]*' -o) - echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV - echo $PACKAGE_VERSION +env: + PYTHON_VERSION: 3.12.4 + DOCKER_REGISTRY: ghcr.io/${{ github.repository }} - - name: Build and push pragma-sdk - if: matrix.package == 'pragma-sdk' - uses: docker/build-push-action@v6 - with: - context: . - file: ./${{ matrix.package }}/Dockerfile - push: true - build-args: | - PRAGMA_PACKAGE_VERSION=${{ env.PACKAGE_VERSION }} - target: production - tags: | - ${{ env.DOCKER_REGISTRY }}/${{ matrix.package }}:${{ env.PACKAGE_VERSION }} - ${{ env.DOCKER_REGISTRY}}/${{ matrix.package }}:latest +jobs: + build_containers: + strategy: + matrix: + package: + [pragma-sdk, price-pusher, vrf-listener, checkpointer, merkle-maker] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push other packages - if: matrix.package != 'pragma-sdk' - uses: docker/build-push-action@v6 - with: - context: . - file: ./${{ matrix.package }}/Dockerfile - push: true - tags: | - ${{ env.DOCKER_REGISTRY }}/${{ matrix.package }}:${{ env.PACKAGE_VERSION }} - ${{ env.DOCKER_REGISTRY}}/${{ matrix.package }}:latest - - bump_version: - needs: [build_containers] - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/master') - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - - name: Install Commitizen - run: pip install --upgrade Commitizen - - name: Configure Git - run: | - git config user.name github-actions - git config user.email github-actions@github.com - - name: Bump version - run: | - git fetch --tags - cz bump --retry || echo "probably nothing to do" - - name: Push changes - run: | - TAG=$(git tag --points-at HEAD) - if [[ $TAG ]]; then - echo "Version bumped to $TAG" - git push - git push --tags - else - echo "Version NOT bumped" - fi - - \ No newline at end of file + - name: Extract package version + run: | + export PACKAGE_VERSION=$(grep 'version = "' ./${{ matrix.package }}/pyproject.toml | grep -m 1 -e '[0-9][0-9a-zA-Z]*[-.a-z0-9]*' -o) + echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV + echo $PACKAGE_VERSION + + - name: Build and push pragma-sdk + if: matrix.package == 'pragma-sdk' + uses: docker/build-push-action@v6 + with: + context: . + file: ./${{ matrix.package }}/Dockerfile + push: true + build-args: | + PRAGMA_PACKAGE_VERSION=${{ env.PACKAGE_VERSION }} + target: production + tags: | + ${{ env.DOCKER_REGISTRY }}/${{ matrix.package }}:${{ env.PACKAGE_VERSION }} + ${{ env.DOCKER_REGISTRY}}/${{ matrix.package }}:latest + + - name: Build and push other packages + if: matrix.package != 'pragma-sdk' + uses: docker/build-push-action@v6 + with: + context: . + file: ./${{ matrix.package }}/Dockerfile + push: true + tags: | + ${{ env.DOCKER_REGISTRY }}/${{ matrix.package }}:${{ env.PACKAGE_VERSION }} + ${{ env.DOCKER_REGISTRY}}/${{ matrix.package }}:latest diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 54249d87..c7c03239 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -1,48 +1,56 @@ --- - name: Task - Lint, Format & Typecheck - - on: - workflow_dispatch: - workflow_call: - - env: - PYTHON_VERSION: 3.12.4 +name: Task - Lint, Format & Typecheck - jobs: - lint-format-typecheck: - continue-on-error: true - runs-on: ubuntu-latest - strategy: - matrix: - package: [pragma-utils, pragma-sdk, price-pusher, vrf-listener, checkpointer, merkle-maker] - fail-fast: false - steps: - - uses: actions/checkout@v3 - - uses: CfirTsabari/actions-pipx@v1 - - name: Install poetry - run: pipx install poetry - - name: Set up Python 3.12.4 - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - cache: "poetry" - - name: Install dependencies - run: | - cd ${{ matrix.package }} - poetry install - - name: Check poetry.lock - run: | - cd ${{ matrix.package }} - poetry lock --check - - name: Run lint - run: | - cd ${{ matrix.package }} - poetry run poe lint - - name: Run format - run: | - cd ${{ matrix.package }} - poetry run poe format_check - - name: Run typecheck - run: | - cd ${{ matrix.package }} - poetry run poe typecheck \ No newline at end of file +on: + workflow_dispatch: + workflow_call: + +env: + PYTHON_VERSION: 3.12.4 + +jobs: + lint-format-typecheck: + continue-on-error: true + runs-on: ubuntu-latest + strategy: + matrix: + package: + [ + pragma-utils, + pragma-sdk, + price-pusher, + vrf-listener, + checkpointer, + merkle-maker, + ] + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: CfirTsabari/actions-pipx@v1 + - name: Install poetry + run: pipx install poetry + - name: Set up Python 3.12.4 + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + - name: Install dependencies + run: | + cd ${{ matrix.package }} + poetry install + - name: Check poetry.lock + run: | + cd ${{ matrix.package }} + poetry lock --check + - name: Run lint + run: | + cd ${{ matrix.package }} + poetry run poe lint + - name: Run format + run: | + cd ${{ matrix.package }} + poetry run poe format_check + - name: Run typecheck + run: | + cd ${{ matrix.package }} + poetry run poe typecheck diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 3f4cd6ed..af13d144 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -1,33 +1,33 @@ --- - name: Task - Publish Package to Test PyPi - - on: - push: - branches: - - master +name: Task - Publish Package to Test PyPi - env: - PYTHON_VERSION: 3.12.4 - - defaults: - run: - working-directory: pragma-sdk +on: + push: + branches: + - master - jobs: - test_pypi_publish: - name: Upload package to Test PyPI - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: CfirTsabari/actions-pipx@v1 - - name: Install poetry - run: pipx install poetry - - uses: actions/setup-python@v5 - with: - python-version: ${{ env.PYTHON_VERSION }} - cache: "poetry" - - run: pipx inject poetry poetry-monorepo-dependency-plugin - - run: poetry config repositories.test-pypi https://test.pypi.org/legacy/ - - run: poetry config pypi-token.test-pypi ${{ secrets.TEST_PYPI_API_TOKEN }} - - run: poetry build -f sdist - - run: poetry publish -r test-pypi --skip-existing \ No newline at end of file +env: + PYTHON_VERSION: 3.12.4 + +defaults: + run: + working-directory: pragma-sdk + +jobs: + test_pypi_publish: + name: Upload package to Test PyPI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: CfirTsabari/actions-pipx@v1 + - name: Install poetry + run: pipx install poetry + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + - run: pipx inject poetry poetry-monorepo-dependency-plugin + - run: poetry config repositories.test-pypi https://test.pypi.org/legacy/ + - run: poetry config pypi-token.test-pypi ${{ secrets.TEST_PYPI_API_TOKEN }} + - run: poetry build -f sdist + - run: poetry publish -r test-pypi --skip-existing diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1374a4c0..74577706 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,30 +1,78 @@ --- - name: Task - Publish Package to Pypi - - on: - workflow_call: +name: Task - Publish Package to Pypi - defaults: - run: - working-directory: pragma-sdk +on: + workflow_call: - env: - PYTHON_VERSION: 3.12.4 +defaults: + run: + working-directory: pragma-sdk - jobs: - pypi_publish: - name: Upload package to PyPI - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: CfirTsabari/actions-pipx@v1 - - name: Install poetry - run: pipx install poetry - - uses: actions/setup-python@v5 - with: - python-version: ${{ env.PYTHON_VERSION }} - cache: "poetry" - - run: pipx inject poetry poetry-monorepo-dependency-plugin - - run: poetry config pypi-token.pypi "${{ secrets.PYPI_API_KEY }}" - - run: poetry build -f sdist - - run: poetry publish --skip-existing +env: + PYTHON_VERSION: 3.12.4 + +jobs: + bump_version: + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/master') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Install Commitizen + run: pip install --upgrade Commitizen + - name: Configure Git + run: | + git config user.name github-actions + git config user.email github-actions@github.com + - name: Bump version + run: | + git fetch --tags + cz bump --retry || echo "probably nothing to do" + - name: Push changes + run: | + TAG=$(git tag --points-at HEAD) + if [[ $TAG ]]; then + echo "Version bumped to $TAG" + git push + git push --tags + else + echo "Version NOT bumped" + fi + + pypi_publish: + needs: [bump_version] + name: Upload package to PyPI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: CfirTsabari/actions-pipx@v1 + - name: Install poetry + run: pipx install poetry + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + - run: pipx inject poetry poetry-monorepo-dependency-plugin + - run: poetry config pypi-token.pypi "${{ secrets.PYPI_API_KEY }}" + - run: poetry build -f sdist + - run: poetry publish --skip-existing + + update_lock: + needs: [pypi_publish] + name: Update lock file + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: CfirTsabari/actions-pipx@v1 + - name: Install poetry + run: pipx install poetry + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + - run: sh scripts/poetry_lock_update.sh diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f41ca8cd..11e17c64 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,23 +1,22 @@ --- - name: Workflow - Pull Request - - on: - workflow_dispatch: - pull_request: - branches: [master] - push: - branches: [master] - - concurrency: - group: - pr-checks-${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - - jobs: - linters: - name: Run linters - uses: ./.github/workflows/linters.yml - - tests: - name: Build & Integration Tests - uses: ./.github/workflows/tests.yml \ No newline at end of file +name: Workflow - Pull Request + +on: + workflow_dispatch: + pull_request: + branches: [master] + push: + branches: [master] + +concurrency: + group: pr-checks-${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + linters: + name: Run linters + uses: ./.github/workflows/linters.yml + + tests: + name: Build & Integration Tests + uses: ./.github/workflows/tests.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60f47acf..b6af8a20 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,16 +1,17 @@ --- - name: Workflow - Release - - on: - workflow_dispatch: - release: - types: [published] +name: Workflow - Release - jobs: - python_package_publish: - name: Publish python package - uses: ./.github/workflows/publish.yml - - docker_release_build: - name: Build docker release - uses: ./.github/workflows/docker-build.yml \ No newline at end of file +on: + workflow_dispatch: + release: + types: [published] + +jobs: + python_package_publish: + name: Publish python package + uses: ./.github/workflows/publish.yml + + docker_release_build: + needs: [python_package_publish] + name: Build docker release + uses: ./.github/workflows/docker-build.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index daf617c0..5611a477 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,97 +1,105 @@ --- - name: Task - Build & Integration Tests - - on: - workflow_dispatch: - workflow_call: - - env: - PYTHON_VERSION: 3.12.4 +name: Task - Build & Integration Tests - jobs: - tests: - continue-on-error: true - runs-on: ubuntu-latest - strategy: - matrix: - package: [pragma-utils, pragma-sdk, price-pusher, vrf-listener, checkpointer, merkle-maker] - fail-fast: false - steps: - - uses: actions/checkout@v3 - with: - submodules: "true" - - uses: CfirTsabari/actions-pipx@v1 - - name: Install poetry - run: pipx install poetry - - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} - cache: "poetry" - - name: Install dependencies - run: | - cd ${{ matrix.package }} - poetry install - - - name: Cache contracts - id: cache-contracts - uses: actions/cache@v3 - with: - path: ./pragma-oracle/target - key: ${{ runner.os }}-contracts-${{ hashFiles('./pragma-oracle/src', 'poetry.lock') }} - - - uses: software-mansion/setup-scarb@v1 - with: - tool-versions: pragma-oracle/.tool-versions - - - name: Compile contracts - if: steps.cache-contracts.outputs.cache-hit != 'true' - working-directory: ./pragma-oracle - run: | - scarb -V - scarb build - - - name: Check ABIs are up-to-date - run: | - # Find and compare *.sierra.json files in both directories - for file in $(find ./pragma-oracle/target/dev -type f -name "*.sierra.json"); do - # Extract the relative path of the file for comparison - rel_path=${file#./pragma-oracle/target/dev} - # Use diff to compare the file with its counterpart in the SDK directory - diff "$file" "pragma-sdk/pragma_sdk/onchain/abis$rel_path" || (echo "Error: $rel_path in pragma-oracle/target does not match with pragma-sdk/pragma_sdk/onchain/abis/" && exit 1) - done - - name: Install rust - run: | - curl https://sh.rustup.rs -sSf | sh -s -- -y - source $HOME/.cargo/env - - - name: Verify Rust and Cargo installation - run: | - rustc --version - cargo --version - - - uses: Swatinem/rust-cache@v2 - - name: Install starknet-devnet - run: cargo install starknet-devnet - - name: Run tests - run: | - # TODO: The tests loop forever if we don't run them one by one for some packages. - # See: https://github.com/astraly-labs/pragma-sdk/issues/153 - cd ${{ matrix.package }} - if [ "${{ matrix.package }}" = "pragma-sdk" ]; then - poetry run poe test_client - poetry run poe test_vrf - poetry run poe test_fetchers - poetry run poe test_merkle_feed - poetry run poe test_unit - poetry run poe test_update_client - else - poetry run poe test - fi - - name: Generate coverage in XML - run: | - cd ${{ matrix.package }} - poetry run coverage xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file +on: + workflow_dispatch: + workflow_call: + +env: + PYTHON_VERSION: 3.12.4 + +jobs: + tests: + continue-on-error: true + runs-on: ubuntu-latest + strategy: + matrix: + package: + [ + pragma-utils, + pragma-sdk, + price-pusher, + vrf-listener, + checkpointer, + merkle-maker, + ] + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + submodules: "true" + - uses: CfirTsabari/actions-pipx@v1 + - name: Install poetry + run: pipx install poetry + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + - name: Install dependencies + run: | + cd ${{ matrix.package }} + poetry install + + - name: Cache contracts + id: cache-contracts + uses: actions/cache@v3 + with: + path: ./pragma-oracle/target + key: ${{ runner.os }}-contracts-${{ hashFiles('./pragma-oracle/src', 'poetry.lock') }} + + - uses: software-mansion/setup-scarb@v1 + with: + tool-versions: pragma-oracle/.tool-versions + + - name: Compile contracts + if: steps.cache-contracts.outputs.cache-hit != 'true' + working-directory: ./pragma-oracle + run: | + scarb -V + scarb build + + - name: Check ABIs are up-to-date + run: | + # Find and compare *.sierra.json files in both directories + for file in $(find ./pragma-oracle/target/dev -type f -name "*.sierra.json"); do + # Extract the relative path of the file for comparison + rel_path=${file#./pragma-oracle/target/dev} + # Use diff to compare the file with its counterpart in the SDK directory + diff "$file" "pragma-sdk/pragma_sdk/onchain/abis$rel_path" || (echo "Error: $rel_path in pragma-oracle/target does not match with pragma-sdk/pragma_sdk/onchain/abis/" && exit 1) + done + - name: Install rust + run: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + source $HOME/.cargo/env + + - name: Verify Rust and Cargo installation + run: | + rustc --version + cargo --version + + - uses: Swatinem/rust-cache@v2 + - name: Install starknet-devnet + run: cargo install starknet-devnet + - name: Run tests + run: | + # TODO: The tests loop forever if we don't run them one by one for some packages. + # See: https://github.com/astraly-labs/pragma-sdk/issues/153 + cd ${{ matrix.package }} + if [ "${{ matrix.package }}" = "pragma-sdk" ]; then + poetry run poe test_client + poetry run poe test_vrf + poetry run poe test_fetchers + poetry run poe test_merkle_feed + poetry run poe test_unit + poetry run poe test_update_client + else + poetry run poe test + fi + - name: Generate coverage in XML + run: | + cd ${{ matrix.package }} + poetry run coverage xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/pragma-sdk/pragma_sdk/onchain/mixins/randomness.py b/pragma-sdk/pragma_sdk/onchain/mixins/randomness.py index d796be66..8b738b9e 100644 --- a/pragma-sdk/pragma_sdk/onchain/mixins/randomness.py +++ b/pragma-sdk/pragma_sdk/onchain/mixins/randomness.py @@ -389,7 +389,9 @@ async def handle_random( statuses = await asyncio.gather( *[ - self.get_request_status(event.caller_address, event.request_id, block_id="pending") + self.get_request_status( + event.caller_address, event.request_id, block_id="pending" + ) for event in events ] )