use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class RskTestFactory method getGenesisInstance.
public static Genesis getGenesisInstance(RskSystemProperties config) {
boolean useRskip92Encoding = config.getActivationConfig().isActive(ConsensusRule.RSKIP92, 0L);
boolean isRskip126Enabled = config.getActivationConfig().isActive(ConsensusRule.RSKIP126, 0L);
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
return new TestGenesisLoader(trieStore, config.genesisInfo(), config.getNetworkConstants().getInitialNonce(), false, useRskip92Encoding, isRskip126Enabled).load();
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class ContractDetailsImplTest method syncStorageWithExternalStorage.
@Test
public void syncStorageWithExternalStorage() {
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();
int ssize = details.getStorageSize();
details = new ContractDetailsImpl(config, details.getEncoded());
Assert.assertEquals(ssize, details.getStorageSize());
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 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));
}
Aggregations