Search in sources :

Example 96 with Repository

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

the class RepositoryImplOriginalTest method test1.

@Test
public void test1() {
    Repository repository = new RepositoryImpl(config);
    repository.increaseNonce(COW);
    repository.increaseNonce(HORSE);
    assertEquals(BigInteger.ONE, repository.getNonce(COW));
    repository.increaseNonce(COW);
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) Test(org.junit.Test)

Example 97 with Repository

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

the class RepositoryImplOriginalTest method test16_5.

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

Example 98 with Repository

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

the class RepositoryImplOriginalTest method test3.

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

Example 99 with Repository

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

the class RepositoryImplOriginalTest method test4.

@Test
public void test4() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    byte[] cowKey = Hex.decode("A1A2A3");
    byte[] cowValue = Hex.decode("A4A5A6");
    byte[] horseKey = Hex.decode("B1B2B3");
    byte[] horseValue = Hex.decode("B4B5B6");
    track.addStorageRow(COW, new DataWord(cowKey), new DataWord(cowValue));
    track.addStorageRow(HORSE, new DataWord(horseKey), new DataWord(horseValue));
    track.commit();
    assertEquals(new DataWord(cowValue), repository.getStorageValue(COW, new DataWord(cowKey)));
    assertEquals(new DataWord(horseValue), repository.getStorageValue(HORSE, new DataWord(horseKey)));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 100 with Repository

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

the class RepositoryImplOriginalTest method test13.

// Let's upload genesis pre-mine just like in the real world
@Test
public void test13() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    Genesis genesis = (Genesis) Genesis.getInstance(config);
    for (RskAddress addr : genesis.getPremine().keySet()) {
        repository.createAccount(addr);
        repository.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
    }
    track.commit();
    // To Review: config Genesis should have an State Root according to the new trie algorithm
    // assertArrayEquals(Genesis.getInstance(SystemProperties.CONFIG).getStateRoot(), repository.getRoot());
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) RskAddress(co.rsk.core.RskAddress) Genesis(org.ethereum.core.Genesis) 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