Skip to content

Commit

Permalink
Merge pull request #968 from ethereum/generators-workflow
Browse files Browse the repository at this point in the history
Generators workflow
  • Loading branch information
djrtwo authored Apr 22, 2019
2 parents 95cf6cb + 318188d commit b51c788
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ venv
build/
output/

yaml_tests/
eth2.0-spec-tests/
.pytest_cache

# Dynamically built from Markdown spec
Expand Down
34 changes: 20 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion test_generators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions test_generators/operations/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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))
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test_generators/operations/genesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


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,
Expand Down Expand Up @@ -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 [
Expand Down

0 comments on commit b51c788

Please sign in to comment.