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;
}
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();
}
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));
}
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));
}
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();
}
Aggregations