Split block validation tests into functions
This commit is contained in:
parent
9dcec214af
commit
84bb40855f
@ -54,36 +54,18 @@ impl TestStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn generate_attestations_for_slot(attestation_slot: u64,
|
||||||
fn test_block_validation() {
|
block_slot: u64,
|
||||||
let stores = TestStore::new();
|
shard_count: u16,
|
||||||
|
validators_per_shard: usize,
|
||||||
let cycle_length: u8 = 2;
|
cycle_length: u8,
|
||||||
let shard_count: u16 = 2;
|
parent_hashes: &[Hash256],
|
||||||
let present_slot = u64::from(cycle_length) * 10000;
|
shard_block_hash: &Hash256,
|
||||||
let justified_slot = present_slot - u64::from(cycle_length);
|
justified_block_hash: &Hash256,
|
||||||
let justified_block_hash = Hash256::from("justified_hash".as_bytes());
|
justified_slot: u64,
|
||||||
let shard_block_hash = Hash256::from("shard_hash".as_bytes());
|
stores: &TestStore)
|
||||||
let parent_hashes: Vec<Hash256> = (0..(cycle_length * 2))
|
-> (AttesterMap, Vec<AttestationRecord>, Vec<Keypair>)
|
||||||
.map(|i| Hash256::from(i as u64))
|
{
|
||||||
.collect();
|
|
||||||
let pow_chain_ref = Hash256::from("pow_chain".as_bytes());
|
|
||||||
let active_state_root = Hash256::from("active_state".as_bytes());
|
|
||||||
let crystallized_state_root = Hash256::from("cry_state".as_bytes());
|
|
||||||
|
|
||||||
stores.pow_chain.put_block_hash(pow_chain_ref.as_ref()).unwrap();
|
|
||||||
stores.block.put_block(justified_block_hash.as_ref(), &vec![42]).unwrap();
|
|
||||||
|
|
||||||
let validators_per_shard = 10;
|
|
||||||
|
|
||||||
let block_slot = present_slot;
|
|
||||||
let validator_index: usize = 0;
|
|
||||||
let proposer_map = {
|
|
||||||
let mut proposer_map = ProposerMap::new();
|
|
||||||
proposer_map.insert(present_slot, validator_index);
|
|
||||||
proposer_map
|
|
||||||
};
|
|
||||||
let (attester_map, attestations, _keypairs) = {
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut attester_map = AttesterMap::new();
|
let mut attester_map = AttesterMap::new();
|
||||||
let mut attestations = vec![];
|
let mut attestations = vec![];
|
||||||
@ -92,7 +74,6 @@ fn test_block_validation() {
|
|||||||
let mut attesters = vec![];
|
let mut attesters = vec![];
|
||||||
let mut attester_bitfield = Bitfield::new();
|
let mut attester_bitfield = Bitfield::new();
|
||||||
let mut aggregate_sig = AggregateSignature::new();
|
let mut aggregate_sig = AggregateSignature::new();
|
||||||
let attestation_slot = block_slot - 1;
|
|
||||||
|
|
||||||
let parent_hashes_slice = {
|
let parent_hashes_slice = {
|
||||||
let distance: usize = (block_slot - attestation_slot) as usize;
|
let distance: usize = (block_slot - attestation_slot) as usize;
|
||||||
@ -106,7 +87,7 @@ fn test_block_validation() {
|
|||||||
stream.append(&attestation_slot);
|
stream.append(&attestation_slot);
|
||||||
stream.append_vec(&parent_hashes_slice.to_vec());
|
stream.append_vec(&parent_hashes_slice.to_vec());
|
||||||
stream.append(&shard);
|
stream.append(&shard);
|
||||||
stream.append(&shard_block_hash);
|
stream.append(shard_block_hash);
|
||||||
stream.append(&justified_slot);
|
stream.append(&justified_slot);
|
||||||
let bytes = stream.drain();
|
let bytes = stream.drain();
|
||||||
canonical_hash(&bytes)
|
canonical_hash(&bytes)
|
||||||
@ -149,16 +130,59 @@ fn test_block_validation() {
|
|||||||
slot: attestation_slot,
|
slot: attestation_slot,
|
||||||
shard_id: shard,
|
shard_id: shard,
|
||||||
oblique_parent_hashes: vec![],
|
oblique_parent_hashes: vec![],
|
||||||
shard_block_hash,
|
shard_block_hash: *shard_block_hash,
|
||||||
attester_bitfield,
|
attester_bitfield,
|
||||||
justified_slot,
|
justified_slot,
|
||||||
justified_block_hash,
|
justified_block_hash: *justified_block_hash,
|
||||||
aggregate_sig,
|
aggregate_sig,
|
||||||
};
|
};
|
||||||
attestations.push(attestation);
|
attestations.push(attestation);
|
||||||
}
|
}
|
||||||
(attester_map, attestations, keypairs)
|
(attester_map, attestations, keypairs)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_block_validation() {
|
||||||
|
let stores = TestStore::new();
|
||||||
|
|
||||||
|
let cycle_length: u8 = 2;
|
||||||
|
let shard_count: u16 = 2;
|
||||||
|
let present_slot = u64::from(cycle_length) * 10000;
|
||||||
|
let justified_slot = present_slot - u64::from(cycle_length);
|
||||||
|
let justified_block_hash = Hash256::from("justified_hash".as_bytes());
|
||||||
|
let shard_block_hash = Hash256::from("shard_hash".as_bytes());
|
||||||
|
let parent_hashes: Vec<Hash256> = (0..(cycle_length * 2))
|
||||||
|
.map(|i| Hash256::from(i as u64))
|
||||||
|
.collect();
|
||||||
|
let pow_chain_ref = Hash256::from("pow_chain".as_bytes());
|
||||||
|
let active_state_root = Hash256::from("active_state".as_bytes());
|
||||||
|
let crystallized_state_root = Hash256::from("cry_state".as_bytes());
|
||||||
|
|
||||||
|
stores.pow_chain.put_block_hash(pow_chain_ref.as_ref()).unwrap();
|
||||||
|
stores.block.put_block(justified_block_hash.as_ref(), &vec![42]).unwrap();
|
||||||
|
|
||||||
|
let validators_per_shard = 10;
|
||||||
|
|
||||||
|
let block_slot = present_slot;
|
||||||
|
let validator_index: usize = 0;
|
||||||
|
let proposer_map = {
|
||||||
|
let mut proposer_map = ProposerMap::new();
|
||||||
|
proposer_map.insert(present_slot, validator_index);
|
||||||
|
proposer_map
|
||||||
};
|
};
|
||||||
|
let attestation_slot = block_slot - 1;
|
||||||
|
let (attester_map, attestations, _keypairs) =
|
||||||
|
generate_attestations_for_slot(
|
||||||
|
attestation_slot,
|
||||||
|
block_slot,
|
||||||
|
shard_count,
|
||||||
|
validators_per_shard,
|
||||||
|
cycle_length,
|
||||||
|
&parent_hashes,
|
||||||
|
&shard_block_hash,
|
||||||
|
&justified_block_hash,
|
||||||
|
justified_slot,
|
||||||
|
&stores);
|
||||||
|
|
||||||
let block = Block {
|
let block = Block {
|
||||||
parent_hash: Hash256::from("parent".as_bytes()),
|
parent_hash: Hash256::from("parent".as_bytes()),
|
||||||
|
Loading…
Reference in New Issue
Block a user