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