Search in sources :

Example 1 with ReferenceTestBlockchain

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

the class GoQuorumBlockProcessorTest method noAccountCreatedWhenBlockRewardIsZeroAndSkipped.

@Test
public void noAccountCreatedWhenBlockRewardIsZeroAndSkipped() {
    final Blockchain blockchain = new ReferenceTestBlockchain();
    final GoQuorumBlockProcessor blockProcessor = new GoQuorumBlockProcessor(transactionProcessor, transactionReceiptFactory, Wei.ZERO, BlockHeader::getCoinbase, true, Optional.of(goQuorumPrivacyParameters));
    final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());
    final Hash initialHash = worldState.rootHash();
    final BlockHeader emptyBlockHeader = new BlockHeaderTestFixture().transactionsRoot(Hash.EMPTY_LIST_HASH).ommersHash(Hash.EMPTY_LIST_HASH).buildHeader();
    blockProcessor.processBlock(blockchain, worldState, emptyBlockHeader, emptyList(), emptyList());
    // An empty block with 0 reward should not change the world state
    assertThat(worldState.rootHash()).isEqualTo(initialHash);
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Test(org.junit.Test)

Example 2 with ReferenceTestBlockchain

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

the class GoQuorumBlockProcessorTest method accountCreatedWhenBlockRewardIsZeroAndNotSkipped.

@Test
public void accountCreatedWhenBlockRewardIsZeroAndNotSkipped() {
    final Blockchain blockchain = new ReferenceTestBlockchain();
    final GoQuorumBlockProcessor blockProcessor = new GoQuorumBlockProcessor(transactionProcessor, transactionReceiptFactory, Wei.ZERO, BlockHeader::getCoinbase, false, Optional.of(goQuorumPrivacyParameters));
    final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());
    final Hash initialHash = worldState.rootHash();
    final BlockHeader emptyBlockHeader = new BlockHeaderTestFixture().transactionsRoot(Hash.EMPTY_LIST_HASH).ommersHash(Hash.EMPTY_LIST_HASH).buildHeader();
    blockProcessor.processBlock(blockchain, worldState, emptyBlockHeader, emptyList(), emptyList());
    // An empty block with 0 reward should change the world state prior to EIP158
    assertThat(worldState.rootHash()).isNotEqualTo(initialHash);
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Test(org.junit.Test)

Example 3 with ReferenceTestBlockchain

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

the class MainnetBlockProcessorTest method accountCreatedWhenBlockRewardIsZeroAndNotSkipped.

@Test
public void accountCreatedWhenBlockRewardIsZeroAndNotSkipped() {
    final Blockchain blockchain = new ReferenceTestBlockchain();
    final MainnetBlockProcessor blockProcessor = new MainnetBlockProcessor(transactionProcessor, transactionReceiptFactory, Wei.ZERO, BlockHeader::getCoinbase, false, Optional.empty());
    final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());
    final Hash initialHash = worldState.rootHash();
    final BlockHeader emptyBlockHeader = new BlockHeaderTestFixture().transactionsRoot(Hash.EMPTY_LIST_HASH).ommersHash(Hash.EMPTY_LIST_HASH).buildHeader();
    blockProcessor.processBlock(blockchain, worldState, emptyBlockHeader, emptyList(), emptyList());
    // An empty block with 0 reward should change the world state prior to EIP158
    assertThat(worldState.rootHash()).isNotEqualTo(initialHash);
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Test(org.junit.Test)

Example 4 with ReferenceTestBlockchain

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

the class DebugOperationTracerTest method validMessageFrameBuilder.

private MessageFrameTestFixture validMessageFrameBuilder() {
    final BlockHeader blockHeader = new BlockHeaderTestFixture().number(1).buildHeader();
    final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(blockHeader.getNumber());
    return new MessageFrameTestFixture().initialGas(INITIAL_GAS).worldUpdater(worldUpdater).gasPrice(Wei.of(25)).blockHeader(blockHeader).blockchain(blockchain).depth(DEPTH);
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) MessageFrameTestFixture(org.hyperledger.besu.ethereum.core.MessageFrameTestFixture) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain)

Example 5 with ReferenceTestBlockchain

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

the class GoQuorumBlockProcessorTest method enclaveNotAvailable.

@Test
public void enclaveNotAvailable() {
    final Blockchain blockchain = new ReferenceTestBlockchain();
    final GoQuorumBlockProcessor blockProcessor = new GoQuorumBlockProcessor(transactionProcessor, transactionReceiptFactory, Wei.ZERO, BlockHeader::getCoinbase, false, Optional.of(goQuorumPrivacyParameters));
    final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());
    final Block block = mock(Block.class);
    final BlockHeader blockHeader = mock(BlockHeader.class);
    final BlockBody blockBody = mock(BlockBody.class);
    final Transaction transaction = mock(Transaction.class);
    when(transaction.getGasLimit()).thenReturn(1000L);
    when(transaction.isGoQuorumPrivateTransaction(true)).thenReturn(true);
    when(transaction.getPayload()).thenReturn(Bytes.wrap(new byte[] { (byte) 1 }));
    when(block.getBody()).thenReturn(blockBody);
    when(blockBody.getTransactions()).thenReturn(Collections.singletonList(transaction));
    when(blockBody.getOmmers()).thenReturn(Collections.emptyList());
    when(blockHeader.getNumber()).thenReturn(20000L);
    when(blockHeader.getGasLimit()).thenReturn(20000L);
    when(block.getHeader()).thenReturn(blockHeader);
    when(goQuorumEnclave.receive(any())).thenThrow(new EnclaveServerException(1, "a"));
    when(transactionProcessor.getTransactionValidator()).thenReturn(transactionValidator);
    when(transactionValidator.getGoQuorumCompatibilityMode()).thenReturn(true);
    assertThatThrownBy(() -> blockProcessor.processBlock(blockchain, worldState, worldState, block)).isExactlyInstanceOf(EnclaveServerException.class).hasMessageContaining("a");
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) Transaction(org.hyperledger.besu.ethereum.core.Transaction) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) EnclaveServerException(org.hyperledger.besu.enclave.EnclaveServerException) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Block(org.hyperledger.besu.ethereum.core.Block) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain) Test(org.junit.Test)

Aggregations

ReferenceTestBlockchain (org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain)9 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)8 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)8 Hash (org.hyperledger.besu.datatypes.Hash)6 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)5 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)5 Test (org.junit.Test)5 Transaction (org.hyperledger.besu.ethereum.core.Transaction)3 DefaultMutableWorldState (org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState)3 MainnetTransactionProcessor (org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor)2 TransactionProcessingResult (org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)2 Account (org.hyperledger.besu.evm.account.Account)2 Log (org.hyperledger.besu.evm.log.Log)2 WorldState (org.hyperledger.besu.evm.worldstate.WorldState)2 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)2 Feature (com.fasterxml.jackson.core.JsonParser.Feature)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1