Search in sources :

Example 36 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test16_2.

@Test
public void test16_2() {
    Repository repository = new RepositoryImpl(config);
    byte[] cowKey1 = "key-c-1".getBytes();
    byte[] cowValue1 = "val-c-1".getBytes();
    byte[] horseKey1 = "key-h-1".getBytes();
    byte[] horseValue1 = "val-h-1".getBytes();
    byte[] cowKey2 = "key-c-2".getBytes();
    byte[] cowValue2 = "val-c-2".getBytes();
    byte[] horseKey2 = "key-h-2".getBytes();
    byte[] horseValue2 = "val-h-2".getBytes();
    // changes level_1
    Repository track1 = repository.startTracking();
    // changes level_2
    Repository track2 = track1.startTracking();
    track2.addStorageRow(COW, new DataWord(cowKey2), new DataWord(cowValue2));
    track2.addStorageRow(HORSE, new DataWord(horseKey2), new DataWord(horseValue2));
    assertNull(track2.getStorageValue(COW, new DataWord(cowKey1)));
    assertNull(track2.getStorageValue(HORSE, new DataWord(horseKey1)));
    assertEquals(new DataWord(cowValue2), track2.getStorageValue(COW, new DataWord(cowKey2)));
    assertEquals(new DataWord(horseValue2), track2.getStorageValue(HORSE, new DataWord(horseKey2)));
    track2.commit();
    // leaving level_2
    assertNull(track1.getStorageValue(COW, new DataWord(cowKey1)));
    assertNull(track1.getStorageValue(HORSE, new DataWord(horseKey1)));
    assertEquals(new DataWord(cowValue2), track1.getStorageValue(COW, new DataWord(cowKey2)));
    assertEquals(new DataWord(horseValue2), track1.getStorageValue(HORSE, new DataWord(horseKey2)));
    track1.commit();
    // leaving level_1
    assertEquals(null, repository.getStorageValue(COW, new DataWord(cowKey1)));
    assertEquals(null, repository.getStorageValue(HORSE, new DataWord(horseKey1)));
    assertEquals(new DataWord(cowValue2), repository.getStorageValue(COW, new DataWord(cowKey2)));
    assertEquals(new DataWord(horseValue2), repository.getStorageValue(HORSE, new DataWord(horseKey2)));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 37 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test16.

@Test
public void test16() {
    Repository repository = new RepositoryImpl(config);
    byte[] cowKey1 = "key-c-1".getBytes();
    byte[] cowValue1 = "val-c-1".getBytes();
    byte[] horseKey1 = "key-h-1".getBytes();
    byte[] horseValue1 = "val-h-1".getBytes();
    byte[] cowKey2 = "key-c-2".getBytes();
    byte[] cowValue2 = "val-c-2".getBytes();
    byte[] horseKey2 = "key-h-2".getBytes();
    byte[] horseValue2 = "val-h-2".getBytes();
    // changes level_1
    Repository track1 = repository.startTracking();
    track1.addStorageRow(COW, new DataWord(cowKey1), new DataWord(cowValue1));
    track1.addStorageRow(HORSE, new DataWord(horseKey1), new DataWord(horseValue1));
    assertEquals(new DataWord(cowValue1), track1.getStorageValue(COW, new DataWord(cowKey1)));
    assertEquals(new DataWord(horseValue1), track1.getStorageValue(HORSE, new DataWord(horseKey1)));
    // changes level_2
    Repository track2 = track1.startTracking();
    track2.addStorageRow(COW, new DataWord(cowKey2), new DataWord(cowValue2));
    track2.addStorageRow(HORSE, new DataWord(horseKey2), new DataWord(horseValue2));
    assertEquals(new DataWord(cowValue1), track2.getStorageValue(COW, new DataWord(cowKey1)));
    assertEquals(new DataWord(horseValue1), track2.getStorageValue(HORSE, new DataWord(horseKey1)));
    assertEquals(new DataWord(cowValue2), track2.getStorageValue(COW, new DataWord(cowKey2)));
    assertEquals(new DataWord(horseValue2), track2.getStorageValue(HORSE, new DataWord(horseKey2)));
    track2.commit();
    // leaving level_2
    assertEquals(new DataWord(cowValue1), track1.getStorageValue(COW, new DataWord(cowKey1)));
    assertEquals(new DataWord(horseValue1), track1.getStorageValue(HORSE, new DataWord(horseKey1)));
    assertEquals(new DataWord(cowValue2), track1.getStorageValue(COW, new DataWord(cowKey2)));
    assertEquals(new DataWord(horseValue2), track1.getStorageValue(HORSE, new DataWord(horseKey2)));
    track1.commit();
    // leaving level_1
    assertEquals(new DataWord(cowValue1), repository.getStorageValue(COW, new DataWord(cowKey1)));
    assertEquals(new DataWord(horseValue1), repository.getStorageValue(HORSE, new DataWord(horseKey1)));
    assertEquals(new DataWord(cowValue2), repository.getStorageValue(COW, new DataWord(cowKey2)));
    assertEquals(new DataWord(horseValue2), repository.getStorageValue(HORSE, new DataWord(horseKey2)));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 38 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RepositoryImplTest method setAndGetStorageValueUsingNewRepositoryForTest.

@Test
public void setAndGetStorageValueUsingNewRepositoryForTest() {
    RskAddress accAddress = randomAccountAddress();
    RepositoryImpl repository = new RepositoryImplForTesting();
    repository.addStorageRow(accAddress, DataWord.ONE, DataWord.ONE);
    DataWord value = repository.getStorageValue(accAddress, DataWord.ONE);
    Assert.assertNotNull(value);
    Assert.assertEquals(DataWord.ONE, value);
}
Also used : RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Example 39 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RepositoryImplTest method getEmptyStorageValue.

@Test
public void getEmptyStorageValue() {
    RskAddress accAddress = randomAccountAddress();
    RepositoryImpl repository = new RepositoryImpl(config);
    repository.createAccount(accAddress);
    DataWord value = repository.getStorageValue(accAddress, DataWord.ONE);
    Assert.assertNull(value);
}
Also used : RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Example 40 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RepositoryTest method test4.

@Test
public void test4() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    byte[] cowKey = Hex.decode("A1A2A3");
    byte[] cowValue = Hex.decode("A4A5A6");
    byte[] horseKey = Hex.decode("B1B2B3");
    byte[] horseValue = Hex.decode("B4B5B6");
    track.addStorageBytes(COW, new DataWord(cowKey), cowValue);
    track.addStorageBytes(HORSE, new DataWord(horseKey), horseValue);
    track.commit();
    assertArrayEquals(cowValue, repository.getStorageBytes(COW, new DataWord(cowKey)));
    assertArrayEquals(horseValue, repository.getStorageBytes(HORSE, new DataWord(horseKey)));
    repository.close();
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) 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