update to a new version of ff crate with serde support

This commit is contained in:
Alex Vlasov 2019-01-09 20:34:17 +02:00
parent 1363d02170
commit 3279e322eb
3 changed files with 56 additions and 3 deletions

@ -2,11 +2,12 @@
name = "pairing" name = "pairing"
# Remember to change version string in README.md. # Remember to change version string in README.md.
version = "0.15.0" version = "0.15.1"
authors = [ authors = [
"Sean Bowe <ewillbefull@gmail.com>", "Sean Bowe <ewillbefull@gmail.com>",
"Jack Grigg <jack@z.cash>", "Jack Grigg <jack@z.cash>",
"Alex Vlasov <alex.m.vlasov@gmail.com>" "Alex Vlasov <alex.m.vlasov@gmail.com>",
"Alex Gluchowski <alex@gluchowski.net>"
] ]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
@ -18,7 +19,12 @@ repository = "https://github.com/matterinc/pairing"
[dependencies] [dependencies]
rand = "0.4" rand = "0.4"
byteorder = "1" byteorder = "1"
ff = { version = "0.4", features = ["derive"] } ff = { git = 'https://github.com/matterinc/ff', features = ["derive"] }
#ff = { path = "../ff", features = ["derive"] }
serde = "1.0.80"
serde_derive = "1.0.80"
serde_json = "1.0.33"
hex = "0.3.2"
[features] [features]
unstable-features = ["expose-arith"] unstable-features = ["expose-arith"]

@ -5,7 +5,49 @@ use ff::{Field, PrimeField, PrimeFieldDecodingError, PrimeFieldRepr};
#[PrimeFieldGenerator = "7"] #[PrimeFieldGenerator = "7"]
pub struct Fr(FrRepr); pub struct Fr(FrRepr);
#[test]
fn test_to_hex() {
assert_eq!(Fr::one().to_hex(), "0000000000000000000000000000000000000000000000000000000000000001");
}
#[test]
fn test_fr_from_hex() {
let fr = Fr::from_hex("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
assert_eq!(fr, Fr::one());
let fr = Fr::from_hex("0x0000000000000000000000000000000000000000000000000000000000000001").unwrap();
assert_eq!(fr, Fr::one());
let fr = Fr::from_hex("0x01").unwrap();
assert_eq!(fr, Fr::one());
let fr = Fr::from_hex("0x00").unwrap();
assert_eq!(fr, Fr::zero());
let fr = Fr::from_hex("00").unwrap();
assert_eq!(fr, Fr::zero());
}
#[test]
fn test_fr_serialize() {
assert_eq!(
serde_json::to_string(&Fr::one()).unwrap(),
r#""0x0000000000000000000000000000000000000000000000000000000000000001""#);
}
#[test]
fn test_fr_deserialize() {
let json = r#""0x0000000000000000000000000000000000000000000000000000000000000001""#;
let fr: Fr = serde_json::from_str(json).unwrap();
assert_eq!(fr, Fr::one());
}
#[test] #[test]
fn test_roots_of_unity() { fn test_roots_of_unity() {
assert_eq!(Fr::S, 28); assert_eq!(Fr::S, 28);
} }
#[test]
fn test_default() {
assert_eq!(Fr::default(), Fr::zero());
}

@ -15,6 +15,11 @@ extern crate byteorder;
extern crate ff; extern crate ff;
extern crate rand; extern crate rand;
extern crate hex;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[cfg(test)] #[cfg(test)]
pub mod tests; pub mod tests;