Skip to content

Commit

Permalink
refactor!: Modernize (#2)
Browse files Browse the repository at this point in the history
- renamed the primary branch from `master` to `main`
- code fully typed
- dependencies cleaned up
- Python 3.8 - 3.12 support
- code modernization, including Sourcery clean-up
- 99% tests coverage
- simplified testing (no more need for docker)
- move CI from Travis to GitHub

It implicitly fixes issues with `pysha3`, and any compilation errors at installation.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
  • Loading branch information
BoboTiG and sourcery-ai[bot] authored Jan 11, 2024
1 parent b05c1df commit 38fa187
Show file tree
Hide file tree
Showing 33 changed files with 1,513 additions and 1,116 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
# GitHub Actions
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily

# Python requirements
- package-ecosystem: pip
directory: /
schedule:
interval: daily
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
push:
tags:
- '*'
workflow_dispatch:

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pip
- name: Install build dependencies
run: |
python -m pip install -U pip
python -m pip install -e '.[dev]'
- name: Build
run: python -m build
- name: Check
run: twine check --strict dist/*
- name: What will we publish?
run: ls -l dist
- name: Publish
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
print_hash: true
67 changes: 67 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Tests

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
quality:
name: Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pip
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -e '.[tests]'
- name: Tests
run: ./checks.sh

tests:
name: "${{ matrix.os.emoji }} ${{ matrix.python.name }}"
runs-on: ${{ matrix.os.runs-on }}
strategy:
fail-fast: false
matrix:
os:
- emoji: 🐧
runs-on: [ubuntu-latest]
- emoji: 🍎
runs-on: [macos-latest]
- emoji: 🪟
runs-on: [windows-latest]
python:
- name: CPython 3.8
runs-on: "3.8"
- name: CPython 3.9
runs-on: "3.9"
- name: CPython 3.10
runs-on: "3.10"
- name: CPython 3.11
runs-on: "3.11"
# Following are disabled because of https://github.com/ethereum/eth-tester/issues/276
# - name: CPython 3.12
# runs-on: "3.12"
# Waaaay to soon for 3.13
# - name: CPython 3.13-dev
# runs-on: "3.13-dev"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.runs-on }}
cache: pip
check-latest: true
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -e '.[tests]'
- name: Tests
run: python -m pytest
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
.eggs/
*.egg-info/
dist/
build/
.pytest_cache/
# Files
.coverage

tests/contracts/build
# Folders
dist/
.mypy_cache/
__pycache__/
.pytest_cache/
.ruff_cache/
venv/
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

23 changes: 13 additions & 10 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# API

### `class EIP712Struct`
#### Important methods
## `class EIP712Struct`

### Primary Methods

- `.from_message(message_dict: dict)` **(class method)** - Given a standard EIP-712 message dictionary (such as produced from `.to_message`), returns a `NamedTuple` containing the `message` and `domain` `EIP712Struct`s.
- `.to_message(domain: EIP712Struct)` - Convert the struct (and given domain struct) into the standard EIP-712 message structure.
- `.signable_bytes(domain: EIP712Struct)` - Get the standard EIP-712 bytes hash, suitable for signing.
- `.from_message(message_dict: dict)` **(Class method)** - Given a standard EIP-712 message dictionary (such as produced from `.to_message`), returns a NamedTuple containing the `message` and `domain` EIP712Structs.

#### Other stuff
- `.encode_value()` - Returns a `bytes` object containing the ordered concatenation of each members bytes32 representation.
- `.encode_type()` **(Class method)** - Gets the "signature" of the struct class. Includes nested structs too!
- `.type_hash()` **(Class method)** - The keccak256 hash of the result of `.encode_type()`.
- `.hash_struct()` - Gets the keccak256 hash of the concatenation of `.type_hash()` and `.encode_value()`
### Secundary Methods

- `.data_dict()` - Returns a dictionary with all data in this struct. Includes nested struct data, if exists.
- `.encode_type()` **(class method)** - Gets the "signature" of the struct class. Includes nested structs too!
- `.encode_value()` - Returns a `bytes` object containing the ordered concatenation of each members `bytes32` representation.
- `.hash_struct()` - Gets the `keccak256` hash of the concatenation of `.type_hash()` and `.encode_value()`
- `.get_data_value(member_name: str)` - Get the value of the given struct member
- `.set_data_value(member_name: str, value: Any)` - Set the value of the given struct member
- `.data_dict()` - Returns a dictionary with all data in this struct. Includes nested struct data, if exists.
- `.get_members()` **(Class method)** - Returns a dictionary mapping each data member's name to it's type.
- `.get_members()` **(class method)** - Returns a dictionary mapping each data member's name to it's type.
- `.type_hash()` **(class method)** - The `keccak256` hash of the result of `.encode_type()`.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019 ConsenSys
Copyright (c) 2024 Mickaël Schoentgen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 38fa187

Please sign in to comment.