Search in sources :

Example 6 with AionContractDetailsImpl

use of org.aion.zero.db.AionContractDetailsImpl 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)

Aggregations

AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)6 DataWord (org.aion.mcf.vm.types.DataWord)5 Test (org.junit.Test)5 Address (org.aion.base.type.Address)4 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)3 HashMap (java.util.HashMap)2 IContractDetails (org.aion.base.db.IContractDetails)1 IRepositoryCache (org.aion.base.db.IRepositoryCache)1