Search in sources :

Example 1 with BlockchainReferenceTestCaseSpec

use of org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec in project besu by hyperledger.

the class BlockchainReferenceTestTools method executeTest.

public static void executeTest(final BlockchainReferenceTestCaseSpec spec) {
    final BlockHeader genesisBlockHeader = spec.getGenesisBlockHeader();
    final MutableWorldState worldState = spec.getWorldStateArchive().getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash()).get();
    assertThat(worldState.rootHash()).isEqualTo(genesisBlockHeader.getStateRoot());
    final ProtocolSchedule schedule = REFERENCE_TEST_PROTOCOL_SCHEDULES.getByName(spec.getNetwork());
    final MutableBlockchain blockchain = spec.getBlockchain();
    final ProtocolContext context = spec.getProtocolContext();
    for (final BlockchainReferenceTestCaseSpec.CandidateBlock candidateBlock : spec.getCandidateBlocks()) {
        if (!candidateBlock.isExecutable()) {
            return;
        }
        try {
            final Block block = candidateBlock.getBlock();
            final ProtocolSpec protocolSpec = schedule.getByBlockNumber(block.getHeader().getNumber());
            final BlockImporter blockImporter = protocolSpec.getBlockImporter();
            final HeaderValidationMode validationMode = "NoProof".equalsIgnoreCase(spec.getSealEngine()) ? HeaderValidationMode.LIGHT : HeaderValidationMode.FULL;
            final boolean imported = blockImporter.importBlock(context, block, validationMode, validationMode);
            assertThat(imported).isEqualTo(candidateBlock.isValid());
        } catch (final RLPException e) {
            assertThat(candidateBlock.isValid()).isFalse();
        }
    }
    Assertions.assertThat(blockchain.getChainHeadHash()).isEqualTo(spec.getLastBlockHash());
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter) BlockchainReferenceTestCaseSpec(org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) RLPException(org.hyperledger.besu.ethereum.rlp.RLPException) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) HeaderValidationMode(org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode)

Aggregations

ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)1 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 HeaderValidationMode (org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1 ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)1 BlockchainReferenceTestCaseSpec (org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec)1 RLPException (org.hyperledger.besu.ethereum.rlp.RLPException)1