Search in sources :

Example 6 with MutableRepository

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());
}
Also used : MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) MutableTrie(co.rsk.trie.MutableTrie) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 7 with MutableRepository

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);
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) Trie(co.rsk.trie.Trie) TrieHashTest(co.rsk.trie.TrieHashTest) Test(org.junit.Test)

Example 8 with MutableRepository

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());
}
Also used : MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) MutableTrie(co.rsk.trie.MutableTrie) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 9 with MutableRepository

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());
}
Also used : MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) MutableTrie(co.rsk.trie.MutableTrie) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 10 with MutableRepository

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());
}
Also used : MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) Trie(co.rsk.trie.Trie) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Aggregations

MutableRepository (org.ethereum.db.MutableRepository)40 Test (org.junit.Test)31 Trie (co.rsk.trie.Trie)26 RskAddress (co.rsk.core.RskAddress)21 Repository (org.ethereum.core.Repository)15 TrieStore (co.rsk.trie.TrieStore)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)12 HashMapDB (org.ethereum.datasource.HashMapDB)12 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)9 BigInteger (java.math.BigInteger)8 Coin (co.rsk.core.Coin)7 DataWord (org.ethereum.vm.DataWord)7 MutableTrieImpl (co.rsk.db.MutableTrieImpl)6 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)5 MutableTrie (co.rsk.trie.MutableTrie)4 ArrayList (java.util.ArrayList)4 Block (org.ethereum.core.Block)4 TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)2 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)2 CountDownLatch (java.util.concurrent.CountDownLatch)2