use of org.ethereum.vm.program.Program in project rskj by rsksmart.
the class VMComplexTest method test4.
// CREATE magic
@Test
public void test4() {
/**
* #The code will run
* ------------------
*
* contract A: 77045e71a7a2c50903d88e564cd72fab11e82051
* -----------
*
* a = 0x7f60c860005461012c6020540000000000000000000000000000000000000000
* b = 0x0060005460206000f20000000000000000000000000000000000000000000000
* create(100, 0 41)
*
* contract B: (the contract to be created the addr will be defined to: 8e45367623a2865132d9bf875d5cfa31b9a0cd94)
* -----------
* a = 200
* b = 300
*/
// Set contract into Database
RskAddress caller_addr = new RskAddress("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
RskAddress contractA_addr = new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051");
byte[] codeA = Hex.decode("7f7f60c860005461012c602054000000000000" + "00000000000000000000000000006000547e60" + "005460206000f2000000000000000000000000" + "0000000000000000000000602054602960006064f0");
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractA_addr);
Repository repository = pi.getRepository();
repository.createAccount(contractA_addr);
repository.saveCode(contractA_addr, codeA);
repository.createAccount(caller_addr);
// ****************** //
// Play the program //
// ****************** //
VM vm = getSubject();
Program program = getProgram(codeA, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
logger.info("============ Results ============");
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
// TODO: check that the value pushed after exec is the new address
repository.close();
}
use of org.ethereum.vm.program.Program in project rskj by rsksmart.
the class VMComplexTest method test1.
// TODO #POC9
@Ignore
// contract call recursive
@Test
public void test1() {
/**
* #The code will run
* ------------------
*
* a = contract.storage[999]
* if a > 0:
* contract.storage[999] = a - 1
*
* # call to contract: 77045e71a7a2c50903d88e564cd72fab11e82051
* send((tx.gas / 10 * 8), 0x77045e71a7a2c50903d88e564cd72fab11e82051, 0)
* else:
* stop
*/
int expectedGas = 436;
DataWord key1 = new DataWord(999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
String contractAddr = "77045e71a7a2c50903d88e564cd72fab11e82051";
String code = "6103e75460005260006000511115630000004c576001600051036103e755600060006000600060007377045e71a7a2c50903d88e564cd72fab11e820516008600a5a0402f1630000004c00565b00";
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("100000000000000000000");
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());
}
Aggregations