Search in sources :

Example 1 with AttesterSlashing

use of tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing 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())));
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with AttesterSlashing

use of tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing in project teku by ConsenSys.

the class FuzzRegressionTest method shouldRejectAttesterSlashingWithInvalidValidatorIndex.

@Test
void shouldRejectAttesterSlashingWithInvalidValidatorIndex() throws Exception {
    final BeaconState state = load("issue2345/state.ssz", spec.getGenesisSchemaDefinitions().getBeaconStateSchema());
    final AttesterSlashing slashing = load("issue2345/attester_slashing.ssz", spec.getGenesisSchemaDefinitions().getAttesterSlashingSchema());
    SszList<AttesterSlashing> slashings = BeaconBlockBodyLists.ofSpec(spec).createAttesterSlashings(slashing);
    assertThatThrownBy(() -> state.updated(mutableState -> spec.getBlockProcessor(mutableState.getSlot()).processAttesterSlashings(mutableState, slashings))).isInstanceOf(BlockProcessingException.class);
}
Also used : AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with AttesterSlashing

use of tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing in project teku by ConsenSys.

the class AttesterSlashingValidatorTest method shouldRejectInvalidAttesterSlashing.

@Test
public void shouldRejectInvalidAttesterSlashing() {
    AttesterSlashing slashing = dataStructureUtil.randomAttesterSlashing();
    when(mockSpec.validateAttesterSlashing(bestState, slashing)).thenReturn(Optional.of(AttesterSlashingInvalidReason.ATTESTATIONS_NOT_SLASHABLE));
    assertThat(attesterSlashingValidator.validateFully(slashing)).isCompletedWithValueMatching(InternalValidationResult::isReject);
}
Also used : AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) Test(org.junit.jupiter.api.Test)

Example 4 with AttesterSlashing

use of tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing in project teku by ConsenSys.

the class AttesterSlashingTopicHandlerTest method handleMessage_validSlashing.

@Test
public void handleMessage_validSlashing() {
    final AttesterSlashing slashing = dataStructureUtil.randomAttesterSlashing();
    when(processor.process(slashing)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.ACCEPT));
    Bytes serialized = gossipEncoding.encode(slashing);
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Valid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 5 with AttesterSlashing

use of tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing in project teku by ConsenSys.

the class AttesterSlashingFuzzInputTest method createInput.

@Override
protected AttesterSlashingFuzzInput createInput() {
    final BeaconState state = dataStructureUtil.randomBeaconState();
    final AttesterSlashing slashing = dataStructureUtil.randomAttesterSlashing();
    return new AttesterSlashingFuzzInput(spec, state, slashing);
}
Also used : AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)17 Test (org.junit.jupiter.api.Test)12 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)7 Bytes (org.apache.tuweni.bytes.Bytes)5 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)4 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)4 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)4 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)4 ValidationResult (io.libp2p.core.pubsub.ValidationResult)3 AttesterSlashingFuzzInput (tech.pegasys.teku.fuzz.input.AttesterSlashingFuzzInput)2 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)2 Deposit (tech.pegasys.teku.spec.datastructures.operations.Deposit)2 SignedContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof)2 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1