Search in sources :

Example 1 with ProgramInvokeMockImpl

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

the class VMPerformanceTest method setup.

@Before
public void setup() {
    invoke = new ProgramInvokeMockImpl();
    long million = 1000000;
    invoke.setGasLimit(1000 * million);
}
Also used : ProgramInvokeMockImpl(org.ethereum.vm.program.invoke.ProgramInvokeMockImpl) Before(org.junit.Before)

Example 2 with ProgramInvokeMockImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeMockImpl 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)

Example 3 with ProgramInvokeMockImpl

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

the class VMComplexTest method test9.

// sha3_memSizeQuadraticCost32
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test9() {
    int expectedGas = 356;
    DataWord key1 = new DataWord(9999);
    DataWord value1 = new DataWord(3);
    // Set contract into Database
    String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
    String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
    String code = "60016103e020600055";
    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)

Example 4 with ProgramInvokeMockImpl

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

the class VMComplexTest method test7.

// sha3_memSizeQuadraticCost33
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test7() {
    int expectedGas = 357;
    DataWord key1 = new DataWord(999);
    DataWord value1 = new DataWord(3);
    // Set contract into Database
    String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
    String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
    String code = "600161040020600055";
    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)

Example 5 with ProgramInvokeMockImpl

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

the class VMComplexTest method test10.

// sha3_memSizeQuadraticCost32_zeroSize
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test10() {
    int expectedGas = 313;
    DataWord key1 = new DataWord(999);
    DataWord value1 = new DataWord(3);
    // Set contract into Database
    String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
    String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
    String code = "600061040020600055";
    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

ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)12 RskAddress (co.rsk.core.RskAddress)10 Repository (org.ethereum.core.Repository)9 Program (org.ethereum.vm.program.Program)9 Test (org.junit.Test)9 Coin (co.rsk.core.Coin)8 BigInteger (java.math.BigInteger)8 Ignore (org.junit.Ignore)8 AccountState (org.ethereum.core.AccountState)5 Before (org.junit.Before)2