Search in sources :

Example 16 with ContractDetails

use of org.ethereum.db.ContractDetails in project rskj by rsksmart.

the class RepositoryImplForTesting method addStorageRow.

@Override
public synchronized void addStorageRow(RskAddress addr, DataWord key, DataWord value) {
    super.addStorageRow(addr, key, value);
    AccountState accountState = getAccountState(addr);
    ContractDetails details = getDetailsDataStore().get(addr);
    accountState.setStateRoot(details.getStorageHash());
    updateAccountState(addr, accountState);
}
Also used : AccountState(org.ethereum.core.AccountState) ContractDetails(org.ethereum.db.ContractDetails)

Example 17 with ContractDetails

use of org.ethereum.db.ContractDetails in project rskj by rsksmart.

the class RepositoryImplOriginalTest method test20.

// testing for snapshot
@Test
public void test20() {
    TrieStore store = new TrieStoreImpl(new HashMapDB());
    Repository repository = new RepositoryImpl(config, store);
    byte[] root = repository.getRoot();
    DataWord cowKey1 = new DataWord("c1");
    DataWord cowKey2 = new DataWord("c2");
    DataWord cowVal1 = new DataWord("c0a1");
    DataWord cowVal0 = new DataWord("c0a0");
    DataWord horseKey1 = new DataWord("e1");
    DataWord horseKey2 = new DataWord("e2");
    DataWord horseVal1 = new DataWord("c0a1");
    DataWord horseVal0 = new DataWord("c0a0");
    // track
    Repository track2 = repository.startTracking();
    track2.addStorageRow(COW, cowKey1, cowVal1);
    track2.addStorageRow(HORSE, horseKey1, horseVal1);
    track2.commit();
    byte[] root2 = repository.getRoot();
    // track
    track2 = repository.startTracking();
    track2.addStorageRow(COW, cowKey2, cowVal0);
    track2.addStorageRow(HORSE, horseKey2, horseVal0);
    track2.commit();
    byte[] root3 = repository.getRoot();
    Repository snapshot = repository.getSnapshotTo(root);
    ContractDetails cowDetails = snapshot.getContractDetails(COW);
    ContractDetails horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(null, cowDetails.get(cowKey1));
    assertEquals(null, cowDetails.get(cowKey2));
    assertEquals(null, horseDetails.get(horseKey1));
    assertEquals(null, horseDetails.get(horseKey2));
    snapshot = repository.getSnapshotTo(root2);
    cowDetails = snapshot.getContractDetails(COW);
    horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(cowVal1, cowDetails.get(cowKey1));
    assertEquals(null, cowDetails.get(cowKey2));
    assertEquals(horseVal1, horseDetails.get(horseKey1));
    assertEquals(null, horseDetails.get(horseKey2));
    snapshot = repository.getSnapshotTo(root3);
    cowDetails = snapshot.getContractDetails(COW);
    horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(cowVal1, cowDetails.get(cowKey1));
    assertEquals(cowVal0, cowDetails.get(cowKey2));
    assertEquals(horseVal1, horseDetails.get(horseKey1));
    assertEquals(horseVal0, horseDetails.get(horseKey2));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 18 with ContractDetails

use of org.ethereum.db.ContractDetails in project rskj by rsksmart.

the class RepositoryTest method test19b.

@Test
public void test19b() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
    byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
    DataWord cowKey1 = new DataWord("c1");
    byte[] cowVal1 = Hex.decode("c0a1");
    byte[] cowVal0 = Hex.decode("c0a0");
    DataWord horseKey1 = new DataWord("e1");
    byte[] horseVal1 = Hex.decode("c0a1");
    byte[] horseVal0 = Hex.decode("c0a0");
    track.addStorageBytes(COW, cowKey1, cowVal0);
    track.addStorageBytes(HORSE, horseKey1, horseVal0);
    track.commit();
    // track
    Repository track2 = repository.startTracking();
    track2.addStorageBytes(HORSE, horseKey1, horseVal0);
    Repository track3 = track2.startTracking();
    ContractDetails cowDetails = track3.getContractDetails(COW);
    cowDetails.putBytes(cowKey1, cowVal1);
    ContractDetails horseDetails = track3.getContractDetails(HORSE);
    horseDetails.putBytes(horseKey1, horseVal1);
    track3.commit();
    track2.rollback();
    ContractDetails cowDetailsOrigin = repository.getContractDetails(COW);
    byte[] cowValOrin = cowDetailsOrigin.getBytes(cowKey1);
    ContractDetails horseDetailsOrigin = repository.getContractDetails(HORSE);
    byte[] horseValOrin = horseDetailsOrigin.getBytes(horseKey1);
    assertArrayEquals(cowVal0, cowValOrin);
    assertArrayEquals(horseVal0, horseValOrin);
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 19 with ContractDetails

use of org.ethereum.db.ContractDetails in project rskj by rsksmart.

the class ReversibleTransactionExecutorTest method executeTransactionGreeterOtherSender.

@Test
public void executeTransactionGreeterOtherSender() {
    TestContract greeter = TestContract.greeter();
    CallTransaction.Function greeterFn = greeter.functions.get("greet");
    ContractDetails contract = contractRunner.addContract(greeter.runtimeBytecode);
    // someone else
    RskAddress from = new RskAddress("0000000000000000000000000000000000000023");
    byte[] gasPrice = Hex.decode("00");
    byte[] value = Hex.decode("00");
    byte[] gasLimit = Hex.decode("f424");
    Block bestBlock = factory.getBlockchain().getBestBlock();
    ProgramResult result = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, greeterFn.encode("greet me"), from.getBytes());
    Assert.assertTrue(result.isRevert());
}
Also used : TestContract(co.rsk.util.TestContract) ProgramResult(org.ethereum.vm.program.ProgramResult) CallTransaction(org.ethereum.core.CallTransaction) Block(org.ethereum.core.Block) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 20 with ContractDetails

