Merge pull request #968 from ethereum/generators-workflow

Generators workflow
This commit is contained in:
Danny Ryan 2019-04-22 11:08:35 -06:00 committed by GitHub
commit b51c7881ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 21 deletions

2
.gitignore vendored
View File

@ -8,7 +8,7 @@ venv
build/ build/
output/ output/
yaml_tests/ eth2.0-spec-tests/
.pytest_cache .pytest_cache
# Dynamically built from Markdown spec # Dynamically built from Markdown spec

View File

@ -2,7 +2,7 @@ SPEC_DIR = ./specs
SCRIPT_DIR = ./scripts SCRIPT_DIR = ./scripts
TEST_LIBS_DIR = ./test_libs TEST_LIBS_DIR = ./test_libs
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
YAML_TEST_DIR = ./yaml_tests YAML_TEST_DIR = ./eth2.0-spec-tests/tests
GENERATOR_DIR = ./test_generators GENERATOR_DIR = ./test_generators
CONFIGS_DIR = ./configs CONFIGS_DIR = ./configs
@ -27,7 +27,7 @@ clean:
rm -rf $(PY_SPEC_ALL_TARGETS) rm -rf $(PY_SPEC_ALL_TARGETS)
# "make gen_yaml_tests" to run generators # "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 # installs the packages to run pyspec tests
install_test: 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) # The function that builds a set of suite files, by calling a generator for the given type (param 1)
define build_yaml_tests define build_yaml_tests
$(info running generator $(1)) # Started!
# Create the output # Create output directory
mkdir -p $(YAML_TEST_DIR)$(1) # Navigate to the generator
# Create a virtual environment, if it does not exist already
# 1) Create a virtual environment # Activate the venv, this is where dependencies are installed for the generator
# 2) Activate the venv, this is where dependencies are installed for the generator # Install all the necessary requirements
# 3) Install all the necessary requirements # Run the generator. The generator is assumed to have an "main.py" file.
# 4) 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.
# 5) We output to the tests dir (generator program should accept a "-o <filepath>" argument. echo "generator $(1) started"; \
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) mkdir -p $(YAML_TEST_DIR)$(1); \
cd $(GENERATOR_DIR)$(1); \
$(info generator $(1) finished) 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 endef
# The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary) # The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary)
$(YAML_TEST_DIR): $(YAML_TEST_DIR):
$(info creating directory, to output yaml targets to: ${YAML_TEST_TARGETS}) $(info creating directory, to output yaml targets to: ${YAML_TEST_TARGETS})
mkdir -p $@ 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. # For any target within the tests dir, build it using the build_yaml_tests function.
# (creation of output dir is a dependency) # (creation of output dir is a dependency)

View File

@ -28,9 +28,12 @@ make clean
This runs all the generators. This runs all the generators.
```bash ```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 ### Running a single generator
The make file auto-detects generators in the `test_generators/` directory, The make file auto-detects generators in the `test_generators/` directory,

View File

@ -29,7 +29,7 @@ def build_deposit_data(state,
message_hash=signing_root(deposit_data), message_hash=signing_root(deposit_data),
privkey=privkey, privkey=privkey,
domain=spec.get_domain( domain=spec.get_domain(
state.fork, state,
spec.get_current_epoch(state), spec.get_current_epoch(state),
spec.DOMAIN_DEPOSIT, spec.DOMAIN_DEPOSIT,
) )
@ -46,7 +46,7 @@ def build_deposit(state,
deposit_data = build_deposit_data(state, pubkey, withdrawal_cred, privkey, amount) 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) index = len(deposit_data_leaves)
deposit_data_leaves.append(item) deposit_data_leaves.append(item)
tree = calc_merkle_tree_from_leaves(tuple(deposit_data_leaves)) 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) 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( deposit = build_deposit(
state, state,

View File

@ -4,7 +4,7 @@ from typing import List
def create_genesis_state(deposits: List[spec.Deposit]) -> spec.BeaconState: 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( return spec.get_genesis_beacon_state(
deposits, deposits,
@ -32,7 +32,7 @@ def create_deposits(pubkeys: List[spec.BLSPubkey], withdrawal_cred: List[spec.By
] ]
# Fill tree with existing deposits # 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)) tree = calc_merkle_tree_from_leaves(tuple(deposit_data_leaves))
return [ return [