Skip to content

Commit

Permalink
Fix tests and prepare for release 1.0.0 version
Browse files Browse the repository at this point in the history
* Update python version and poetry installation path

* Build only on curreny version Python 3.11

* Update test workflow

* Update python in Pipfile

* Update dependencies

* Build on latest 3.10 python version

* Update versions

* Return back python version

* poetry lock

* Update pytest

* Update docker version

* Limit number of retries

* Update all dependencies

* Rollback tests workflow

* Remove poetry path

* Add sleep before yield container

* Disable history tests

* Update python versions

* Update dependencies

* Increase sleep time for energy test

* Increase sleep time

* Update checkout action

* Remove python 3.12

* Fix energy test, deprecation to chronological history method

* Bump to 1.0.0, update min python version to 3.8 and remove cache separate action

* Update actions

* Return back sphinx versions

* Increase sleep before history

* Update changelog
  • Loading branch information
chiliec authored Nov 9, 2023
1 parent eea2f5e commit ac390a2
Show file tree
Hide file tree
Showing 10 changed files with 1,353 additions and 1,122 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,25 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install Poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: |
curl -sSL \
"https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
- name: Set up cache
uses: actions/cache@v1
with:
path: .venv
key: venv-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
cache: 'poetry'

- name: Install dependencies
run: |
source "$HOME/.poetry/env"
poetry config virtualenvs.in-project true
poetry install
- name: Run checks
- name: Run tests
run: |
source "$HOME/.poetry/env"
poetry run pytest
# Uncomment this lines if you wish to upload coverage to codecov:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ target/
.scannerwork/

