Search in sources :

Example 11 with WorldUpdater

use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.

the class DefaultMutableWorldStateTest method streamAccounts_singleAccount.

@Test
public void streamAccounts_singleAccount() {
    final MutableWorldState worldState = createEmpty();
    final WorldUpdater updater = worldState.updater();
    updater.createAccount(ADDRESS).getMutable().setBalance(Wei.of(100000));
    updater.commit();
    List<StreamableAccount> accounts = worldState.streamAccounts(Bytes32.ZERO, 10).collect(Collectors.toList());
    assertThat(accounts.size()).isEqualTo(1L);
    assertThat(accounts.get(0).getAddress()).hasValue(ADDRESS);
    assertThat(accounts.get(0).getBalance()).isEqualTo(Wei.of(100000));
    // Check again after persisting
    worldState.persist(null);
    accounts = worldState.streamAccounts(Bytes32.ZERO, 10).collect(Collectors.toList());
    assertThat(accounts.size()).isEqualTo(1L);
    assertThat(accounts.get(0).getAddress()).hasValue(ADDRESS);
    assertThat(accounts.get(0).getBalance()).isEqualTo(Wei.of(100000));
}
Also used : StreamableAccount(org.hyperledger.besu.evm.worldstate.WorldState.StreamableAccount) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) Test(org.junit.Test)

Example 12 with WorldUpdater

use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.

the class DefaultMutableWorldStateTest method removeAccount_AccountDoesNotExist.

@Test
public void removeAccount_AccountDoesNotExist() {
    final MutableWorldState worldState = createEmpty();
    final WorldUpdater updater = worldState.updater();
    updater.deleteAccount(ADDRESS);
    updater.commit();
    assertThat(worldState.rootHash()).isEqualTo(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH);
    worldState.persist(null);
    assertThat(worldState.rootHash()).isEqualTo(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) Test(org.junit.Test)

Example 13 with WorldUpdater

use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.

the class DefaultMutableWorldStateTest method replaceStorageValue_ZeroValue.

@Test
public void replaceStorageValue_ZeroValue() {
    final MutableWorldState worldState = createEmpty();
    final WorldUpdater updater = worldState.updater();
    final MutableAccount account = updater.createAccount(ADDRESS).getMutable();
    account.setBalance(Wei.of(100000));
    account.setStorageValue(UInt256.ONE, UInt256.valueOf(2));
    account.setStorageValue(UInt256.ONE, UInt256.ZERO);
    updater.commit();
    assertThat(worldState.rootHash()).isEqualTo(Hash.fromHexString("0xa3e1c133a5a51b03399ed9ad0380f3182e9e18322f232b816dd4b9094f871e1b"));
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) Test(org.junit.Test)

Example 14 with WorldUpdater

use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.

the class DefaultMutableWorldStateTest method removeAccount_UpdatedAccount.

@Test
public void removeAccount_UpdatedAccount() {
    final MutableWorldState worldState = createEmpty();
    final WorldUpdater updater = worldState.updater();
    updater.createAccount(ADDRESS).getMutable().setBalance(Wei.of(100000));
    updater.deleteAccount(ADDRESS);
    updater.commit();
    assertThat(worldState.rootHash()).isEqualTo(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH);
    worldState.persist(null);
    assertThat(worldState.rootHash()).isEqualTo(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) Test(org.junit.Test)

Example 15 with WorldUpdater

use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.

the class DefaultMutableWorldStateTest method originalStorageValueIsAlwaysZeroIfStorageWasCleared.

@Test
public void originalStorageValueIsAlwaysZeroIfStorageWasCleared() {
    final MutableWorldState worldState = createEmpty();
    final WorldUpdater setupUpdater = worldState.updater();
    final MutableAccount setupAccount = setupUpdater.createAccount(ADDRESS).getMutable();
    setupAccount.setStorageValue(UInt256.ONE, UInt256.valueOf(2));
    setupUpdater.commit();
    final WorldUpdater updater = worldState.updater();
    final MutableAccount account = updater.getOrCreate(ADDRESS).getMutable();
    account.clearStorage();
    assertThat(account.getOriginalStorageValue(UInt256.ONE)).isEqualTo(UInt256.ZERO);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) Test(org.junit.Test)

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