Search in sources :

Example 1 with BlockHeaderTestFixture

use of org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture in project besu by hyperledger.

the class SStoreOperationTest method createMessageFrame.

private MessageFrame createMessageFrame(final Address address, final Gas initialGas, final Gas remainingGas) {
    final Blockchain blockchain = mock(Blockchain.class);
    final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
    final WorldUpdater worldStateUpdater = worldStateArchive.getMutable().updater();
    final BlockHeader blockHeader = new BlockHeaderTestFixture().buildHeader();
    final MessageFrame frame = new MessageFrameTestFixture().address(address).worldUpdater(worldStateUpdater).blockHeader(blockHeader).blockchain(blockchain).initialGas(initialGas).build();
    worldStateUpdater.getOrCreate(address).getMutable().setBalance(Wei.of(1));
    worldStateUpdater.commit();
    frame.setGasRemaining(remainingGas);
    return frame;
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) MessageFrameTestFixture(org.hyperledger.besu.ethereum.core.MessageFrameTestFixture) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Example 2 with BlockHeaderTestFixture

use of org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture in project besu by hyperledger.

the class PkiQbftBlockCreatorTest method before.

@Before
public void before() {
    blockCreator = mock(BlockCreator.class);
    cmsCreator = mock(CmsCreator.class);
    pkiQbftBlockCreator = new PkiQbftBlockCreator(blockCreator, cmsCreator, extraDataCodec);
    blockHeaderBuilder = new BlockHeaderTestFixture();
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) BlockCreator(org.hyperledger.besu.ethereum.blockcreation.BlockCreator) CmsCreator(org.hyperledger.besu.pki.cms.CmsCreator) Before(org.junit.Before)

Example 3 with BlockHeaderTestFixture

use of org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture in project besu by hyperledger.

the class QbftGetSignerMetricsTest method generateBlock.

private SignerMetricResult generateBlock(final long number) {
    final Address proposerAddressBlock = VALIDATORS[(int) (number % VALIDATORS.length)];
    final BlockHeader header = new BlockHeaderTestFixture().number(number).buildHeader();
    when(blockchainQueries.getBlockHeaderByNumber(number)).thenReturn(Optional.of(header));
    when(blockInterface.getProposerOfBlock(header)).thenReturn(proposerAddressBlock);
    when(validatorProvider.getValidatorsAfterBlock(header)).thenReturn(Arrays.asList(VALIDATORS));
    final SignerMetricResult signerMetricResult = new SignerMetricResult(proposerAddressBlock);
    signerMetricResult.incrementeNbBlock();
    signerMetricResult.setLastProposedBlockNumber(number);
    return signerMetricResult;
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Address(org.hyperledger.besu.datatypes.Address) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult)

Example 4 with BlockHeaderTestFixture

use of org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture in project besu by hyperledger.

the class QbftBlockHeaderUtils method createPresetHeaderBuilder.

public static BlockHeaderTestFixture createPresetHeaderBuilder(final long number, final NodeKey proposerNodeKey, final List<Address> validators, final BlockHeader parent, final HeaderModifier modifier, final Optional<Wei> baseFee) {
    final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
    final QbftExtraDataCodec qbftExtraDataEncoder = new QbftExtraDataCodec();
    populateDefaultBlockHeader(number, proposerNodeKey, parent, modifier, builder, qbftExtraDataEncoder, baseFee);
    final BftExtraData bftExtraData = BftExtraDataFixture.createExtraData(builder.buildHeader(), Bytes.wrap(new byte[BftExtraDataCodec.EXTRA_VANITY_LENGTH]), Optional.of(Vote.authVote(Address.fromHexString("1"))), validators, singletonList(proposerNodeKey), ROUND_NUMBER, qbftExtraDataEncoder);
    builder.extraData(qbftExtraDataEncoder.encode(bftExtraData));
    return builder;
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData)

Example 5 with BlockHeaderTestFixture

use of org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture in project besu by hyperledger.

the class AncestryValidationRuleTest method incrementingNumberAndLinkedHashesReturnTrue.

@Test
public void incrementingNumberAndLinkedHashesReturnTrue() {
    final AncestryValidationRule uut = new AncestryValidationRule();
    final BlockHeader parentHeader = new BlockHeaderTestFixture().buildHeader();
    final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
    headerBuilder.parentHash(parentHeader.getHash());
    headerBuilder.number(parentHeader.getNumber() + 1);
    final BlockHeader header = headerBuilder.buildHeader();
    assertThat(uut.validate(header, parentHeader)).isTrue();
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Aggregations

BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)188 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)157 Test (org.junit.Test)149 Hash (org.hyperledger.besu.datatypes.Hash)29 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)23 Address (org.hyperledger.besu.datatypes.Address)21 Block (org.hyperledger.besu.ethereum.core.Block)21 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)17 List (java.util.List)14 KeyPair (org.hyperledger.besu.crypto.KeyPair)13 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)12 EnginePayloadStatusResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult)12 Before (org.junit.Before)12 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)9 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)9 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)8 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)8 ArrayList (java.util.ArrayList)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 Bytes (org.apache.tuweni.bytes.Bytes)7