### Question:
ProposerSlashingValidator { public InternalValidationResult validate(ProposerSlashing slashing) { if (!isFirstValidSlashingForValidator(slashing)) { LOG.trace( "ProposerSlashingValidator: Slashing is not the first one for the given validator."); return IGNORE; } if (!passesProcessProposerSlashingConditions(slashing)) { return REJECT; } if (receivedValidSlashingForProposerSet.add( slashing.getHeader_1().getMessage().getProposer_index())) { return ACCEPT; } else { LOG.trace( "ProposerSlashingValidator: Slashing is not the first one for the given validator."); return IGNORE; } } ProposerSlashingValidator(
      RecentChainData recentChainData,
      ProposerSlashingStateTransitionValidator proposerSlashingStateTransitionValidator,
      ProposerSlashingSignatureVerifier proposerSlashingSignatureVerifier); InternalValidationResult validate(ProposerSlashing slashing);  }### Answer:
@Test public void shouldAcceptValidProposerSlashing() throws Exception { beaconChainUtil.initializeStorage(); beaconChainUtil.createAndImportBlockAtSlot(6); ProposerSlashing slashing = dataStructureUtil.randomProposerSlashing(); when(stateTransitionValidator.validate(recentChainData.getBestState().orElseThrow(), slashing)) .thenReturn(Optional.empty()); when(signatureVerifier.verifySignature( recentChainData.getBestState().orElseThrow(), slashing, BLSSignatureVerifier.SIMPLE)) .thenReturn(true); assertThat(proposerSlashingValidator.validate(slashing)).isEqualTo(ACCEPT); }
@Test public void shouldRejectInvalidProposerSlashing() throws Exception { beaconChainUtil.initializeStorage(); beaconChainUtil.createAndImportBlockAtSlot(6); ProposerSlashing slashing = dataStructureUtil.randomProposerSlashing(); when(stateTransitionValidator.validate(recentChainData.getBestState().orElseThrow(), slashing)) .thenReturn( Optional.of( ProposerSlashingStateTransitionValidator.ProposerSlashingInvalidReason .PROPOSER_INDICES_DIFFERENT)); when(signatureVerifier.verifySignature( recentChainData.getBestState().orElseThrow(), slashing, BLSSignatureVerifier.SIMPLE)) .thenReturn(true); assertThat(proposerSlashingValidator.validate(slashing)).isEqualTo(REJECT); }
@Test public void shouldRejectProposerSlashingWithInvalidSignature() throws Exception { beaconChainUtil.initializeStorage(); beaconChainUtil.createAndImportBlockAtSlot(6); ProposerSlashing slashing = dataStructureUtil.randomProposerSlashing(); when(stateTransitionValidator.validate(recentChainData.getBestState().orElseThrow(), slashing)) .thenReturn(Optional.empty()); when(signatureVerifier.verifySignature( recentChainData.getBestState().orElseThrow(), slashing, BLSSignatureVerifier.SIMPLE)) .thenReturn(false); assertThat(proposerSlashingValidator.validate(slashing)).isEqualTo(REJECT); }
@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(stateTransitionValidator.validate(eq(recentChainData.getBestState().orElseThrow()), any())) .thenReturn(Optional.empty()); when(signatureVerifier.verifySignature( eq(recentChainData.getBestState().orElseThrow()), any(), eq(BLSSignatureVerifier.SIMPLE))) .thenReturn(true); assertThat(proposerSlashingValidator.validate(slashing1)).isEqualTo(ACCEPT); assertThat(proposerSlashingValidator.validate(slashing2)).isEqualTo(IGNORE); }