Search in sources :

Example 21 with WorldUpdater

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"));
}
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 22 with WorldUpdater

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

Example 23 with WorldUpdater

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"));
}
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 24 with WorldUpdater

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

Example 25 with WorldUpdater

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