use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class ContractDetailsImplTest method syncStorageAndGetKeyValues.
@Test
public void syncStorageAndGetKeyValues() {
TrieStore store = new TrieStoreImpl(new HashMapDB());
Trie trie = new TrieImpl(store, false);
byte[] accountAddress = randomAddress();
ContractDetailsImpl details = new ContractDetailsImpl(config, accountAddress, trie, null);
int nkeys = IN_MEMORY_STORAGE_LIMIT;
for (int k = 1; k <= nkeys + 1; k++) details.put(new DataWord(k), new DataWord(k * 2));
Assert.assertTrue(details.hasExternalStorage());
details.syncStorage();
for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(details.get(new DataWord(k)));
ContractDetailsImpl clone = new ContractDetailsImpl(config, details.getEncoded());
Assert.assertNotNull(clone);
Assert.assertTrue(clone.hasExternalStorage());
Assert.assertEquals(details.getStorageSize(), clone.getStorageSize());
for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(clone.get(new DataWord(k)));
for (int k = 1; k <= nkeys + 1; k++) clone.put(new DataWord(k), new DataWord(k * 3));
Assert.assertTrue(clone.hasExternalStorage());
Assert.assertEquals(details.getStorageSize(), clone.getStorageSize());
ContractDetailsImpl snapshot = (ContractDetailsImpl) clone.getSnapshotTo(clone.getStorageHash());
Assert.assertTrue(snapshot.hasExternalStorage());
Assert.assertEquals(clone.getStorageSize(), snapshot.getStorageSize());
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class ContractDetailsImplTest method syncStorageInDetailsWithTrieInMemory.
@Test
public void syncStorageInDetailsWithTrieInMemory() {
TrieStore store = new TrieStoreImpl(new HashMapDB());
Trie trie = new TrieImpl(store, false);
byte[] accountAddress = randomAddress();
ContractDetailsImpl details = new ContractDetailsImpl(config, accountAddress, trie, null);
details.put(new DataWord(42), DataWord.ONE);
details.syncStorage();
Assert.assertNotNull(details.get(new DataWord(42)));
}
use of co.rsk.trie.TrieStore 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 co.rsk.trie.TrieStore in project rskj by rsksmart.
the class RepositoryImplTest method syncToRootAfterCreatingAnAccount.
@Test
public void syncToRootAfterCreatingAnAccount() {
TrieStore store = new TrieStoreImpl(new HashMapDB());
RepositoryImpl repository = new RepositoryImpl(config, store);
repository.flush();
RskAddress accAddress = randomAccountAddress();
byte[] initialRoot = repository.getRoot();
repository.createAccount(accAddress);
repository.flush();
byte[] newRoot = repository.getRoot();
Assert.assertTrue(repository.isExist(accAddress));
repository.syncToRoot(initialRoot);
Assert.assertFalse(repository.isExist(accAddress));
repository.syncToRoot(newRoot);
Assert.assertTrue(repository.isExist(accAddress));
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class RepositoryImplTest method getAccountsKeysOnSnapshot.
@Test
public void getAccountsKeysOnSnapshot() {
RskAddress accAddress1 = randomAccountAddress();
RskAddress accAddress2 = randomAccountAddress();
TrieStore store = new TrieStoreImpl(new HashMapDB());
RepositoryImpl repository = new RepositoryImpl(config, store);
repository.createAccount(accAddress1);
repository.flush();
byte[] root = repository.getRoot();
repository.createAccount(accAddress2);
repository.syncToRoot(root);
Set<RskAddress> keys = repository.getAccountsKeys();
Assert.assertNotNull(keys);
Assert.assertFalse(keys.isEmpty());
Assert.assertEquals(1, keys.size());
}
Aggregations