Search in sources :

Example 41 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method saveAndRetrieveTrieNodeWith33BytesValue.

@Test
public void saveAndRetrieveTrieNodeWith33BytesValue() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    byte[] key = "foo".getBytes();
    byte[] value = new byte[33];
    Trie trie = new TrieImpl(store, true).put(key, value);
    store.save(trie);
    Assert.assertEquals(2, map.keys().size());
    Assert.assertNotNull(map.get(trie.getHash().getBytes()));
    Assert.assertArrayEquals(trie.toMessage(), map.get(trie.getHash().getBytes()));
    Assert.assertEquals(2, store.getSaveCount());
    Trie newTrie = store.retrieve(trie.getHash().getBytes());
    Assert.assertNotNull(newTrie);
    Assert.assertEquals(1, newTrie.trieSize());
    Assert.assertNotNull(newTrie.get(key));
    Assert.assertArrayEquals(value, newTrie.get(key));
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 42 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method saveFullTrieWithLongValueUpdateAndSaveAgainUsingBinaryTrie.

@Test
public void saveFullTrieWithLongValueUpdateAndSaveAgainUsingBinaryTrie() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true).put("foo", TrieImplValueTest.makeValue(100));
    trie.save();
    Assert.assertEquals(2, store.getSaveCount());
    trie = trie.put("foo", TrieImplValueTest.makeValue(200));
    trie.save();
    Assert.assertEquals(4, store.getSaveCount());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 43 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TrieCopyToTest method copyTrieWithOneHundredValues.

@Test
public void copyTrieWithOneHundredValues() {
    HashMapDB map1 = new HashMapDB();
    TrieStoreImpl store1 = new TrieStoreImpl(map1);
    HashMapDB map2 = new HashMapDB();
    TrieStoreImpl store2 = new TrieStoreImpl(map2);
    Trie trie = new TrieImpl(store1, true);
    for (int k = 0; k < 100; k++) {
        trie = trie.put(k + "", (k + "").getBytes());
    }
    trie.save();
    trie.copyTo(store2);
    Trie result = store2.retrieve(trie.getHash().getBytes());
    Assert.assertNotNull(result);
    Assert.assertEquals(trie.getHash(), result.getHash());
    for (int k = 0; k < 100; k++) {
        Assert.assertArrayEquals((k + "").getBytes(), result.get(k + ""));
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 44 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TrieCopyToTest method copyTwoTriesWithOneHundredValues.

@Test
public void copyTwoTriesWithOneHundredValues() {
    HashMapDB map1 = new HashMapDB();
    TrieStoreImpl store1 = new TrieStoreImpl(map1);
    HashMapDB map2 = new HashMapDB();
    TrieStoreImpl store2 = new TrieStoreImpl(map2);
    Trie trie1 = new TrieImpl(store1, true);
    Trie trie2 = new TrieImpl(store1, true);
    for (int k = 0; k < 100; k++) {
        trie1 = trie1.put(k + "", (k + "").getBytes());
        trie2 = trie2.put(k + 100 + "", (k + 100 + "").getBytes());
    }
    trie1.save();
    trie2.save();
    trie1.copyTo(store2);
    trie2.copyTo(store2);
    Trie result1 = store2.retrieve(trie1.getHash().getBytes());
    Assert.assertNotNull(result1);
    Assert.assertEquals(trie1.getHash(), result1.getHash());
    for (int k = 0; k < 100; k++) {
        Assert.assertArrayEquals((k + "").getBytes(), result1.get(k + ""));
    }
    Trie result2 = store2.retrieve(trie2.getHash().getBytes());
    Assert.assertNotNull(result2);
    Assert.assertEquals(trie2.getHash(), result2.getHash());
    for (int k = 0; k < 100; k++) {
        Assert.assertArrayEquals((k + 100 + "").getBytes(), result2.get(k + 100 + ""));
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 45 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TrieImplSaveRetrieveTest method updateSaveRetrieveAndGetOneThousandKeyValues.

@Test
public void updateSaveRetrieveAndGetOneThousandKeyValues() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, false);
    for (int k = 0; k < 1000; k++) trie = trie.put(k + "", (k + "").getBytes());
    trie.save();
    Trie trie2 = store.retrieve(trie.getHash().getBytes());
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    for (int k = 0; k < 1000; k++) {
        String key = k + "";
        byte[] expected = trie.get(key);
        byte[] value = trie2.get(key);
        Assert.assertArrayEquals(expected, value);
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)141 Test (org.junit.Test)130 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)28 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)23 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)22 SimpleBlock (co.rsk.peg.simples.SimpleBlock)18 ArrayList (java.util.ArrayList)18 RepositoryImpl (co.rsk.db.RepositoryImpl)15 DataWord (org.ethereum.vm.DataWord)14 Repository (org.ethereum.core.Repository)12 RskAddress (co.rsk.core.RskAddress)11 TrieStore (co.rsk.trie.TrieStore)10 BlockBuilder (co.rsk.test.builders.BlockBuilder)9 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)8 ReceiptStore (org.ethereum.db.ReceiptStore)8 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)8 Keccak256 (co.rsk.crypto.Keccak256)7 World (co.rsk.test.World)7 TrieImpl (co.rsk.trie.TrieImpl)6 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)6