-
Notifications
You must be signed in to change notification settings - Fork 0
Add test vectors for Praos (ver03) #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think only adding test vectors without test runner is a bit odd. |
leave only ver03 vectors and make them jsons
61308ca
to
e08a12d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some improvements suggestion towards more idiomatic Rust :)
src/vrf03.rs
Outdated
let output_expected = | ||
hex::decode(test_vector.get("beta").unwrap().as_str().unwrap()).unwrap(); | ||
|
||
assert_eq!(vrf_name, "PraosVRF"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these assertions seem rather pointless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, removed!
src/vrf03.rs
Outdated
let test_vector: serde_json::Value = | ||
serde_json::from_reader(file).expect("JSON was not well-formatted"); | ||
|
||
let vrf_name = test_vector.get("vrf").unwrap().as_str().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should create a VRFTestVector
structure and have serve take care of deserialisation, along with proper types for each member. Using automatic derivation should remove quite a lot of boilerplate conversion I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is some code I wrote to handle deserialisation from hex encoded string into bytes: https://github.com/pragma-org/amaru/blob/81a72af8a5b145ecfcee9a255d129fb703efdccf/crates/ouroboros/tests/validation.rs#L109
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you very much for this remark and request. Used serde and its deserialization as requested!
src/vrf03.rs
Outdated
|
||
#[test] | ||
fn check_against_cardano_base() { | ||
check_against_golden("./tests/test_vectors/vrf_ver03_generated_1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a static const test_vectors : [&'static str; 8] = [ .... ]
and then iterate over the vector, eg. a parametric test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a proposed patch to simplify the deserialisation of test vectors. Also, I wonder what's the relationship between those JSON formatted test vectors and the ones which are inline part of the code?
Last suggestion: instead of adding one file for each test vector, just add one vrf03_golden_tests.json
file containing a list.
The PR adds test vectors as checked/generated in cardano-base for VRF:
The mirror PR generating/checking the added test vectors is here : IntersectMBO/cardano-base#519