From 6ae5d34d0f3f1063841dab726514067c96e7dcf6 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 16 Mar 2019 14:31:43 +1100 Subject: [PATCH] Update testing builders as per state 0.5.0 update --- .../src/test_utils/testing_attestation_data_builder.rs | 2 +- .../types/src/test_utils/testing_beacon_block_builder.rs | 4 ++-- .../types/src/test_utils/testing_beacon_state_builder.rs | 9 +++++++-- .../src/test_utils/testing_proposer_slashing_builder.rs | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/eth2/types/src/test_utils/testing_attestation_data_builder.rs b/eth2/types/src/test_utils/testing_attestation_data_builder.rs index f31de2fbd..a270e3859 100644 --- a/eth2/types/src/test_utils/testing_attestation_data_builder.rs +++ b/eth2/types/src/test_utils/testing_attestation_data_builder.rs @@ -20,7 +20,7 @@ impl TestingAttestationDataBuilder { let source_epoch = if is_previous_epoch { state.previous_justified_epoch } else { - state.justified_epoch + state.current_justified_epoch }; let target_root = if is_previous_epoch { diff --git a/eth2/types/src/test_utils/testing_beacon_block_builder.rs b/eth2/types/src/test_utils/testing_beacon_block_builder.rs index e0e4677d4..7fb3d8e09 100644 --- a/eth2/types/src/test_utils/testing_beacon_block_builder.rs +++ b/eth2/types/src/test_utils/testing_beacon_block_builder.rs @@ -19,7 +19,7 @@ impl TestingBeaconBlockBuilder { /// Create a new builder from genesis. pub fn new(spec: &ChainSpec) -> Self { Self { - block: BeaconBlock::genesis(spec.zero_hash, spec), + block: BeaconBlock::empty(spec), } } @@ -34,7 +34,7 @@ impl TestingBeaconBlockBuilder { pub fn sign(&mut self, sk: &SecretKey, fork: &Fork, spec: &ChainSpec) { let message = self.block.signed_root(); let epoch = self.block.slot.epoch(spec.slots_per_epoch); - let domain = spec.get_domain(epoch, Domain::Proposal, fork); + let domain = spec.get_domain(epoch, Domain::BeaconBlock, fork); self.block.signature = Signature::new(&message, domain, sk); } diff --git a/eth2/types/src/test_utils/testing_beacon_state_builder.rs b/eth2/types/src/test_utils/testing_beacon_state_builder.rs index 5b96dc455..8ef4f76ce 100644 --- a/eth2/types/src/test_utils/testing_beacon_state_builder.rs +++ b/eth2/types/src/test_utils/testing_beacon_state_builder.rs @@ -190,7 +190,7 @@ impl TestingBeaconStateBuilder { state.current_shuffling_seed = Hash256::from_low_u64_le(1); state.previous_justified_epoch = epoch - 3; - state.justified_epoch = epoch - 2; + state.current_justified_epoch = epoch - 2; state.justification_bitfield = u64::max_value(); state.finalized_epoch = epoch - 3; @@ -232,8 +232,13 @@ impl TestingBeaconStateBuilder { // The entire committee should have signed the pending attestation. let signers = vec![true; committee.len()]; builder.add_committee_participation(signers); + let attestation = builder.build(); - state.latest_attestations.push(builder.build()) + if attestation.data.slot.epoch(spec.slots_per_epoch) < state.current_epoch(spec) { + state.previous_epoch_attestations.push(attestation) + } else { + state.current_epoch_attestations.push(attestation) + } } } } diff --git a/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs b/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs index fc38c185d..0773cd6da 100644 --- a/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs +++ b/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs @@ -41,13 +41,13 @@ impl TestingProposerSlashingBuilder { proposal_1.signature = { let message = proposal_1.signed_root(); let epoch = slot.epoch(spec.slots_per_epoch); - signer(proposer_index, &message[..], epoch, Domain::Proposal) + signer(proposer_index, &message[..], epoch, Domain::BeaconBlock) }; proposal_2.signature = { let message = proposal_2.signed_root(); let epoch = slot.epoch(spec.slots_per_epoch); - signer(proposer_index, &message[..], epoch, Domain::Proposal) + signer(proposer_index, &message[..], epoch, Domain::BeaconBlock) }; ProposerSlashing {