2019-10-28 07:53:10 +00:00
|
|
|
# Eth2 Executable Python Spec (PySpec)
|
2019-03-27 16:28:20 +00:00
|
|
|
|
2019-10-28 07:53:10 +00:00
|
|
|
The executable Python spec is built from the Eth2 specification,
|
2019-03-27 16:43:56 +00:00
|
|
|
complemented with the necessary helper functions for hashing, BLS, and more.
|
|
|
|
|
|
|
|
With this executable spec,
|
|
|
|
test-generators can easily create test-vectors for client implementations,
|
2019-05-06 15:30:32 +00:00
|
|
|
and the spec itself can be verified to be consistent and coherent through sanity tests implemented with pytest.
|
2019-03-27 16:43:56 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
## Dev Install
|
2019-03-28 16:51:49 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
First, create a `venv` and install the developer dependencies (`test` and `lint` extras):
|
2019-03-28 16:51:49 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
```shell
|
|
|
|
make install_test
|
|
|
|
```
|
2019-03-28 16:51:49 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
All the dynamic parts of the spec are built with:
|
2019-03-28 16:51:49 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
```shell
|
|
|
|
(venv) python setup.py pyspecdev
|
2020-01-25 00:26:10 +00:00
|
|
|
```
|
2019-04-17 07:47:56 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
Unlike the regular install, this outputs spec files to their intended source location,
|
|
|
|
to enable debuggers to navigate between packages and generated code, without fragile directory linking.
|
|
|
|
|
|
|
|
By default, when installing the `eth2spec` as package in non-develop mode,
|
|
|
|
the distutils implementation of the `setup` runs `build`, which is extended to run the same `pyspec` work,
|
|
|
|
but outputs into the standard `./build/lib` output.
|
|
|
|
This enables the `eth2.0-specs` repository to be installed like any other python package.
|
2019-04-17 07:47:56 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
|
|
|
|
## Py-tests
|
2019-04-20 01:33:15 +00:00
|
|
|
|
2019-04-17 07:47:56 +00:00
|
|
|
These tests are not intended for client-consumption.
|
2020-01-25 00:26:10 +00:00
|
|
|
These tests are testing the spec itself, to verify consistency and provide feedback on modifications of the spec.
|
|
|
|
However, most of the tests can be run in generator-mode, to output test vectors for client-consumption.
|
2019-04-17 07:47:56 +00:00
|
|
|
|
|
|
|
### How to run tests
|
|
|
|
|
|
|
|
#### Automated
|
|
|
|
|
2019-06-16 23:38:48 +00:00
|
|
|
Run `make test` from the root of the specs repository (after running `make install_test` if have not before).
|
2019-04-17 07:47:56 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
Note that the `make` commands run through the build steps: it runs the `build` output, not the local package source files.
|
|
|
|
|
2019-04-17 07:47:56 +00:00
|
|
|
#### Manual
|
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
See `Dev install` for test pre-requisites.
|
2019-04-17 07:47:56 +00:00
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
Tests are built for `pytest`.
|
|
|
|
|
|
|
|
Caveats:
|
|
|
|
- Working directory must be `./tests/core/pyspec`. The work-directory is important to locate eth2 configuration files.
|
|
|
|
- Run `pytest` as module. It avoids environment differences, and the behavior is different too:
|
|
|
|
`pytest` as module adds the current directory to the `sys.path`
|
|
|
|
|
|
|
|
Full test usage, with explicit configuration for illustration of options usage:
|
|
|
|
```shell
|
2021-05-18 14:17:02 +00:00
|
|
|
(venv) python -m pytest --preset=minimal eth2spec
|
2019-04-17 07:47:56 +00:00
|
|
|
```
|
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
Or, to run a specific test file, specify the full path:
|
|
|
|
```shell
|
2021-05-18 14:17:02 +00:00
|
|
|
(venv) python -m pytest --preset=minimal ./eth2spec/test/phase0/block_processing/test_process_attestation.py
|
2019-04-17 07:47:56 +00:00
|
|
|
```
|
2021-04-21 01:17:33 +00:00
|
|
|
|
|
|
|
Or, to run a specific test function (specify the `eth2spec` module, or the script path if the keyword is ambiguous):
|
|
|
|
```shell
|
2021-05-18 14:17:02 +00:00
|
|
|
(venv) python -m pytest --preset=minimal -k test_success_multi_proposer_index_iterations eth2spec
|
2019-04-17 07:47:56 +00:00
|
|
|
```
|
|
|
|
|
2020-05-11 17:18:49 +00:00
|
|
|
Options:
|
2021-05-18 14:17:02 +00:00
|
|
|
- `--preset`, to change the preset (compile-time configurables). Defaults to `minimal`, can be set to `mainnet`.
|
|
|
|
Use `@spec_configured_state_test({config here...}` to override runtime configurables on a per-test basis.
|
2020-05-11 17:18:49 +00:00
|
|
|
- `--disable-bls`, to disable BLS (only for tests that can run without)
|
|
|
|
- `--bls-type`, `milagro` or `py_ecc` (default)
|
|
|
|
|
2019-06-16 23:38:48 +00:00
|
|
|
### How to view code coverage report
|
|
|
|
|
|
|
|
Run `make open_cov` from the root of the specs repository after running `make test` to open the html code coverage report.
|
|
|
|
|
2021-04-21 01:17:33 +00:00
|
|
|
### Advanced
|
|
|
|
|
|
|
|
Building spec files from any markdown sources, to a custom location:
|
|
|
|
```bash
|
|
|
|
(venv) python setup.py pyspec --spec-fork=phase0 --md-doc-paths="specs/phase0/beacon-chain.md specs/phase0/fork-choice.md" --out-dir=my_spec_dir
|
|
|
|
```
|
2019-04-17 07:47:56 +00:00
|
|
|
|
2019-03-28 16:51:49 +00:00
|
|
|
## Contributing
|
|
|
|
|
2019-03-27 16:43:56 +00:00
|
|
|
Contributions are welcome, but consider implementing your idea as part of the spec itself first.
|
|
|
|
The pyspec is not a replacement.
|
2019-04-17 07:47:56 +00:00
|
|
|
|
2019-03-27 16:43:56 +00:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
2020-01-10 18:42:55 +00:00
|
|
|
Same as the spec itself; see [LICENSE](../../../LICENSE) file in the specs repository root.
|