use of co.rsk.trie.Trie 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.Trie in project rskj by rsksmart.
the class ContractDetailsImplTest method putDataWordZeroAsDeleteValue.
@Test
public void putDataWordZeroAsDeleteValue() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
details.put(DataWord.ONE, new DataWord(42));
details.put(DataWord.ONE, DataWord.ZERO);
Trie trie = details.getTrie();
byte[] value = trie.get(DataWord.ONE.getData());
Assert.assertNull(value);
Assert.assertEquals(0, details.getStorageSize());
}
use of co.rsk.trie.Trie 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.Trie 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.Trie in project rskj by rsksmart.
the class ContractDetailsImplTest method putDataWordWithoutLeadingZeroes.
@Test
public void putDataWordWithoutLeadingZeroes() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
details.put(DataWord.ONE, new DataWord(42));
Trie trie = details.getTrie();
byte[] value = trie.get(DataWord.ONE.getData());
Assert.assertNotNull(value);
Assert.assertEquals(1, value.length);
Assert.assertEquals(42, value[0]);
Assert.assertEquals(1, details.getStorageSize());
}
Aggregations