Search in sources :

Example 1 with WorldUpdater

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());
}
Also used : WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Gas(org.hyperledger.besu.evm.Gas) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Wei(org.hyperledger.besu.datatypes.Wei) Code(org.hyperledger.besu.evm.Code) Test(org.junit.jupiter.api.Test)

Example 2 with WorldUpdater

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;
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) MessageFrameTestFixture(org.hyperledger.besu.ethereum.core.MessageFrameTestFixture) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Example 3 with WorldUpdater

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;
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) WrappedEvmAccount(org.hyperledger.besu.evm.worldstate.WrappedEvmAccount) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount)

Example 4 with WorldUpdater

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());
}
Also used : WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) KeyValueStorageTransaction(org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) Test(org.junit.Test)

Example 5 with WorldUpdater

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;
}
Also used : WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) HashMap(java.util.HashMap) Map(java.util.Map) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Aggregations

WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)72 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)37 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)33 Test (org.junit.Test)33 TransactionProcessingResult (org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)16 Wei (org.hyperledger.besu.datatypes.Wei)14 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)14 Address (org.hyperledger.besu.datatypes.Address)13 ArrayList (java.util.ArrayList)12 Hash (org.hyperledger.besu.datatypes.Hash)12 Transaction (org.hyperledger.besu.ethereum.core.Transaction)12 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)11 Bytes (org.apache.tuweni.bytes.Bytes)9 Bytes32 (org.apache.tuweni.bytes.Bytes32)9 BlockHashLookup (org.hyperledger.besu.ethereum.vm.BlockHashLookup)9 UInt256 (org.apache.tuweni.units.bigints.UInt256)8 ProcessableBlockHeader (org.hyperledger.besu.ethereum.core.ProcessableBlockHeader)8 Code (org.hyperledger.besu.evm.Code)8 Account (org.hyperledger.besu.evm.account.Account)8 Map (java.util.Map)6