use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class MutableTrieCacheTest method testStorageKeysMixOneLevel.
@Test
public void testStorageKeysMixOneLevel() {
// SUTs
MutableTrieImpl baseMutableTrie = new MutableTrieImpl(null, new Trie());
MutableTrieCache mtCache = new MutableTrieCache(baseMutableTrie);
MutableTrieCache otherCache = new MutableTrieCache(mtCache);
// setup
// helpers for interacting with the SUTs
MutableRepository baseRepository = new MutableRepository(baseMutableTrie);
MutableRepository cacheRepository = new MutableRepository(mtCache);
MutableRepository otherCacheRepository = new MutableRepository(otherCache);
RskAddress addr = new RskAddress("b86ca7db8c7ae687ac8d098789987eee12333fc7");
baseRepository.createAccount(addr);
baseRepository.setupContract(addr);
DataWord sk120 = toStorageKey("120");
DataWord sk121 = toStorageKey("121");
DataWord sk122 = toStorageKey("122");
DataWord sk123 = toStorageKey("123");
DataWord sk124 = toStorageKey("124");
baseRepository.addStorageBytes(addr, sk120, toBytes("HAL"));
baseRepository.addStorageBytes(addr, sk121, toBytes("HAL"));
baseRepository.addStorageBytes(addr, sk122, toBytes("HAL"));
cacheRepository.addStorageBytes(addr, sk120, null);
cacheRepository.addStorageBytes(addr, sk121, toBytes("LAH"));
cacheRepository.addStorageBytes(addr, sk123, toBytes("LAH"));
otherCacheRepository.addStorageBytes(addr, sk124, toBytes("HAL"));
// assertions
Iterator<DataWord> storageKeys = mtCache.getStorageKeys(addr);
Set<DataWord> keys = new HashSet<>();
storageKeys.forEachRemaining(keys::add);
assertFalse(keys.contains(sk120));
assertTrue(keys.contains(sk121));
assertTrue(keys.contains(sk122));
assertTrue(keys.contains(sk123));
assertFalse(keys.contains(sk124));
assertEquals(3, keys.size());
storageKeys = otherCache.getStorageKeys(addr);
keys = new HashSet<>();
storageKeys.forEachRemaining(keys::add);
assertFalse(keys.contains(sk120));
assertTrue(keys.contains(sk121));
assertTrue(keys.contains(sk122));
assertTrue(keys.contains(sk123));
assertTrue(keys.contains(sk124));
assertEquals(4, keys.size());
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class RepositoryImplTest method setAndGetStorageValueUsingNewRepositoryForTest.
@Test
public void setAndGetStorageValueUsingNewRepositoryForTest() {
RskAddress accAddress = randomAccountAddress();
Repository repository = new MutableRepository(new MutableTrieImpl(null, new Trie()));
repository.addStorageRow(accAddress, DataWord.ONE, DataWord.ONE);
DataWord value = repository.getStorageValue(accAddress, DataWord.ONE);
Assert.assertNotNull(value);
Assert.assertEquals(DataWord.ONE, value);
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class MutableTrieCacheTest method testStorageKeysNoCache.
@Test
public void testStorageKeysNoCache() {
// SUTs
MutableTrieImpl baseMutableTrie = new MutableTrieImpl(null, new Trie());
MutableTrieCache mtCache = new MutableTrieCache(baseMutableTrie);
// setup
// helpers for interacting with the SUTs
MutableRepository baseRepository = new MutableRepository(baseMutableTrie);
RskAddress addr = new RskAddress("b86ca7db8c7ae687ac8d098789987eee12333fc7");
DataWord sk120 = toStorageKey("120");
DataWord sk121 = toStorageKey("121");
baseRepository.addStorageBytes(addr, sk120, toBytes("HAL"));
baseRepository.addStorageBytes(addr, sk121, toBytes("HAL"));
Iterator<DataWord> storageKeys = mtCache.getStorageKeys(addr);
Set<DataWord> keys = new HashSet<>();
storageKeys.forEachRemaining(keys::add);
assertTrue(keys.contains(sk120));
assertTrue(keys.contains(sk121));
assertEquals(2, keys.size());
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class MutableTrieCacheTest method testStorageKeysDeletedAccount.
@Test
public void testStorageKeysDeletedAccount() {
// SUTs
MutableTrieImpl baseMutableTrie = new MutableTrieImpl(null, new Trie());
MutableTrieCache mtCache = new MutableTrieCache(baseMutableTrie);
// setup
// helpers for interacting with the SUTs
MutableRepository cacheRepository = new MutableRepository(mtCache);
MutableRepository baseRepository = new MutableRepository(baseMutableTrie);
RskAddress addr = new RskAddress("b86ca7db8c7ae687ac8d098789987eee12333fc7");
DataWord sk120 = toStorageKey("120");
DataWord sk121 = toStorageKey("121");
baseRepository.addStorageBytes(addr, sk120, toBytes("HAL"));
cacheRepository.delete(addr);
Iterator<DataWord> storageKeys = mtCache.getStorageKeys(addr);
Set<DataWord> keys = new HashSet<>();
storageKeys.forEachRemaining(keys::add);
assertFalse(keys.contains(sk120));
assertFalse(keys.contains(sk121));
assertEquals(0, keys.size());
cacheRepository.addStorageBytes(addr, sk121, toBytes("HAL"));
storageKeys = mtCache.getStorageKeys(addr);
keys = new HashSet<>();
storageKeys.forEachRemaining(keys::add);
assertFalse(keys.contains(sk120));
assertTrue(keys.contains(sk121));
assertEquals(1, keys.size());
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class RemascStorageProviderTest method setSaveRetrieveAndGetBrokenSelectionRule.
@Test
public void setSaveRetrieveAndGetBrokenSelectionRule() throws IOException {
RskAddress accountAddress = randomAddress();
Repository repository = new MutableRepository(new MutableTrieImpl(null, new Trie()));
RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
provider.setBrokenSelectionRule(Boolean.TRUE);
provider.save();
RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);
Assert.assertEquals(Boolean.TRUE, newProvider.getBrokenSelectionRule());
}
Aggregations