Skip to content

Commit

Permalink
Improvements (#4)
Browse files Browse the repository at this point in the history
* Improvements

- added .coveragerc, fixed abstract class coverage,
- added mypy,
- fixed typechecking errors,
- added docstrings,
- added missing validation,
- dropped custom String type,
- cleaned up serializer.py,
- bumped base58 to 2.0.0,
- added tests for RPC client,
- fixed typehints in docs,
- added check for building docs
  • Loading branch information
ksiazkowicz committed Apr 2, 2020
1 parent 3aa11ea commit 4508d53
Show file tree
Hide file tree
Showing 19 changed files with 929 additions and 191 deletions.
10 changes: 10 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[run]
source = aioeos

[report]
exclude_lines =
pragma: no cover
if TYPE_CHECKING:

[xml]
output = coverage.xml
22 changes: 22 additions & 0 deletions .github/workflows/docscheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Build Docs"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
docs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: ammaraskar/sphinx-action@master
with:
pre-build-command: "pip install -r requirements.txt"
docs-folder: "docs/"
- uses: actions/upload-artifact@v1
with:
name: DocumentationHTML
path: docs/build/html/
6 changes: 4 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Lint with flake8
run: |
poetry run flake8
- name: Lint with mypy
run: |
poetry run mypy aioeos
- name: Test with pytest
run: |
poetry run pytest --cov --cov-report xml
Expand All @@ -39,5 +42,4 @@ jobs:
with:
file: ./coverage.xml # optional
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
name: codecov-umbrella # optional
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ __pycache__
venv
build
dist
.mypy_cache

# ides
.vscode
Expand Down
10 changes: 5 additions & 5 deletions aioeos/contracts/eosio_token.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Helpers for creating actions on eosio.token contract"""
from aioeos.types import EosAction
from aioeos import types


def transfer(
Expand All @@ -8,8 +8,8 @@ def transfer(
quantity: str,
memo: str = '',
authorization=[]
) -> EosAction:
return EosAction(
) -> types.EosAction:
return types.EosAction(
account='eosio.token',
name='transfer',
authorization=authorization,
Expand All @@ -22,8 +22,8 @@ def transfer(
)


def close(owner, symbol, authorization=[]) -> EosAction:
return EosAction(
def close(owner, symbol, authorization=[]) -> types.EosAction:
return types.EosAction(
account='eosio.token',
name='close',
authorization=authorization,
Expand Down
22 changes: 18 additions & 4 deletions aioeos/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ class EosMissingTaposFieldsException(EosRpcException):
"""TAPOS fields are missing from Transaction object"""


class EosSerializerUnsupportedTypeException(EosRpcException):
"""Our serializer doesn't support provided object type, shouldn't happen"""


class EosDeadlineException(EosRpcException):
"""Transaction timed out"""

Expand All @@ -43,3 +39,21 @@ class EosAssertMessageException(EosRpcException):
Generic assertion error from smart contract, can mean literally anything,
need to parse C++ traceback to figure out what went wrong.
"""


class EosSerializerException(Exception):
"""Base exception class for serializer errors"""


class EosSerializerUnsupportedTypeException(EosSerializerException):
"""Our serializer doesn't support provided object type"""


class EosSerializerAbiNameTooLongException(EosSerializerException):
def __init__(self):
super().__init__('Value is too long, expected up to 13 characters')


class EosSerializerAbiNameInvalidCharactersException(EosSerializerException):
def __init__(self):
super().__init__('Value contains invalid characters')
15 changes: 6 additions & 9 deletions aioeos/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ class EOSKey:
- Only public_key - EOSKey instance has no private key
"""

def __init__(self, private_key=None, public_key=None):
def __init__(self, *, private_key: str = None, public_key: str = None):
assert not (private_key and public_key), 'Pass only 1 key'
if private_key:
# Private Key can be either a SigningKey instance or string
if isinstance(private_key, ecdsa.SigningKey):
self._sk = private_key
else:
private_key = self._parse_key(private_key)
self._sk = ecdsa.SigningKey.from_string(
private_key, curve=ecdsa.SECP256k1
)
private_key = self._parse_key(private_key)
self._sk = ecdsa.SigningKey.from_string(
private_key, curve=ecdsa.SECP256k1
)
elif not public_key:
entropy = ecdsa.util.PRNG(secrets.randbits(512))
self._sk = ecdsa.SigningKey.generate(
Expand Down
4 changes: 2 additions & 2 deletions aioeos/rpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import base64
from aiohttp.client import ClientSession
from aiohttp import ClientSession
from aioeos import exceptions


Expand Down Expand Up @@ -32,7 +32,7 @@ async def post(self, endpoint, json={}):
raise ERROR_NAME_MAP.get(
error.get('name'),
exceptions.EosRpcException
)(data=error)
)(error)
return resp_dict

async def abi_json_to_bin(self, code, action, args):
Expand Down

0 comments on commit 4508d53

Please sign in to comment.