Skip to content

Commit

Permalink
Improve the usability of regenerate.sh and document it.
Browse files Browse the repository at this point in the history
Signed-off-by: Daira Hopwood <[email protected]>
  • Loading branch information
daira committed Mar 21, 2023
1 parent 826e67c commit c019a29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
Code to generate test vectors for various parts of Zcash.

The generated test vectors are checked into the repository:
- `test-vectors/json/`: JSON format.
- `test-vectors/rust/`: Rust format, suitable for copying into a Rust library or

- `test-vectors/json/*.json`: JSON format.
- `test-vectors/rust/*.rs`: Rust format, suitable for copying into a Rust library or
application to use from `#[cfg(test)]` code.
- `test-vectors/zcash/`: Bitcoin-flavoured JSON format (where 256-bit values are
- `test-vectors/zcash/*.json`: Bitcoin-flavoured JSON format (where 256-bit values are
encoded as byte-reversed hex strings), for use in `zcashd` unit tests.

To generate the test vectors yourself (for example, to generate a larger set
after adjusting:

- Install [`poetry`](https://python-poetry.org/).
- `poetry install`
- `./regenerate.sh <opt_output_types>`
- `<opt_output_types>` defaults to `rust json zcash`.

To generate an individual output file:

- `poetry run SCRIPT_NAME [-t json|rust|zcash]`
- `SCRIPT_NAME` is one of the scripts listed in `pyproject.toml`.

Expand Down
14 changes: 12 additions & 2 deletions regenerate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

poetry install -q

tv_scripts=(
bip_0032
f4jumble
Expand Down Expand Up @@ -27,8 +29,16 @@ tv_scripts=(
zip_0244
zip_0316)

formats="${*:-rust json zcash}"

for generator in "${tv_scripts[@]}"
do
echo "# $generator"
poetry run $generator -t $1 >test-vectors/$1/$generator.$2
for format in $formats
do
filetype="${format/rust/rs}"
filetype="${filetype/zcash/json}"
output_file="test-vectors/$format/$generator.$filetype"
echo $output_file
poetry run $generator -t $format >$output_file
done
done

0 comments on commit c019a29

Please sign in to comment.