Search in sources :

Example 21 with Program

use of org.ethereum.vm.program.Program in project rskj by rsksmart.

the class VMExecutionTest method swapnFourthItem.

@Test
public void swapnFourthItem() {
    Program program = executeCode("PUSH1 0x01 PUSH1 0x02 PUSH1 0x03 PUSH1 0x04 PUSH1 0x02 SWAPN", 6);
    Stack stack = program.getStack();
    Assert.assertEquals(4, stack.size());
    Assert.assertEquals(new DataWord(1), stack.peek());
    Assert.assertEquals(new DataWord(4), stack.get(0));
    Assert.assertEquals(new DataWord(2), stack.get(1));
    Assert.assertEquals(new DataWord(3), stack.get(2));
}
Also used : Program(org.ethereum.vm.program.Program) DataWord(org.ethereum.vm.DataWord) Stack(org.ethereum.vm.program.Stack) Test(org.junit.Test)

Example 22 with Program

use of org.ethereum.vm.program.Program in project rskj by rsksmart.

the class VMExecutionTest method callDataCopyBasicGasCost.

@Test
public void callDataCopyBasicGasCost() {
    Program program = executeCode(// push some values for CALLDATACOPY
    "PUSH1 0x00 PUSH1 0x00 PUSH1 0x01 " + // call CALLDATACOPY
    "0x37", 4);
    Assert.assertNotNull(program);
    Assert.assertNotNull(program.getResult());
    Assert.assertNull(program.getResult().getException());
    Assert.assertEquals(12, program.getResult().getGasUsed());
}
Also used : Program(org.ethereum.vm.program.Program) Test(org.junit.Test)

Example 23 with Program

use of org.ethereum.vm.program.Program in project rskj by rsksmart.

the class VMExecutionTest method testSub.

@Test
public void testSub() {
    Program program = executeCode("PUSH1 1 PUSH1 2 SUB", 3);
    Stack stack = program.getStack();
    Assert.assertEquals(1, stack.size());
    Assert.assertEquals(new DataWord(1), stack.peek());
}
Also used : Program(org.ethereum.vm.program.Program) DataWord(org.ethereum.vm.DataWord) Stack(org.ethereum.vm.program.Stack) Test(org.junit.Test)

Example 24 with Program

use of org.ethereum.vm.program.Program in project rskj by rsksmart.

the class VMExecutionTest method executeCode.

private Program executeCode(byte[] code, int nsteps) {
    VM vm = new VM(vmConfig, precompiledContracts);
    Program program = new Program(vmConfig, precompiledContracts, mock(BlockchainConfig.class), code, invoke, null);
    for (int k = 0; k < nsteps; k++) vm.step(program);
    return program;
}
Also used : BlockchainConfig(org.ethereum.config.BlockchainConfig) Program(org.ethereum.vm.program.Program) VM(org.ethereum.vm.VM)

Example 25 with Program

use of org.ethereum.vm.program.Program in project rskj by rsksmart.

the class VMExecutionTest method testCode.

private void testCode(byte[] code, int nsteps, String expected) {
    Program program = executeCode(code, nsteps);
    assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase());
}
Also used : Program(org.ethereum.vm.program.Program)

Aggregations

Program (org.ethereum.vm.program.Program)37 Test (org.junit.Test)27 RskAddress (co.rsk.core.RskAddress)14 DataWord (org.ethereum.vm.DataWord)13 Stack (org.ethereum.vm.program.Stack)13 Coin (co.rsk.core.Coin)12 BigInteger (java.math.BigInteger)12 Repository (org.ethereum.core.Repository)10 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)9 Ignore (org.junit.Ignore)9 BlockchainConfig (org.ethereum.config.BlockchainConfig)7 AccountState (org.ethereum.core.AccountState)5 ProgramInvoke (org.ethereum.vm.program.invoke.ProgramInvoke)4 ContractDetails (org.ethereum.db.ContractDetails)3 VM (org.ethereum.vm.VM)3 RskSystemProperties (co.rsk.config.RskSystemProperties)2 VmConfig (co.rsk.config.VmConfig)2 IOException (java.io.IOException)2 List (java.util.List)2 EMPTY_BYTE_ARRAY (org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY)2