Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move deposit contract rules to its own Makefile #3940

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
33 changes: 1 addition & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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!
Expand Down
42 changes: 42 additions & 0 deletions solidity_deposit_contract/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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_preinstallation.txt; \
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
6 changes: 3 additions & 3 deletions solidity_deposit_contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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:

Expand Down
6 changes: 3 additions & 3 deletions solidity_deposit_contract/web3_tester/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
../../
2 changes: 1 addition & 1 deletion solidity_deposit_contract/web3_tester/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions solidity_deposit_contract/web3_tester/tests/test_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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',
)

Expand All @@ -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()
Expand Down