Fix operation_pool release-only tests

This commit is contained in:
Paul Hauner 2019-05-10 09:45:28 +10:00
parent be9f8aa0bf
commit 3115bf7d36
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6

View File

@ -716,47 +716,46 @@ mod tests {
(spec, state) (spec, state)
} }
/// Create a signed attestation for use in tests.
/// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`.
// #[cfg(not(debug_assertions))]
fn signed_attestation<
R: std::slice::SliceIndex<[usize], Output = [usize]>,
B: BeaconStateTypes,
>(
committee: &CrosslinkCommittee,
keypairs: &[Keypair],
signing_range: R,
slot: Slot,
state: &BeaconState<B>,
spec: &ChainSpec,
extra_signer: Option<usize>,
) -> Attestation {
let mut builder = TestingAttestationBuilder::new(
state,
&committee.committee,
slot,
committee.shard,
spec,
);
let signers = &committee.committee[signing_range];
let committee_keys = signers.iter().map(|&i| &keypairs[i].sk).collect::<Vec<_>>();
builder.sign(signers, &committee_keys, &state.fork, spec);
extra_signer.map(|c_idx| {
let validator_index = committee.committee[c_idx];
builder.sign(
&[validator_index],
&[&keypairs[validator_index].sk],
&state.fork,
spec,
)
});
builder.build()
}
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
mod release_tests { mod release_tests {
use super::*; use super::*;
/// Create a signed attestation for use in tests.
/// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`.
fn signed_attestation<
R: std::slice::SliceIndex<[usize], Output = [usize]>,
B: BeaconStateTypes,
>(
committee: &CrosslinkCommittee,
keypairs: &[Keypair],
signing_range: R,
slot: Slot,
state: &BeaconState<B>,
spec: &ChainSpec,
extra_signer: Option<usize>,
) -> Attestation {
let mut builder = TestingAttestationBuilder::new(
state,
&committee.committee,
slot,
committee.shard,
spec,
);
let signers = &committee.committee[signing_range];
let committee_keys = signers.iter().map(|&i| &keypairs[i].sk).collect::<Vec<_>>();
builder.sign(signers, &committee_keys, &state.fork, spec);
extra_signer.map(|c_idx| {
let validator_index = committee.committee[c_idx];
builder.sign(
&[validator_index],
&[&keypairs[validator_index].sk],
&state.fork,
spec,
)
});
builder.build()
}
/// Test state for attestation-related tests. /// Test state for attestation-related tests.
fn attestation_test_state<B: BeaconStateTypes>( fn attestation_test_state<B: BeaconStateTypes>(
num_committees: usize, num_committees: usize,
@ -779,7 +778,7 @@ mod tests {
} }
/// Set the latest crosslink in the state to match the attestation. /// Set the latest crosslink in the state to match the attestation.
fn fake_latest_crosslink<T: BeaconStateTypes>( fn fake_latest_crosslink<B: BeaconStateTypes>(
att: &Attestation, att: &Attestation,
state: &mut BeaconState<B>, state: &mut BeaconState<B>,
spec: &ChainSpec, spec: &ChainSpec,
@ -960,10 +959,12 @@ mod tests {
/// are also signed by the 0th member of the committee. /// are also signed by the 0th member of the committee.
#[test] #[test]
fn attestation_get_max() { fn attestation_get_max() {
let spec = &ChainSpec::foundation();
let small_step_size = 2; let small_step_size = 2;
let big_step_size = 4; let big_step_size = 4;
let (ref mut state, ref keypairs) = attestation_test_state(spec, big_step_size);
let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationStateTypes>(big_step_size);
let op_pool = OperationPool::new(); let op_pool = OperationPool::new();
let slot = state.slot - 1; let slot = state.slot - 1;