use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method usingSameExternalStorage.
@Test
public void usingSameExternalStorage() {
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();
ContractDetailsImpl details1 = new ContractDetailsImpl(config, details.getEncoded());
ContractDetailsImpl details2 = new ContractDetailsImpl(config, details.getEncoded());
Assert.assertTrue(details1.hasExternalStorage());
Assert.assertTrue(details2.hasExternalStorage());
for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(details1.get(new DataWord(k)));
for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(details2.get(new DataWord(k)));
details1.syncStorage();
details2.syncStorage();
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method getStorageFromNonEmptyDetails.
@Test
public void getStorageFromNonEmptyDetails() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
details.put(DataWord.ZERO, DataWord.ONE);
details.put(DataWord.ONE, new DataWord(42));
Map<DataWord, DataWord> map = details.getStorage();
Assert.assertNotNull(map);
Assert.assertFalse(map.isEmpty());
Assert.assertEquals(2, map.size());
Assert.assertTrue(map.containsKey(DataWord.ZERO));
Assert.assertTrue(map.containsKey(DataWord.ONE));
Assert.assertEquals(DataWord.ONE, map.get(DataWord.ZERO));
Assert.assertEquals(new DataWord(42), map.get(DataWord.ONE));
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method getSnapshot.
@Test
public void getSnapshot() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
byte[] initialRoot = details.getStorageHash();
List<DataWord> keys = new ArrayList<>();
keys.add(DataWord.ZERO);
keys.add(DataWord.ONE);
List<DataWord> values = new ArrayList<>();
values.add(new DataWord(42));
values.add(new DataWord(144));
details.setStorage(keys, values);
byte[] root = details.getStorageHash();
List<DataWord> keys2 = new ArrayList<>();
keys2.add(new DataWord(2));
keys2.add(new DataWord(3));
List<DataWord> values2 = new ArrayList<>();
values2.add(new DataWord(1));
values2.add(new DataWord(2));
details.setStorage(keys2, values2);
ContractDetails result = details.getSnapshotTo(root);
Assert.assertEquals(new DataWord(42), result.get(DataWord.ZERO));
Assert.assertEquals(new DataWord(144), result.get(DataWord.ONE));
Assert.assertEquals(null, result.get(new DataWord(2)));
Assert.assertEquals(null, result.get(new DataWord(3)));
ContractDetails result2 = details.getSnapshotTo(initialRoot);
Assert.assertEquals(null, result2.get(DataWord.ZERO));
Assert.assertEquals(null, result2.get(DataWord.ONE));
Assert.assertEquals(null, result2.get(new DataWord(2)));
Assert.assertEquals(null, result2.get(new DataWord(3)));
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method getEncodedAndCreateClone.
@Test
public void getEncodedAndCreateClone() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
List<DataWord> keys = new ArrayList<>();
keys.add(DataWord.ZERO);
keys.add(DataWord.ONE);
List<DataWord> values = new ArrayList<>();
values.add(new DataWord(42));
values.add(new DataWord(144));
details.setStorage(keys, values);
byte[] root = details.getStorageHash();
byte[] encoded = details.getEncoded();
Assert.assertNotNull(encoded);
ContractDetailsImpl result = new ContractDetailsImpl(config, encoded);
Assert.assertEquals(new DataWord(42), result.get(DataWord.ZERO));
Assert.assertEquals(new DataWord(144), result.get(DataWord.ONE));
Assert.assertEquals(null, result.get(new DataWord(2)));
Assert.assertEquals(null, result.get(new DataWord(3)));
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method setStorageUsingKeysAndValues.
@Test
public void setStorageUsingKeysAndValues() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
List<DataWord> keys = new ArrayList<>();
keys.add(DataWord.ZERO);
keys.add(DataWord.ONE);
List<DataWord> values = new ArrayList<>();
values.add(new DataWord(42));
values.add(new DataWord(144));
details.setStorage(keys, values);
Assert.assertEquals(new DataWord(42), details.get(DataWord.ZERO));
Assert.assertEquals(new DataWord(144), details.get(DataWord.ONE));
}
Aggregations