Begin updating tests to reflect changes to bitfield
This commit is contained in:
parent
832d1bd295
commit
72cf7ad1bd
@ -103,7 +103,7 @@ mod tests {
|
|||||||
shard_id: 9,
|
shard_id: 9,
|
||||||
oblique_parent_hashes: vec![Hash256::from(&vec![14; 32][..])],
|
oblique_parent_hashes: vec![Hash256::from(&vec![14; 32][..])],
|
||||||
shard_block_hash: Hash256::from(&vec![15; 32][..]),
|
shard_block_hash: Hash256::from(&vec![15; 32][..]),
|
||||||
attester_bitfield: Bitfield::from(&vec![17; 42][..]),
|
attester_bitfield: Bitfield::from_bytes(&vec![17; 42][..]),
|
||||||
justified_slot: 19,
|
justified_slot: 19,
|
||||||
justified_block_hash: Hash256::from(&vec![15; 32][..]),
|
justified_block_hash: Hash256::from(&vec![15; 32][..]),
|
||||||
aggregate_sig: AggregateSignature::new(),
|
aggregate_sig: AggregateSignature::new(),
|
||||||
|
@ -62,7 +62,7 @@ mod tests {
|
|||||||
shard_id: 9,
|
shard_id: 9,
|
||||||
oblique_parent_hashes: vec![Hash256::from(&vec![14; 32][..])],
|
oblique_parent_hashes: vec![Hash256::from(&vec![14; 32][..])],
|
||||||
shard_block_hash: Hash256::from(&vec![15; 32][..]),
|
shard_block_hash: Hash256::from(&vec![15; 32][..]),
|
||||||
attester_bitfield: Bitfield::from(&vec![17; 42][..]),
|
attester_bitfield: Bitfield::from_bytes(&vec![17; 42][..]),
|
||||||
justified_slot: 19,
|
justified_slot: 19,
|
||||||
justified_block_hash: Hash256::from(&vec![15; 32][..]),
|
justified_block_hash: Hash256::from(&vec![15; 32][..]),
|
||||||
aggregate_sig: AggregateSignature::new(),
|
aggregate_sig: AggregateSignature::new(),
|
||||||
@ -72,7 +72,7 @@ mod tests {
|
|||||||
shard_id: 7,
|
shard_id: 7,
|
||||||
oblique_parent_hashes: vec![Hash256::from(&vec![15; 32][..])],
|
oblique_parent_hashes: vec![Hash256::from(&vec![15; 32][..])],
|
||||||
shard_block_hash: Hash256::from(&vec![14; 32][..]),
|
shard_block_hash: Hash256::from(&vec![14; 32][..]),
|
||||||
attester_bitfield: Bitfield::from(&vec![19; 42][..]),
|
attester_bitfield: Bitfield::from_bytes(&vec![19; 42][..]),
|
||||||
justified_slot: 15,
|
justified_slot: 15,
|
||||||
justified_block_hash: Hash256::from(&vec![17; 32][..]),
|
justified_block_hash: Hash256::from(&vec![17; 32][..]),
|
||||||
aggregate_sig: AggregateSignature::new(),
|
aggregate_sig: AggregateSignature::new(),
|
||||||
|
@ -128,7 +128,7 @@ mod tests {
|
|||||||
all_keypairs.append(&mut non_signing_keypairs.clone());
|
all_keypairs.append(&mut non_signing_keypairs.clone());
|
||||||
|
|
||||||
let attestation_indices: Vec<usize> = (0..all_keypairs.len()).collect();
|
let attestation_indices: Vec<usize> = (0..all_keypairs.len()).collect();
|
||||||
let mut bitfield = Bitfield::new();
|
let mut bitfield = Bitfield::from_elem(all_keypairs.len(), false);
|
||||||
for i in 0..signing_keypairs.len() {
|
for i in 0..signing_keypairs.len() {
|
||||||
bitfield.set(i, true).unwrap();
|
bitfield.set(i, true).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ pub fn generate_attestation(
|
|||||||
signing_keys: &[Option<SecretKey>],
|
signing_keys: &[Option<SecretKey>],
|
||||||
block_store: &BeaconBlockStore<MemoryDB>,
|
block_store: &BeaconBlockStore<MemoryDB>,
|
||||||
) -> AttestationRecord {
|
) -> AttestationRecord {
|
||||||
let mut attester_bitfield = Bitfield::new();
|
let mut attester_bitfield = Bitfield::from_elem(signing_keys.len(), false);
|
||||||
let mut aggregate_sig = AggregateSignature::new();
|
let mut aggregate_sig = AggregateSignature::new();
|
||||||
|
|
||||||
let parent_hashes_slice = {
|
let parent_hashes_slice = {
|
||||||
|
@ -129,12 +129,10 @@ fn test_attestation_validation_invalid_bad_bitfield_length() {
|
|||||||
/*
|
/*
|
||||||
* Extend the bitfield by one byte
|
* Extend the bitfield by one byte
|
||||||
*
|
*
|
||||||
* This is a little hacky and makes assumptions about the internals
|
* We take advantage of the fact that setting a bit outside the current bounds will grow the bitvector.
|
||||||
* of the bitfield.
|
|
||||||
*/
|
*/
|
||||||
let one_byte_higher = rig.attester_count + 8;
|
let one_byte_higher = rig.attester_count + 8;
|
||||||
rig.attestation.attester_bitfield.set(one_byte_higher, true).unwrap();
|
rig.attestation.attester_bitfield.set(one_byte_higher, false);
|
||||||
rig.attestation.attester_bitfield.set(one_byte_higher, false).unwrap();
|
|
||||||
|
|
||||||
let result = rig.context.validate_attestation(&rig.attestation);
|
let result = rig.context.validate_attestation(&rig.attestation);
|
||||||
assert_eq!(result, Err(AttestationValidationError::BadBitfieldLength));
|
assert_eq!(result, Err(AttestationValidationError::BadBitfieldLength));
|
||||||
@ -145,7 +143,7 @@ fn test_attestation_validation_invalid_invalid_bitfield_end_bit() {
|
|||||||
let mut rig = generic_rig();
|
let mut rig = generic_rig();
|
||||||
|
|
||||||
let one_bit_high = rig.attester_count + 1;
|
let one_bit_high = rig.attester_count + 1;
|
||||||
rig.attestation.attester_bitfield.set(one_bit_high, true).unwrap();
|
rig.attestation.attester_bitfield.set(one_bit_high, true);
|
||||||
|
|
||||||
let result = rig.context.validate_attestation(&rig.attestation);
|
let result = rig.context.validate_attestation(&rig.attestation);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -169,7 +167,7 @@ fn test_attestation_validation_invalid_invalid_bitfield_end_bit_with_irreguar_bi
|
|||||||
*/
|
*/
|
||||||
let one_bit_high = rig.attester_count + 1;
|
let one_bit_high = rig.attester_count + 1;
|
||||||
assert!(one_bit_high % 8 != 0, "the test is ineffective in this case.");
|
assert!(one_bit_high % 8 != 0, "the test is ineffective in this case.");
|
||||||
rig.attestation.attester_bitfield.set(one_bit_high, true).unwrap();
|
rig.attestation.attester_bitfield.set(one_bit_high, true);
|
||||||
|
|
||||||
let result = rig.context.validate_attestation(&rig.attestation);
|
let result = rig.context.validate_attestation(&rig.attestation);
|
||||||
assert_eq!(result, Err(AttestationValidationError::InvalidBitfieldEndBits));
|
assert_eq!(result, Err(AttestationValidationError::InvalidBitfieldEndBits));
|
||||||
|
Loading…
Reference in New Issue
Block a user