Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone tests #81

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
35 changes: 29 additions & 6 deletions .github/workflows/onpush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,45 @@ jobs:
strategy:
matrix:
python-ver: ["3.9", "3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-22.04, macos-latest]

runs-on: ${{matrix.os }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Clone autonity.py
uses: actions/checkout@v4

# This step won't be needed after pytest-autonity is available from PyPI
- name: Clone pytest-autonity
uses: actions/checkout@v4
with:
submodules: recursive
repository: autonity/pytest-autonity
path: build/pytest-autonity
ref: v0.1.0
token: ${{ secrets.ACCESS_TOKEN }}

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-ver }}

- name: Install Hatch
run: pip install --upgrade hatch

- name: Get Autonity run ID
id: get_run_id
run: echo run_id=$(cat AUTONITY_RUN_ID) >> $GITHUB_OUTPUT

- name: Download Autonity build artifacts
uses: actions/download-artifact@v4
with:
path: build/autonity
repository: clearmatics/autonity
github-token: ${{ secrets.ACCESS_TOKEN }}
run-id: ${{ steps.get_run_id.outputs.run_id }}

- name: Lint
run: hatch run lint:check

- name: Test
run: hatch run +py=${{ env.PYTHON_VERSION }} test:all
env:
RPC_URL: ${{ secrets.RPC_URL }}
run: hatch run +py=${{ matrix.python-ver }} test:all
PYTEST_AUTONITY_URL: file:///home/runner/work/autonity.py/autonity.py/build/pytest-autonity
176 changes: 176 additions & 0 deletions .github/workflows/upstream-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
name: Upstream Trigger

on:
repository_dispatch:
types:
- new_autonity_push
- new_autonity_release

env:
PYTHON_VERSION: 3.13

jobs:
update-bindings:
runs-on: ubuntu-latest

permissions:
contents: write # For `git push`
pull-requests: write # For `gh pr create`

steps:
- name: Log triggering event
run: echo '${{ toJSON(github.event) }}'

- name: Clone autonity.py
uses: actions/checkout@v4
with:
ref: develop

- name: Clone autonity
uses: actions/checkout@v4
with:
repository: autonity/autonity
path: build/autonity
ref: ${{ github.event.client_payload.sha }}
fetch-depth: 0 # To be able to get the most recent tag for AUTONITY_VERSION

# This step won't be needed after pyabigen is available from PyPI
- name: Clone pyabigen
uses: actions/checkout@v4
with:
repository: clearmatics/pyabigen
path: build/pyabigen
ref: v0.2.13
token: ${{ secrets.ACCESS_TOKEN }}

# This step won't be needed after pytest-autonity is available from PyPI
- name: Clone pytest-autonity
uses: actions/checkout@v4
with:
repository: autonity/pytest-autonity
path: build/pytest-autonity
ref: v0.1.0
token: ${{ secrets.ACCESS_TOKEN }}

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Hatch
run: pip install --upgrade hatch

- name: Download Autonity build artifacts
uses: actions/download-artifact@v4
with:
path: build/autonity
repository: autonity/autonity
github-token: ${{ secrets.ACCESS_TOKEN }}
run-id: ${{ github.event.client_payload.run_id }}

- name: Set Autonity permissions
run: chmod +x build/autonity/build/bin/autonity

- name: Configure Git
run: |
git config user.name 'GitHub Actions Bot'
git config user.email '[email protected]'

- name: Get Autonity short commit hash
id: get_autonity_commit
run: echo sha=$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT
working-directory: build/autonity

- name: Get Autonity tag
id: get_autonity_tag
run: echo tag=$(git describe --tags) >> $GITHUB_OUTPUT
working-directory: build/autonity

- name: Update Autonity version & run ID
run: |
echo ${{ steps.get_autonity_tag.outputs.tag }} > AUTONITY_VERSION
echo ${{ github.event.client_payload.run_id }} > AUTONITY_RUN_ID

