Search in sources :

Example 1 with StateTestSuite

use of org.ethereum.jsontestsuite.StateTestSuite in project rskj by rsksmart.

the class TransactionTest method constantCallConflictTest.

@Test
public void constantCallConflictTest() throws Exception {
    /*
          0x095e7baea6a6c7c4c2dfeb977efac326af552d87 contract is the following Solidity code:

         contract Test {
            uint a = 256;

            function set(uint s) {
                a = s;
            }

            function get() returns (uint) {
                return a;
            }
        }
        */
    String json = "{ " + "    'test1' : { " + "        'env' : { " + "            'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " + "            'currentDifficulty' : '0x0100', " + "            'currentGasLimit' : '0x0f4240', " + "            'currentNumber' : '0x00', " + "            'currentTimestamp' : '0x01', " + "            'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " + "        }, " + "        'logs' : [ " + "        ], " + "        'out' : '0x', " + "        'post' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a76586a0', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x0400' " + "                } " + "            }, " + "            '" + PrecompiledContracts.REMASC_ADDR_STR + "' : { " + "                'balance' : '0x67EB', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0DE0B6B3A7621175', " + "                'code' : '0x', " + "                'nonce' : '0x01', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " + "        'pre' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x02' " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'transaction' : { " + "            'data' : '0x60fe47b10000000000000000000000000000000000000000000000000000000000000400', " + "            'gasLimit' : '0x061a80', " + "            'gasPrice' : '0x01', " + "            'nonce' : '0x00', " + "            'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " + "            'to' : '095e7baea6a6c7c4c2dfeb977efac326af552d87', " + "            'value' : '0x0186a0' " + "        } " + "    } " + "}";
    StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
    List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")) {

        @Override
        protected ProgramResult executeTransaction(Transaction tx) {
            // first emulating the constant call (Ethereum.callConstantFunction)
            // to ensure it doesn't affect the final state
            {
                Repository track = repository.startTracking();
                Transaction txConst = CallTransaction.createCallTransaction(config, 0, 0, 100000000000000L, new RskAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), 0, CallTransaction.Function.fromSignature("get"));
                txConst.sign(new byte[32]);
                Block bestBlock = block;
                TransactionExecutor executor = new TransactionExecutor(config, txConst, 0, bestBlock.getCoinbase(), track, new BlockStoreDummy(), null, invokeFactory, bestBlock).setLocalCall(true);
                executor.init();
                executor.execute();
                executor.go();
                executor.finalization();
                track.rollback();
                System.out.println("Return value: " + new CallTransaction.IntType("uint").decode(executor.getResult().getHReturn()));
            }
            // now executing the JSON test transaction
            return super.executeTransaction(tx);
        }
    }.runImpl();
    if (!res.isEmpty())
        throw new RuntimeException("Test failed: " + res);
}
Also used : ProgramResult(org.ethereum.vm.program.ProgramResult) BlockStoreDummy(org.ethereum.db.BlockStoreDummy) StateTestRunner(org.ethereum.jsontestsuite.runners.StateTestRunner) StateTestSuite(org.ethereum.jsontestsuite.StateTestSuite) Test(org.junit.Test)

Example 2 with StateTestSuite

use of org.ethereum.jsontestsuite.StateTestSuite in project rskj by rsksmart.

the class TransactionTest method constantCallConflictTest.