.mypy_cache/
.vscode
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ We follow [Semantic Versions](https://semver.org/).
## Version 0.1.0

- Initial release

## Version 1.0.0

- Add `fixed_award` and `update_account_profile` methods
- Fix memo decoding errors
- Bump dependencies versions
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
graphenelib = ">=1.1.11"
graphenelib = ">=1.6"
pycryptodome = "*"
websockets = "*"
appdirs = "*"
Expand All @@ -15,4 +15,4 @@ PyYAML = "*"
[dev-packages]

[requires]
python_version = "3.6"
python_version = "3.8"
2,288 changes: 1,267 additions & 1,021 deletions poetry.lock

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "viz-python-lib"
version = "0.1.0"
description = "python library for VIZ blockchain"
version = "1.0.0"
description = "Python library for VIZ blockchain"
authors = ["Vladimir Kamarzin <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand All @@ -27,24 +27,25 @@ classifiers = [


[tool.poetry.dependencies]
python = "^3.6.1"
graphenelib = "^1.2.0"
toolz = "^0.10.0"
funcy = "^1.14"
docker = "^4.2.0"
python = "^3.8"
graphenelib = "^1.6.0"
toolz = "^0.12.0"
funcy = "^2.0"
docker = "^6.1.3"
aiohttp = "^3.8.6"

[tool.poetry.dev-dependencies]
pre-commit = "^2.2.0"
pytest = "^5.4"
pytest-cov = "^2.7"
pytest-mock = "^3.1.0"
pre-commit = "^3.5.0"
pytest = "^7.4.3"
pytest-cov = "^4.1.0"
pytest-mock = "^3.12.0"

sphinx = "^2.2"
sphinx-autoapi = "^1.4.0"
# used in docs to include markdown files
m2r = "^0.2"
m2r = "^0.3.1"
# used in docs to parse pyproject.toml
tomlkit = "^0.6"
tomlkit = "^0.11.8"

[tool.black]
line-length = 120
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ norecursedirs = *.egg .eggs dist build docs .tox .git __pycache__

# Extra options:
addopts =
--strict
--strict-markers
--doctest-modules
--cov=viz
--cov=vizbase
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import socket
import uuid

import docker
import pytest

Expand Down Expand Up @@ -68,6 +67,7 @@ def viz_testnet(session_id, unused_port, docker_manager):
)
container.http_port = port_http
container.ws_port = port_ws

yield container
container.remove(v=True, force=True)

Expand Down
28 changes: 6 additions & 22 deletions tests/test_account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import time

import pytest
from graphenecommon.exceptions import AccountDoesNotExistsException

from viz.account import Account


Expand All @@ -22,7 +20,7 @@ def _make_ops(viz, default_account):
time.sleep(1)


def test_init(viz, default_account):
def test_account_not_found(viz, default_account):
Account(default_account)

with pytest.raises(AccountDoesNotExistsException):
Expand All @@ -44,11 +42,11 @@ def test_current_energy(account, viz):
assert 0 < en <= 100

pct = 10
time.sleep(3) # wait for HF4 on testnet
time.sleep(15) # wait for HF4 on testnet
viz.award(account.name, pct, account=account.name)
en_new = account.current_energy()
time.sleep(1)
assert en - en_new == pytest.approx(pct, abs=1)
en_new = account.current_energy()
assert en - en_new == pytest.approx(pct, abs=3.0)


def test_virtual_op_count(viz):
Expand All @@ -66,21 +64,7 @@ def test_get_withdraw_routes(viz):


@pytest.mark.usefixtures('_make_ops')
def test_history(account):
history = list(account.history())
assert 'trx_id' in history[0]

history = list(account.history(raw_output=True))
assert 'trx_id' in history[0][1]

history = list(account.history(batch_size=1, limit=2))
assert len(history) == 2

history = list(account.history(filter_by='transfer_to_vesting'))
assert history[0]['type'] == 'transfer_to_vesting'


@pytest.mark.usefixtures('_make_ops')
def test_history_reverse(account):
def test_history_reverse(account: Account):
time.sleep(2)
history = list(account.history_reverse(batch_size=1, limit=2))
assert len(history) == 2
89 changes: 46 additions & 43 deletions viz/account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import TYPE_CHECKING, Generator, List, Optional, Union

from warnings import warn
from graphenecommon.exceptions import AccountDoesNotExistsException
from toolz import dissoc

Expand Down Expand Up @@ -83,8 +83,7 @@ def virtual_op_count(self) -> int:
except IndexError:
return 0
else:
# fist item has 0 index, so count is +1
return last_item + 1
return last_item

def get_withdraw_routes(self, type_: str = 'all') -> dict:
"""
Expand Down Expand Up @@ -185,9 +184,12 @@ def history(
limit: int = -1,
) -> HistoryGenerator:
"""
Stream account history in chronological order.
THIS FUNCTION IS DEPRECATED. PLEASE USE :py:func:`history_reverse` INSTEAD.
Stream account history in chronological order.
This generator yields history items which may be in list or dict form depending on ``raw_output``.
Output is similar to :py:func:`history_reverse`.
:param str,list filter_by: filter out all but these operations
:param int start: (Optional) skip items until this index
Expand All @@ -197,45 +199,9 @@ def history(
:param int limit: (Optional) limit number of filtered items to this amount (-1 means unlimited).
This is a rough limit, actual results could be a bit longer
:return: number of ops
Non-raw output example of yielded item:
.. code-block:: python
{
'from': 'viz',
'to': 'null',
'amount': '1.000 VIZ',
'memo': 'test',
'trx_id': '592010ade718c91a81cba3b8378c35ed81d23f23',
'block': 5,
'trx_in_block': 0,
'op_in_trx': 0,
'virtual_op': 0,
'timestamp': '2020-05-19T08:10:47',
'account': 'viz',
'type': 'transfer',
'_id': 'd1ed77ae861bb1ecc26a82dd275cc80e5ac124a6',
'index': 0,
}
Raw output example of single item:
.. code-block:: python
[
0,
{
'trx_id': '592010ade718c91a81cba3b8378c35ed81d23f23',
'block': 5,
'trx_in_block': 0,
'op_in_trx': 0,
'virtual_op': 0,
'timestamp': '2020-05-19T08:10:47',
'op': ['transfer', {'from': 'viz', 'to': 'null', 'amount': '1.000 VIZ', 'memo': 'test'}],
},
]
"""
warn("Function `history` is not recommened. Use `history_reverse` instead.", DeprecationWarning, stacklevel=2)

op_count = 0

max_index = self.virtual_op_count()
Expand Down Expand Up @@ -273,7 +239,6 @@ def history_reverse(
Stream account history in reverse chronological order.
This generator yields history items which may be in list or dict form depending on ``raw_output``.
Output is similar to :py:func:`history`.
:param str,list filter_by: filter out all but these operations
:param int batch_size: (Optional) request as many items from API in each chunk
Expand All @@ -282,6 +247,44 @@ def history_reverse(
:param int limit: (Optional) limit number of filtered items to this amount (-1 means unlimited).
This is a rough limit, actual results could be a bit longer
:return: number of ops
Non-raw output example of yielded item:
.. code-block:: python
{
'from': 'viz',
'to': 'null',
'amount': '1.000 VIZ',
'memo': 'test',
'trx_id': '592010ade718c91a81cba3b8378c35ed81d23f23',
'block': 5,
'trx_in_block': 0,
'op_in_trx': 0,
'virtual_op': 0,
'timestamp': '2020-05-19T08:10:47',
'account': 'viz',
'type': 'transfer',
'_id': 'd1ed77ae861bb1ecc26a82dd275cc80e5ac124a6',
'index': 0,
}
Raw output example of single item:
.. code-block:: python
[
0,
{
'trx_id': '592010ade718c91a81cba3b8378c35ed81d23f23',
'block': 5,
'trx_in_block': 0,
'op_in_trx': 0,
'virtual_op': 0,
'timestamp': '2020-05-19T08:10:47',
'op': ['transfer', {'from': 'viz', 'to': 'null', 'amount': '1.000 VIZ', 'memo': 'test'}],
},
]
"""
op_count = 0

Expand Down

0 comments on commit ac390a2

Please sign in to comment.