Search in sources :

Example 1 with ProposerSlashing

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())));
}
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 ProposerSlashing

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);
}
Also used : ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) Test(org.junit.jupiter.api.Test)

Example 3 with ProposerSlashing

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();
}
Also used : ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) HashMap(java.util.HashMap) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 4 with ProposerSlashing

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);
}
Also used : ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) Test(org.junit.jupiter.api.Test)

Example 5 with ProposerSlashing

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);
}
Also used : ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) Test(org.junit.jupiter.api.Test)

Aggregations

ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)20 Test (org.junit.jupiter.api.Test)15 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)6 Bytes (org.apache.tuweni.bytes.Bytes)5 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)5 AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)4 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)4 ValidationResult (io.libp2p.core.pubsub.ValidationResult)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 ProposerSlashingFuzzInput (tech.pegasys.teku.fuzz.input.ProposerSlashingFuzzInput)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 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1