use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project hedera-services by hashgraph.
the class CallEvmTxProcessorTest 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 = callEvmTxProcessor.buildInitialFrame(commonInitialFrame, worldState.updater(), (Address) transaction.getTo().get(), Bytes.EMPTY);
// expect:
assertEquals(transaction.getSender(), buildMessageFrame.getSenderAddress());
assertEquals(transaction.getValue(), buildMessageFrame.getApparentValue());
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater 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;
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class PrivacyBlockProcessorTest method mockPrivateStateArchive.
private MutableWorldState mockPrivateStateArchive() {
final MutableWorldState mockPrivateState = mock(MutableWorldState.class);
final WorldUpdater mockWorldUpdater = mock(WorldUpdater.class);
final WrappedEvmAccount mockWrappedEvmAccount = mock(WrappedEvmAccount.class);
final MutableAccount mockMutableAccount = mock(MutableAccount.class);
when(mockWrappedEvmAccount.getMutable()).thenReturn(mockMutableAccount);
when(mockWorldUpdater.createAccount(any())).thenReturn(mockWrappedEvmAccount);
when(mockPrivateState.updater()).thenReturn(mockWorldUpdater);
when(mockPrivateState.rootHash()).thenReturn(Hash.ZERO);
return mockPrivateState;
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class LogRollingTests method rollBackOnce.
@Test
public void rollBackOnce() {
final BonsaiPersistedWorldState worldState = new BonsaiPersistedWorldState(archive, new BonsaiWorldStateKeyValueStorage(accountStorage, codeStorage, storageStorage, trieBranchStorage, trieLogStorage));
final WorldUpdater updater = worldState.updater();
final MutableAccount mutableAccount = updater.createAccount(addressOne, 1, Wei.of(1L)).getMutable();
mutableAccount.setCode(Bytes.of(0, 1, 2));
mutableAccount.setStorageValue(UInt256.ONE, UInt256.ONE);
updater.commit();
worldState.persist(headerOne);
final WorldUpdater updater2 = worldState.updater();
final MutableAccount mutableAccount2 = updater2.getAccount(addressOne).getMutable();
mutableAccount2.setStorageValue(UInt256.ONE, UInt256.valueOf(2));
updater2.commit();
worldState.persist(headerTwo);
final BonsaiWorldStateUpdater firstRollbackUpdater = (BonsaiWorldStateUpdater) worldState.updater();
final TrieLogLayer layerTwo = getTrieLogLayer(trieLogStorage, headerTwo.getHash());
firstRollbackUpdater.rollBack(layerTwo);
worldState.persist(headerOne);
final BonsaiPersistedWorldState secondWorldState = new BonsaiPersistedWorldState(secondArchive, new BonsaiWorldStateKeyValueStorage(secondAccountStorage, secondCodeStorage, secondStorageStorage, secondTrieBranchStorage, secondTrieLogStorage));
final WorldUpdater secondUpdater = secondWorldState.updater();
final MutableAccount secondMutableAccount = secondUpdater.createAccount(addressOne, 1, Wei.of(1L)).getMutable();
secondMutableAccount.setCode(Bytes.of(0, 1, 2));
secondMutableAccount.setStorageValue(UInt256.ONE, UInt256.ONE);
secondUpdater.commit();
secondWorldState.persist(null);
assertKeyValueStorageEqual(accountStorage, secondAccountStorage);
assertKeyValueStorageEqual(codeStorage, secondCodeStorage);
assertKeyValueStorageEqual(storageStorage, secondStorageStorage);
final KeyValueStorageTransaction tx = trieBranchStorage.startTransaction();
tx.remove(BonsaiWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY);
tx.commit();
assertKeyValueStorageEqual(trieBranchStorage, secondTrieBranchStorage);
// trie logs won't be the same, we don't delete the roll back log
assertKeyValueSubset(trieLogStorage, secondTrieLogStorage);
assertThat(secondWorldState.rootHash()).isEqualByComparingTo(worldState.rootHash());
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class ReferenceTestWorldState method create.
@JsonCreator
public static ReferenceTestWorldState create(final Map<String, AccountMock> accounts) {
final ReferenceTestWorldState worldState = new ReferenceTestWorldState();
final WorldUpdater updater = worldState.updater();
for (final Map.Entry<String, AccountMock> entry : accounts.entrySet()) {
insertAccount(updater, Address.fromHexString(entry.getKey()), entry.getValue());
}
updater.commit();
return worldState;
}
Aggregations