### Question:
EIP1559BlockHeaderGasPriceValidationRule implements DetachedBlockHeaderValidationRule { @Override public boolean validate(final BlockHeader header, final BlockHeader parent) { try { if (!eip1559.isEIP1559(header.getNumber())) { return true; } if (eip1559.isForkBlock(header.getNumber())) { return feeMarket.getInitialBasefee() == header.getBaseFee().orElseThrow(EIP1559MissingBaseFeeFromBlockHeader::new); } final Long parentBaseFee = parent.getBaseFee().orElseThrow(EIP1559MissingBaseFeeFromBlockHeader::new); final Long currentBaseFee = header.getBaseFee().orElseThrow(EIP1559MissingBaseFeeFromBlockHeader::new); final long targetGasUsed = eip1559.targetGasUsed(parent); final long baseFee = eip1559.computeBaseFee(parentBaseFee, parent.getGasUsed(), targetGasUsed); if (baseFee != header.getBaseFee().orElseThrow()) { LOG.trace( "Invalid block header: basefee {} does not equal expected basefee {}", header.getBaseFee().orElseThrow(), baseFee); return false; } return baseFee == currentBaseFee && eip1559.isValidBaseFee(parentBaseFee, currentBaseFee); } catch (final EIP1559MissingBaseFeeFromBlockHeader e) { LOG.trace(e.getMessage()); return false; } } EIP1559BlockHeaderGasPriceValidationRule(final EIP1559 eip1559); @Override boolean validate(final BlockHeader header, final BlockHeader parent);  }### Answer:
@Test public void eipActivationShouldBeGuardedProperly() { disableEIP1559(); assertThatThrownBy( () -> validationRule.validate(blockHeader(FORK_BLOCK - 1, 0, Optional.empty()), null)) .isInstanceOf(RuntimeException.class) .hasMessageContaining("EIP-1559 is not enabled"); }
@Test public void shouldReturnTrueBeforeFork() { enableEIP1559(); assertThat(validationRule.validate(blockHeader(FORK_BLOCK - 1, 0, Optional.empty()), null)) .isTrue(); disableEIP1559(); }
@Test public void shouldReturnTrueIfInitialBaseFeeAtForkBlock() { enableEIP1559(); assertThat( validationRule.validate( blockHeader(FORK_BLOCK, 0, Optional.of(feeMarket.getInitialBasefee())), null)) .isTrue(); disableEIP1559(); }
@Test public void shouldReturnFalseIfNotInitialBaseFeeAtForkBlock() { enableEIP1559(); assertThat( validationRule.validate( blockHeader(FORK_BLOCK, 0, Optional.of(feeMarket.getInitialBasefee() - 1)), null)) .isFalse(); disableEIP1559(); }
@Test public void shouldReturnIfNoBaseFeeAfterForkBlock() { enableEIP1559(); assertThat( validationRule.validate( blockHeader(FORK_BLOCK + 2, 0, Optional.empty()), blockHeader(FORK_BLOCK + 1, 0, Optional.empty()))) .isFalse(); disableEIP1559(); }