diff options
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | SolidityEndToEndTest.cpp | 302 | ||||
-rw-r--r-- | SolidityNameAndTypeResolution.cpp | 12 | ||||
-rw-r--r-- | SolidityNatspecJSON.cpp | 13 | ||||
-rw-r--r-- | TestHelper.cpp | 13 | ||||
-rw-r--r-- | TestHelper.h | 2 | ||||
-rw-r--r-- | boostTest.cpp | 2 | ||||
-rw-r--r-- | checkRandomTest.cpp | 297 | ||||
-rw-r--r-- | createRandomTest.cpp | 24 | ||||
-rw-r--r-- | solidityExecutionFramework.h | 41 | ||||
-rw-r--r-- | vm.cpp | 17 | ||||
-rw-r--r-- | vmArithmeticTestFiller.json | 168 | ||||
-rw-r--r-- | vmSystemOperationsTestFiller.json | 30 |
13 files changed, 817 insertions, 110 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cedc117..764bf928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_policy(SET CMP0015 NEW) aux_source_directory(. SRC_LIST) list(REMOVE_ITEM SRC_LIST "./createRandomTest.cpp") +list(REMOVE_ITEM SRC_LIST "./checkRandomTest.cpp") include_directories(${Boost_INCLUDE_DIRS}) include_directories(${CRYPTOPP_INCLUDE_DIRS}) @@ -12,6 +13,7 @@ include_directories(..) file(GLOB HEADERS "*.h") add_executable(testeth ${SRC_LIST} ${HEADERS}) add_executable(createRandomTest createRandomTest.cpp vm.cpp TestHelper.cpp) +add_executable(checkRandomTest checkRandomTest.cpp vm.cpp TestHelper.cpp) target_link_libraries(testeth ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) target_link_libraries(testeth ${CURL_LIBRARIES}) @@ -29,3 +31,7 @@ endif() target_link_libraries(createRandomTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) target_link_libraries(createRandomTest ethereum) target_link_libraries(createRandomTest ethcore) +target_link_libraries(checkRandomTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) +target_link_libraries(checkRandomTest ethereum) +target_link_libraries(checkRandomTest ethcore) + diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index bc184dfc..16787c8e 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -28,6 +28,10 @@ #include <libdevcrypto/SHA3.h> #include <test/solidityExecutionFramework.h> +#ifdef _MSC_VER +#pragma warning(disable: 4307) //integral constant overflow for high_bits_cleaning +#endif + using namespace std; namespace dev @@ -331,10 +335,23 @@ BOOST_AUTO_TEST_CASE(packing_unpacking_types) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("run(bool,uint32,uint64)", fromHex("01""0f0f0f0f""f0f0f0f0f0f0f0f0")) + BOOST_CHECK(callContractFunction("run(bool,uint32,uint64)", true, fromHex("0f0f0f0f"), fromHex("f0f0f0f0f0f0f0f0")) == fromHex("00000000000000000000000000000000000000""01""f0f0f0f0""0f0f0f0f0f0f0f0f")); } +BOOST_AUTO_TEST_CASE(packing_signed_types) +{ + char const* sourceCode = "contract test {\n" + " function run() returns(int8 y) {\n" + " uint8 x = 0xfa;\n" + " return int8(x);\n" + " }\n" + "}\n"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("run()") + == fromHex("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa")); +} + BOOST_AUTO_TEST_CASE(multiple_return_values) { char const* sourceCode = "contract test {\n" @@ -343,8 +360,7 @@ BOOST_AUTO_TEST_CASE(multiple_return_values) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("run(bool,uint256)", bytes(1, 1) + toBigEndian(u256(0xcd))) - == toBigEndian(u256(0xcd)) + bytes(1, 1) + toBigEndian(u256(0))); + BOOST_CHECK(callContractFunction("run(bool,uint256)", true, 0xcd) == encodeArgs(0xcd, true, 0)); } BOOST_AUTO_TEST_CASE(short_circuiting) @@ -450,20 +466,8 @@ BOOST_AUTO_TEST_CASE(strings) " }\n" "}\n"; compileAndRun(sourceCode); - bytes expectation(32, 0); - expectation[0] = byte('a'); - expectation[1] = byte('b'); - expectation[2] = byte('c'); - expectation[3] = byte(0); - expectation[4] = byte(0xff); - expectation[5] = byte('_'); - expectation[6] = byte('_'); - BOOST_CHECK(callContractFunction("fixed()", bytes()) == expectation); - expectation = bytes(17, 0); - expectation[0] = 0; - expectation[1] = 2; - expectation[16] = 1; - BOOST_CHECK(callContractFunction("pipeThrough(string2,bool)", bytes({0x00, 0x02, 0x01})) == expectation); + BOOST_CHECK(callContractFunction("fixed()") == encodeArgs(string("abc\0\xff__", 7))); + BOOST_CHECK(callContractFunction("pipeThrough(string2,bool)", string("\0\x02", 2), true) == encodeArgs(string("\0\x2", 2), true)); } BOOST_AUTO_TEST_CASE(empty_string_on_stack) @@ -477,7 +481,7 @@ BOOST_AUTO_TEST_CASE(empty_string_on_stack) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("run(string0,uint8)", bytes(1, 0x02)) == bytes({0x00, 0x02, 0x61/*'a'*/, 0x62/*'b'*/, 0x63/*'c'*/, 0x00})); + BOOST_CHECK(callContractFunction("run(string0,uint8)", string(), byte(0x02)) == encodeArgs(0x2, string(""), string("abc\0"))); } BOOST_AUTO_TEST_CASE(state_smoke_test) @@ -495,14 +499,14 @@ BOOST_AUTO_TEST_CASE(state_smoke_test) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x00)) == toBigEndian(u256(0))); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x01)) == toBigEndian(u256(0))); - BOOST_CHECK(callContractFunction("set(uint8,uint256)", bytes(1, 0x00) + toBigEndian(u256(0x1234))) == bytes()); - BOOST_CHECK(callContractFunction("set(uint8,uint256)", bytes(1, 0x01) + toBigEndian(u256(0x8765))) == bytes()); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x00)) == toBigEndian(u256(0x1234))); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x01)) == toBigEndian(u256(0x8765))); - BOOST_CHECK(callContractFunction("set(uint8,uint256)", bytes(1, 0x00) + toBigEndian(u256(0x3))) == bytes()); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x00)) == toBigEndian(u256(0x3))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(0)); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(0)); + BOOST_CHECK(callContractFunction("set(uint8,uint256)", byte(0x00), 0x1234) == encodeArgs()); + BOOST_CHECK(callContractFunction("set(uint8,uint256)", byte(0x01), 0x8765) == encodeArgs()); + BOOST_CHECK(callContractFunction("get(uint8)", byte( 0x00)) == encodeArgs(0x1234)); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(0x8765)); + BOOST_CHECK(callContractFunction("set(uint8,uint256)", byte(0x00), 0x3) == encodeArgs()); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(0x3)); } BOOST_AUTO_TEST_CASE(compound_assign) @@ -553,22 +557,21 @@ BOOST_AUTO_TEST_CASE(simple_mapping) "}"; compileAndRun(sourceCode); - // msvc seems to have problems with initializer-list, when there is only 1 param in the list - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x00)) == bytes(1, 0x00)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x01)) == bytes(1, 0x00)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0xa7)) == bytes(1, 0x00)); - callContractFunction("set(uint8,uint8)", bytes({0x01, 0xa1})); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x00)) == bytes(1, 0x00)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x01)) == bytes(1, 0xa1)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0xa7)) == bytes(1, 0x00)); - callContractFunction("set(uint8,uint8)", bytes({0x00, 0xef})); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x00)) == bytes(1, 0xef)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x01)) == bytes(1, 0xa1)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0xa7)) == bytes(1, 0x00)); - callContractFunction("set(uint8,uint8)", bytes({0x01, 0x05})); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x00)) == bytes(1, 0xef)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0x01)) == bytes(1, 0x05)); - BOOST_CHECK(callContractFunction("get(uint8)", bytes(1, 0xa7)) == bytes(1, 0x00)); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0)) == encodeArgs(byte(0x00))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0x00))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00))); + callContractFunction("set(uint8,uint8)", byte(0x01), byte(0xa1)); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(byte(0x00))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0xa1))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00))); + callContractFunction("set(uint8,uint8)", byte(0x00), byte(0xef)); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(byte(0xef))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0xa1))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00))); + callContractFunction("set(uint8,uint8)", byte(0x01), byte(0x05)); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(byte(0xef))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0x05))); + BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00))); } BOOST_AUTO_TEST_CASE(mapping_state) @@ -736,9 +739,9 @@ BOOST_AUTO_TEST_CASE(structs) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("check()") == bytes(1, 0x00)); + BOOST_CHECK(callContractFunction("check()") == encodeArgs(false)); BOOST_CHECK(callContractFunction("set()") == bytes()); - BOOST_CHECK(callContractFunction("check()") == bytes(1, 0x01)); + BOOST_CHECK(callContractFunction("check()") == encodeArgs(true)); } BOOST_AUTO_TEST_CASE(struct_reference) @@ -764,9 +767,9 @@ BOOST_AUTO_TEST_CASE(struct_reference) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("check()") == bytes(1, 0x00)); + BOOST_CHECK(callContractFunction("check()") == encodeArgs(false)); BOOST_CHECK(callContractFunction("set()") == bytes()); - BOOST_CHECK(callContractFunction("check()") == bytes(1, 0x01)); + BOOST_CHECK(callContractFunction("check()") == encodeArgs(true)); } BOOST_AUTO_TEST_CASE(constructor) @@ -799,7 +802,7 @@ BOOST_AUTO_TEST_CASE(balance) " }\n" "}\n"; compileAndRun(sourceCode, 23); - BOOST_CHECK(callContractFunction("getBalance()") == toBigEndian(u256(23))); + BOOST_CHECK(callContractFunction("getBalance()") == encodeArgs(23)); } BOOST_AUTO_TEST_CASE(blockchain) @@ -812,7 +815,7 @@ BOOST_AUTO_TEST_CASE(blockchain) " }\n" "}\n"; compileAndRun(sourceCode, 27); - BOOST_CHECK(callContractFunction("someInfo()", bytes{0}, u256(28)) == toBigEndian(u256(28)) + bytes(20, 0) + toBigEndian(u256(1))); + BOOST_CHECK(callContractFunctionWithValue("someInfo()", 28) == encodeArgs(28, 0, 1)); } BOOST_AUTO_TEST_CASE(function_types) @@ -831,10 +834,25 @@ BOOST_AUTO_TEST_CASE(function_types) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("a(bool)", bytes{0}) == toBigEndian(u256(11))); - BOOST_CHECK(callContractFunction("a(bool)", bytes{1}) == toBigEndian(u256(12))); + BOOST_CHECK(callContractFunction("a(bool)", false) == encodeArgs(11)); + BOOST_CHECK(callContractFunction("a(bool)", true) == encodeArgs(12)); +} + +BOOST_AUTO_TEST_CASE(type_conversions_cleanup) +{ + // 22-byte integer converted to a contract (i.e. address, 20 bytes), converted to a 32 byte + // integer should drop the first two bytes + char const* sourceCode = R"( + contract Test { + function test() returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); } + })"; + compileAndRun(sourceCode); + BOOST_REQUIRE(callContractFunction("test()") == bytes({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, + 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22})); } + BOOST_AUTO_TEST_CASE(send_ether) { char const* sourceCode = "contract test {\n" @@ -846,7 +864,7 @@ BOOST_AUTO_TEST_CASE(send_ether) u256 amount(130); compileAndRun(sourceCode, amount + 1); u160 address(23); - BOOST_CHECK(callContractFunction("a(address,uint256)", address, amount) == toBigEndian(u256(1))); + BOOST_CHECK(callContractFunction("a(address,uint256)", address, amount) == encodeArgs(1)); BOOST_CHECK_EQUAL(m_state.balance(address), amount); } @@ -1031,7 +1049,7 @@ BOOST_AUTO_TEST_CASE(ecrecover) u256 r("0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f"); u256 s("0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549"); u160 addr("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"); - BOOST_CHECK(callContractFunction("a(hash256,uint8,hash256,hash256)", h, v, r, s) == toBigEndian(addr)); + BOOST_CHECK(callContractFunction("a(hash256,uint8,hash256,hash256)", h, v, r, s) == encodeArgs(addr)); } BOOST_AUTO_TEST_CASE(inter_contract_calls) @@ -1055,13 +1073,13 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls) } })"; compileAndRun(sourceCode, 0, "Helper"); - u160 const helperAddress = m_contractAddress; + u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("setHelper(address)", helperAddress) == bytes()); - BOOST_REQUIRE(callContractFunction("getHelper()", helperAddress) == toBigEndian(helperAddress)); + BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes()); + BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress)); u256 a(3456789); u256 b("0x282837623374623234aa74"); - BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == toBigEndian(a * b)); + BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == encodeArgs(a * b)); } BOOST_AUTO_TEST_CASE(inter_contract_calls_with_complex_parameters) @@ -1085,14 +1103,14 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_complex_parameters) } })"; compileAndRun(sourceCode, 0, "Helper"); - u160 const helperAddress = m_contractAddress; + u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("setHelper(address)", helperAddress) == bytes()); - BOOST_REQUIRE(callContractFunction("getHelper()", helperAddress) == toBigEndian(helperAddress)); + BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes()); + BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress)); u256 a(3456789); u256 b("0x282837623374623234aa74"); - BOOST_REQUIRE(callContractFunction("callHelper(uint256,bool,uint256)", a, true, b) == toBigEndian(a * 3)); - BOOST_REQUIRE(callContractFunction("callHelper(uint256,bool,uint256)", a, false, b) == toBigEndian(b * 3)); + BOOST_REQUIRE(callContractFunction("callHelper(uint256,bool,uint256)", a, true, b) == encodeArgs(a * 3)); + BOOST_REQUIRE(callContractFunction("callHelper(uint256,bool,uint256)", a, false, b) == encodeArgs(b * 3)); } BOOST_AUTO_TEST_CASE(inter_contract_calls_accessing_this) @@ -1116,11 +1134,11 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_accessing_this) } })"; compileAndRun(sourceCode, 0, "Helper"); - u160 const helperAddress = m_contractAddress; + u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("setHelper(address)", helperAddress) == bytes()); - BOOST_REQUIRE(callContractFunction("getHelper()", helperAddress) == toBigEndian(helperAddress)); - BOOST_REQUIRE(callContractFunction("callHelper()") == toBigEndian(helperAddress)); + BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes()); + BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress)); + BOOST_REQUIRE(callContractFunction("callHelper()") == encodeArgs(c_helperAddress)); } BOOST_AUTO_TEST_CASE(calls_to_this) @@ -1147,13 +1165,13 @@ BOOST_AUTO_TEST_CASE(calls_to_this) } })"; compileAndRun(sourceCode, 0, "Helper"); - u160 const helperAddress = m_contractAddress; + u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("setHelper(address)", helperAddress) == bytes()); - BOOST_REQUIRE(callContractFunction("getHelper()", helperAddress) == toBigEndian(helperAddress)); + BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes()); + BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress)); u256 a(3456789); u256 b("0x282837623374623234aa74"); - BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == toBigEndian(a * b + 10)); + BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == encodeArgs(a * b + 10)); } BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) @@ -1182,13 +1200,13 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) } })"; compileAndRun(sourceCode, 0, "Helper"); - u160 const helperAddress = m_contractAddress; + u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("setHelper(address)", helperAddress) == bytes()); - BOOST_REQUIRE(callContractFunction("getHelper()", helperAddress) == toBigEndian(helperAddress)); + BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes()); + BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress)); u256 a(3456789); u256 b("0x282837623374623234aa74"); - BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == toBigEndian(a * b + 9)); + BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == encodeArgs(a * b + 9)); } BOOST_AUTO_TEST_CASE(strings_in_calls) @@ -1212,11 +1230,11 @@ BOOST_AUTO_TEST_CASE(strings_in_calls) } })"; compileAndRun(sourceCode, 0, "Helper"); - u160 const helperAddress = m_contractAddress; + u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("setHelper(address)", helperAddress) == bytes()); - BOOST_REQUIRE(callContractFunction("getHelper()", helperAddress) == toBigEndian(helperAddress)); - BOOST_CHECK(callContractFunction("callHelper(string2,bool)", bytes({0, 'a', 1})) == bytes({0, 'a', 0, 0, 0})); + BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes()); + BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress)); + BOOST_CHECK(callContractFunction("callHelper(string2,bool)", string("\0a", 2), true) == encodeArgs(string("\0a\0\0\0", 5))); } BOOST_AUTO_TEST_CASE(constructor_arguments) @@ -1241,8 +1259,8 @@ BOOST_AUTO_TEST_CASE(constructor_arguments) function getName() returns (string3 ret) { return h.getName(); } })"; compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("getFlag()") == bytes({byte(0x01)})); - BOOST_REQUIRE(callContractFunction("getName()") == bytes({'a', 'b', 'c'})); + BOOST_REQUIRE(callContractFunction("getFlag()") == encodeArgs(true)); + BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc")); } BOOST_AUTO_TEST_CASE(functions_called_by_constructor) @@ -1259,7 +1277,131 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) function setName(string3 _name) { name = _name; } })"; compileAndRun(sourceCode); - BOOST_REQUIRE(callContractFunction("getName()") == bytes({'a', 'b', 'c'})); + BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc")); +} + +BOOST_AUTO_TEST_CASE(contracts_as_addresses) +{ + char const* sourceCode = R"( + contract helper { + } + contract test { + helper h; + function test() { h = new helper(); h.send(5); } + function getBalance() returns (uint256 myBalance, uint256 helperBalance) { + myBalance = this.balance; + helperBalance = h.balance; + } + } + )"; + compileAndRun(sourceCode, 20); + BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5))); +} + +BOOST_AUTO_TEST_CASE(gas_and_value_basic) +{ + char const* sourceCode = R"( + contract helper { + bool flag; + function getBalance() returns (uint256 myBalance) { + return this.balance; + } + function setFlag() { flag = true; } + function getFlag() returns (bool fl) { return flag; } + } + contract test { + helper h; + function test() { h = new helper(); } + function sendAmount(uint amount) returns (uint256 bal) { + return h.getBalance.value(amount)(); + } + function outOfGas() returns (bool flagBefore, bool flagAfter, uint myBal) { + flagBefore = h.getFlag(); + h.setFlag.gas(2)(); // should fail due to OOG, return value can be garbage + flagAfter = h.getFlag(); + myBal = this.balance; + } + } + )"; + compileAndRun(sourceCode, 20); + BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(5)); + // call to helper should not succeed but amount should be transferred anyway + BOOST_REQUIRE(callContractFunction("outOfGas()", 5) == encodeArgs(false, false, 20 - 5)); +} + +BOOST_AUTO_TEST_CASE(value_complex) +{ + char const* sourceCode = R"( + contract helper { + function getBalance() returns (uint256 myBalance) { + return this.balance; + } + } + contract test { + helper h; + function test() { h = new helper(); } + function sendAmount(uint amount) returns (uint256 bal) { + var x1 = h.getBalance.value(amount); + uint someStackElement = 20; + var x2 = x1.gas(1000); + return x2.value(amount + 3)();// overwrite value + } + } + )"; + compileAndRun(sourceCode, 20); + BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(8)); +} + +BOOST_AUTO_TEST_CASE(value_insane) +{ + char const* sourceCode = R"( + contract helper { + function getBalance() returns (uint256 myBalance) { + return this.balance; + } + } + contract test { + helper h; + function test() { h = new helper(); } + function sendAmount(uint amount) returns (uint256 bal) { + var x1 = h.getBalance.value; + uint someStackElement = 20; + var x2 = x1(amount).gas; + var x3 = x2(1000).value; + return x3(amount + 3)();// overwrite value + } + } + )"; + compileAndRun(sourceCode, 20); + BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(8)); +} + +BOOST_AUTO_TEST_CASE(value_for_constructor) +{ + char const* sourceCode = R"( + contract Helper { + string3 name; + bool flag; + function Helper(string3 x, bool f) { + name = x; + flag = f; + } + function getName() returns (string3 ret) { return name; } + function getFlag() returns (bool ret) { return flag; } + } + contract Main { + Helper h; + function Main() { + h = new Helper.value(10)("abc", true); + } + function getFlag() returns (bool ret) { return h.getFlag(); } + function getName() returns (string3 ret) { return h.getName(); } + function getBalances() returns (uint me, uint them) { me = this.balance; them = h.balance;} + })"; + compileAndRun(sourceCode, 22, "Main"); + BOOST_REQUIRE(callContractFunction("getFlag()") == encodeArgs(true)); + BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc")); + BOOST_REQUIRE(callContractFunction("getBalances()") == encodeArgs(12, 10)); } BOOST_AUTO_TEST_SUITE_END() diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 94271b1f..e2b4f160 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -357,6 +357,18 @@ BOOST_AUTO_TEST_CASE(function_canonical_signature_type_aliases) } } + +BOOST_AUTO_TEST_CASE(hash_collision_in_interface) +{ + char const* text = "contract test {\n" + " function gsf() {\n" + " }\n" + " function tgeo() {\n" + " }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/SolidityNatspecJSON.cpp b/SolidityNatspecJSON.cpp index f6a33247..7edb97a7 100644 --- a/SolidityNatspecJSON.cpp +++ b/SolidityNatspecJSON.cpp @@ -510,6 +510,19 @@ BOOST_AUTO_TEST_CASE(dev_title_at_function_error) BOOST_CHECK_THROW(checkNatspec(sourceCode, natspec, false), DocstringParsingError); } +// test for bug where having no tags in docstring would cause infinite loop +BOOST_AUTO_TEST_CASE(natspec_no_tags) +{ + char const* sourceCode = "contract test {\n" + " /// I do something awesome\n" + " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + "}\n"; + + char const* natspec = "{\"methods\": {}}"; + + checkNatspec(sourceCode, natspec, false); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/TestHelper.cpp b/TestHelper.cpp index ff330d60..355a5080 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -350,6 +350,19 @@ void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs) } } +void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates) +{ + BOOST_REQUIRE_EQUAL(_resultCallCreates.size(), _expectedCallCreates.size()); + + for (size_t i = 0; i < _resultCallCreates.size(); ++i) + { + BOOST_CHECK(_resultCallCreates[i].data() == _expectedCallCreates[i].data()); + BOOST_CHECK(_resultCallCreates[i].receiveAddress() == _expectedCallCreates[i].receiveAddress()); + BOOST_CHECK(_resultCallCreates[i].gas() == _expectedCallCreates[i].gas()); + BOOST_CHECK(_resultCallCreates[i].value() == _expectedCallCreates[i].value()); + } +} + std::string getTestPath() { string testPath; diff --git a/TestHelper.h b/TestHelper.h index 85017c84..2ef5c6d5 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -73,6 +73,8 @@ json_spirit::mArray exportLog(eth::LogEntries _logs); void checkOutput(bytes const& _output, json_spirit::mObject& _o); void checkStorage(std::map<u256, u256> _expectedStore, std::map<u256, u256> _resultStore, Address _expectedAddr); void checkLog(eth::LogEntries _resultLogs, eth::LogEntries _expectedLogs); +void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates); + void executeTests(const std::string& _name, const std::string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests); std::string getTestPath(); void userDefinedTest(std::string testTypeFlag, std::function<void(json_spirit::mValue&, bool)> doTests); diff --git a/boostTest.cpp b/boostTest.cpp index cef3cc0a..1523a7a1 100644 --- a/boostTest.cpp +++ b/boostTest.cpp @@ -23,6 +23,6 @@ #define BOOST_TEST_MODULE EthereumTests #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" +#define BOOST_DISABLE_WIN32 //disables SEH warning #include <boost/test/included/unit_test.hpp> -#pragma warning(pop) #pragma GCC diagnostic pop diff --git a/checkRandomTest.cpp b/checkRandomTest.cpp new file mode 100644 index 00000000..e3442d43 --- /dev/null +++ b/checkRandomTest.cpp @@ -0,0 +1,297 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. +*/ +/** @file checkRandomTest.cpp + * @author Christoph Jentzsch <jentzsch.simulationsoftware@gmail.com> + * @date 2015 + * Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation. + */ + +#include <libdevcore/Common.h> +#include <libdevcore/Exceptions.h> +#include <libdevcore/Log.h> +#include <libevm/VMFactory.h> +#include "vm.h" +#pragma GCC diagnostic ignored "-Wunused-parameter" + +using namespace std; +using namespace json_spirit; +using namespace dev::test; +using namespace dev; + +bool doVMTest(mValue& v); + +int main(int argc, char *argv[]) +{ + g_logVerbosity = 0; + bool ret = false; + + try + { + mValue v; + string s; + for (int i = 1; i < argc; ++i) + s += argv[i]; + if (asserts(s.length() > 0)) + { + cout << "Content of argument is empty\n"; + return 1; + } + read_string(s, v); + ret = doVMTest(v); + } + catch (Exception const& _e) + { + cout << "Failed test with Exception: " << diagnostic_information(_e) << endl; + ret = false; + } + catch (std::exception const& _e) + { + cout << "Failed test with Exception: " << _e.what() << endl; + ret = false; + } + return ret; +} + +bool doVMTest(mValue& v) +{ + eth::VMFactory::setKind(eth::VMKind::JIT); + + for (auto& i: v.get_obj()) + { + cnote << i.first; + mObject& o = i.second.get_obj(); + + assert(o.count("env") > 0); + assert(o.count("pre") > 0); + assert(o.count("exec") > 0); + + FakeExtVM fev; + fev.importEnv(o["env"].get_obj()); + fev.importState(o["pre"].get_obj()); + + fev.importExec(o["exec"].get_obj()); + if (fev.code.empty()) + { + fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); + fev.code = fev.thisTxCode; + } + + bytes output; + u256 gas; + bool vmExceptionOccured = false; + try + { + auto vm = eth::VMFactory::create(fev.gas); + output = vm->go(fev, fev.simpleTrace()).toBytes(); + gas = vm->gas(); + } + catch (eth::VMException) + { + cnote << "Safe VM Exception"; + vmExceptionOccured = true; + } + catch (Exception const& _e) + { + cnote << "VM did throw an exception: " << diagnostic_information(_e); + cnote << "Failed VM Test with Exception: " << _e.what(); + return 1; + } + catch (std::exception const& _e) + { + cnote << "VM did throw an exception: " << _e.what(); + cnote << "Failed VM Test with Exception: " << _e.what(); + return 1; + } + + // delete null entries in storage for the sake of comparison + for (auto &a: fev.addresses) + { + vector<u256> keystoDelete; + for (auto &s: get<2>(a.second)) + { + if (s.second == 0) + keystoDelete.push_back(s.first); + } + for (auto const key: keystoDelete ) + { + get<2>(a.second).erase(key); + } + } + + if (o.count("post") > 0) // No exceptions expected + { + if (asserts(!vmExceptionOccured) || asserts(o.count("post") > 0) || asserts(o.count("callcreates") > 0) || asserts(o.count("out") > 0) || asserts(o.count("gas") > 0) || asserts(o.count("logs") > 0)) + return 1; + + dev::test::FakeExtVM test; + test.importState(o["post"].get_obj()); + test.importCallCreates(o["callcreates"].get_array()); + test.sub.logs = importLog(o["logs"].get_array()); + + //checkOutput(output, o); + int j = 0; + if (o["out"].type() == array_type) + for (auto const& d: o["out"].get_array()) + { + if (asserts(output[j] == toInt(d))) + { + cout << "Output byte [" << j << "] different!"; + return 1; + } + ++j; + } + else if (o["out"].get_str().find("0x") == 0) + { + if (asserts(output == fromHex(o["out"].get_str().substr(2)))) + return 1; + } + else + { + if (asserts(output == fromHex(o["out"].get_str()))) + return 1; + } + + if (asserts(toInt(o["gas"]) == gas)) + return 1; + + auto& expectedAddrs = test.addresses; + auto& resultAddrs = fev.addresses; + for (auto&& expectedPair : expectedAddrs) + { + auto& expectedAddr = expectedPair.first; + auto resultAddrIt = resultAddrs.find(expectedAddr); + if (resultAddrIt == resultAddrs.end()) + { + cout << "Missing expected address " << expectedAddr; + return 1; + } + else + { + auto& expectedState = expectedPair.second; + auto& resultState = resultAddrIt->second; + if (asserts(std::get<0>(expectedState) == std::get<0>(resultState))) + { + cout << expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState); + return 1; + } + if (asserts(std::get<1>(expectedState) == std::get<1>(resultState))) + { + cout << expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState); + return 1; + } + if (asserts(std::get<3>(expectedState) == std::get<3>(resultState))) + { + cout << expectedAddr << ": incorrect code"; + return 1; + } + + //checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr); + for (auto&& expectedStorePair : std::get<2>(expectedState)) + { + auto& expectedStoreKey = expectedStorePair.first; + auto resultStoreIt = std::get<2>(resultState).find(expectedStoreKey); + if (resultStoreIt == std::get<2>(resultState).end()) + { + cout << expectedAddr << ": missing store key " << expectedStoreKey << endl; + return 1; + } + else + { + auto& expectedStoreValue = expectedStorePair.second; + auto& resultStoreValue = resultStoreIt->second; + if (asserts(expectedStoreValue == resultStoreValue)) + { + cout << expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue << endl; + return 1; + } + } + } + if (assertsEqual(std::get<2>(resultState).size(), std::get<2>(expectedState).size())) + return 1; + for (auto&& resultStorePair: std::get<2>(resultState)) + { + if (!std::get<2>(expectedState).count(resultStorePair.first)) + { + cout << expectedAddr << ": unexpected store key " << resultStorePair.first << endl; + return 1; + } + } + } + } + + //checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses); + for (auto& resultPair : fev.addresses) + { + auto& resultAddr = resultPair.first; + auto expectedAddrIt = test.addresses.find(resultAddr); + if (expectedAddrIt == test.addresses.end()) + { + cout << "Missing result address " << resultAddr << endl; + return 1; + } + } + if (asserts(test.addresses == fev.addresses)) + return 1; + + if (asserts(test.callcreates == fev.callcreates)) + return 1; + + //checkCallCreates(fev.callcreates, test.callcreates); + { + if (assertsEqual(test.callcreates.size(), fev.callcreates.size())) + return 1; + + for (size_t i = 0; i < test.callcreates.size(); ++i) + { + if (asserts(test.callcreates[i].data() == fev.callcreates[i].data())) + return 1; + if (asserts(test.callcreates[i].receiveAddress() == fev.callcreates[i].receiveAddress())) + return 1; + if (asserts(test.callcreates[i].gas() == fev.callcreates[i].gas())) + return 1; + if (asserts(test.callcreates[i].value() == fev.callcreates[i].value())) + return 1; + } + } + + //checkLog(fev.sub.logs, test.sub.logs); + { + if (assertsEqual(fev.sub.logs.size(), test.sub.logs.size())) + return 1; + + for (size_t i = 0; i < fev.sub.logs.size(); ++i) + { + if (assertsEqual(fev.sub.logs[i].address, test.sub.logs[i].address)) + return 1; + if (assertsEqual(fev.sub.logs[i].topics, test.sub.logs[i].topics)) + return 1; + if (asserts(fev.sub.logs[i].data == test.sub.logs[i].data)) + return 1; + } + } + + } + else // Exception expected + { + if (asserts(vmExceptionOccured)) + return 1; + } + } + // test passed + return 0; +} + diff --git a/createRandomTest.cpp b/createRandomTest.cpp index 1af12f64..fa5ed7bd 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -54,18 +54,26 @@ int main(int argc, char *argv[]) gen.seed(static_cast<unsigned int>(timeSinceEpoch)); boost::random::uniform_int_distribution<> lengthOfCodeDist(2, 16); boost::random::uniform_int_distribution<> opcodeDist(0, 255); + boost::random::uniform_int_distribution<> BlockInfoOpcodeDist(0x40, 0x45); boost::random::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > randGen(gen, opcodeDist); + boost::random::variate_generator<boost::mt19937&, + boost::random::uniform_int_distribution<> > randGenBlockInfoOpcode(gen, BlockInfoOpcodeDist); int lengthOfCode = lengthOfCodeDist(gen); string randomCode; for (int i = 0; i < lengthOfCode; ++i) { - uint8_t opcode = randGen(); + if (i < 8 && (randGen() < 192)) + { + randomCode += toHex(toCompactBigEndian((uint8_t)randGenBlockInfoOpcode())); + continue; + } - // disregard all invalid commands, except of one (0x10) - if (dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || opcode == 0x10) + uint8_t opcode = randGen(); + // disregard all invalid commands, except of one (0x0c) + if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (randGen() > 250))) randomCode += toHex(toCompactBigEndian(opcode)); else i--; @@ -76,10 +84,10 @@ int main(int argc, char *argv[]) \"randomVMtest\": {\n\ \"env\" : {\n\ \"previousHash\" : \"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6\",\n\ - \"currentNumber\" : \"0\",\n\ + \"currentNumber\" : \"300\",\n\ \"currentGasLimit\" : \"1000000\",\n\ - \"currentDifficulty\" : \"256\",\n\ - \"currentTimestamp\" : 1,\n\ + \"currentDifficulty\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\ + \"currentTimestamp\" : 2,\n\ \"currentCoinbase\" : \"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba\"\n\ },\n\ \"pre\" : {\n\ @@ -106,7 +114,7 @@ int main(int argc, char *argv[]) read_string(s, v); // insert new random code - v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode; + v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode + (randGen() > 128 ? "55" : ""); // execute code in vm doMyTests(v); @@ -119,6 +127,8 @@ int main(int argc, char *argv[]) void doMyTests(json_spirit::mValue& v) { + eth::VMFactory::setKind(eth::VMKind::Interpreter); + for (auto& i: v.get_obj()) { cnote << i.first; diff --git a/solidityExecutionFramework.h b/solidityExecutionFramework.h index 5ef23fdb..8d3c7e77 100644 --- a/solidityExecutionFramework.h +++ b/solidityExecutionFramework.h @@ -32,9 +32,6 @@ namespace dev { -/// Provides additional overloads for toBigEndian to encode arguments and return values. -inline bytes toBigEndian(byte _value) { return bytes({_value}); } -inline bytes toBigEndian(bool _value) { return bytes({byte(_value)}); } namespace solidity { @@ -56,18 +53,20 @@ public: return m_output; } - bytes const& callContractFunction(std::string _sig, bytes const& _data = bytes(), - u256 const& _value = 0) + template <class... Args> + bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, + Args const&... _arguments) { + FixedHash<4> hash(dev::sha3(_sig)); - sendMessage(hash.asBytes() + _data, false, _value); + sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value); return m_output; } template <class... Args> bytes const& callContractFunction(std::string _sig, Args const&... _arguments) { - return callContractFunction(_sig, argsToBigEndian(_arguments...)); + return callContractFunctionWithValue(_sig, 0, _arguments...); } template <class CppFunction, class... Args> @@ -89,19 +88,33 @@ public: bytes cppResult = callCppAndEncodeResult(_cppFunction, argument); BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match." "\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult) + - "\nArgument: " + toHex(toBigEndian(argument))); + "\nArgument: " + toHex(encode(argument))); } } -private: - template <class FirstArg, class... Args> - bytes argsToBigEndian(FirstArg const& _firstArg, Args const&... _followingArgs) const + static bytes encode(bool _value) { return encode(byte(_value)); } + static bytes encode(int _value) { return encode(u256(_value)); } + static bytes encode(char const* _value) { return encode(std::string(_value)); } + static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } + static bytes encode(u256 const& _value) { return toBigEndian(_value); } + static bytes encode(bytes const& _value, bool _padLeft = true) { - return toBigEndian(_firstArg) + argsToBigEndian(_followingArgs...); + bytes padding = bytes((32 - _value.size() % 32) % 32, 0); + return _padLeft ? padding + _value : _value + padding; } + static bytes encode(std::string const& _value) { return encode(asBytes(_value), false); } - bytes argsToBigEndian() const { return bytes(); } + template <class FirstArg, class... Args> + static bytes encodeArgs(FirstArg const& _firstArg, Args const&... _followingArgs) + { + return encode(_firstArg) + encodeArgs(_followingArgs...); + } + static bytes encodeArgs() + { + return bytes(); + } +private: template <class CppFunction, class... Args> auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) -> typename std::enable_if<std::is_void<decltype(_cppFunction(_arguments...))>::value, bytes>::type @@ -113,7 +126,7 @@ private: auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) -> typename std::enable_if<!std::is_void<decltype(_cppFunction(_arguments...))>::value, bytes>::type { - return toBigEndian(_cppFunction(_arguments...)); + return encode(_cppFunction(_arguments...)); } void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) @@ -232,13 +232,13 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) for (mValue& v: _callcreates) { auto tx = v.get_obj(); - BOOST_REQUIRE(tx.count("data") > 0); - BOOST_REQUIRE(tx.count("value") > 0); - BOOST_REQUIRE(tx.count("destination") > 0); - BOOST_REQUIRE(tx.count("gasLimit") > 0); + assert(tx.count("data") > 0); + assert(tx.count("value") > 0); + assert(tx.count("destination") > 0); + assert(tx.count("gasLimit") > 0); Transaction t = tx["destination"].get_str().empty() ? - Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data.toBytes()) : - Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data.toBytes()); + Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), fromHex(tx["data"].get_str())) : + Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), fromHex(tx["data"].get_str())); callcreates.push_back(t); } } @@ -345,7 +345,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) output = vm->go(fev, fev.simpleTrace()).toBytes(); gas = vm->gas(); } - catch (VMException const& _e) + catch (VMException const&) { cnote << "Safe VM Exception"; vmExceptionOccured = true; @@ -448,7 +448,8 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) } checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses); - BOOST_CHECK(test.callcreates == fev.callcreates); + + checkCallCreates(fev.callcreates, test.callcreates); checkLog(fev.sub.logs, test.sub.logs); } diff --git a/vmArithmeticTestFiller.json b/vmArithmeticTestFiller.json index 12574f51..9e8b3f61 100644 --- a/vmArithmeticTestFiller.json +++ b/vmArithmeticTestFiller.json @@ -1346,6 +1346,90 @@ } }, + "addmodDivByZero": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "{ [[ 0 ]] (ADDMOD 4 1 0) } ", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "data" : "", + "gasPrice" : "100000000000000", + "gas" : "10000" + } + }, + + "addmodDivByZero1": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "{ [[ 0 ]] (ADDMOD 0 1 0) } ", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "data" : "", + "gasPrice" : "100000000000000", + "gas" : "10000" + } + }, + + "addmodDivByZero1": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "{ [[ 0 ]] (ADDMOD 1 0 0) } ", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "data" : "", + "gasPrice" : "100000000000000", + "gas" : "10000" + } + }, + "mulmod0": { "env" : { @@ -1543,6 +1627,90 @@ } }, + "mulmoddivByZero": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "{ [[ 0 ]] (MULMOD 5 1 0) } ", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "data" : "", + "gasPrice" : "100000000000000", + "gas" : "10000" + } + }, + + "mulmoddivByZero1": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "{ [[ 0 ]] (MULMOD 0 1 0) } ", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "data" : "", + "gasPrice" : "100000000000000", + "gas" : "10000" + } + }, + + "mulmoddivByZero2": { + "env" : { + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", + "currentNumber" : "0", + "currentGasLimit" : "1000000", + "currentDifficulty" : "256", + "currentTimestamp" : 1, + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "nonce" : 0, + "code" : "{ [[ 0 ]] (MULMOD 1 0 0) } ", + "storage": {} + } + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000", + "data" : "", + "gasPrice" : "100000000000000", + "gas" : "10000" + } + }, + "exp0": { "env" : { diff --git a/vmSystemOperationsTestFiller.json b/vmSystemOperationsTestFiller.json index 1df2697e..a5cd7903 100644 --- a/vmSystemOperationsTestFiller.json +++ b/vmSystemOperationsTestFiller.json @@ -147,6 +147,36 @@ } }, + "CallToPrecompiledContract" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentGasLimit" : "1000000", + "currentNumber" : "0", + "currentTimestamp" : "2", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "code" : "0x4243434242434243f14555", + "data" : "0x", + "gas" : "10000", + "gasPrice" : "100000000000000", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x4243434242434243f14555", + "nonce" : "0", + "storage" : { + } + } + } + }, + "CallToReturn1": { "env" : { "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", |