Search in sources :

Example 6 with Program

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());
}
Also used : Program(org.ethereum.vm.program.Program) DataWord(org.ethereum.vm.DataWord) Stack(org.ethereum.vm.program.Stack) Test(org.junit.Test)

Example 7 with Program

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());
}
Also used : Program(org.ethereum.vm.program.Program) Test(org.junit.Test)

Example 8 with Program

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));
}
Also used : BlockchainConfig(org.ethereum.config.BlockchainConfig) Program(org.ethereum.vm.program.Program) Test(org.junit.Test)

Example 9 with Program

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);
}
Also used : Program(org.ethereum.vm.program.Program) RskSystemProperties(co.rsk.config.RskSystemProperties) Before(org.junit.Before)

Example 10 with Program

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());
}
Also used : Program(org.ethereum.vm.program.Program) AccountState(org.ethereum.core.AccountState) Coin(co.rsk.core.Coin) ProgramInvokeMockImpl(org.ethereum.vm.program.invoke.ProgramInvokeMockImpl) Repository(org.ethereum.core.Repository) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) Ignore(org.junit.Ignore) 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