Skip to content
Snippets Groups Projects
Unverified Commit cbb2e6de authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

use curve templates in the FEC tests

parent 1b59e43b
No related branches found
No related tags found
No related merge requests found
Pipeline #3750 passed
...@@ -154,12 +154,7 @@ mod tests { ...@@ -154,12 +154,7 @@ mod tests {
]; ];
const LOST_SHARDS: [usize; 3] = [1, 3, 6]; const LOST_SHARDS: [usize; 3] = [1, 3, 6];
fn to_big_int_from_bytes(i: &[u8]) -> <Bls12_381 as Pairing>::ScalarField { fn decoding_template<E: Pairing>() {
<Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(i)
}
#[test]
fn decoding() {
let hash = Sha256::hash(DATA).to_vec(); let hash = Sha256::hash(DATA).to_vec();
let mut shards = SHARDS let mut shards = SHARDS
...@@ -167,7 +162,7 @@ mod tests { ...@@ -167,7 +162,7 @@ mod tests {
.map(|r| { .map(|r| {
Some( Some(
r.iter() r.iter()
.map(|s| to_big_int_from_bytes(&s.to_le_bytes())) .map(|s| E::ScalarField::from_le_bytes_mod_order(&s.to_le_bytes()))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
) )
}) })
...@@ -183,16 +178,21 @@ mod tests { ...@@ -183,16 +178,21 @@ mod tests {
k: K as u32, k: K as u32,
linear_combination: vec![LinearCombinationElement { linear_combination: vec![LinearCombinationElement {
index: i as u32, index: i as u32,
weight: <Bls12_381 as Pairing>::ScalarField::one(), weight: E::ScalarField::one(),
}], }],
hash: hash.clone(), hash: hash.clone(),
bytes: field::merge_elements_into_bytes::<Bls12_381>(bytes), bytes: field::merge_elements_into_bytes::<E>(bytes),
size: DATA.len(), size: DATA.len(),
}); });
} }
} }
assert_eq!(DATA, decode::<GF, Bls12_381>(blocks).unwrap()) assert_eq!(DATA, decode::<GF, E>(blocks).unwrap())
}
#[test]
fn decoding() {
decoding_template::<Bls12_381>();
} }
fn create_fake_shard<E: Pairing>( fn create_fake_shard<E: Pairing>(
...@@ -211,38 +211,37 @@ mod tests { ...@@ -211,38 +211,37 @@ mod tests {
} }
} }
#[test] fn recoding_template<E: Pairing>() {
fn recoding() { let a: Shard<E> = create_fake_shard(
let a: Shard<Bls12_381> = create_fake_shard(
&[LinearCombinationElement { &[LinearCombinationElement {
index: 0, index: 0,
weight: <Bls12_381 as Pairing>::ScalarField::one(), weight: E::ScalarField::one(),
}], }],
&[1, 2, 3], &[1, 2, 3],
); );
let b: Shard<Bls12_381> = create_fake_shard( let b: Shard<E> = create_fake_shard(
&[LinearCombinationElement { &[LinearCombinationElement {
index: 1, index: 1,
weight: <Bls12_381 as Pairing>::ScalarField::one(), weight: E::ScalarField::one(),
}], }],
&[4, 5, 6], &[4, 5, 6],
); );
assert_eq!( assert_eq!(
a.mul(<Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[2])), a.mul(E::ScalarField::from_le_bytes_mod_order(&[2])),
create_fake_shard( create_fake_shard(
&[LinearCombinationElement { &[LinearCombinationElement {
index: 0, index: 0,
weight: <Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[2]), weight: E::ScalarField::from_le_bytes_mod_order(&[2]),
}], }],
&[2, 4, 6], &[2, 4, 6],
) )
); );
let c = a.combine( let c = a.combine(
<Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[3]), E::ScalarField::from_le_bytes_mod_order(&[3]),
&b, &b,
<Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[5]), E::ScalarField::from_le_bytes_mod_order(&[5]),
); );
assert_eq!( assert_eq!(
...@@ -251,11 +250,11 @@ mod tests { ...@@ -251,11 +250,11 @@ mod tests {
&[ &[
LinearCombinationElement { LinearCombinationElement {
index: 0, index: 0,
weight: <Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[3]), weight: E::ScalarField::from_le_bytes_mod_order(&[3]),
}, },
LinearCombinationElement { LinearCombinationElement {
index: 1, index: 1,
weight: <Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[5]), weight: E::ScalarField::from_le_bytes_mod_order(&[5]),
} }
], ],
&[23, 31, 39] &[23, 31, 39]
...@@ -264,27 +263,32 @@ mod tests { ...@@ -264,27 +263,32 @@ mod tests {
assert_eq!( assert_eq!(
c.combine( c.combine(
<Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[2]), E::ScalarField::from_le_bytes_mod_order(&[2]),
&a, &a,
<Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[4]), E::ScalarField::from_le_bytes_mod_order(&[4]),
), ),
create_fake_shard( create_fake_shard(
&[ &[
LinearCombinationElement { LinearCombinationElement {
index: 0, index: 0,
weight: <Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[6]), weight: E::ScalarField::from_le_bytes_mod_order(&[6]),
}, },
LinearCombinationElement { LinearCombinationElement {
index: 1, index: 1,
weight: <Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[10]), weight: E::ScalarField::from_le_bytes_mod_order(&[10]),
}, },
LinearCombinationElement { LinearCombinationElement {
index: 0, index: 0,
weight: <Bls12_381 as Pairing>::ScalarField::from_le_bytes_mod_order(&[4]), weight: E::ScalarField::from_le_bytes_mod_order(&[4]),
} }
], ],
&[50, 70, 90], &[50, 70, 90],
) )
); );
} }
#[test]
fn recoding() {
recoding_template::<Bls12_381>();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment