当前位置: 首页>>代码示例>>Java>>正文


Java ProgramInvokeMockImpl类代码示例

本文整理汇总了Java中org.ethereum.vm.program.invoke.ProgramInvokeMockImpl的典型用法代码示例。如果您正苦于以下问题:Java ProgramInvokeMockImpl类的具体用法?Java ProgramInvokeMockImpl怎么用?Java ProgramInvokeMockImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProgramInvokeMockImpl类属于org.ethereum.vm.program.invoke包,在下文中一共展示了ProgramInvokeMockImpl类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Before
public void setup() {
    byte[] ownerAddress = Hex.decode("77045E71A7A2C50903D88E564CD72FAB11E82051");
    byte[] msgData = Hex.decode("00000000000000000000000000000000000000000000000000000000000000A1" +
            "00000000000000000000000000000000000000000000000000000000000000B1");

    invoke = new ProgramInvokeMockImpl(msgData);
    invoke.setOwnerAddress(ownerAddress);

    invoke.getRepository().createAccount(ownerAddress);
    invoke.getRepository().addBalance(ownerAddress, BigInteger.valueOf(1000L));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:13,代码来源:VMCustomTest.java

示例2: setup

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Before
public void setup() {
    invoke = new ProgramInvokeMockImpl();
    compiler = new BytecodeCompiler();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:6,代码来源:VMExecutionTest.java

示例3: setup

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Before
public void setup() {
    invoke = new ProgramInvokeMockImpl();
    long million=1000000;
    invoke.setGasLimit(1000*million);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:7,代码来源:VMPerformanceTest.java

示例4: setup

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Before
public void setup() {
    invoke = new ProgramInvokeMockImpl();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:5,代码来源:VMTest.java

示例5: test1

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore //TODO #POC9
@Test // contract call recursive
public void test1() {

    /**
     *       #The code will run
     *       ------------------

             a = contract.storage[999]
             if a > 0:
                 contract.storage[999] = a - 1

                 # call to contract: 77045e71a7a2c50903d88e564cd72fab11e82051
                 send((tx.gas / 10 * 8), 0x77045e71a7a2c50903d88e564cd72fab11e82051, 0)
             else:
                 stop
     */

    int expectedGas = 436;

    DataWord key1 = new DataWord(999);
    DataWord value1 = new DataWord(3);

    // Set contract into Database
    String callerAddr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
    String contractAddr = "77045e71a7a2c50903d88e564cd72fab11e82051";
    String code =
            "6103e75460005260006000511115630000004c576001600051036103e755600060006000600060007377045e71a7a2c50903d88e564cd72fab11e820516008600a5a0402f1630000004c00565b00";

    byte[] contractAddrB = Hex.decode(contractAddr);
    byte[] callerAddrB = Hex.decode(callerAddr);
    byte[] codeB = Hex.decode(code);

    byte[] codeKey = HashUtil.sha3(codeB);
    AccountState accountState = new AccountState(BigInteger.ZERO, BigInteger.ZERO);
    accountState.setCodeHash(codeKey);

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractAddrB);
    Repository repository = pi.getRepository();

    repository.createAccount(callerAddrB);
    repository.addBalance(callerAddrB, new BigInteger("100000000000000000000"));

    repository.createAccount(contractAddrB);
    repository.saveCode(contractAddrB, codeB);
    repository.addStorageRow(contractAddrB, key1, value1);

    // Play the program
    VM vm = new VM(ConfigHelper.CONFIG);
    Program program = new Program(ConfigHelper.CONFIG, codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");

    BigInteger 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());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:73,代码来源:VMComplexTest.java

示例6: test4

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Test // CREATE magic
public void test4() {

    /**
     *       #The code will run
     *       ------------------

     contract A: 77045e71a7a2c50903d88e564cd72fab11e82051
     -----------

         a = 0x7f60c860005461012c6020540000000000000000000000000000000000000000
         b = 0x0060005460206000f20000000000000000000000000000000000000000000000
         create(100, 0 41)


     contract B: (the contract to be created the addr will be defined to: 8e45367623a2865132d9bf875d5cfa31b9a0cd94)
     -----------
         a = 200
         b = 300

     */

    // Set contract into Database
    byte[] caller_addr_bytes = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");

    byte[] contractA_addr_bytes = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051");

    byte[] codeA = Hex.decode("7f7f60c860005461012c602054000000000000" +
            "00000000000000000000000000006000547e60" +
            "005460206000f2000000000000000000000000" +
            "0000000000000000000000602054602960006064f0");

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractA_addr_bytes);

    Repository repository = pi.getRepository();

    repository.createAccount(contractA_addr_bytes);
    repository.saveCode(contractA_addr_bytes, codeA);

    repository.createAccount(caller_addr_bytes);

    // ****************** //
    //  Play the program  //
    // ****************** //
    VM vm = new VM(ConfigHelper.CONFIG);
    Program program = new Program(ConfigHelper.CONFIG, codeA, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    logger.info("============ Results ============");

    System.out.println("*** Used gas: " + program.getResult().getGasUsed());
    // TODO: check that the value pushed after exec is the new address
    repository.close();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:62,代码来源:VMComplexTest.java

示例7: test6

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore
@Test // contractB call itself with code from contractA
public void test6() {
    /**
     *       #The code will run
     *       ------------------

     contract A: 945304eb96065b2a98b57a48a06ae28d285a71b5
     ---------------

     PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP
     PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE

     contract B: 0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6
     -----------
         { (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
           (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa)
           [[ 0 ]] (CALLSTATELESS 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 64 0)
         }
     */

    // Set contract into Database
    byte[] caller_addr_bytes = Hex.decode("cd1722f3947def4cf144679da39c4c32bdc35681");

    byte[] contractA_addr_bytes = Hex.decode("945304eb96065b2a98b57a48a06ae28d285a71b5");
    byte[] contractB_addr_bytes = Hex.decode("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6");

    byte[] codeA = Hex.decode("60003554156009570060203560003555");
    byte[] codeB = Hex.decode("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000527faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020526000604060406000601773945304eb96065b2a98b57a48a06ae28d285a71b5620f4240f3600055");

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractB_addr_bytes);
    pi.setGasLimit(10000000000000l);

    Repository repository = pi.getRepository();
    repository.createAccount(contractA_addr_bytes);
    repository.saveCode(contractA_addr_bytes, codeA);
    repository.addBalance(contractA_addr_bytes, BigInteger.valueOf(23));

    repository.createAccount(contractB_addr_bytes);
    repository.saveCode(contractB_addr_bytes, codeB);
    repository.addBalance(contractB_addr_bytes, new BigInteger("1000000000000000000"));

    repository.createAccount(caller_addr_bytes);
    repository.addBalance(caller_addr_bytes, new BigInteger("100000000000000000000"));

    // ****************** //
    //  Play the program  //
    // ****************** //
    VM vm = new VM(ConfigHelper.CONFIG);
    Program program = new Program(ConfigHelper.CONFIG, codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");
    System.out.println("*** Used gas: " + program.getResult().getGasUsed());

    DataWord memValue1 = program.memoryLoad(new DataWord(0));
    DataWord memValue2 = program.memoryLoad(new DataWord(32));

    DataWord storeValue1 = repository.getStorageValue(contractB_addr_bytes, new DataWord(00));

    repository.close();

    assertEquals("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", memValue1.toString());
    assertEquals("aaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa", memValue2.toString());

    assertEquals("0x1", storeValue1.shortHex());

    // TODO: check that the value pushed after exec is 1
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:78,代码来源:VMComplexTest.java

示例8: test7

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore //TODO #POC9
@Test // contract call quadratic memory use
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";

    byte[] contractAddrB = Hex.decode(contractAddr);
    byte[] callerAddrB = Hex.decode(callerAddr);
    byte[] codeB = Hex.decode(code);

    byte[] codeKey = HashUtil.sha3(codeB);
    AccountState accountState = new AccountState(BigInteger.ZERO, BigInteger.ZERO);
    accountState.setCodeHash(codeKey);

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractAddrB);
    Repository repository = pi.getRepository();

    repository.createAccount(callerAddrB);
    repository.addBalance(callerAddrB, new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935"));

    repository.createAccount(contractAddrB);
    repository.saveCode(contractAddrB, codeB);
    repository.addStorageRow(contractAddrB, key1, value1);

    // Play the program
    VM vm = new VM(ConfigHelper.CONFIG);
    Program program = new Program(ConfigHelper.CONFIG, codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");

    BigInteger 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());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:58,代码来源:VMComplexTest.java

示例9: test8

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore //TODO #POC9
@Test // contract call quadratic memory use
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";

    byte[] contractAddrB = Hex.decode(contractAddr);
    byte[] callerAddrB = Hex.decode(callerAddr);
    byte[] codeB = Hex.decode(code);

    byte[] codeKey = HashUtil.sha3(codeB);
    AccountState accountState = new AccountState(BigInteger.ZERO, BigInteger.ZERO);
    accountState.setCodeHash(codeKey);

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractAddrB);
    Repository repository = pi.getRepository();

    repository.createAccount(callerAddrB);
    repository.addBalance(callerAddrB, new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935"));

    repository.createAccount(contractAddrB);
    repository.saveCode(contractAddrB, codeB);
    repository.addStorageRow(contractAddrB, key1, value1);

    // Play the program
    VM vm = new VM(ConfigHelper.CONFIG);
    Program program = new Program(ConfigHelper.CONFIG, codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");

    BigInteger 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());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:58,代码来源:VMComplexTest.java

示例10: test9

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore //TODO #POC9
@Test // contract call quadratic memory use
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";

    byte[] contractAddrB = Hex.decode(contractAddr);
    byte[] callerAddrB = Hex.decode(callerAddr);
    byte[] codeB = Hex.decode(code);

    byte[] codeKey = HashUtil.sha3(codeB);
    AccountState accountState = new AccountState(BigInteger.ZERO, BigInteger.ZERO);
    accountState.setCodeHash(codeKey);

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractAddrB);
    Repository repository = pi.getRepository();

    repository.createAccount(callerAddrB);
    repository.addBalance(callerAddrB, new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935"));

    repository.createAccount(contractAddrB);
    repository.saveCode(contractAddrB, codeB);
    repository.addStorageRow(contractAddrB, key1, value1);

    // Play the program
    VM vm = new VM(ConfigHelper.CONFIG);
    Program program = new Program(ConfigHelper.CONFIG, codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");

    BigInteger 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());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:58,代码来源:VMComplexTest.java

示例11: test10

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore //TODO #POC9
@Test // contract call quadratic memory use
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";

    byte[] contractAddrB = Hex.decode(contractAddr);
    byte[] callerAddrB = Hex.decode(callerAddr);
    byte[] codeB = Hex.decode(code);

    byte[] codeKey = HashUtil.sha3(codeB);
    AccountState accountState = new AccountState(BigInteger.ZERO, BigInteger.ZERO);
    accountState.setCodeHash(codeKey);

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractAddrB);
    Repository repository = pi.getRepository();

    repository.createAccount(callerAddrB);
    repository.addBalance(callerAddrB, new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935"));

    repository.createAccount(contractAddrB);
    repository.saveCode(contractAddrB, codeB);
    repository.addStorageRow(contractAddrB, key1, value1);

    // Play the program
    VM vm = new VM(ConfigHelper.CONFIG);
    Program program = new Program(ConfigHelper.CONFIG, codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");

    BigInteger 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());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:58,代码来源:VMComplexTest.java

示例12: test1

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore //TODO #POC9
@Test // contract call recursive
public void test1() {

    /**
     *       #The code will run
     *       ------------------

             a = contract.storage[999]
             if a > 0:
                 contract.storage[999] = a - 1

                 # call to contract: 77045e71a7a2c50903d88e564cd72fab11e82051
                 send((tx.gas / 10 * 8), 0x77045e71a7a2c50903d88e564cd72fab11e82051, 0)
             else:
                 stop
     */

    int expectedGas = 436;

    DataWord key1 = new DataWord(999);
    DataWord value1 = new DataWord(3);

    // Set contract into Database
    String callerAddr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
    String contractAddr = "77045e71a7a2c50903d88e564cd72fab11e82051";
    String code =
            "6103e75460005260006000511115630000004c576001600051036103e755600060006000600060007377045e71a7a2c50903d88e564cd72fab11e820516008600a5a0402f1630000004c00565b00";

    byte[] contractAddrB = Hex.decode(contractAddr);
    byte[] callerAddrB = Hex.decode(callerAddr);
    byte[] codeB = Hex.decode(code);

    byte[] codeKey = HashUtil.sha3(codeB);
    AccountState accountState = new AccountState(SystemProperties.getDefault())
            .withCodeHash(codeKey);

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractAddrB);
    Repository repository = pi.getRepository();

    repository.createAccount(callerAddrB);
    repository.addBalance(callerAddrB, new BigInteger("100000000000000000000"));

    repository.createAccount(contractAddrB);
    repository.saveCode(contractAddrB, codeB);
    repository.addStorageRow(contractAddrB, key1, value1);

    // Play the program
    VM vm = new VM();
    Program program = new Program(codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");

    BigInteger 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());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:73,代码来源:VMComplexTest.java

示例13: test4

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Test // CREATE magic
public void test4() {

    /**
     *       #The code will run
     *       ------------------

     contract A: 77045e71a7a2c50903d88e564cd72fab11e82051
     -----------

         a = 0x7f60c860005461012c6020540000000000000000000000000000000000000000
         b = 0x0060005460206000f20000000000000000000000000000000000000000000000
         create(100, 0 41)


     contract B: (the contract to be created the addr will be defined to: 8e45367623a2865132d9bf875d5cfa31b9a0cd94)
     -----------
         a = 200
         b = 300

     */

    // Set contract into Database
    byte[] caller_addr_bytes = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");

    byte[] contractA_addr_bytes = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051");

    byte[] codeA = Hex.decode("7f7f60c860005461012c602054000000000000" +
            "00000000000000000000000000006000547e60" +
            "005460206000f2000000000000000000000000" +
            "0000000000000000000000602054602960006064f0");

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractA_addr_bytes);

    Repository repository = pi.getRepository();

    repository.createAccount(contractA_addr_bytes);
    repository.saveCode(contractA_addr_bytes, codeA);

    repository.createAccount(caller_addr_bytes);

    // ****************** //
    //  Play the program  //
    // ****************** //
    VM vm = new VM();
    Program program = new Program(codeA, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    logger.info("============ Results ============");

    System.out.println("*** Used gas: " + program.getResult().getGasUsed());
    // TODO: check that the value pushed after exec is the new address
    repository.close();
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:62,代码来源:VMComplexTest.java

示例14: test6

import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; //导入依赖的package包/类
@Ignore
@Test // contractB call itself with code from contractA
public void test6() {
    /**
     *       #The code will run
     *       ------------------

     contract A: 945304eb96065b2a98b57a48a06ae28d285a71b5
     ---------------

     PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP
     PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE

     contract B: 0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6
     -----------
         { (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
           (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa)
           [[ 0 ]] (CALLSTATELESS 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 64 0)
         }
     */

    // Set contract into Database
    byte[] caller_addr_bytes = Hex.decode("cd1722f3947def4cf144679da39c4c32bdc35681");

    byte[] contractA_addr_bytes = Hex.decode("945304eb96065b2a98b57a48a06ae28d285a71b5");
    byte[] contractB_addr_bytes = Hex.decode("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6");

    byte[] codeA = Hex.decode("60003554156009570060203560003555");
    byte[] codeB = Hex.decode("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000527faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020526000604060406000601773945304eb96065b2a98b57a48a06ae28d285a71b5620f4240f3600055");

    ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
    pi.setOwnerAddress(contractB_addr_bytes);
    pi.setGasLimit(10000000000000l);

    Repository repository = pi.getRepository();
    repository.createAccount(contractA_addr_bytes);
    repository.saveCode(contractA_addr_bytes, codeA);
    repository.addBalance(contractA_addr_bytes, BigInteger.valueOf(23));

    repository.createAccount(contractB_addr_bytes);
    repository.saveCode(contractB_addr_bytes, codeB);
    repository.addBalance(contractB_addr_bytes, new BigInteger("1000000000000000000"));

    repository.createAccount(caller_addr_bytes);
    repository.addBalance(caller_addr_bytes, new BigInteger("100000000000000000000"));

    // ****************** //
    //  Play the program  //
    // ****************** //
    VM vm = new VM();
    Program program = new Program(codeB, pi);

    try {
        while (!program.isStopped())
            vm.step(program);
    } catch (RuntimeException e) {
        program.setRuntimeFailure(e);
    }

    System.out.println();
    System.out.println("============ Results ============");
    System.out.println("*** Used gas: " + program.getResult().getGasUsed());

    DataWord memValue1 = program.memoryLoad(new DataWord(0));
    DataWord memValue2 = program.memoryLoad(new DataWord(32));

    DataWord storeValue1 = repository.getStorageValue(contractB_addr_bytes, new DataWord(00));

    repository.close();

    assertEquals("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", memValue1.toString());
    assertEquals("aaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa", memValue2.toString());

    assertEquals("0x1", storeValue1.shortHex());

    // TODO: check that the value pushed after exec is 1
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:78,代码来源:VMComplexTest.java


注:本文中的org.ethereum.vm.program.invoke.ProgramInvokeMockImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。