Skip to content

Commit 7922b62

Browse files
authored
Merge pull request #3940 from jtraglia/move-depcon-make-rules
Move deposit contract rules to its own Makefile
2 parents 179cde6 + 8a22776 commit 7922b62

File tree

7 files changed

+54
-135
lines changed

7 files changed

+54
-135
lines changed

.circleci/config.yml

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,6 @@ commands:
4444
venv_name: v25-pyspec
4545
reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }}
4646
venv_path: ./venv
47-
restore_deposit_contract_tester_cached_venv:
48-
description: "Restore the venv from cache for the deposit contract tester"
49-
steps:
50-
- restore_cached_venv:
51-
venv_name: v23-deposit-contract-tester
52-
reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }}-{{ checksum "solidity_deposit_contract/web3_tester/requirements.txt" }}
53-
save_deposit_contract_tester_cached_venv:
54-
description: "Save the venv to cache for later use of the deposit contract tester"
55-
steps:
56-
- save_cached_venv:
57-
venv_name: v23-deposit-contract-tester
58-
reqs_checksum: cache-{{ checksum "setup.py" }}-{{ checksum "requirements_preinstallation.txt" }}-{{ checksum "solidity_deposit_contract/web3_tester/requirements.txt" }}
59-
venv_path: ./solidity_deposit_contract/web3_tester/venv
6047
jobs:
6148
checkout_specs:
6249
docker:
@@ -226,71 +213,6 @@ jobs:
226213
- run:
227214
name: Run linter for test generators
228215
command: make lint_generators
229-
build_deposit_contract:
230-
docker:
231-
- image: ethereum/solc:0.6.11-alpine
232-
steps:
233-
- checkout
234-
- run:
235-
name: Install build essentials
236-
command: |
237-
apk update
238-
apk add git make
239-
- run:
240-
name: Compile the contract
241-
command: |
242-
make compile_deposit_contract
243-
git diff --color --exit-code
244-
- persist_to_workspace:
245-
root: .
246-
paths:
247-
- ./solidity_deposit_contract/deposit_contract.json
248-
- ./build/combined.json
249-
- ./solidity_deposit_contract/lib
250-
test_deposit_contract:
251-
docker:
252-
- image: nixorg/nix:circleci
253-
steps:
254-
- checkout
255-
- restore_cache:
256-
key: nix-store-test-v2
257-
- attach_workspace:
258-
at: /tmp/
259-
- run:
260-
name: Test the contract
261-
command: |
262-
mkdir build
263-
cp -r /tmp/build/* build
264-
cp -r /tmp/solidity_deposit_contract/lib/* ./solidity_deposit_contract/lib
265-
cp -r /tmp/solidity_deposit_contract/deposit_contract.json ./solidity_deposit_contract/deposit_contract.json
266-
nix-shell --command 'make test_deposit_contract' ./solidity_deposit_contract/shell.nix
267-
- save_cache:
268-
key: nix-store-test-v2
269-
paths:
270-
- /nix
271-
install_deposit_contract_web3_tester:
272-
docker:
273-
- image: cimg/python:3.12.4
274-
working_directory: ~/specs-repo
275-
steps:
276-
- restore_cache:
277-
key: v3-specs-repo-{{ .Branch }}-{{ .Revision }}
278-
- restore_deposit_contract_tester_cached_venv
279-
- run:
280-
name: Install deposit contract tester requirements
281-
command: make install_deposit_contract_web3_tester
282-
- save_deposit_contract_tester_cached_venv
283-
test_deposit_contract_web3_tests:
284-
docker:
285-
- image: cimg/python:3.12.4
286-
working_directory: ~/specs-repo
287-
steps:
288-
- restore_cache:
289-
key: v3-specs-repo-{{ .Branch }}-{{ .Revision }}
290-
- restore_deposit_contract_tester_cached_venv
291-
- run:
292-
name: Run deposit contract test with web3.py
293-
command: make test_deposit_contract_web3_tests
294216
workflows:
295217
version: 2.1
296218
test_spec:
@@ -328,17 +250,3 @@ workflows:
328250
- lint:
329251
requires:
330252
- install_pyspec_test
331-
# NOTE: Since phase 0 has been launched, we disabled the deposit contract tests.
332-
# - install_deposit_contract_web3_tester:
333-
# requires:
334-
# - checkout_specs
335-
# - test_deposit_contract_web3_tests:
336-
# requires:
337-
# - install_deposit_contract_web3_tester
338-
build_and_test_deposit_contract:
339-
jobs:
340-
- build_deposit_contract
341-
# NOTE: Since phase 0 has been launched, we disabled the deposit contract tests.
342-
# - test_deposit_contract:
343-
# requires:
344-
# - build_deposit_contract

Makefile

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ ETH2SPEC_MODULE_DIR = $(PY_SPEC_DIR)/eth2spec
88
TEST_REPORT_DIR = $(PY_SPEC_DIR)/test-reports
99
TEST_VECTOR_DIR = ../consensus-spec-tests/tests
1010
GENERATOR_DIR = ./tests/generators
11-
SOLIDITY_DEPOSIT_CONTRACT_DIR = ./solidity_deposit_contract
12-
SOLIDITY_DEPOSIT_CONTRACT_SOURCE = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/deposit_contract.sol
13-
SOLIDITY_FILE_NAME = deposit_contract.json
14-
DEPOSIT_CONTRACT_TESTER_DIR = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/web3_tester
1511
CONFIGS_DIR = ./configs
1612
TEST_PRESET_TYPE ?= minimal
1713
# Collect a list of generator names
@@ -50,15 +46,8 @@ GENERATOR_ERROR_LOG_FILE = $(CURRENT_DIR)/$(TEST_VECTOR_DIR)/testgen_error_log.t
5046

5147
SCRIPTS_DIR = ${CURRENT_DIR}/scripts
5248

53-
export DAPP_SKIP_BUILD:=1
54-
export DAPP_SRC:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR)
55-
export DAPP_LIB:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR)/lib
56-
export DAPP_JSON:=build/combined.json
57-
5849
.PHONY: clean partial_clean all test citest lint generate_tests pyspec install_test open_cov \
59-
install_deposit_contract_tester test_deposit_contract install_deposit_contract_compiler \
60-
compile_deposit_contract test_compile_deposit_contract check_toc \
61-
detect_generator_incomplete detect_generator_error_log
50+
check_toc detect_generator_incomplete detect_generator_error_log
6251

6352
all: $(PY_SPEC_ALL_TARGETS)
6453

@@ -170,26 +159,6 @@ lint_generators: pyspec
170159
. venv/bin/activate; cd $(TEST_GENERATORS_DIR); \
171160
flake8 --config $(LINTER_CONFIG_FILE)
172161

173-
compile_deposit_contract:
174-
@cd $(SOLIDITY_DEPOSIT_CONTRACT_DIR)
175-
@git submodule update --recursive --init
176-
@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
177-
@/bin/echo -n '{"abi": ' > $(SOLIDITY_FILE_NAME)
178-
@cat build/DepositContract.abi >> $(SOLIDITY_FILE_NAME)
179-
@/bin/echo -n ', "bytecode": "0x' >> $(SOLIDITY_FILE_NAME)
180-
@cat build/DepositContract.bin >> $(SOLIDITY_FILE_NAME)
181-
@/bin/echo -n '"}' >> $(SOLIDITY_FILE_NAME)
182-
183-
test_deposit_contract:
184-
dapp test -v --fuzz-runs 5
185-
186-
install_deposit_contract_web3_tester:
187-
cd $(DEPOSIT_CONTRACT_TESTER_DIR); python3 -m venv venv; . venv/bin/activate; python3 -m pip install -r requirements.txt
188-
189-
test_deposit_contract_web3_tests:
190-
cd $(DEPOSIT_CONTRACT_TESTER_DIR); . venv/bin/activate; \
191-
python3 -m pytest .
192-
193162
# Runs a generator, identified by param 1
194163
define run_generator
195164
# Started!

solidity_deposit_contract/Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
SOLIDITY_FILE_NAME = deposit_contract.json
2+
SOLIDITY_DEPOSIT_CONTRACT_SOURCE = deposit_contract.sol
3+
DEPOSIT_CONTRACT_TESTER_DIR = web3_tester
4+
5+
export DAPP_SKIP_BUILD:=1
6+
export DAPP_SRC:=$(CURDIR)
7+
export DAPP_LIB:=$(CURDIR)/lib
8+
export DAPP_JSON:=build/combined.json
9+
10+
all: \
11+
compile_deposit_contract \
12+
install_deposit_contract_web3_tester \
13+
test_deposit_contract_web3_tests
14+
15+
compile_deposit_contract:
16+
@git submodule update --recursive --init
17+
@solc --metadata-literal --optimize --optimize-runs 5000000 --bin --abi \
18+
--combined-json=abi,bin,bin-runtime,srcmap,srcmap-runtime,ast,metadata,storage-layout \
19+
--overwrite -o build $(SOLIDITY_DEPOSIT_CONTRACT_SOURCE) tests/deposit_contract.t.sol
20+
@/bin/echo -n '{"abi": ' > $(SOLIDITY_FILE_NAME)
21+
@cat build/DepositContract.abi >> $(SOLIDITY_FILE_NAME)
22+
@/bin/echo -n ', "bytecode": "0x' >> $(SOLIDITY_FILE_NAME)
23+
@cat build/DepositContract.bin >> $(SOLIDITY_FILE_NAME)
24+
@/bin/echo -n '"}' >> $(SOLIDITY_FILE_NAME)
25+
26+
test_deposit_contract:
27+
@dapp test -v --fuzz-runs 5
28+
29+
install_deposit_contract_web3_tester:
30+
@cd $(DEPOSIT_CONTRACT_TESTER_DIR); \
31+
python3 -m venv venv; \
32+
source venv/bin/activate; \
33+
python3 -m pip install -r ../../requirements_preinstallation.txt; \
34+
python3 -m pip install -r requirements.txt
35+
36+
test_deposit_contract_web3_tests:
37+
@cd $(DEPOSIT_CONTRACT_TESTER_DIR); \
38+
source venv/bin/activate; \
39+
python3 -m pytest .
40+
41+
clean:
42+
@git clean -fdx

solidity_deposit_contract/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ In August 2020, version `r2` was released with metadata modifications and relice
1313

1414
## Compiling solidity deposit contract
1515

16-
In the `eth2.0-specs` directory run:
16+
In this directory run:
1717
```sh
1818
make compile_deposit_contract
1919
```
@@ -31,8 +31,8 @@ solc --optimize --optimize-runs 5000000 --metadata-literal --bin deposit_contrac
3131

3232
## Running web3 tests
3333

34-
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).
35-
2. In the `eth2.0-specs` directory run `make test_deposit_contract_web3_tests` to execute the tests.
34+
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).
35+
2. In this directory run `make test_deposit_contract_web3_tests` to execute the tests.
3636

3737
## Running randomized `dapp` tests:
3838

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
eth-tester[py-evm]>=0.3.0b1,<0.4
2-
web3==5.4.0
3-
pytest==3.6.1
1+
eth-tester[py-evm]>=0.12.0b1
2+
web3>=6.11.0
3+
pytest>=4.4
44
# The eth2spec
55
../../

solidity_deposit_contract/web3_tester/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def registration_contract(w3, tester):
5151
abi=contract_abi,
5252
bytecode=contract_bytecode)
5353
tx_hash = registration.constructor().transact()
54-
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
54+
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
5555
registration_deployed = w3.eth.contract(
5656
address=tx_receipt.contractAddress,
5757
abi=contract_abi

solidity_deposit_contract/web3_tester/tests/test_deposit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
import eth_utils
44

5-
from eth2spec.phase0.spec import DepositData
5+
from eth2spec.phase0.mainnet import DepositData
66
from eth2spec.utils.ssz.ssz_typing import List
77
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
88

@@ -119,7 +119,7 @@ def test_deposit_inputs(registration_contract,
119119

120120

121121
def test_deposit_event_log(registration_contract, a0, w3):
122-
log_filter = registration_contract.events.DepositEvent.createFilter(
122+
log_filter = registration_contract.events.DepositEvent.create_filter(
123123
fromBlock='latest',
124124
)
125125
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):
154154

155155

156156
def test_deposit_tree(registration_contract, w3, assert_tx_failed):
157-
log_filter = registration_contract.events.DepositEvent.createFilter(
157+
log_filter = registration_contract.events.DepositEvent.create_filter(
158158
fromBlock='latest',
159159
)
160160

@@ -178,7 +178,7 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed):
178178
tx_hash = registration_contract.functions.deposit(
179179
*deposit_input,
180180
).transact({"value": deposit_amount_list[i] * eth_utils.denoms.gwei})
181-
receipt = w3.eth.getTransactionReceipt(tx_hash)
181+
receipt = w3.eth.get_transaction_receipt(tx_hash)
182182
print("deposit transaction consumes %d gas" % receipt['gasUsed'])
183183

184184
logs = log_filter.get_new_entries()

0 commit comments

Comments
 (0)