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));
}
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());
}
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 + ""));
}
}
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 + ""));
}
}
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);
}
}
Aggregations