Search in sources :

Example 91 with DataWord

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());
}
Also used : DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 92 with DataWord

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);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) TrieImpl(co.rsk.trie.TrieImpl) DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 93 with DataWord

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());
}
Also used : DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) Test(org.junit.Test)

Example 94 with DataWord

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)));
}
Also used : DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) Test(org.junit.Test)

Example 95 with DataWord

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());
}
Also used : DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) Test(org.junit.Test)

Aggregations

DataWord (org.ethereum.vm.DataWord)133 Test (org.junit.Test)88 Repository (org.ethereum.core.Repository)41 RskAddress (co.rsk.core.RskAddress)25 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)22 BigInteger (java.math.BigInteger)19 LogInfo (org.ethereum.vm.LogInfo)17 HashMapDB (org.ethereum.datasource.HashMapDB)14 Program (org.ethereum.vm.program.Program)13 Stack (org.ethereum.vm.program.Stack)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 RepositoryImpl (co.rsk.db.RepositoryImpl)9 ContractDetails (org.ethereum.db.ContractDetails)9 Trie (co.rsk.trie.Trie)8 CallTransaction (org.ethereum.core.CallTransaction)8 TrieImpl (co.rsk.trie.TrieImpl)7 TrieStore (co.rsk.trie.TrieStore)7 Coin (co.rsk.core.Coin)5