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