use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class DefaultMutableWorldStateTest method revert.
@Test
public void revert() {
final MutableWorldState worldState = createEmpty();
final WorldUpdater updater1 = worldState.updater();
final MutableAccount account1 = updater1.createAccount(ADDRESS).getMutable();
account1.setBalance(Wei.of(200000));
updater1.commit();
final WorldUpdater updater2 = worldState.updater();
final MutableAccount account2 = updater2.getAccount(ADDRESS).getMutable();
account2.setBalance(Wei.of(300000));
assertThat(updater2.get(ADDRESS).getBalance()).isEqualTo(Wei.of(300000));
updater2.revert();
assertThat(updater2.get(ADDRESS).getBalance()).isEqualTo(Wei.of(200000));
updater2.commit();
assertThat(worldState.get(ADDRESS).getBalance()).isEqualTo(Wei.of(200000));
assertThat(worldState.rootHash()).isEqualTo(Hash.fromHexString("0xbfa4e0598cc2b810a8ccc4a2d9a4c575574d05c9c4a7f915e6b8545953a5051e"));
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class DefaultMutableWorldStateTest method getAccountNonce_AccountExists.
@Test
public void getAccountNonce_AccountExists() {
final MutableWorldState worldState = createEmpty();
final WorldUpdater updater = worldState.updater();
updater.createAccount(ADDRESS).getMutable().setNonce(1L);
updater.commit();
assertThat(worldState.get(ADDRESS).getNonce()).isEqualTo(1L);
assertThat(worldState.rootHash()).isEqualTo(Hash.fromHexString("0x9648b05cc2eef5513ae2edfe16bfcedb3d1c60ffb5dff3fc501bd3e4ae39f536"));
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class DefaultMutableWorldStateTest method setStorageValue_NonzeroValue.
@Test
public void setStorageValue_NonzeroValue() {
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));
updater.commit();
assertThat(worldState.get(ADDRESS).getStorageValue(UInt256.ONE)).isEqualTo(UInt256.valueOf(2));
assertThat(worldState.rootHash()).isEqualTo(Hash.fromHexString("0xd31ce0bf3bf8790083a8ebde418244fda3b1cca952d7119ed244f86d03044656"));
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class DefaultMutableWorldStateTest method getAccountBalance_AccountExists.
@Test
public void getAccountBalance_AccountExists() {
final MutableWorldState worldState = createEmpty();
final WorldUpdater updater = worldState.updater();
updater.createAccount(ADDRESS).getMutable().setBalance(Wei.of(100000));
updater.commit();
assertThat(worldState.get(ADDRESS).getBalance()).isEqualTo(Wei.of(100000));
}
use of org.hyperledger.besu.evm.worldstate.WorldUpdater in project besu by hyperledger.
the class DefaultMutableWorldStateTest method replaceAccountCode.
@Test
public void replaceAccountCode() {
final MutableWorldState worldState = createEmpty();
final WorldUpdater updater = worldState.updater();
final MutableAccount account = updater.createAccount(ADDRESS).getMutable();
account.setBalance(Wei.of(100000));
account.setCode(Bytes.of(1, 2, 3));
account.setCode(Bytes.of(3, 2, 1));
updater.commit();
assertThat(worldState.get(ADDRESS).getCode()).isEqualTo(Bytes.of(3, 2, 1));
assertThat(worldState.rootHash()).isEqualTo(Hash.fromHexString("0xc14f5e30581de9155ea092affa665fad83bcd9f98e45c4a42885b9b36d939702"));
}
Aggregations