- name: Update bindings
run: make
env:
PYABIGEN_URL: file:///home/runner/work/autonity.py/autonity.py/build/pyabigen

- name: Lint code
run: hatch run lint:check

- name: Run tests
run: hatch run +py=${{ env.PYTHON_VERSION }} test:all
env:
PYTEST_AUTONITY_URL: file:///home/runner/work/autonity.py/autonity.py/build/pytest-autonity

- name: Commit changes to develop
if: github.event.action == 'new_autonity_push'
run: |
git add autonity/contracts/*.py AUTONITY_*
git commit \
-m 'Update for Autonity commit ${{ steps.get_autonity_commit.outputs.sha }}' \
-m 'Triggered by https://github.com/autonity/autonity/commit/${{ steps.get_autonity_commit.outputs.sha }}'
git push

- name: Get hash of latest commit on develop
id: get_latest_commit
run: echo sha=$(git rev-parse HEAD) >> $GITHUB_OUTPUT

- name: Commit changes to new branch & create pull request
if: github.event.action == 'new_autonity_release'
id: create_pull_request
run: |
git branch $BRANCH
git checkout $BRANCH
git add autonity/contracts/*.py AUTONITY_*
git commit \
-m 'Update for Autonity release ${{ steps.get_autonity_tag.outputs.tag }}' \
-m 'Triggered by https://github.com/autonity/autonity/releases/tag/${{ steps.get_autonity_tag.outputs.tag }}'
git push origin $BRANCH
gh pr create \
-B master \
-H $BRANCH \
--title 'Update bindings for Autonity ${{ steps.get_autonity_tag.outputs.tag }}' \
--body 'Merge changes from `develop` until commit ${{ steps.get_latest_commit.outputs.sha }} into `master`.'
echo link=$(gh pr view --json title,url --jq '"[\(.title)](\(.url))"') >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: autonity-${{ steps.get_autonity_tag.outputs.tag }}

- name: Trigger autonity-cli build
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.ACCESS_TOKEN }}
repository: autonity/autonity-cli
event-type: new_autonity_bindings
client-payload: >
{
"sha": "${{ steps.get_latest_commit.outputs.sha }}"
}

- name: Send Slack pull request notification
if: success() && github.event.action == 'new_autonity_release'
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: '#pydev-alerts'
SLACK_USERNAME: GitHub Actions Bot
SLACK_ICON_EMOJI: ':github:'
SLACK_MESSAGE: |
:github-merged: A new automated pull request has been opened.

${{ steps.create_pull_request.outputs.link }}

- name: Send Slack failure notification
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: '#pydev-alerts'
SLACK_USERNAME: GitHub Actions Bot
SLACK_ICON_EMOJI: ':github:'
SLACK_MESSAGE: |
:warning: Workflow run failed.

[Upstream commit](https://github.com/autonity/autonity/commit/${{ github.event.client_payload.sha }})
Empty file added AUTONITY_RUN_ID
Empty file.
32 changes: 24 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
VERSION := $(shell cat AUTONITY_VERSION)
AUTONITY := build/autonity
ABIDIR := $(AUTONITY)/params/generated
SRCDIR := $(AUTONITY)/autonity/solidity/contracts
AUTONITY_DIR := build/autonity
AUTONITY_BIN := $(AUTONITY_DIR)/build/bin/autonity
ABIDIR := $(AUTONITY_DIR)/params/generated
SRCDIR := $(AUTONITY_DIR)/autonity/solidity/contracts
OUTDIR := autonity/contracts
CI := ${CI}

abigen = hatch run generate:pyabigen \
--version $(VERSION) \
--src $(word 1,$(1)) \
--devdoc $(word 2,$(1)) \
--userdoc $(word 3,$(1)) \
$(word 4,$(1))

gentargets = $(shell find $(SRCDIR) -name $(1).sol) \
$(addprefix $(ABIDIR)/$(1),.docdev .docuser .abi) \
pyproject.toml
Expand Down Expand Up @@ -55,16 +58,29 @@ $(OUTDIR)/supply_control.py: $(call gentargets,SupplyControl)
$(OUTDIR)/upgrade_manager.py: $(call gentargets,UpgradeManager)
$(call abigen,$^) --exclude setOperator >$@

$(ABIDIR)/%.abi $(ABIDIR)/%.docdev $(ABIDIR)/%.docuser: $(AUTONITY) AUTONITY_VERSION
# -- The targets below are not available in GitHub workflows --
ifneq ($(CI),true)

$(ABIDIR)/%.abi $(ABIDIR)/%.docdev $(ABIDIR)/%.docuser: $(AUTONITY_DIR) AUTONITY_VERSION
cd $< && \
git fetch origin && \
git checkout $(VERSION) && \
git checkout -d $(VERSION) && \
make contracts

$(AUTONITY):
$(AUTONITY_BIN): $(AUTONITY_DIR) AUTONITY_VERSION
cd $< && \
git fetch origin && \
git checkout -d $(VERSION) && \
make autonity

$(AUTONITY_DIR):
git clone [email protected]:autonity/autonity.git $@

autonity: $(AUTONITY_BIN)

clean:
rm -rf $(AUTONITY)
rm -rf $(AUTONITY_DIR)

.PHONY = autonity clean

.PHONY = clean
endif
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ using [pipx](https://pipx.pypa.io/):
pipx install hatch
```

### Branches

The repository has the following permanent branches:

- `master`: Compatible with the upcoming Autonity release.
- `stable`: Compatible with the most recent Autonity release.
- `develop`: Compatible with the head of Autonity's `develop` branch.

### Installing Python interpreters (optional)

This project aims to be compatible with all the officially-supported versions of
Expand Down Expand Up @@ -105,6 +113,13 @@ Installed pypy3.10 @ /home/develop/.local/share/hatch/pythons/pypy3.10

### Building and testing

First clone [Autonity](https://github.com/autonity/autonity) and build the
Autonity Go Client binary with:

```sh
make autonity
```

To launch the tests across all supported Python versions, run:

```sh
Expand All @@ -127,12 +142,17 @@ hatch run lint:check

### Updating the contract bindings

Contract bindings are kept in sync with the Autonity protocol contracts via
GitHub Actions workflows. However bindings might need to be re-generated
manually in case contracts are being renamed or added or removed.

To update contract bindings for a new version of the Autonity protocol, add the
new [AGC](https://github.com/autonity/autonity) version (Git tag or commit ID)
to `AUTONITY_VERSION`, then generate the contract bindings with `make`:
new [AGC](https://github.com/autonity/autonity) Git tag (the output of
`git describe --tags`) to `AUTONITY_VERSION`, then generate the contract
bindings with `make`:

```console
echo v0.14.0 > AUTONITY_VERSION
echo v1.0.2-alpha > AUTONITY_VERSION
make
```

Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ path = "autonity/__version__.py"

[tool.hatch.envs.generate]
detached = true
dependencies = ["pyabigen@git+https://github.com/clearmatics/[email protected]"]
dependencies = ["pyabigen@git+{env:PYABIGEN_URL:==https://github.com/clearmatics/[email protected]}"]

[tool.hatch.envs.test]
dependencies = ["pytest"]
dependencies = [
"pytest",
"pytest-xdist[psutil]",
"pytest-autonity@git+{env:PYTEST_AUTONITY_URL:==https://github.com/autonity/pytest-autonity}"
]

[[tool.hatch.envs.test.matrix]]
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]

[tool.hatch.envs.test.scripts]
all = "pytest -v {args:tests}"
all = "pytest -v -n auto --autonity-bin build/autonity/build/bin/autonity {args:tests}"

[tool.hatch.envs.lint]
dependencies = ["black", "ruff", "mypy", "pyright"]
Expand Down
Loading
Loading