|
|
@ -20,26 +20,37 @@ import org.hyperledger.besu.datatypes.BlobGas; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; |
|
|
|
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; |
|
|
|
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; |
|
|
|
|
|
|
|
import org.hyperledger.besu.evm.gascalculator.PragueGasCalculator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.tuweni.units.bigints.UInt64; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
/** Tests for the {@link BlobGasValidationRule} class. */ |
|
|
|
/** Tests for the {@link BlobGasValidationRule} class. */ |
|
|
|
public class BlobGasValidationRuleTest { |
|
|
|
public class BlobGasValidationRuleTest { |
|
|
|
|
|
|
|
|
|
|
|
private CancunGasCalculator gasCalculator; |
|
|
|
private CancunGasCalculator cancunGasCalculator; |
|
|
|
private BlobGasValidationRule blobGasValidationRule; |
|
|
|
private BlobGasValidationRule cancunBlobGasValidationRule; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PragueGasCalculator pragueGasCalculator; |
|
|
|
|
|
|
|
private BlobGasValidationRule pragueBlobGasValidationRule; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
@BeforeEach |
|
|
|
public void setUp() { |
|
|
|
public void setUp() { |
|
|
|
gasCalculator = new CancunGasCalculator(); |
|
|
|
cancunGasCalculator = new CancunGasCalculator(); |
|
|
|
blobGasValidationRule = new BlobGasValidationRule(gasCalculator); |
|
|
|
cancunBlobGasValidationRule = new BlobGasValidationRule(cancunGasCalculator); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragueGasCalculator = new PragueGasCalculator(); |
|
|
|
|
|
|
|
pragueBlobGasValidationRule = new BlobGasValidationRule(pragueGasCalculator); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Tests that the header blob gas matches the calculated blob gas and passes validation. */ |
|
|
|
/** |
|
|
|
|
|
|
|
* Cancun EIP-4844 - Tests that the header blob gas matches the calculated blob gas and passes |
|
|
|
|
|
|
|
* validation. |
|
|
|
|
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void validateHeader_BlobGasMatchesCalculated_SuccessValidation() { |
|
|
|
public void validateHeader_BlobGasMatchesCalculated_SuccessValidation() { |
|
|
|
long target = gasCalculator.getTargetBlobGasPerBlock(); |
|
|
|
long target = cancunGasCalculator.getTargetBlobGasPerBlock(); |
|
|
|
|
|
|
|
|
|
|
|
// Create parent header
|
|
|
|
// Create parent header
|
|
|
|
final BlockHeaderTestFixture parentBuilder = new BlockHeaderTestFixture(); |
|
|
|
final BlockHeaderTestFixture parentBuilder = new BlockHeaderTestFixture(); |
|
|
@ -52,15 +63,16 @@ public class BlobGasValidationRuleTest { |
|
|
|
headerBuilder.excessBlobGas(BlobGas.of(1L)); |
|
|
|
headerBuilder.excessBlobGas(BlobGas.of(1L)); |
|
|
|
final BlockHeader header = headerBuilder.buildHeader(); |
|
|
|
final BlockHeader header = headerBuilder.buildHeader(); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(blobGasValidationRule.validate(header, parentHeader)).isTrue(); |
|
|
|
assertThat(cancunBlobGasValidationRule.validate(header, parentHeader)).isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Tests that the header blob gas is different from the calculated blob gas and fails validation. |
|
|
|
* Cancun EIP-4844 - Tests that the header blob gas is different from the calculated blob gas and |
|
|
|
|
|
|
|
* fails validation. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void validateHeader_BlobGasDifferentFromCalculated_FailsValidation() { |
|
|
|
public void validateHeader_BlobGasDifferentFromCalculated_FailsValidation() { |
|
|
|
long target = gasCalculator.getTargetBlobGasPerBlock(); |
|
|
|
long target = cancunGasCalculator.getTargetBlobGasPerBlock(); |
|
|
|
|
|
|
|
|
|
|
|
// Create parent header
|
|
|
|
// Create parent header
|
|
|
|
final BlockHeaderTestFixture parentBuilder = new BlockHeaderTestFixture(); |
|
|
|
final BlockHeaderTestFixture parentBuilder = new BlockHeaderTestFixture(); |
|
|
@ -72,6 +84,48 @@ public class BlobGasValidationRuleTest { |
|
|
|
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); |
|
|
|
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); |
|
|
|
final BlockHeader header = headerBuilder.buildHeader(); |
|
|
|
final BlockHeader header = headerBuilder.buildHeader(); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(blobGasValidationRule.validate(header, parentHeader)).isFalse(); |
|
|
|
assertThat(cancunBlobGasValidationRule.validate(header, parentHeader)).isFalse(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Prague EIP-7742 - Tests that the header blob gas matches the calculated blob gas and passes |
|
|
|
|
|
|
|
* validation. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void validateHeader_BlobGasMatchesCalculated_SuccessValidation_Prague_Target3() { |
|
|
|
|
|
|
|
// Create parent header
|
|
|
|
|
|
|
|
final BlockHeaderTestFixture parentBuilder = new BlockHeaderTestFixture(); |
|
|
|
|
|
|
|
parentBuilder.excessBlobGas(BlobGas.of(1L)); |
|
|
|
|
|
|
|
parentBuilder.blobGasUsed(pragueGasCalculator.blobGasCost(3)); |
|
|
|
|
|
|
|
parentBuilder.targetBlobCount(UInt64.valueOf(3)); |
|
|
|
|
|
|
|
final BlockHeader parentHeader = parentBuilder.buildHeader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create block header with matching excessBlobGas
|
|
|
|
|
|
|
|
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); |
|
|
|
|
|
|
|
headerBuilder.excessBlobGas(BlobGas.of(1L)); |
|
|
|
|
|
|
|
final BlockHeader header = headerBuilder.buildHeader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(pragueBlobGasValidationRule.validate(header, parentHeader)).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Prague EIP-7742 - Tests that the header blob gas matches the calculated blob gas and passes |
|
|
|
|
|
|
|
* validation. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void validateHeader_BlobGasMatchesCalculated_SuccessValidation_Prague_Target4() { |
|
|
|
|
|
|
|
// Create parent header
|
|
|
|
|
|
|
|
final BlockHeaderTestFixture parentBuilder = new BlockHeaderTestFixture(); |
|
|
|
|
|
|
|
parentBuilder.excessBlobGas(BlobGas.of(1L)); |
|
|
|
|
|
|
|
parentBuilder.blobGasUsed(pragueGasCalculator.blobGasCost(4)); |
|
|
|
|
|
|
|
parentBuilder.targetBlobCount(UInt64.valueOf(4)); |
|
|
|
|
|
|
|
final BlockHeader parentHeader = parentBuilder.buildHeader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create block header with matching excessBlobGas
|
|
|
|
|
|
|
|
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); |
|
|
|
|
|
|
|
headerBuilder.excessBlobGas(BlobGas.of(1L)); |
|
|
|
|
|
|
|
final BlockHeader header = headerBuilder.buildHeader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(pragueBlobGasValidationRule.validate(header, parentHeader)).isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|