diff --git a/.circleci/config.yml b/.circleci/config.yml index f3c5f6a81..8d44c76ac 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ jobs: reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}' - run: name: Install pyspec requirements - command: make install_test && make install_lint + command: make install_test && make install_lint && make install_deposit_contract_test - save_cached_venv: venv_name: v1-pyspec-03 reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}' @@ -97,6 +97,19 @@ jobs: - run: name: Run linter command: make lint + deposit_contract: + docker: + - image: circleci/python:3.6 + working_directory: ~/specs-repo + steps: + - restore_cache: + key: v1-specs-repo-{{ .Branch }}-{{ .Revision }} + - restore_cached_venv: + venv_name: v1-pyspec-03 + reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}' + - run: + name: Run deposit contract test + command: make test_deposit_contract workflows: version: 2.1 test_spec: @@ -111,3 +124,6 @@ workflows: - lint: requires: - test + - deposit_contract: + requires: + - test diff --git a/Makefile b/Makefile index a6b379b71..ff1891a7c 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ TEST_LIBS_DIR = ./test_libs PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec YAML_TEST_DIR = ./eth2.0-spec-tests/tests GENERATOR_DIR = ./test_generators +DEPOSIT_CONTRACT_DIR = ./deposit_contract CONFIGS_DIR = ./configs # Collect a list of generator names @@ -46,6 +47,15 @@ lint: $(PY_SPEC_ALL_TARGETS) cd $(PY_SPEC_DIR); . venv/bin/activate; \ flake8 --max-line-length=120 ./eth2spec; +install_deposit_contract_test: + cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; \ + cd ../..; cd $(DEPOSIT_CONTRACT_DIR); \ + pip3 install -r requirements-testing.txt + +test_deposit_contract: + cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; \ + cd ../.. && cd $(DEPOSIT_CONTRACT_DIR) && python -m pytest . + # "make pyspec" to create the pyspec for all phases. pyspec: $(PY_SPEC_ALL_TARGETS) diff --git a/deposit_contract/requirements-testing.txt b/deposit_contract/requirements-testing.txt index 5900af8f0..c1f96a012 100644 --- a/deposit_contract/requirements-testing.txt +++ b/deposit_contract/requirements-testing.txt @@ -1,7 +1,6 @@ -pytest>=3.6,<3.7 -tox==3.0.0, -eth-tester[py-evm]==0.1.0b29, -vyper==0.1.0b9, -web3==4.8.3, -pytest==3.6.1, -../../test_libs/pyspec +tox==3.0.0 +eth-tester[py-evm]==0.1.0b29 +vyper==0.1.0b9 +web3==4.8.3 +pytest==3.6.1 +../test_libs/pyspec diff --git a/deposit_contract/tests/contracts/conftest.py b/deposit_contract/tests/contracts/conftest.py index 634ab26fa..69ece247d 100644 --- a/deposit_contract/tests/contracts/conftest.py +++ b/deposit_contract/tests/contracts/conftest.py @@ -5,10 +5,6 @@ import re import pytest -from deposit_contract.contracts.utils import ( - get_deposit_contract_code, - get_deposit_contract_json, -) import eth_tester from eth_tester import ( EthereumTester, @@ -21,6 +17,11 @@ from web3 import Web3 from web3.providers.eth_tester import ( EthereumTesterProvider, ) +from .utils import ( + get_deposit_contract_code, + get_deposit_contract_json, +) + # Constants MIN_DEPOSIT_AMOUNT = 1000000000 # Gwei diff --git a/deposit_contract/tests/contracts/test_compile.py b/deposit_contract/tests/contracts/test_compile.py index 72593fd5b..fc732a6db 100644 --- a/deposit_contract/tests/contracts/test_compile.py +++ b/deposit_contract/tests/contracts/test_compile.py @@ -1,11 +1,12 @@ -from deposit_contract.contracts.utils import ( - get_deposit_contract_code, - get_deposit_contract_json, -) from vyper import ( compiler, ) +from .utils import ( + get_deposit_contract_code, + get_deposit_contract_json, +) + def test_compile_deposit_contract(): compiled_deposit_contract_json = get_deposit_contract_json() diff --git a/deposit_contract/tests/contracts/test_deposit.py b/deposit_contract/tests/contracts/test_deposit.py index 600d74c85..92371421e 100644 --- a/deposit_contract/tests/contracts/test_deposit.py +++ b/deposit_contract/tests/contracts/test_deposit.py @@ -13,22 +13,13 @@ from tests.contracts.conftest import ( FULL_DEPOSIT_AMOUNT, MIN_DEPOSIT_AMOUNT, ) -from eth2spec.utils.minimal_ssz import +from eth2spec.utils.minimal_ssz import ( SSZType, hash_tree_root, ) - - -DepositData = SSZType({ - # BLS pubkey - 'pubkey': 'bytes48', - # Withdrawal credentials - 'withdrawal_credentials': 'bytes32', - # Amount in Gwei - 'amount': 'uint64', - # Container self-signature - 'signature': 'bytes96', -}) +from eth2spec.phase0.spec import ( + DepositData, +) def hash(data): diff --git a/deposit_contract/contracts/utils.py b/deposit_contract/tests/contracts/utils.py similarity index 64% rename from deposit_contract/contracts/utils.py rename to deposit_contract/tests/contracts/utils.py index 2aa42ecd3..de7c54489 100644 --- a/deposit_contract/contracts/utils.py +++ b/deposit_contract/tests/contracts/utils.py @@ -5,12 +5,12 @@ DIR = os.path.dirname(__file__) def get_deposit_contract_code(): - file_path = os.path.join(DIR, './validator_registration.v.py') + file_path = os.path.join(DIR, './../../contracts/validator_registration.v.py') deposit_contract_code = open(file_path).read() return deposit_contract_code def get_deposit_contract_json(): - file_path = os.path.join(DIR, './validator_registration.json') + file_path = os.path.join(DIR, './../../contracts/validator_registration.json') deposit_contract_json = open(file_path).read() return json.loads(deposit_contract_json) diff --git a/deposit_contract/tests/core/conftest.py b/deposit_contract/tests/core/conftest.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/deposit_contract/tests/core/test_import.py b/deposit_contract/tests/core/test_import.py deleted file mode 100644 index d25e6ed67..000000000 --- a/deposit_contract/tests/core/test_import.py +++ /dev/null @@ -1,4 +0,0 @@ - - -def test_import(): - import deposit_contract # noqa: F401