diff --git a/.gitignore b/.gitignore index 6a4dae1030..b15ec557cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,38 @@ .DS_Store __pycache__ +.AppleDouble +.LSOverride + +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +*.manifest +*.spec + +pip-log.txt +pip-delete-this-directory.txt + +.tox/ diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000000..581108ad6f --- /dev/null +++ b/mypy.ini @@ -0,0 +1,9 @@ +[mypy] +disallow_incomplete_defs = True +disallow_untyped_defs = True + +warn_unused_ignores = True +warn_unused_configs = True +warn_redundant_casts = True + +ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..9b0bc46621 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.isort] +profile = "black" +multi_line_output = 3 + +[tool.black] +line-length = 79 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000..954af6382b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,29 @@ +[metadata] +name = eth1spec +description = Ethereum specification, provided as a Python package for tooling + and testing +version = 0.1.0 +url = https://github.com/ethereum/eth2.0-specs + +[options] +packages = eth1spec +package_dir = + =src + +python_requires = >=3.7 +install_requires = + pysha3>=1,<2 + coincurve>=15,<16 + +[options.extras_require] +test = + pytest>=6.2,<7 + pytest-cov>=2.12,<3 + +lint = + isort>=5.8,<6 + mypy==0.812; implementation_name == "cpython" + black==21.5b2; implementation_name == "cpython" + flake8>=3.9,<4 + +# vim: set ft=dosini: diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000..938f7a0d3e --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +import pathlib + +import setuptools + +here = pathlib.Path(__file__).parent.resolve() + +long_description = (here / "README.md").read_text(encoding="utf-8") + +setuptools.setup( + long_description=long_description, + long_description_content_type="text/markdown", +) diff --git a/spec/requirements.txt b/spec/requirements.txt deleted file mode 100644 index 3c6cd0d3e0..0000000000 --- a/spec/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pysha3==1.0 -coincurve==15.0 diff --git a/spec/crypto.py b/src/eth1spec/crypto.py similarity index 100% rename from spec/crypto.py rename to src/eth1spec/crypto.py diff --git a/spec/eth_types.py b/src/eth1spec/eth_types.py similarity index 100% rename from spec/eth_types.py rename to src/eth1spec/eth_types.py diff --git a/spec/evm.py b/src/eth1spec/evm.py similarity index 100% rename from spec/evm.py rename to src/eth1spec/evm.py diff --git a/spec/main.py b/src/eth1spec/main.py similarity index 100% rename from spec/main.py rename to src/eth1spec/main.py diff --git a/spec/rlp.py b/src/eth1spec/rlp.py similarity index 100% rename from spec/rlp.py rename to src/eth1spec/rlp.py diff --git a/spec/spec.py b/src/eth1spec/spec.py similarity index 100% rename from spec/spec.py rename to src/eth1spec/spec.py diff --git a/spec/trie.py b/src/eth1spec/trie.py similarity index 100% rename from spec/trie.py rename to src/eth1spec/trie.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/fixtures b/tests/fixtures deleted file mode 160000 index 82f6a5a736..0000000000 --- a/tests/fixtures +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 82f6a5a7362e703a64dce303dd0c30f264b8195f diff --git a/spec/fixtures/genesis/alloc.json b/tests/fixtures/genesis/alloc.json similarity index 100% rename from spec/fixtures/genesis/alloc.json rename to tests/fixtures/genesis/alloc.json diff --git a/spec/fixtures/genesis/env.json b/tests/fixtures/genesis/env.json similarity index 100% rename from spec/fixtures/genesis/env.json rename to tests/fixtures/genesis/env.json diff --git a/spec/fixtures/genesis/txs.json b/tests/fixtures/genesis/txs.json similarity index 100% rename from spec/fixtures/genesis/txs.json rename to tests/fixtures/genesis/txs.json diff --git a/spec/fixtures/sample/alloc.json b/tests/fixtures/sample/alloc.json similarity index 100% rename from spec/fixtures/sample/alloc.json rename to tests/fixtures/sample/alloc.json diff --git a/spec/fixtures/sample/env.json b/tests/fixtures/sample/env.json similarity index 100% rename from spec/fixtures/sample/env.json rename to tests/fixtures/sample/env.json diff --git a/spec/fixtures/sample/txs.json b/tests/fixtures/sample/txs.json similarity index 100% rename from spec/fixtures/sample/txs.json rename to tests/fixtures/sample/txs.json diff --git a/tests/test_spec.py b/tests/test_spec.py new file mode 100644 index 0000000000..0f6816f185 --- /dev/null +++ b/tests/test_spec.py @@ -0,0 +1,18 @@ +from eth1spec.spec import Account, State, get_account + + +def test_get_account(): + account = Account( + nonce=0, + balance=1, + code_hash=b"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + ) + + state = State() + state[b"aaaaaaaaaaaaaaaaaaaa"] = account + + actual = get_account(state, b"aaaaaaaaaaaaaaaaaaaa") + + assert actual.nonce == 0 + assert actual.balance == 1 + assert actual.code_hash == b"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000000..50407f2d0c --- /dev/null +++ b/tox.ini @@ -0,0 +1,22 @@ +[tox] +envlist = py3,pypy3 + +[testenv] +extras = + test + lint +commands = + isort src tests setup.py --check --diff + black src tests setup.py --check --diff + pyflakes src tests setup.py + mypy src tests setup.py + pytest + +[testenv:pypy3] +extras = + test + lint +commands = + isort src tests setup.py --check --diff + pyflakes src tests setup.py + pytest