Search in sources :

Example 91 with Repository

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

the class TransactionPoolImplTest method createSampleNewTransactionPoolWithAccounts.

private static TransactionPoolImpl createSampleNewTransactionPoolWithAccounts(int naccounts, Coin balance, BlockChainImpl blockChain) {
    Block best = blockChain.getStatus().getBestBlock();
    Repository repository = blockChain.getRepository();
    Repository track = repository.startTracking();
    for (int k = 1; k <= naccounts; k++) {
        Account account = createAccount(k);
        track.createAccount(account.getAddress());
        track.addBalance(account.getAddress(), balance);
    }
    track.commit();
    best.setStateRoot(repository.getRoot());
    best.flushRLP();
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, blockChain.getRepository(), blockChain.getBlockStore(), null, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
    blockChain.setTransactionPool(transactionPool);
    return transactionPool;
}
Also used : Account(org.ethereum.core.Account) Repository(org.ethereum.core.Repository) Block(org.ethereum.core.Block) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)

Example 92 with Repository

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

the class RepositoryImplOriginalTest method test10.

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

Example 93 with Repository

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

the class RepositoryImplOriginalTest method test18.

@Test
public void test18() {
    Repository repository = new RepositoryImpl(config);
    // track
    Repository repoTrack2 = repository.startTracking();
    RskAddress pig = new RskAddress("F0B8C9D84DD2B877E0B952130B73E218106FEC04");
    RskAddress precompiled = new RskAddress("0000000000000000000000000000000000000002");
    byte[] cowCode = Hex.decode("A1A2A3");
    byte[] horseCode = Hex.decode("B1B2B3");
    repository.saveCode(COW, cowCode);
    repository.saveCode(HORSE, horseCode);
    repository.delete(HORSE);
    assertEquals(true, repoTrack2.isExist(COW));
    assertEquals(false, repoTrack2.isExist(HORSE));
    assertEquals(false, repoTrack2.isExist(pig));
    assertEquals(false, repoTrack2.isExist(precompiled));
}
Also used : Repository(org.ethereum.core.Repository) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 94 with Repository

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

the class RepositoryImplOriginalTest method test20.

// testing for snapshot
@Test
public void test20() {
    TrieStore store = new TrieStoreImpl(new HashMapDB());
    Repository repository = new RepositoryImpl(config, store);
    byte[] root = repository.getRoot();
    DataWord cowKey1 = new DataWord("c1");
    DataWord cowKey2 = new DataWord("c2");
    DataWord cowVal1 = new DataWord("c0a1");
    DataWord cowVal0 = new DataWord("c0a0");
    DataWord horseKey1 = new DataWord("e1");
    DataWord horseKey2 = new DataWord("e2");
    DataWord horseVal1 = new DataWord("c0a1");
    DataWord horseVal0 = new DataWord("c0a0");
    // track
    Repository track2 = repository.startTracking();
    track2.addStorageRow(COW, cowKey1, cowVal1);
    track2.addStorageRow(HORSE, horseKey1, horseVal1);
    track2.commit();
    byte[] root2 = repository.getRoot();
    // track
    track2 = repository.startTracking();
    track2.addStorageRow(COW, cowKey2, cowVal0);
    track2.addStorageRow(HORSE, horseKey2, horseVal0);
    track2.commit();
    byte[] root3 = repository.getRoot();
    Repository snapshot = repository.getSnapshotTo(root);
    ContractDetails cowDetails = snapshot.getContractDetails(COW);
    ContractDetails horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(null, cowDetails.get(cowKey1));
    assertEquals(null, cowDetails.get(cowKey2));
    assertEquals(null, horseDetails.get(horseKey1));
    assertEquals(null, horseDetails.get(horseKey2));
    snapshot = repository.getSnapshotTo(root2);
    cowDetails = snapshot.getContractDetails(COW);
    horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(cowVal1, cowDetails.get(cowKey1));
    assertEquals(null, cowDetails.get(cowKey2));
    assertEquals(horseVal1, horseDetails.get(horseKey1));
    assertEquals(null, horseDetails.get(horseKey2));
    snapshot = repository.getSnapshotTo(root3);
    cowDetails = snapshot.getContractDetails(COW);
    horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(cowVal1, cowDetails.get(cowKey1));
    assertEquals(cowVal0, cowDetails.get(cowKey2));
    assertEquals(horseVal1, horseDetails.get(horseKey1));
    assertEquals(horseVal0, horseDetails.get(horseKey2));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 95 with Repository

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

the class RepositoryImplOriginalTest method test9.

@Test
public void test9() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    DataWord cowKey = new DataWord(Hex.decode("A1A2A3"));
    DataWord cowValue = new DataWord(Hex.decode("A4A5A6"));
    DataWord horseKey = new DataWord(Hex.decode("B1B2B3"));
    DataWord horseValue = new DataWord(Hex.decode("B4B5B6"));
    track.addStorageRow(COW, cowKey, cowValue);
    track.addStorageRow(HORSE, horseKey, horseValue);
    assertEquals(cowValue, track.getStorageValue(COW, cowKey));
    assertEquals(horseValue, track.getStorageValue(HORSE, horseKey));
    track.commit();
    assertEquals(cowValue, repository.getStorageValue(COW, cowKey));
    assertEquals(horseValue, repository.getStorageValue(HORSE, horseKey));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) 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