Search in sources :

Example 6 with IRepositoryCache

use of org.aion.base.db.IRepositoryCache in project aion by aionnetwork.

the class AionRepositoryImplTest method testAccountStateUpdateStorageRowFlush.

@Test
public void testAccountStateUpdateStorageRowFlush() {
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    IRepositoryCache track = repository.startTracking();
    Address defaultAccount = Address.wrap(ByteUtil.hexStringToBytes("CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3"));
    track.addBalance(defaultAccount, BigInteger.valueOf(1));
    // Consider the original root the one after an account has been added
    byte[] originalRoot = repository.getRoot();
    byte[] key = HashUtil.blake128("hello".getBytes());
    byte[] value = HashUtil.blake128("world".getBytes());
    track.addStorageRow(defaultAccount, new DataWord(key), new DataWord(value));
    // does not call parent's flush
    track.flush();
    repository.flush();
    /**
     * Verify that the account has been flushed
     */
    IByteArrayKeyValueDatabase detailsDB = repository.getDetailsDatabase();
    Optional<byte[]> serializedDetails = detailsDB.get(defaultAccount.toBytes());
    assertThat(serializedDetails.isPresent()).isEqualTo(true);
    AionContractDetailsImpl details = new AionContractDetailsImpl(0, 1000000);
    details.decode(serializedDetails.get());
    assertThat(details.get(new DataWord(key))).isEqualTo(new DataWord(value));
}
Also used : Address(org.aion.base.type.Address) IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) IRepositoryCache(org.aion.base.db.IRepositoryCache) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) DataWord(org.aion.mcf.vm.types.DataWord) AionContractDetailsImpl(org.aion.zero.db.AionContractDetailsImpl) Test(org.junit.Test)

Example 7 with IRepositoryCache

use of org.aion.base.db.IRepositoryCache in project aion by aionnetwork.

the class AionRepositoryImplTest method testAccountAddCodeStorage.

@Test
public void testAccountAddCodeStorage() {
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    IRepositoryCache track = repository.startTracking();
    Address defaultAccount = Address.wrap(ByteUtil.hexStringToBytes("CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3"));
    track.addBalance(defaultAccount, BigInteger.valueOf(1));
    byte[] originalRoot = repository.getRoot();
    track.saveCode(defaultAccount, defaultAccount.toBytes());
    track.flush();
    byte[] newRoot = repository.getRoot();
    assertThat(newRoot).isNotEqualTo(originalRoot);
    assertThat(repository.getCode(defaultAccount)).isEqualTo(defaultAccount.toBytes());
    System.out.println(String.format("originalRoot: %s", ByteUtil.toHexString(originalRoot)));
    System.out.println(String.format("newRoot: %s", ByteUtil.toHexString(originalRoot)));
}
Also used : Address(org.aion.base.type.Address) IRepositoryCache(org.aion.base.db.IRepositoryCache) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) Test(org.junit.Test)

Example 8 with IRepositoryCache

use of org.aion.base.db.IRepositoryCache in project aion by aionnetwork.

the class AionRepositoryImplTest method testAccountStateUpdate.

@Test
public void testAccountStateUpdate() {
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    byte[] originalRoot = repository.getRoot();
    Address defaultAccount = Address.wrap(ByteUtil.hexStringToBytes("CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3"));
    IRepositoryCache track = repository.startTracking();
    track.addBalance(defaultAccount, BigInteger.valueOf(1));
    track.flush();
    byte[] newRoot = repository.getRoot();
    System.out.println(String.format("original root: %s", ByteUtil.toHexString(originalRoot)));
    System.out.println(String.format("new root: %s", ByteUtil.toHexString(newRoot)));
    assertThat(newRoot).isNotEqualTo(originalRoot);
}
Also used : Address(org.aion.base.type.Address) IRepositoryCache(org.aion.base.db.IRepositoryCache) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) Test(org.junit.Test)

Aggregations

IRepositoryCache (org.aion.base.db.IRepositoryCache)8 Address (org.aion.base.type.Address)8 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)7 Test (org.junit.Test)7 DataWord (org.aion.mcf.vm.types.DataWord)3 BigInteger (java.math.BigInteger)2 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)1 IEvent (org.aion.evtmgr.IEvent)1 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)1 AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)1 AionBlock (org.aion.zero.impl.types.AionBlock)1