@Test
public void constantCallConflictTest() throws Exception {
    /*
          0x095e7baea6a6c7c4c2dfeb977efac326af552d87 contract is the following Solidity code:

         contract Test {
            uint a = 256;

            function set(uint s) {
                a = s;
            }

            function get() returns (uint) {
                return a;
            }
        }
        */
    String json = "{ " + "    'test1' : { " + "        'env' : { " + "            'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " + "            'currentDifficulty' : '0x0100', " + "            'currentGasLimit' : '0x0f4240', " + "            'currentNumber' : '0x00', " + "            'currentTimestamp' : '0x01', " + "            'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " + "        }, " + "        'logs' : [ " + "        ], " + "        'out' : '0x', " + "        'post' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a76586a0', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x0400' " + "                } " + "            }, " + "            '0000000000000000000000000000000001000008' : { " + "                'balance' : '0x67EB', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0DE0B6B3A7621175', " + "                'code' : '0x', " + "                'nonce' : '0x01', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " + "        'pre' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x02' " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'transaction' : { " + "            'data' : '0x60fe47b10000000000000000000000000000000000000000000000000000000000000400', " + "            'gasLimit' : '0x061a80', " + "            'gasPrice' : '0x01', " + "            'nonce' : '0x00', " + "            'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " + "            'to' : '095e7baea6a6c7c4c2dfeb977efac326af552d87', " + "            'value' : '0x0186a0' " + "        } " + "    } " + "}";
    StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
    List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")) {

        @Override
        protected ProgramResult executeTransaction(Transaction tx) {
            // first emulating the constant call (Ethereum.callConstantFunction)
            // to ensure it doesn't affect the final state
            {
                Repository track = repository.startTracking();
                Transaction txConst = CallTransaction.createCallTransaction(config, 0, 0, 100000000000000L, new RskAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), 0, CallTransaction.Function.fromSignature("get"));
                txConst.sign(new byte[32]);
                Block bestBlock = block;
                TransactionExecutor executor = new TransactionExecutor(config, txConst, 0, bestBlock.getCoinbase(), track, new BlockStoreDummy(), null, invokeFactory, bestBlock).setLocalCall(true);
                executor.init();
                executor.execute();
                executor.go();
                executor.finalization();
                track.rollback();
                System.out.println("Return value: " + new CallTransaction.IntType("uint").decode(executor.getResult().getHReturn()));
            }
            // now executing the JSON test transaction
            return super.executeTransaction(tx);
        }
    }.runImpl();
    if (!res.isEmpty())
        throw new RuntimeException("Test failed: " + res);
}
Also used : ProgramResult(org.ethereum.vm.program.ProgramResult) BlockStoreDummy(org.ethereum.db.BlockStoreDummy) StateTestRunner(org.ethereum.jsontestsuite.runners.StateTestRunner) StateTestSuite(org.ethereum.jsontestsuite.StateTestSuite) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 3 with StateTestSuite

use of org.ethereum.jsontestsuite.StateTestSuite in project rskj by rsksmart.

the class TransactionTest method contractCreationTest.

// This test fails post EIP150
@Ignore
@Test
public void contractCreationTest() throws Exception {
    // Checks Homestead updates (1) & (3) from
    // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.mediawiki
    /*
          trying to create a contract with the following Solidity code:

         contract Test {
            uint a = 256;

            function set(uint s) {
                a = s;
            }

            function get() returns (uint) {
                return a;
            }
         }
        */
    // [actual gas required] - 1
    int iBitLowGas = 0x015f84;
    String aBitLowGas = "0x0" + Integer.toHexString(iBitLowGas);
    String senderPostBalance = "0x0" + Long.toHexString(1000000000000000000L - iBitLowGas);
    String json = "{ " + "    'test1' : { " + "        'env' : { " + "            'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " + "            'currentDifficulty' : '0x0100', " + "            'currentGasLimit' : '0x0f4240', " + "            'currentNumber' : '0x01', " + "            'currentTimestamp' : '0x01', " + "            'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " + "        }, " + "        'logs' : [ " + "        ], " + "        'out' : '0x', " + "        'post' : { " + "            '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba' : { " + "                'balance' : '" + aBitLowGas + "', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            }," + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '" + senderPostBalance + "', " + "                'code' : '0x', " + "                'nonce' : '0x01', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " + "        'pre' : { " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'transaction' : { " + "            'data' : '0x6060604052610100600060005055603b8060196000396000f3606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "            'gasLimit' : '" + aBitLowGas + "', " + "            'gasPrice' : '0x01', " + "            'nonce' : '0x00', " + "            'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " + "            'to' : '', " + "            'value' : '0x0' " + "        } " + "    } " + "}";
    StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
    System.out.println(json.replaceAll("'", "\""));
    try {
        config.setBlockchainConfig(new GenesisConfig());
        List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")).runImpl();
        if (!res.isEmpty())
            throw new RuntimeException("Test failed: " + res);
    } finally {
        config.setBlockchainConfig(new MainNetConfig());
    }
}
Also used : StateTestRunner(org.ethereum.jsontestsuite.runners.StateTestRunner) StateTestSuite(org.ethereum.jsontestsuite.StateTestSuite) MainNetConfig(org.ethereum.config.net.MainNetConfig) GenesisConfig(org.ethereum.config.blockchain.GenesisConfig) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

StateTestSuite (org.ethereum.jsontestsuite.StateTestSuite)3 StateTestRunner (org.ethereum.jsontestsuite.runners.StateTestRunner)3 Test (org.junit.Test)3 BlockStoreDummy (org.ethereum.db.BlockStoreDummy)2 ProgramResult (org.ethereum.vm.program.ProgramResult)2 RskAddress (co.rsk.core.RskAddress)1 GenesisConfig (org.ethereum.config.blockchain.GenesisConfig)1 MainNetConfig (org.ethereum.config.net.MainNetConfig)1 Ignore (org.junit.Ignore)1