use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RepositoryImplOriginalTest method test16_2.
@Test
public void test16_2() {
Repository repository = new RepositoryImpl(config);
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
// changes level_1
Repository track1 = repository.startTracking();
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageRow(COW, new DataWord(cowKey2), new DataWord(cowValue2));
track2.addStorageRow(HORSE, new DataWord(horseKey2), new DataWord(horseValue2));
assertNull(track2.getStorageValue(COW, new DataWord(cowKey1)));
assertNull(track2.getStorageValue(HORSE, new DataWord(horseKey1)));
assertEquals(new DataWord(cowValue2), track2.getStorageValue(COW, new DataWord(cowKey2)));
assertEquals(new DataWord(horseValue2), track2.getStorageValue(HORSE, new DataWord(horseKey2)));
track2.commit();
// leaving level_2
assertNull(track1.getStorageValue(COW, new DataWord(cowKey1)));
assertNull(track1.getStorageValue(HORSE, new DataWord(horseKey1)));
assertEquals(new DataWord(cowValue2), track1.getStorageValue(COW, new DataWord(cowKey2)));
assertEquals(new DataWord(horseValue2), track1.getStorageValue(HORSE, new DataWord(horseKey2)));
track1.commit();
// leaving level_1
assertEquals(null, repository.getStorageValue(COW, new DataWord(cowKey1)));
assertEquals(null, repository.getStorageValue(HORSE, new DataWord(horseKey1)));
assertEquals(new DataWord(cowValue2), repository.getStorageValue(COW, new DataWord(cowKey2)));
assertEquals(new DataWord(horseValue2), repository.getStorageValue(HORSE, new DataWord(horseKey2)));
repository.close();
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RepositoryImplOriginalTest method test6.
@Test
public void test6() {
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(COW);
track.increaseNonce(HORSE);
assertEquals(BigInteger.TEN, track.getNonce(COW));
assertEquals(BigInteger.ONE, track.getNonce(HORSE));
track.rollback();
assertEquals(BigInteger.ZERO, repository.getNonce(COW));
assertEquals(BigInteger.ZERO, repository.getNonce(HORSE));
repository.close();
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RepositoryImplOriginalTest method test16.
@Test
public void test16() {
Repository repository = new RepositoryImpl(config);
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
// changes level_1
Repository track1 = repository.startTracking();
track1.addStorageRow(COW, new DataWord(cowKey1), new DataWord(cowValue1));
track1.addStorageRow(HORSE, new DataWord(horseKey1), new DataWord(horseValue1));
assertEquals(new DataWord(cowValue1), track1.getStorageValue(COW, new DataWord(cowKey1)));
assertEquals(new DataWord(horseValue1), track1.getStorageValue(HORSE, new DataWord(horseKey1)));
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageRow(COW, new DataWord(cowKey2), new DataWord(cowValue2));
track2.addStorageRow(HORSE, new DataWord(horseKey2), new DataWord(horseValue2));
assertEquals(new DataWord(cowValue1), track2.getStorageValue(COW, new DataWord(cowKey1)));
assertEquals(new DataWord(horseValue1), track2.getStorageValue(HORSE, new DataWord(horseKey1)));
assertEquals(new DataWord(cowValue2), track2.getStorageValue(COW, new DataWord(cowKey2)));
assertEquals(new DataWord(horseValue2), track2.getStorageValue(HORSE, new DataWord(horseKey2)));
track2.commit();
// leaving level_2
assertEquals(new DataWord(cowValue1), track1.getStorageValue(COW, new DataWord(cowKey1)));
assertEquals(new DataWord(horseValue1), track1.getStorageValue(HORSE, new DataWord(horseKey1)));
assertEquals(new DataWord(cowValue2), track1.getStorageValue(COW, new DataWord(cowKey2)));
assertEquals(new DataWord(horseValue2), track1.getStorageValue(HORSE, new DataWord(horseKey2)));
track1.commit();
// leaving level_1
assertEquals(new DataWord(cowValue1), repository.getStorageValue(COW, new DataWord(cowKey1)));
assertEquals(new DataWord(horseValue1), repository.getStorageValue(HORSE, new DataWord(horseKey1)));
assertEquals(new DataWord(cowValue2), repository.getStorageValue(COW, new DataWord(cowKey2)));
assertEquals(new DataWord(horseValue2), repository.getStorageValue(HORSE, new DataWord(horseKey2)));
repository.close();
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RepositoryImplOriginalTest method test7_1.
@Test
public void test7_1() {
Repository repository = new RepositoryImpl(config);
Repository track1 = repository.startTracking();
track1.addBalance(COW, Coin.valueOf(10L));
track1.addBalance(HORSE, Coin.valueOf(1L));
assertEquals(BigInteger.TEN, track1.getBalance(COW).asBigInteger());
assertEquals(BigInteger.ONE, track1.getBalance(HORSE).asBigInteger());
Repository track2 = track1.startTracking();
assertEquals(BigInteger.TEN, track2.getBalance(COW).asBigInteger());
assertEquals(BigInteger.ONE, track2.getBalance(HORSE).asBigInteger());
track2.addBalance(COW, Coin.valueOf(10L));
track2.addBalance(COW, Coin.valueOf(10L));
track2.addBalance(COW, Coin.valueOf(10L));
track2.commit();
track1.commit();
assertEquals(new BigInteger("40"), repository.getBalance(COW).asBigInteger());
assertEquals(BigInteger.ONE, repository.getBalance(HORSE).asBigInteger());
repository.close();
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RepositoryImplTest method createAccountInTrackAndRollback.
@Test
public void createAccountInTrackAndRollback() {
RskAddress accAddress = randomAccountAddress();
RepositoryImpl repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
Assert.assertNotNull(track);
track.createAccount(accAddress);
track.rollback();
Assert.assertFalse(repository.isExist(accAddress));
}
Aggregations