use of org.ethereum.db.ContractDetails in project rskj by rsksmart.

the class ReversibleTransactionExecutorTest method executeTransactionCountCallsMultipleTimes.

@Test
public void executeTransactionCountCallsMultipleTimes() {
    TestContract countcalls = TestContract.countcalls();
    CallTransaction.Function callsFn = countcalls.functions.get("calls");
    ContractDetails contract = contractRunner.addContract(countcalls.runtimeBytecode);
    // someone else
    RskAddress from = new RskAddress("0000000000000000000000000000000000000023");
    byte[] gasPrice = Hex.decode("00");
    byte[] value = Hex.decode("00");
    byte[] gasLimit = Hex.decode("f424");
    Block bestBlock = factory.getBlockchain().getBestBlock();
    ProgramResult result = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, callsFn.encodeSignature(), from.getBytes());
    Assert.assertNull(result.getException());
    Assert.assertArrayEquals(new String[] { "calls: 1" }, callsFn.decodeResult(result.getHReturn()));
    ProgramResult result2 = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, callsFn.encodeSignature(), from.getBytes());
    Assert.assertNull(result2.getException());
    Assert.assertArrayEquals(new String[] { "calls: 1" }, callsFn.decodeResult(result2.getHReturn()));
}
Also used : TestContract(co.rsk.util.TestContract) ProgramResult(org.ethereum.vm.program.ProgramResult) CallTransaction(org.ethereum.core.CallTransaction) Block(org.ethereum.core.Block) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Aggregations

ContractDetails (org.ethereum.db.ContractDetails)24 Test (org.junit.Test)13 DataWord (org.ethereum.vm.DataWord)9 Repository (org.ethereum.core.Repository)8 RskAddress (co.rsk.core.RskAddress)7 AccountState (org.ethereum.core.AccountState)7 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)6 HashMapDB (org.ethereum.datasource.HashMapDB)6 ProgramResult (org.ethereum.vm.program.ProgramResult)5 TestContract (co.rsk.util.TestContract)4 BigInteger (java.math.BigInteger)4 Block (org.ethereum.core.Block)4 CallTransaction (org.ethereum.core.CallTransaction)4 Coin (co.rsk.core.Coin)3 TrieStore (co.rsk.trie.TrieStore)3 HashMap (java.util.HashMap)3 RskSystemProperties (co.rsk.config.RskSystemProperties)2 VmConfig (co.rsk.config.VmConfig)2 RepositoryImpl (co.rsk.db.RepositoryImpl)2 ArrayList (java.util.ArrayList)2