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)));
}
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);
}
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()));
}
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));
}
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));
}
Aggregations