use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class VMComplexTest method test9.
// sha3_memSizeQuadraticCost32
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test9() {
int expectedGas = 356;
DataWord key1 = new DataWord(9999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "60016103e020600055";
RskAddress contractAddrB = new RskAddress(contractAddr);
RskAddress callerAddrB = new RskAddress(callerAddr);
byte[] codeB = Hex.decode(code);
byte[] codeKey = HashUtil.keccak256(codeB);
AccountState accountState = new AccountState();
accountState.setCodeHash(codeKey);
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractAddrB);
Repository repository = pi.getRepository();
repository.createAccount(callerAddrB);
final BigInteger value = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
repository.addBalance(callerAddrB, new Coin(value));
repository.createAccount(contractAddrB);
repository.saveCode(contractAddrB, codeB);
repository.addStorageRow(contractAddrB, key1, value1);
// Play the program
VM vm = getSubject();
Program program = getProgram(codeB, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
System.out.println();
System.out.println("============ Results ============");
Coin balance = repository.getBalance(callerAddrB);
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
System.out.println("*** Contract Balance: " + balance);
// todo: assert caller balance after contract exec
repository.close();
assertEquals(expectedGas, program.getResult().getGasUsed());
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class VMComplexTest method test7.
// sha3_memSizeQuadraticCost33
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test7() {
int expectedGas = 357;
DataWord key1 = new DataWord(999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "600161040020600055";
RskAddress contractAddrB = new RskAddress(contractAddr);
RskAddress callerAddrB = new RskAddress(callerAddr);
byte[] codeB = Hex.decode(code);
byte[] codeKey = HashUtil.keccak256(codeB);
AccountState accountState = new AccountState();
accountState.setCodeHash(codeKey);
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractAddrB);
Repository repository = pi.getRepository();
repository.createAccount(callerAddrB);
final BigInteger value = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
repository.addBalance(callerAddrB, new Coin(value));
repository.createAccount(contractAddrB);
repository.saveCode(contractAddrB, codeB);
repository.addStorageRow(contractAddrB, key1, value1);
// Play the program
VM vm = getSubject();
Program program = getProgram(codeB, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
System.out.println();
System.out.println("============ Results ============");
Coin balance = repository.getBalance(callerAddrB);
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
System.out.println("*** Contract Balance: " + balance);
// todo: assert caller balance after contract exec
repository.close();
assertEquals(expectedGas, program.getResult().getGasUsed());
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class VMComplexTest method test10.
// sha3_memSizeQuadraticCost32_zeroSize
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test10() {
int expectedGas = 313;
DataWord key1 = new DataWord(999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "600061040020600055";
RskAddress contractAddrB = new RskAddress(contractAddr);
RskAddress callerAddrB = new RskAddress(callerAddr);
byte[] codeB = Hex.decode(code);
byte[] codeKey = HashUtil.keccak256(codeB);
AccountState accountState = new AccountState();
accountState.setCodeHash(codeKey);
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractAddrB);
Repository repository = pi.getRepository();
repository.createAccount(callerAddrB);
final BigInteger value = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
repository.addBalance(callerAddrB, new Coin(value));
repository.createAccount(contractAddrB);
repository.saveCode(contractAddrB, codeB);
repository.addStorageRow(contractAddrB, key1, value1);
// Play the program
VM vm = getSubject();
Program program = getProgram(codeB, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
System.out.println();
System.out.println("============ Results ============");
Coin balance = repository.getBalance(callerAddrB);
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
System.out.println("*** Contract Balance: " + balance);
// todo: assert caller balance after contract exec
repository.close();
assertEquals(expectedGas, program.getResult().getGasUsed());
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryTrack method hibernate.
@Override
public void hibernate(RskAddress addr) {
synchronized (repository) {
AccountState accountState = getAccountState(addr);
if (accountState == null) {
accountState = createAccount(addr);
}
getContractDetails(addr).setDirty(true);
accountState.hibernate();
}
logger.trace("hibernate addr: [{}]", addr);
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryTrack method setNonce.
public BigInteger setNonce(RskAddress addr, BigInteger bigInteger) {
synchronized (repository) {
AccountState accountState = getAccountState(addr);
if (accountState == null) {
accountState = createAccount(addr);
}
getContractDetails(addr).setDirty(true);
BigInteger saveNonce = accountState.getNonce();
accountState.setNonce(bigInteger);
logger.trace("increase nonce addr: [{}], from: [{}], to: [{}]", addr, saveNonce, accountState.getNonce());
return accountState.getNonce();
}
}
Aggregations