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);
}
}
Aggregations