use of org.ethereum.vm.DataWord 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 org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method testExternalStorageSerialization.
@Test
public void testExternalStorageSerialization() {
byte[] address = randomAddress();
byte[] code = randomBytes(512);
Map<DataWord, DataWord> elements = new HashMap<>();
HashMapDB externalStorage = new HashMapDB();
ContractDetailsImpl original = new ContractDetailsImpl(config, address, new TrieImpl(new TrieStoreImpl(externalStorage), true), code);
for (int i = 0; i < IN_MEMORY_STORAGE_LIMIT + 10; i++) {
DataWord key = randomDataWord();
DataWord value = randomDataWord();
elements.put(key, value);
original.put(key, value);
}
original.syncStorage();
byte[] rlp = original.getEncoded();
ContractDetailsImpl deserialized = new ContractDetailsImpl(config, rlp);
Assert.assertEquals(toHexString(address), toHexString(deserialized.getAddress()));
Assert.assertEquals(toHexString(code), toHexString(deserialized.getCode()));
Map<DataWord, DataWord> storage = deserialized.getStorage();
Assert.assertEquals(elements.size(), storage.size());
for (DataWord key : elements.keySet()) {
Assert.assertEquals(elements.get(key), storage.get(key));
}
DataWord deletedKey = elements.keySet().iterator().next();
deserialized.put(deletedKey, DataWord.ZERO);
deserialized.put(randomDataWord(), DataWord.ZERO);
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method getStorageSizeInNonEmptyDetails.
@Test
public void getStorageSizeInNonEmptyDetails() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
details.put(DataWord.ZERO, DataWord.ONE);
details.put(DataWord.ONE, new DataWord(42));
Assert.assertEquals(2, details.getStorageSize());
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method getStorageFromNonEmptyDetailsUsingKeys.
@Test
public void getStorageFromNonEmptyDetailsUsingKeys() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
details.put(DataWord.ZERO, DataWord.ONE);
details.put(DataWord.ONE, new DataWord(42));
details.put(new DataWord(3), new DataWord(144));
Collection<DataWord> keys = new HashSet<>();
keys.add(DataWord.ZERO);
keys.add(new DataWord(3));
Map<DataWord, DataWord> map = details.getStorage(keys);
Assert.assertNotNull(map);
Assert.assertFalse(map.isEmpty());
Assert.assertEquals(2, map.size());
Assert.assertTrue(map.containsKey(DataWord.ZERO));
Assert.assertTrue(map.containsKey(new DataWord(3)));
Assert.assertEquals(DataWord.ONE, map.get(DataWord.ZERO));
Assert.assertEquals(new DataWord(144), map.get(new DataWord(3)));
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method contractDetailsWithStorageDataIsNotNullObject.
@Test
public void contractDetailsWithStorageDataIsNotNullObject() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
details.put(DataWord.ONE, new DataWord(42));
Assert.assertFalse(details.isNullObject());
}
Aggregations