Search in sources :

Example 31 with Repository

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();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 32 with Repository

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();
}
Also used : Repository(org.ethereum.core.Repository) Test(org.junit.Test)

Example 33 with Repository

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();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 34 with Repository

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();
}
Also used : Repository(org.ethereum.core.Repository) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 35 with Repository

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));
}
Also used : Repository(org.ethereum.core.Repository) RskAddress(co.rsk.core.RskAddress) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Aggregations

Repository (org.ethereum.core.Repository)136 Test (org.junit.Test)109 RskAddress (co.rsk.core.RskAddress)59 DataWord (org.ethereum.vm.DataWord)43 BigInteger (java.math.BigInteger)31 RepositoryImpl (co.rsk.db.RepositoryImpl)25 Coin (co.rsk.core.Coin)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 HashMapDB (org.ethereum.datasource.HashMapDB)12 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)11 Transaction (org.ethereum.core.Transaction)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)10 ArrayList (java.util.ArrayList)10 Program (org.ethereum.vm.program.Program)10 Block (org.ethereum.core.Block)9 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)9 RskSystemProperties (co.rsk.config.RskSystemProperties)8 IOException (java.io.IOException)8 List (java.util.List)8