Search in sources :

Example 26 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class DetailsDataStoreTest method test4.

@Test
public void test4() {
    DatabaseImpl db = new DatabaseImpl(new HashMapDB());
    DetailsDataStore dds = new DetailsDataStore(config, db);
    RskAddress c_key = new RskAddress("0000000000000000000000000000000000001a2b");
    ContractDetails contractDetails = dds.get(c_key);
    assertNull(contractDetails);
}
Also used : RskAddress(co.rsk.core.RskAddress) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 27 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class DetailsDataStoreTest method test1.

@Test
public void test1() {
    DatabaseImpl db = new DatabaseImpl(new HashMapDB());
    DetailsDataStore dds = new DetailsDataStore(config, db);
    RskAddress c_key = new RskAddress("0000000000000000000000000000000000001a2b");
    byte[] code = Hex.decode("60606060");
    byte[] key = Hex.decode("11");
    byte[] value = Hex.decode("aa");
    ContractDetails contractDetails = new ContractDetailsImpl(config);
    contractDetails.setAddress(randomAddress().getBytes());
    contractDetails.setCode(code);
    contractDetails.put(new DataWord(key), new DataWord(value));
    dds.update(c_key, contractDetails);
    ContractDetails contractDetails_ = dds.get(c_key);
    String encoded1 = Hex.toHexString(contractDetails.getEncoded());
    String encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
    dds.flush();
    contractDetails_ = dds.get(c_key);
    encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
}
Also used : ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 28 with RskAddress

use of co.rsk.core.RskAddress 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 29 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class RepositoryImplTest method randomAccountAddress.

private static RskAddress randomAccountAddress() {
    byte[] bytes = new byte[20];
    new Random().nextBytes(bytes);
    return new RskAddress(bytes);
}
Also used : Random(java.util.Random) RskAddress(co.rsk.core.RskAddress)

Example 30 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class RepositoryImplTest method updateAccountState.

@Test
public void updateAccountState() {
    RskAddress accAddress = randomAccountAddress();
    RepositoryImpl repository = new RepositoryImpl(config);
    AccountState accState = repository.createAccount(accAddress);
    accState.incrementNonce();
    accState.addToBalance(Coin.valueOf(1L));
    repository.updateAccountState(accAddress, accState);
    AccountState newAccState = repository.getAccountState(accAddress);
    Assert.assertNotNull(newAccState);
    Assert.assertEquals(BigInteger.ONE, newAccState.getNonce());
    Assert.assertEquals(BigInteger.ONE, newAccState.getBalance().asBigInteger());
}
Also used : RskAddress(co.rsk.core.RskAddress) AccountState(org.ethereum.core.AccountState) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Aggregations

RskAddress (co.rsk.core.RskAddress)174 Test (org.junit.Test)102 Repository (org.ethereum.core.Repository)60 BigInteger (java.math.BigInteger)47 Coin (co.rsk.core.Coin)38 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 DataWord (org.ethereum.vm.DataWord)27 TrieImplHashTest (co.rsk.trie.TrieImplHashTest)24 RepositoryImpl (co.rsk.db.RepositoryImpl)16 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)15 Transaction (org.ethereum.core.Transaction)15 Program (org.ethereum.vm.program.Program)15 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 AccountState (org.ethereum.core.AccountState)12 HashMapDB (org.ethereum.datasource.HashMapDB)11 ArrayList (java.util.ArrayList)10 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)10 BridgeConstants (co.rsk.config.BridgeConstants)8 RskSystemProperties (co.rsk.config.RskSystemProperties)8 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)8