use of org.ethereum.vm.program.Program in project rskj by rsksmart.
the class VMExecutionTest method txindexExecution.
@Test
public void txindexExecution() {
invoke.setTransactionIndex(new DataWord(42));
Program program = executeCode("TXINDEX", 1);
Stack stack = program.getStack();
Assert.assertEquals(1, stack.size());
Assert.assertEquals(new DataWord(42), stack.peek());
}
use of org.ethereum.vm.program.Program in project rskj by rsksmart.
the class VMExecutionTest method returnDataCopyBasicGasCost.
@Test
public void returnDataCopyBasicGasCost() {
Program program = executeCode(// push some values for RETURNDATACOPY
"PUSH1 0x00 PUSH1 0x00 PUSH1 0x01 " + // call RETURNDATACOPY
"0x3e", 4);
Assert.assertNotNull(program);
Assert.assertNotNull(program.getResult());
Assert.assertNull(program.getResult().getException());
Assert.assertEquals(12, program.getResult().getGasUsed());
}
use of org.ethereum.vm.program.Program in project rskj by rsksmart.
the class VMExecutionTest method dupnArgumentIsNotJumpdest.
@Test
public void dupnArgumentIsNotJumpdest() {
byte[] code = compiler.compile("JUMPDEST DUPN 0x5b 0x5b");
Program program = new Program(vmConfig, precompiledContracts, mock(BlockchainConfig.class), code, invoke, null);
BitSet jumpdestSet = program.getJumpdestSet();
Assert.assertNotNull(jumpdestSet);
Assert.assertEquals(4, jumpdestSet.size());
Assert.assertTrue(jumpdestSet.get(0));
Assert.assertFalse(jumpdestSet.get(1));
Assert.assertTrue(jumpdestSet.get(2));
Assert.assertTrue(jumpdestSet.get(3));
}
use of org.ethereum.vm.program.Program in project rskj by rsksmart.
the class ProgramMemoryTest method createProgram.
@Before
public void createProgram() {
RskSystemProperties config = new RskSystemProperties();
program = new Program(config.getVmConfig(), new PrecompiledContracts(config), mock(BlockchainConfig.class), ByteUtil.EMPTY_BYTE_ARRAY, pi, null);
}
use of org.ethereum.vm.program.Program in project rskj by rsksmart.
the class VMComplexTest method test8.
// sha3_memSizeQuadraticCost31
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test8() {
int expectedGas = 354;
DataWord key1 = new DataWord(999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "60016103c020600055";
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());
}
Aggregations