Search in sources :

Example 1 with EnvironmentInformation

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

the class VMReferenceTest method runTest.

@Override
protected void runTest() {
    final MutableWorldState worldState = new DefaultMutableWorldState(spec.getInitialWorldState());
    final EnvironmentInformation execEnv = spec.getExec();
    final ProtocolSpec protocolSpec = MainnetProtocolSpecs.frontierDefinition(OptionalInt.empty(), OptionalInt.empty(), false, EvmConfiguration.DEFAULT).privacyParameters(PrivacyParameters.DEFAULT).privateTransactionValidatorBuilder(() -> new PrivateTransactionValidator(CHAIN_ID)).badBlocksManager(new BadBlockManager()).build(new MutableProtocolSchedule(CHAIN_ID));
    final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(execEnv.getBlockHeader().getNumber());
    final MessageFrame frame = MessageFrame.builder().type(MessageFrame.Type.MESSAGE_CALL).messageFrameStack(new ArrayDeque<>()).worldUpdater(worldState.updater()).initialGas(spec.getExec().getGas()).contract(execEnv.getAccountAddress()).address(execEnv.getAccountAddress()).originator(execEnv.getOriginAddress()).gasPrice(execEnv.getGasPrice()).inputData(execEnv.getData()).sender(execEnv.getCallerAddress()).value(execEnv.getValue()).apparentValue(execEnv.getValue()).code(execEnv.getCode()).blockValues(execEnv.getBlockHeader()).depth(execEnv.getDepth()).completer(c -> {
    }).miningBeneficiary(execEnv.getBlockHeader().getCoinbase()).blockHashLookup(new BlockHashLookup(execEnv.getBlockHeader(), blockchain)).maxStackSize(MessageFrame.DEFAULT_MAX_STACK_SIZE).build();
    // This is normally set inside the containing message executing the code.
    frame.setState(MessageFrame.State.CODE_EXECUTING);
    protocolSpec.getEvm().runToHalt(frame, OperationTracer.NO_TRACING);
    if (spec.isExceptionHaltExpected()) {
        assertThat(frame.getState() == MessageFrame.State.EXCEPTIONAL_HALT).withFailMessage("VM should have exceptionally halted").isTrue();
    } else {
        // This is normally performed when the message processor executing the VM
        // executes to completion successfully.
        frame.getWorldUpdater().commit();
        assertThat(frame.getState() == MessageFrame.State.EXCEPTIONAL_HALT).withFailMessage("VM should not have exceptionally halted with " + frame.getExceptionalHaltReason()).isFalse();
        assertThat(frame.getOutputData()).withFailMessage("VM output differs").isEqualTo(spec.getOut());
        assertThat(worldState.rootHash()).withFailMessage("Final world state differs").isEqualTo(spec.getFinalWorldState().rootHash());
        final Gas actualGas = frame.getRemainingGas();
        final Gas expectedGas = spec.getFinalGas();
        final Gas difference = (expectedGas.compareTo(actualGas) > 0) ? expectedGas.minus(actualGas) : actualGas.minus(expectedGas);
        assertThat(actualGas).withFailMessage("Final gas does not match, with difference of %s", difference).isEqualTo(expectedGas);
    }
}
Also used : MutableProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule) DefaultMutableWorldState(org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) DefaultMutableWorldState(org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState) Gas(org.hyperledger.besu.evm.Gas) EnvironmentInformation(org.hyperledger.besu.ethereum.referencetests.EnvironmentInformation) PrivateTransactionValidator(org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator) BadBlockManager(org.hyperledger.besu.ethereum.chain.BadBlockManager) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain)

Aggregations

BadBlockManager (org.hyperledger.besu.ethereum.chain.BadBlockManager)1 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 MutableProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule)1 ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)1 PrivateTransactionValidator (org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator)1 EnvironmentInformation (org.hyperledger.besu.ethereum.referencetests.EnvironmentInformation)1 ReferenceTestBlockchain (org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain)1 DefaultMutableWorldState (org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState)1 Gas (org.hyperledger.besu.evm.Gas)1 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)1