Merge pull request #968 from ethereum/generators-workflow
Generators workflow
This commit is contained in:
commit
b51c7881ba
|
@ -8,7 +8,7 @@ venv
|
|||
build/
|
||||
output/
|
||||
|
||||
yaml_tests/
|
||||
eth2.0-spec-tests/
|
||||
.pytest_cache
|
||||
|
||||
# Dynamically built from Markdown spec
|
||||
|
|
34
Makefile
34
Makefile
|
@ -2,7 +2,7 @@ SPEC_DIR = ./specs
|
|||
SCRIPT_DIR = ./scripts
|
||||
TEST_LIBS_DIR = ./test_libs
|
||||
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
||||
YAML_TEST_DIR = ./yaml_tests
|
||||
YAML_TEST_DIR = ./eth2.0-spec-tests/tests
|
||||
GENERATOR_DIR = ./test_generators
|
||||
CONFIGS_DIR = ./configs
|
||||
|
||||
|
@ -27,7 +27,7 @@ clean:
|
|||
rm -rf $(PY_SPEC_ALL_TARGETS)
|
||||
|
||||
# "make gen_yaml_tests" to run generators
|
||||
gen_yaml_tests: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR) $(YAML_TEST_TARGETS)
|
||||
gen_yaml_tests: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_TARGETS)
|
||||
|
||||
# installs the packages to run pyspec tests
|
||||
install_test:
|
||||
|
@ -54,24 +54,30 @@ CURRENT_DIR = ${CURDIR}
|
|||
|
||||
# The function that builds a set of suite files, by calling a generator for the given type (param 1)
|
||||
define build_yaml_tests
|
||||
$(info running generator $(1))
|
||||
# Create the output
|
||||
mkdir -p $(YAML_TEST_DIR)$(1)
|
||||
|
||||
# 1) Create a virtual environment
|
||||
# 2) Activate the venv, this is where dependencies are installed for the generator
|
||||
# 3) Install all the necessary requirements
|
||||
# 4) Run the generator. The generator is assumed to have an "main.py" file.
|
||||
# 5) We output to the tests dir (generator program should accept a "-o <filepath>" argument.
|
||||
cd $(GENERATOR_DIR)$(1); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt; python3 main.py -o $(CURRENT_DIR)/$(YAML_TEST_DIR)$(1) -c $(CURRENT_DIR)/$(CONFIGS_DIR)
|
||||
|
||||
$(info generator $(1) finished)
|
||||
# Started!
|
||||
# Create output directory
|
||||
# Navigate to the generator
|
||||
# Create a virtual environment, if it does not exist already
|
||||
# Activate the venv, this is where dependencies are installed for the generator
|
||||
# Install all the necessary requirements
|
||||
# Run the generator. The generator is assumed to have an "main.py" file.
|
||||
# We output to the tests dir (generator program should accept a "-o <filepath>" argument.
|
||||
echo "generator $(1) started"; \
|
||||
mkdir -p $(YAML_TEST_DIR)$(1); \
|
||||
cd $(GENERATOR_DIR)$(1); \
|
||||
if ! test -d venv; then python3 -m venv venv; fi; \
|
||||
. venv/bin/activate; \
|
||||
pip3 install -r requirements.txt; \
|
||||
python3 main.py -o $(CURRENT_DIR)/$(YAML_TEST_DIR)$(1) -c $(CURRENT_DIR)/$(CONFIGS_DIR); \
|
||||
echo "generator $(1) finished"
|
||||
endef
|
||||
|
||||
# The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary)
|
||||
$(YAML_TEST_DIR):
|
||||
$(info creating directory, to output yaml targets to: ${YAML_TEST_TARGETS})
|
||||
mkdir -p $@
|
||||
$(YAML_TEST_DIR)/:
|
||||
$(info ignoring duplicate yaml tests dir)
|
||||
|
||||
# For any target within the tests dir, build it using the build_yaml_tests function.
|
||||
# (creation of output dir is a dependency)
|
||||
|
|
|
@ -28,9 +28,12 @@ make clean
|
|||
This runs all the generators.
|
||||
|
||||
```bash
|
||||
make gen_yaml_tests
|
||||
make -j 4 gen_yaml_tests
|
||||
```
|
||||
|
||||
The `-j N` flag makes the generators run in parallel, with `N` being the amount of cores.
|
||||
|
||||
|
||||
### Running a single generator
|
||||
|
||||
The make file auto-detects generators in the `test_generators/` directory,
|
||||
|
|
|
@ -29,7 +29,7 @@ def build_deposit_data(state,
|
|||
message_hash=signing_root(deposit_data),
|
||||
privkey=privkey,
|
||||
domain=spec.get_domain(
|
||||
state.fork,
|
||||
state,
|
||||
spec.get_current_epoch(state),
|
||||
spec.DOMAIN_DEPOSIT,
|
||||
)
|
||||
|
@ -46,7 +46,7 @@ def build_deposit(state,
|
|||
|
||||
deposit_data = build_deposit_data(state, pubkey, withdrawal_cred, privkey, amount)
|
||||
|
||||
item = spec.hash(deposit_data.serialize())
|
||||
item = deposit_data.hash_tree_root()
|
||||
index = len(deposit_data_leaves)
|
||||
deposit_data_leaves.append(item)
|
||||
tree = calc_merkle_tree_from_leaves(tuple(deposit_data_leaves))
|
||||
|
@ -69,7 +69,7 @@ def build_deposit_for_index(initial_validator_count: int, index: int) -> Tuple[s
|
|||
)
|
||||
state = genesis.create_genesis_state(genesis_deposits)
|
||||
|
||||
deposit_data_leaves = [spec.hash(dep.data.serialize()) for dep in genesis_deposits]
|
||||
deposit_data_leaves = [dep.data.hash_tree_root() for dep in genesis_deposits]
|
||||
|
||||
deposit = build_deposit(
|
||||
state,
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import List
|
|||
|
||||
|
||||
def create_genesis_state(deposits: List[spec.Deposit]) -> spec.BeaconState:
|
||||
deposit_root = get_merkle_root((tuple([spec.hash(dep.data.serialize()) for dep in deposits])))
|
||||
deposit_root = get_merkle_root((tuple([(dep.data.hash_tree_root()) for dep in deposits])))
|
||||
|
||||
return spec.get_genesis_beacon_state(
|
||||
deposits,
|
||||
|
@ -32,7 +32,7 @@ def create_deposits(pubkeys: List[spec.BLSPubkey], withdrawal_cred: List[spec.By
|
|||
]
|
||||
|
||||
# Fill tree with existing deposits
|
||||
deposit_data_leaves = [spec.hash(data.serialize()) for data in deposit_data]
|
||||
deposit_data_leaves = [data.hash_tree_root() for data in deposit_data]
|
||||
tree = calc_merkle_tree_from_leaves(tuple(deposit_data_leaves))
|
||||
|
||||
return [
|
||||
|
|
Loading…
Reference in New Issue