From 223d7346f9f592c12b5f02bcf5b55d919dcb397e Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 23 Sep 2024 14:23:38 -0500 Subject: [PATCH] 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 c805b456b..b1e8b2fd6 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 000000000..164df20a9 --- /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 8dadab0bc..92c8298bf 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 57b5f6b7a..31686eabf 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 4b16446a1..e4b794ffb 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 @@ from random import randint 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()