Search in sources :

Example 26 with Program

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

the class VMExecutionTest method dupnFirstItem.

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

Example 27 with Program

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

the class VMExecutionTest method testJumpSkippingInvalidJump.

@Test
public void testJumpSkippingInvalidJump() {
    Program program = executeCode("PUSH1 0x05 JUMP PUSH1 0xa0 JUMPDEST PUSH1 0x01", 4);
    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 28 with Program

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

the class VMExecutionTest method dupnFourthItem.

@Test
public void dupnFourthItem() {
    Program program = executeCode("PUSH1 0x01 PUSH1 0x02 PUSH1 0x03 PUSH1 0x04 PUSH1 0x03 DUPN", 6);
    Stack stack = program.getStack();
    Assert.assertEquals(5, stack.size());
    Assert.assertEquals(new DataWord(1), stack.peek());
    for (int k = 0; k < 4; k++) Assert.assertEquals(new DataWord(k + 1), stack.get(k));
}
Also used : Program(org.ethereum.vm.program.Program) DataWord(org.ethereum.vm.DataWord) Stack(org.ethereum.vm.program.Stack) Test(org.junit.Test)

Example 29 with Program

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

the class VMExecutionTest method testPush1.

@Test
public void testPush1() {
    Program program = executeCode("PUSH1 0xa0", 1);
    Stack stack = program.getStack();
    Assert.assertEquals(1, stack.size());
    Assert.assertEquals(new DataWord(0xa0), 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 30 with Program

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

the class VMExecutionTest method swapnArgumentIsNotJumpdest.

@Test
public void swapnArgumentIsNotJumpdest() {
    byte[] code = compiler.compile("JUMPDEST SWAPN 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));
}
Also used : BlockchainConfig(org.ethereum.config.BlockchainConfig) Program(org.ethereum.vm.program.Program) Test(org.junit.Test)

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