use of org.ethereum.vm.DataWord 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 org.ethereum.vm.DataWord 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 org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method test_1.
@Test
public void test_1() {
byte[] code = Hex.decode("60016002");
byte[] key_1 = Hex.decode("111111");
byte[] val_1 = Hex.decode("aaaaaa");
byte[] key_2 = Hex.decode("222222");
byte[] val_2 = Hex.decode("bbbbbb");
ContractDetailsImpl contractDetails = new ContractDetailsImpl(config);
contractDetails.setCode(code);
contractDetails.put(new DataWord(key_1), new DataWord(val_1));
contractDetails.put(new DataWord(key_2), new DataWord(val_2));
byte[] data = contractDetails.getEncoded();
ContractDetailsImpl contractDetails_ = new ContractDetailsImpl(config, data);
Assert.assertEquals(Hex.toHexString(code), Hex.toHexString(contractDetails_.getCode()));
Assert.assertEquals(Hex.toHexString(val_1), Hex.toHexString(contractDetails_.get(new DataWord(key_1)).getNoLeadZeroesData()));
Assert.assertEquals(Hex.toHexString(val_2), Hex.toHexString(contractDetails_.get(new DataWord(key_2)).getNoLeadZeroesData()));
}
use of org.ethereum.vm.DataWord 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());
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ContractDetailsImplTest method getStorageKeysInNonEmptyDetails.
@Test
public void getStorageKeysInNonEmptyDetails() {
ContractDetailsImpl details = new ContractDetailsImpl(config);
details.put(DataWord.ZERO, DataWord.ONE);
details.put(DataWord.ONE, new DataWord(42));
Set<DataWord> keys = details.getStorageKeys();
Assert.assertNotNull(keys);
Assert.assertEquals(2, keys.size());
Assert.assertTrue(keys.contains(DataWord.ZERO));
Assert.assertTrue(keys.contains(DataWord.ONE));
}
Aggregations