Search in sources :

Example 26 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test16_4.

@Test
public void test16_4() {
    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();
    Repository track = repository.startTracking();
    track.addStorageRow(COW, new DataWord(cowKey1), new DataWord(cowValue1));
    track.commit();
    // changes level_1
    Repository track1 = repository.startTracking();
    // changes level_2
    Repository track2 = track1.startTracking();
    track2.addStorageRow(COW, new DataWord(cowKey2), new DataWord(cowValue2));
    track2.commit();
    // leaving level_2
    track1.commit();
    // leaving level_1
    assertEquals(new DataWord(cowValue1), track1.getStorageValue(COW, new DataWord(cowKey1)));
    assertEquals(new DataWord(cowValue2), track1.getStorageValue(COW, new DataWord(cowKey2)));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 27 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test5.

@Test
public void test5() {
    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);
    track.commit();
    assertEquals(BigInteger.TEN, repository.getNonce(COW));
    assertEquals(BigInteger.ONE, repository.getNonce(HORSE));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) Test(org.junit.Test)

Example 28 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test11.

@Test
public void test11() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    byte[] cowCode = Hex.decode("A1A2A3");
    byte[] horseCode = Hex.decode("B1B2B3");
    track.saveCode(COW, cowCode);
    track.saveCode(HORSE, horseCode);
    assertArrayEquals(cowCode, track.getCode(COW));
    assertArrayEquals(horseCode, track.getCode(HORSE));
    track.commit();
    assertArrayEquals(cowCode, repository.getCode(COW));
    assertArrayEquals(horseCode, repository.getCode(HORSE));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) Test(org.junit.Test)

Example 29 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test12.

@Test
public void test12() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    byte[] cowCode = Hex.decode("A1A2A3");
    byte[] horseCode = Hex.decode("B1B2B3");
    track.saveCode(COW, cowCode);
    track.saveCode(HORSE, horseCode);
    assertArrayEquals(cowCode, track.getCode(COW));
    assertArrayEquals(horseCode, track.getCode(HORSE));
    track.rollback();
    assertArrayEquals(EMPTY_BYTE_ARRAY, repository.getCode(COW));
    assertArrayEquals(EMPTY_BYTE_ARRAY, repository.getCode(HORSE));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) Test(org.junit.Test)

Example 30 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test7.

@Test
public void test7() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    track.addBalance(COW, Coin.valueOf(10L));
    track.addBalance(HORSE, Coin.valueOf(1L));
    assertEquals(BigInteger.TEN, track.getBalance(COW).asBigInteger());
    assertEquals(BigInteger.ONE, track.getBalance(HORSE).asBigInteger());
    track.commit();
    assertEquals(BigInteger.TEN, repository.getBalance(COW).asBigInteger());
    assertEquals(BigInteger.ONE, repository.getBalance(HORSE).asBigInteger());
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) 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