Search in sources :

Example 36 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class AionRepositoryImplTest method testAccountStateUpdateStorageRow.

@Test
public void testAccountStateUpdateStorageRow() {
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    RepositoryCache track = repository.startTracking();
    AionAddress defaultAccount = new AionAddress(ByteUtil.hexStringToBytes(value1));
    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).toWrapper(), new DataWord(value).toWrapper());
    track.saveVmType(defaultAccount, InternalVmType.FVM);
    track.flushTo(repository, true);
    byte[] retrievedValue = repository.getStorageValue(defaultAccount, new DataWord(key).toWrapper()).getNoLeadZeroesData();
    assertThat(retrievedValue).isEqualTo(value);
    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)));
}
Also used : AionAddress(org.aion.types.AionAddress) RepositoryCache(org.aion.base.db.RepositoryCache) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 37 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class AionRepositoryImplTest method testRepoTrackUpdateStorageRow.

/**
 * Repo track test suite
 */
/**
 * This test confirms that updates done on the repo track are successfully translated into the
 * root repository.
 */
@Test
public void testRepoTrackUpdateStorageRow() {
    final AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    final RepositoryCache repoTrack = repository.startTracking();
    final AionAddress defaultAccount = new AionAddress(ByteUtil.hexStringToBytes(value1));
    final byte[] key = HashUtil.blake128("hello".getBytes());
    final byte[] value = HashUtil.blake128("world".getBytes());
    repoTrack.addBalance(defaultAccount, BigInteger.valueOf(1));
    final byte[] originalRoot = repository.getRoot();
    repoTrack.addStorageRow(defaultAccount, new DataWord(key).toWrapper(), new DataWord(value).toWrapper());
    repoTrack.saveVmType(defaultAccount, InternalVmType.FVM);
    ByteArrayWrapper retrievedStorageValue = repoTrack.getStorageValue(defaultAccount, new DataWord(key).toWrapper());
    assertThat(retrievedStorageValue).isEqualTo(new DataWord(value).toWrapper());
    // commit changes, then check that the root has updated
    repoTrack.flushTo(repository, true);
    assertThat(repository.getStorageValue(defaultAccount, new DataWord(key).toWrapper())).isEqualTo(retrievedStorageValue);
    final byte[] newRoot = repository.getRoot();
    assertThat(newRoot).isNotEqualTo(originalRoot);
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) RepositoryCache(org.aion.base.db.RepositoryCache) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 38 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class AionRepositoryCacheTest method testGetStorageValueWithSingleZeroKey.

@Test
public void testGetStorageValueWithSingleZeroKey() {
    AionAddress address = getNewAddress();
    ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    cache.addStorageRow(address, DataWord.ZERO.toWrapper(), value);
    assertEquals(value, cache.getStorageValue(address, DataWord.ZERO.toWrapper()));
    value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
    cache.addStorageRow(address, DataWord.ZERO.toWrapper(), value);
    assertEquals(value, cache.getStorageValue(address, DataWord.ZERO.toWrapper()));
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 39 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class AionRepositoryCacheTest method testOverwriteValueWithSingleZero.

@Test
public void testOverwriteValueWithSingleZero() {
    AionAddress address = getNewAddress();
    ByteArrayWrapper key = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    ByteArrayWrapper value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
    cache.addStorageRow(address, key, value);
    assertEquals(value, cache.getStorageValue(address, key));
    cache.removeStorageRow(address, key);
    assertNull(cache.getStorageValue(address, key));
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 40 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class AionRepositoryCacheTest method testGetStorageValueWithDoubleZeroKey.

@Test
public void testGetStorageValueWithDoubleZeroKey() {
    AionAddress address = getNewAddress();
    ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    cache.addStorageRow(address, ZERO_WRAPPED_32, value);
    assertEquals(value, cache.getStorageValue(address, ZERO_WRAPPED_32));
    value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
    cache.addStorageRow(address, ZERO_WRAPPED_32, value);
    assertEquals(value, cache.getStorageValue(address, ZERO_WRAPPED_32));
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Aggregations

DataWord (org.aion.util.types.DataWord)49 Test (org.junit.Test)37 AionAddress (org.aion.types.AionAddress)36 AionTransaction (org.aion.base.AionTransaction)29 BigInteger (java.math.BigInteger)23 RepositoryCache (org.aion.base.db.RepositoryCache)23 AionTxExecSummary (org.aion.base.AionTxExecSummary)18 MiningBlock (org.aion.zero.impl.types.MiningBlock)14 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)12 BlockContext (org.aion.zero.impl.types.BlockContext)12 ECKey (org.aion.crypto.ECKey)7 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)7 Log (org.aion.types.Log)4 HashMap (java.util.HashMap)3 AionTxReceipt (org.aion.base.AionTxReceipt)3 ImportResult (org.aion.zero.impl.core.ImportResult)3 Map (java.util.Map)2 InternalTransaction (org.aion.types.InternalTransaction)2 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)2 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)2