use of tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing in project teku by ConsenSys.
the class BlockOperationSelectorFactoryTest method shouldIncludeValidOperations.
@Test
void shouldIncludeValidOperations() {
final UInt64 slot = UInt64.valueOf(2);
final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(slot);
final SignedVoluntaryExit voluntaryExit = dataStructureUtil.randomSignedVoluntaryExit();
final ProposerSlashing proposerSlashing = dataStructureUtil.randomProposerSlashing();
final AttesterSlashing attesterSlashing = dataStructureUtil.randomAttesterSlashing();
final SignedContributionAndProof contribution = dataStructureUtil.randomSignedContributionAndProof(1, parentRoot);
addToPool(voluntaryExitPool, voluntaryExit);
addToPool(proposerSlashingPool, proposerSlashing);
addToPool(attesterSlashingPool, attesterSlashing);
assertThat(contributionPool.add(contribution)).isCompletedWithValue(ACCEPT);
factory.createSelector(parentRoot, blockSlotState, randaoReveal, Optional.empty()).accept(bodyBuilder);
assertThat(bodyBuilder.randaoReveal).isEqualTo(randaoReveal);
assertThat(bodyBuilder.graffiti).isEqualTo(defaultGraffiti);
assertThat(bodyBuilder.proposerSlashings).containsOnly(proposerSlashing);
assertThat(bodyBuilder.attesterSlashings).containsOnly(attesterSlashing);
assertThat(bodyBuilder.voluntaryExits).containsOnly(voluntaryExit);
assertThat(bodyBuilder.syncAggregate).isEqualTo(spec.getSyncCommitteeUtilRequired(slot).createSyncAggregate(List.of(contribution.getMessage().getContribution())));
}
use of tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing in project teku by ConsenSys.
the class OperationPoolTest method shouldNotIncludeInvalidatedItemsFromPool.
@Test
void shouldNotIncludeInvalidatedItemsFromPool() {
OperationValidator<ProposerSlashing> validator = mock(OperationValidator.class);
OperationPool<ProposerSlashing> pool = new OperationPool<>("ProposerSlashingPool", metricsSystem, beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getProposerSlashingsSchema), validator);
ProposerSlashing slashing1 = dataStructureUtil.randomProposerSlashing();
ProposerSlashing slashing2 = dataStructureUtil.randomProposerSlashing();
when(validator.validateFully(any())).thenReturn(completedFuture(ACCEPT));
pool.add(slashing1);
pool.add(slashing2);
when(validator.validateForStateTransition(any(), eq(slashing1))).thenReturn(Optional.of(ExitInvalidReason.SUBMITTED_TOO_EARLY));
when(validator.validateForStateTransition(any(), eq(slashing2))).thenReturn(Optional.empty());
assertThat(pool.getItemsForBlock(state)).containsOnly(slashing2);
}
use of tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing in project teku by ConsenSys.
the class OperationPoolTest method subscribeOperationAdded.
@Test
void subscribeOperationAdded() {
OperationValidator<ProposerSlashing> validator = mock(OperationValidator.class);
OperationPool<ProposerSlashing> pool = new OperationPool<>("ProposerSlashingPool", metricsSystem, beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getProposerSlashingsSchema), validator);
// Set up subscriber
final Map<ProposerSlashing, InternalValidationResult> addedSlashings = new HashMap<>();
OperationAddedSubscriber<ProposerSlashing> subscriber = addedSlashings::put;
pool.subscribeOperationAdded(subscriber);
ProposerSlashing slashing1 = dataStructureUtil.randomProposerSlashing();
ProposerSlashing slashing2 = dataStructureUtil.randomProposerSlashing();
ProposerSlashing slashing3 = dataStructureUtil.randomProposerSlashing();
ProposerSlashing slashing4 = dataStructureUtil.randomProposerSlashing();
when(validator.validateFully(slashing1)).thenReturn(completedFuture(ACCEPT));
when(validator.validateFully(slashing2)).thenReturn(completedFuture(SAVE_FOR_FUTURE));
when(validator.validateFully(slashing3)).thenReturn(completedFuture(InternalValidationResult.reject("Nah")));
when(validator.validateFully(slashing4)).thenReturn(completedFuture(IGNORE));
pool.add(slashing1);
pool.add(slashing2);
pool.add(slashing3);
pool.add(slashing4);
assertThat(addedSlashings.size()).isEqualTo(2);
assertThat(addedSlashings).containsKey(slashing1);
assertThat(addedSlashings.get(slashing1).isAccept()).isTrue();
assertThat(addedSlashings).containsKey(slashing2);
assertThat(addedSlashings.get(slashing2).isSaveForFuture()).isTrue();
}
use of tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing in project teku by ConsenSys.
the class ProposerSlashingValidatorTest method shouldRejectInvalidProposerSlashing.
@Test
public void shouldRejectInvalidProposerSlashing() throws Exception {
beaconChainUtil.initializeStorage();
beaconChainUtil.createAndImportBlockAtSlot(6);
ProposerSlashing slashing = dataStructureUtil.randomProposerSlashing();
when(mockSpec.validateProposerSlashing(getBestState(), slashing)).thenReturn(Optional.of(ProposerSlashingInvalidReason.PROPOSER_INDICES_DIFFERENT));
when(mockSpec.verifyProposerSlashingSignature(getBestState(), slashing, BLSSignatureVerifier.SIMPLE)).thenReturn(true);
assertValidationResult(slashing, REJECT);
}
use of tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing in project teku by ConsenSys.
the class ProposerSlashingValidatorTest method shouldIgnoreProposerSlashingForTheSameProposer.
@Test
public void shouldIgnoreProposerSlashingForTheSameProposer() throws Exception {
beaconChainUtil.initializeStorage();
beaconChainUtil.createAndImportBlockAtSlot(6);
ProposerSlashing slashing1 = dataStructureUtil.randomProposerSlashing();
ProposerSlashing slashing2 = new ProposerSlashing(slashing1.getHeader_1(), slashing1.getHeader_2());
when(mockSpec.validateProposerSlashing(eq(getBestState()), any())).thenReturn(Optional.empty());
when(mockSpec.verifyProposerSlashingSignature(eq(getBestState()), any(), eq(BLSSignatureVerifier.SIMPLE))).thenReturn(true);
assertValidationResult(slashing1, ACCEPT);
assertValidationResult(slashing2, IGNORE);
}
Aggregations