From 223d7346f9f592c12b5f02bcf5b55d919dcb397e Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 23 Sep 2024 14:23:38 -0500 Subject: [PATCH 1/3] Move deposit contract rules to its own Makefile --- Makefile | 33 +-------------- solidity_deposit_contract/Makefile | 41 +++++++++++++++++++ .../web3_tester/requirements.txt | 6 +-- .../web3_tester/tests/conftest.py | 2 +- .../web3_tester/tests/test_deposit.py | 8 ++-- 5 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 solidity_deposit_contract/Makefile diff --git a/Makefile b/Makefile index c805b456b0..b1e8b2fd62 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,6 @@ ETH2SPEC_MODULE_DIR = $(PY_SPEC_DIR)/eth2spec TEST_REPORT_DIR = $(PY_SPEC_DIR)/test-reports TEST_VECTOR_DIR = ../consensus-spec-tests/tests GENERATOR_DIR = ./tests/generators -SOLIDITY_DEPOSIT_CONTRACT_DIR = ./solidity_deposit_contract -SOLIDITY_DEPOSIT_CONTRACT_SOURCE = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/deposit_contract.sol -SOLIDITY_FILE_NAME = deposit_contract.json -DEPOSIT_CONTRACT_TESTER_DIR = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/web3_tester CONFIGS_DIR = ./configs TEST_PRESET_TYPE ?= minimal # Collect a list of generator names @@ -50,15 +46,8 @@ GENERATOR_ERROR_LOG_FILE = $(CURRENT_DIR)/$(TEST_VECTOR_DIR)/testgen_error_log.t SCRIPTS_DIR = ${CURRENT_DIR}/scripts -export DAPP_SKIP_BUILD:=1 -export DAPP_SRC:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR) -export DAPP_LIB:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR)/lib -export DAPP_JSON:=build/combined.json - .PHONY: clean partial_clean all test citest lint generate_tests pyspec install_test open_cov \ - install_deposit_contract_tester test_deposit_contract install_deposit_contract_compiler \ - compile_deposit_contract test_compile_deposit_contract check_toc \ - detect_generator_incomplete detect_generator_error_log + check_toc detect_generator_incomplete detect_generator_error_log all: $(PY_SPEC_ALL_TARGETS) @@ -162,26 +151,6 @@ lint_generators: pyspec . venv/bin/activate; cd $(TEST_GENERATORS_DIR); \ flake8 --config $(LINTER_CONFIG_FILE) -compile_deposit_contract: - @cd $(SOLIDITY_DEPOSIT_CONTRACT_DIR) - @git submodule update --recursive --init - @solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout --overwrite -o build $(SOLIDITY_DEPOSIT_CONTRACT_SOURCE) $(SOLIDITY_DEPOSIT_CONTRACT_DIR)/tests/deposit_contract.t.sol - @/bin/echo -n '{"abi": ' > $(SOLIDITY_FILE_NAME) - @cat build/DepositContract.abi >> $(SOLIDITY_FILE_NAME) - @/bin/echo -n ', "bytecode": "0x' >> $(SOLIDITY_FILE_NAME) - @cat build/DepositContract.bin >> $(SOLIDITY_FILE_NAME) - @/bin/echo -n '"}' >> $(SOLIDITY_FILE_NAME) - -test_deposit_contract: - dapp test -v --fuzz-runs 5 - -install_deposit_contract_web3_tester: - cd $(DEPOSIT_CONTRACT_TESTER_DIR); python3 -m venv venv; . venv/bin/activate; python3 -m pip install -r requirements.txt - -test_deposit_contract_web3_tests: - cd $(DEPOSIT_CONTRACT_TESTER_DIR); . venv/bin/activate; \ - python3 -m pytest . - # Runs a generator, identified by param 1 define run_generator # Started! diff --git a/solidity_deposit_contract/Makefile b/solidity_deposit_contract/Makefile new file mode 100644 index 0000000000..164df20a99 --- /dev/null +++ b/solidity_deposit_contract/Makefile @@ -0,0 +1,41 @@ +SOLIDITY_FILE_NAME = deposit_contract.json +SOLIDITY_DEPOSIT_CONTRACT_SOURCE = deposit_contract.sol +DEPOSIT_CONTRACT_TESTER_DIR = web3_tester + +export DAPP_SKIP_BUILD:=1 +export DAPP_SRC:=$(CURDIR) +export DAPP_LIB:=$(CURDIR)/lib +export DAPP_JSON:=build/combined.json + +all: \ + compile_deposit_contract \ + install_deposit_contract_web3_tester \ + test_deposit_contract_web3_tests + +compile_deposit_contract: + @git submodule update --recursive --init + @solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi \ + --combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout \ + --overwrite -o build $(SOLIDITY_DEPOSIT_CONTRACT_SOURCE) tests/deposit_contract.t.sol + @/bin/echo -n '{"abi": ' > $(SOLIDITY_FILE_NAME) + @cat build/DepositContract.abi >> $(SOLIDITY_FILE_NAME) + @/bin/echo -n ', "bytecode": "0x' >> $(SOLIDITY_FILE_NAME) + @cat build/DepositContract.bin >> $(SOLIDITY_FILE_NAME) + @/bin/echo -n '"}' >> $(SOLIDITY_FILE_NAME) + +test_deposit_contract: + @dapp test -v --fuzz-runs 5 + +install_deposit_contract_web3_tester: + @cd $(DEPOSIT_CONTRACT_TESTER_DIR); \ + python3 -m venv venv; \ + source venv/bin/activate; \ + python3 -m pip install -r requirements.txt + +test_deposit_contract_web3_tests: + @cd $(DEPOSIT_CONTRACT_TESTER_DIR); \ + source venv/bin/activate; \ + python3 -m pytest . + +clean: + @git clean -fdx \ No newline at end of file diff --git a/solidity_deposit_contract/web3_tester/requirements.txt b/solidity_deposit_contract/web3_tester/requirements.txt index 8dadab0bc2..92c8298bfb 100644 --- a/solidity_deposit_contract/web3_tester/requirements.txt +++ b/solidity_deposit_contract/web3_tester/requirements.txt @@ -1,5 +1,5 @@ -eth-tester[py-evm]>=0.3.0b1,<0.4 -web3==5.4.0 -pytest==3.6.1 +eth-tester[py-evm]>=0.12.0b1 +web3>=6.11.0 +pytest>=4.4 # The eth2spec ../../ diff --git a/solidity_deposit_contract/web3_tester/tests/conftest.py b/solidity_deposit_contract/web3_tester/tests/conftest.py index 57b5f6b7a7..31686eabf3 100644 --- a/solidity_deposit_contract/web3_tester/tests/conftest.py +++ b/solidity_deposit_contract/web3_tester/tests/conftest.py @@ -51,7 +51,7 @@ def registration_contract(w3, tester): abi=contract_abi, bytecode=contract_bytecode) tx_hash = registration.constructor().transact() - tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash) + tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) registration_deployed = w3.eth.contract( address=tx_receipt.contractAddress, abi=contract_abi diff --git a/solidity_deposit_contract/web3_tester/tests/test_deposit.py b/solidity_deposit_contract/web3_tester/tests/test_deposit.py index 4b16446a16..e4b794ffbf 100644 --- a/solidity_deposit_contract/web3_tester/tests/test_deposit.py +++ b/solidity_deposit_contract/web3_tester/tests/test_deposit.py @@ -2,7 +2,7 @@ import pytest import eth_utils -from eth2spec.phase0.spec import DepositData +from eth2spec.phase0.mainnet import DepositData from eth2spec.utils.ssz.ssz_typing import List from eth2spec.utils.ssz.ssz_impl import hash_tree_root @@ -119,7 +119,7 @@ def test_deposit_inputs(registration_contract, def test_deposit_event_log(registration_contract, a0, w3): - log_filter = registration_contract.events.DepositEvent.createFilter( + log_filter = registration_contract.events.DepositEvent.create_filter( fromBlock='latest', ) deposit_amount_list = [randint(MIN_DEPOSIT_AMOUNT, FULL_DEPOSIT_AMOUNT * 2) for _ in range(3)] @@ -154,7 +154,7 @@ def test_deposit_event_log(registration_contract, a0, w3): def test_deposit_tree(registration_contract, w3, assert_tx_failed): - log_filter = registration_contract.events.DepositEvent.createFilter( + log_filter = registration_contract.events.DepositEvent.create_filter( fromBlock='latest', ) @@ -178,7 +178,7 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed): tx_hash = registration_contract.functions.deposit( *deposit_input, ).transact({"value": deposit_amount_list[i] * eth_utils.denoms.gwei}) - receipt = w3.eth.getTransactionReceipt(tx_hash) + receipt = w3.eth.get_transaction_receipt(tx_hash) print("deposit transaction consumes %d gas" % receipt['gasUsed']) logs = log_filter.get_new_entries() From 01793e5e4391c01717d0da8d58db3ed62d9987dc Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 23 Sep 2024 14:28:21 -0500 Subject: [PATCH 2/3] Update README and CI workflow --- .circleci/config.yml | 92 ----------------------------- solidity_deposit_contract/README.md | 6 +- 2 files changed, 3 insertions(+), 95 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7ac281dea9..17db49b3a9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,19 +44,6 @@ commands: venv_name: v25-pyspec reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }} venv_path: ./venv - restore_deposit_contract_tester_cached_venv: - description: "Restore the venv from cache for the deposit contract tester" - steps: - - restore_cached_venv: - venv_name: v23-deposit-contract-tester - reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }}-{{ checksum "solidity_deposit_contract/web3_tester/requirements.txt" }} - save_deposit_contract_tester_cached_venv: - description: "Save the venv to cache for later use of the deposit contract tester" - steps: - - save_cached_venv: - venv_name: v23-deposit-contract-tester - reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }}-{{ checksum "solidity_deposit_contract/web3_tester/requirements.txt" }} - venv_path: ./solidity_deposit_contract/web3_tester/venv jobs: checkout_specs: docker: @@ -226,71 +213,6 @@ jobs: - run: name: Run linter for test generators command: make lint_generators - build_deposit_contract: - docker: - - image: ethereum/solc:0.6.11-alpine - steps: - - checkout - - run: - name: Install build essentials - command: | - apk update - apk add git make - - run: - name: Compile the contract - command: | - make compile_deposit_contract - git diff --color --exit-code - - persist_to_workspace: - root: . - paths: - - ./solidity_deposit_contract/deposit_contract.json - - ./build/combined.json - - ./solidity_deposit_contract/lib - test_deposit_contract: - docker: - - image: nixorg/nix:circleci - steps: - - checkout - - restore_cache: - key: nix-store-test-v2 - - attach_workspace: - at: /tmp/ - - run: - name: Test the contract - command: | - mkdir build - cp -r /tmp/build/* build - cp -r /tmp/solidity_deposit_contract/lib/* ./solidity_deposit_contract/lib - cp -r /tmp/solidity_deposit_contract/deposit_contract.json ./solidity_deposit_contract/deposit_contract.json - nix-shell --command 'make test_deposit_contract' ./solidity_deposit_contract/shell.nix - - save_cache: - key: nix-store-test-v2 - paths: - - /nix - install_deposit_contract_web3_tester: - docker: - - image: cimg/python:3.12.4 - working_directory: ~/specs-repo - steps: - - restore_cache: - key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} - - restore_deposit_contract_tester_cached_venv - - run: - name: Install deposit contract tester requirements - command: make install_deposit_contract_web3_tester - - save_deposit_contract_tester_cached_venv - test_deposit_contract_web3_tests: - docker: - - image: cimg/python:3.12.4 - working_directory: ~/specs-repo - steps: - - restore_cache: - key: v3-specs-repo-{{ .Branch }}-{{ .Revision }} - - restore_deposit_contract_tester_cached_venv - - run: - name: Run deposit contract test with web3.py - command: make test_deposit_contract_web3_tests workflows: version: 2.1 test_spec: @@ -328,17 +250,3 @@ workflows: - lint: requires: - install_pyspec_test - # NOTE: Since phase 0 has been launched, we disabled the deposit contract tests. - # - install_deposit_contract_web3_tester: - # requires: - # - checkout_specs - # - test_deposit_contract_web3_tests: - # requires: - # - install_deposit_contract_web3_tester - build_and_test_deposit_contract: - jobs: - - build_deposit_contract - # NOTE: Since phase 0 has been launched, we disabled the deposit contract tests. - # - test_deposit_contract: - # requires: - # - build_deposit_contract diff --git a/solidity_deposit_contract/README.md b/solidity_deposit_contract/README.md index 0388d7d2f5..298ea92fef 100644 --- a/solidity_deposit_contract/README.md +++ b/solidity_deposit_contract/README.md @@ -13,7 +13,7 @@ In August 2020, version `r2` was released with metadata modifications and relice ## Compiling solidity deposit contract -In the `eth2.0-specs` directory run: +In this directory run: ```sh make compile_deposit_contract ``` @@ -31,8 +31,8 @@ solc --optimize --optimize-runs 5000000 --metadata-literal --bin deposit_contrac ## Running web3 tests -1. In the `eth2.0-specs` directory run `make install_deposit_contract_web3_tester` to install the tools needed (make sure to have Python 3.7 and pip installed). -2. In the `eth2.0-specs` directory run `make test_deposit_contract_web3_tests` to execute the tests. +1. In this directory run `make install_deposit_contract_web3_tester` to install the tools needed (make sure to have Python 3 and pip installed). +2. In this directory run `make test_deposit_contract_web3_tests` to execute the tests. ## Running randomized `dapp` tests: From 8a2277660f4bf0116129e89014ec66570b82a90b Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 14 Oct 2024 11:12:32 -0500 Subject: [PATCH 3/3] Also install preinstallation requirements --- solidity_deposit_contract/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solidity_deposit_contract/Makefile b/solidity_deposit_contract/Makefile index 164df20a99..a353d931bb 100644 --- a/solidity_deposit_contract/Makefile +++ b/solidity_deposit_contract/Makefile @@ -30,6 +30,7 @@ install_deposit_contract_web3_tester: @cd $(DEPOSIT_CONTRACT_TESTER_DIR); \ python3 -m venv venv; \ source venv/bin/activate; \ + python3 -m pip install -r ../../requirements_preinstallation.txt; \ python3 -m pip install -r requirements.txt test_deposit_contract_web3_tests: @@ -38,4 +39,4 @@ test_deposit_contract_web3_tests: python3 -m pytest . clean: - @git clean -fdx \ No newline at end of file + @git clean -fdx