use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class GeneralStateReferenceTestTools method executeTest.
public static void executeTest(final GeneralStateTestCaseEipSpec spec) {
final BlockHeader blockHeader = spec.getBlockHeader();
final WorldState initialWorldState = spec.getInitialWorldState();
final Transaction transaction = spec.getTransaction();
// will handle the case where we receive the TXs in a serialized form.
if (transaction == null) {
assertThat(spec.getExpectException()).withFailMessage("Transaction was not assembled, but no exception was expected").isNotNull();
return;
}
final MutableWorldState worldState = new DefaultMutableWorldState(initialWorldState);
// `TransactionProcessor`, so these tests are skipped.
if (transaction.getGasLimit() > blockHeader.getGasLimit() - blockHeader.getGasUsed()) {
return;
}
final MainnetTransactionProcessor processor = transactionProcessor(spec.getFork());
final WorldUpdater worldStateUpdater = worldState.updater();
final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(blockHeader.getNumber());
final TransactionProcessingResult result = processor.processTransaction(blockchain, worldStateUpdater, blockHeader, transaction, blockHeader.getCoinbase(), new BlockHashLookup(blockHeader, blockchain), false, TransactionValidationParams.processingBlock());
if (!result.isInvalid()) {
final Account coinbase = worldStateUpdater.getOrCreate(spec.getBlockHeader().getCoinbase());
if (coinbase != null && coinbase.isEmpty() && shouldClearEmptyAccounts(spec.getFork())) {
worldStateUpdater.deleteAccount(coinbase.getAddress());
}
worldStateUpdater.commit();
}
// Check the world state root hash.
final Hash expectedRootHash = spec.getExpectedRootHash();
assertThat(worldState.rootHash()).withFailMessage("Unexpected world state root hash; expected state: %s, computed state: %s", spec.getExpectedRootHash(), worldState.rootHash()).isEqualTo(expectedRootHash);
// Check the logs.
final Hash expectedLogsHash = spec.getExpectedLogsHash();
Optional.ofNullable(expectedLogsHash).ifPresent(expected -> {
final List<Log> logs = result.getLogs();
assertThat(Hash.hash(RLP.encode(out -> out.writeList(logs, Log::writeTo)))).withFailMessage("Unmatched logs hash. Generated logs: %s", logs).isEqualTo(expected);
});
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project hedera-services by hashgraph.
the class CallLocalEvmTxProcessorTest method assertTransactionSenderAndValue.
@Test
void assertTransactionSenderAndValue() {
// setup:
doReturn(Optional.of(receiver.getId().asEvmAddress())).when(transaction).getTo();
given(worldState.updater()).willReturn(mock(HederaWorldState.Updater.class));
given(codeCache.getIfPresent(any())).willReturn(new Code());
given(transaction.getSender()).willReturn(sender.getId().asEvmAddress());
given(transaction.getValue()).willReturn(Wei.of(1L));
final MessageFrame.Builder commonInitialFrame = MessageFrame.builder().messageFrameStack(mock(Deque.class)).maxStackSize(MAX_STACK_SIZE).worldUpdater(mock(WorldUpdater.class)).initialGas(mock(Gas.class)).originator(sender.getId().asEvmAddress()).gasPrice(mock(Wei.class)).sender(sender.getId().asEvmAddress()).value(Wei.of(transaction.getValue().getAsBigInteger())).apparentValue(Wei.of(transaction.getValue().getAsBigInteger())).blockValues(mock(BlockValues.class)).depth(0).completer(__ -> {
}).miningBeneficiary(mock(Address.class)).blockHashLookup(h -> null);
// when:
MessageFrame buildMessageFrame = callLocalEvmTxProcessor.buildInitialFrame(commonInitialFrame, worldState.updater(), (Address) transaction.getTo().get(), Bytes.EMPTY);
// expect:
assertEquals(transaction.getSender(), buildMessageFrame.getSenderAddress());
assertEquals(transaction.getValue(), buildMessageFrame.getApparentValue());
}
Aggregations