Search in sources :

Example 96 with DataWord

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());
}
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) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 97 with DataWord

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)));
}
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) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 98 with DataWord

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

Example 99 with DataWord

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

Example 100 with DataWord

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));
}
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