diff options
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 120 |
1 files changed, 80 insertions, 40 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 1efcfde0..40962294 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -177,7 +177,8 @@ BOOST_AUTO_TEST_CASE(conditional_expression_with_return_values) function f(bool cond, uint v) returns (uint a, uint b) { cond ? a = v : b = v; } - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("f(bool,uint256)", true, u256(20)), encodeArgs(u256(20), u256(0))); ABI_CHECK(callContractFunction("f(bool,uint256)", false, u256(20)), encodeArgs(u256(0), u256(20))); @@ -482,6 +483,27 @@ BOOST_AUTO_TEST_CASE(do_while_loop) testContractAgainstCppOnRange("f(uint256)", do_while_loop_cpp, 0, 5); } +BOOST_AUTO_TEST_CASE(do_while_loop_continue) +{ + char const* sourceCode = R"( + contract test { + function f() public pure returns(uint r) { + uint i = 0; + do + { + if (i > 0) return 0; + i++; + continue; + } while (false); + return 42; + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("f()"), encodeArgs(42)); +} + BOOST_AUTO_TEST_CASE(nested_loops) { // tests that break and continue statements in nested loops jump to the correct place @@ -1667,7 +1689,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_smaller_size) char const* sourceCode = R"( contract Test { function bytesToUint(bytes4 s) returns (uint16 h) { - return uint16(s); + return uint16(uint32(s)); } } )"; @@ -1683,7 +1705,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_greater_size) char const* sourceCode = R"( contract Test { function bytesToUint(bytes4 s) returns (uint64 h) { - return uint64(s); + return uint64(uint32(s)); } } )"; @@ -1730,7 +1752,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_smaller_size) char const* sourceCode = R"( contract Test { function uintToBytes(uint32 h) returns (bytes2 s) { - return bytes2(h); + return bytes2(uint16(h)); } } )"; @@ -1746,7 +1768,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_greater_size) char const* sourceCode = R"( contract Test { function UintToBytes(uint16 h) returns (bytes8 s) { - return bytes8(h); + return bytes8(uint64(h)); } } )"; @@ -2216,7 +2238,8 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls) function setHelper(address haddress) { h = Helper(haddress); } - })"; + } + )"; compileAndRun(sourceCode, 0, "Helper"); u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); @@ -2246,7 +2269,8 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_complex_parameters) function setHelper(address haddress) { h = Helper(haddress); } - })"; + } + )"; compileAndRun(sourceCode, 0, "Helper"); u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); @@ -2277,7 +2301,8 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_accessing_this) function setHelper(address addr) { h = Helper(addr); } - })"; + } + )"; compileAndRun(sourceCode, 0, "Helper"); u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); @@ -2308,7 +2333,8 @@ BOOST_AUTO_TEST_CASE(calls_to_this) function setHelper(address addr) { h = Helper(addr); } - })"; + } + )"; compileAndRun(sourceCode, 0, "Helper"); u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); @@ -2343,7 +2369,8 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) function setHelper(address haddress) { h = Helper(haddress); } - })"; + } + )"; compileAndRun(sourceCode, 0, "Helper"); u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); @@ -2373,7 +2400,8 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_in_calls) function setHelper(address addr) { h = Helper(addr); } - })"; + } + )"; compileAndRun(sourceCode, 0, "Helper"); u160 const c_helperAddress = m_contractAddress; compileAndRun(sourceCode, 0, "Main"); @@ -2403,7 +2431,8 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_internal) } function getFlag() returns (bool ret) { return h.getFlag(); } function getName() returns (bytes3 ret) { return h.getName(); } - })"; + } + )"; compileAndRun(sourceCode, 0, "Main"); ABI_CHECK(callContractFunction("getFlag()"), encodeArgs(true)); ABI_CHECK(callContractFunction("getName()"), encodeArgs("abc")); @@ -2506,7 +2535,8 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) } function getName() returns (bytes3 ret) { return name; } function setName(bytes3 _name) private { name = _name; } - })"; + } + )"; compileAndRun(sourceCode); BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc")); } @@ -2632,7 +2662,8 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) function getFlag() returns (bool ret) { return h.getFlag(); } function getName() returns (bytes3 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")); @@ -3128,7 +3159,7 @@ BOOST_AUTO_TEST_CASE(event) function deposit(bytes32 _id, bool _manually) payable { if (_manually) { bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f; - log3(bytes32(msg.value), s, bytes32(msg.sender), _id); + log3(bytes32(msg.value), s, bytes32(uint256(msg.sender)), _id); } else { Deposit(msg.sender, _id, msg.value); } @@ -3525,7 +3556,7 @@ BOOST_AUTO_TEST_CASE(event_indexed_string) event E(string indexed r, uint[4] indexed t); function deposit() { bytes(x).length = 90; - for (uint i = 0; i < 90; i++) + for (uint8 i = 0; i < 90; i++) bytes(x)[i] = byte(i); y[0] = 4; y[1] = 5; @@ -3737,7 +3768,8 @@ BOOST_AUTO_TEST_CASE(sha3_multiple_arguments) { d = sha3(a, b, c); } - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("foo(uint256,uint256,uint256)", 10, 12, 13), encodeArgs( @@ -4404,7 +4436,8 @@ BOOST_AUTO_TEST_CASE(inline_member_init) b = m_b; c = m_c; } - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("get()"), encodeArgs(5, 6, 8)); } @@ -4421,7 +4454,8 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence) function Derived(){} uint m_derived = 6; function getDMember() returns (uint i) { return m_derived; } - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("getBMember()"), encodeArgs(5)); ABI_CHECK(callContractFunction("getDMember()"), encodeArgs(6)); @@ -4437,7 +4471,8 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence_without_constructor) contract Derived is Base { uint m_derived = 6; function getDMember() returns (uint i) { return m_derived; } - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("getBMember()"), encodeArgs(5)); ABI_CHECK(callContractFunction("getDMember()"), encodeArgs(6)); @@ -4753,7 +4788,7 @@ BOOST_AUTO_TEST_CASE(array_copy_different_packing) function test() returns (bytes10 a, bytes10 b, bytes10 c, bytes10 d, bytes10 e) { data1.length = 9; for (uint i = 0; i < data1.length; ++i) - data1[i] = bytes8(i); + data1[i] = bytes8(uint64(i)); data2 = data1; a = data2[1]; b = data2[2]; @@ -4781,7 +4816,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_simple) bytes17[10] data2; // 1 per slot, no offset counter function test() returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) { for (uint i = 0; i < data1.length; ++i) - data1[i] = bytes8(i); + data1[i] = bytes8(uint64(i)); data2[8] = data2[9] = 2; data2 = data1; a = data2[1]; @@ -4813,14 +4848,14 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover) uint i; for (i = 0; i < data2.length; ++i) data2[i] = 0xffff; - check = uint(data2[31]) * 0x10000 | uint(data2[14]); + check = uint(uint16(data2[31])) * 0x10000 | uint(uint16(data2[14])); for (i = 0; i < data1.length; ++i) data1[i] = byte(uint8(1 + i)); data2 = data1; for (i = 0; i < 16; ++i) - res1 |= uint(data2[i]) * 0x10000**i; + res1 |= uint(uint16(data2[i])) * 0x10000**i; for (i = 0; i < 16; ++i) - res2 |= uint(data2[16 + i]) * 0x10000**i; + res2 |= uint(uint16(data2[16 + i])) * 0x10000**i; } } )"; @@ -4846,7 +4881,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover2) data1[2] = 3; data1[3] = 4; for (uint i = 0; i < data2.length; ++i) - data2[i] = bytes10(0xffff00 | (1 + i)); + data2[i] = bytes10(uint80(0xffff00 | (1 + i))); data2 = data1; r1 = data2[3]; r2 = data2[4]; @@ -5060,7 +5095,7 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) contract c { bytes data; function test() returns (uint) { - for (uint i = 1; i < 40; i++) + for (uint8 i = 1; i < 40; i++) { data.push(byte(i)); if (data.length != i) return 0x1000 + i; @@ -5106,11 +5141,11 @@ BOOST_AUTO_TEST_CASE(bytes_index_access) contract c { bytes data; function direct(bytes arg, uint index) external returns (uint) { - return uint(arg[index]); + return uint(uint8(arg[index])); } function storageCopyRead(bytes arg, uint index) external returns (uint) { data = arg; - return uint(data[index]); + return uint(uint8(data[index])); } function storageWrite() external returns (uint) { data.length = 35; @@ -5121,7 +5156,7 @@ BOOST_AUTO_TEST_CASE(bytes_index_access) data[31] |= 8; data[30] = 1; data[32] = 3; - return uint(data[30]) * 0x100 | uint(data[31]) * 0x10 | uint(data[32]); + return uint(uint8(data[30])) * 0x100 | uint(uint8(data[31])) * 0x10 | uint(uint8(data[32])); } } )"; @@ -5144,7 +5179,7 @@ BOOST_AUTO_TEST_CASE(bytes_delete_element) function test1() external returns (bool) { data.length = 100; for (uint i = 0; i < data.length; i++) - data[i] = byte(i); + data[i] = byte(uint8(i)); delete data[94]; delete data[96]; delete data[98]; @@ -5303,7 +5338,8 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base) {} } contract Final is Derived(4) { - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("m_i()"), encodeArgs(4)); } @@ -5326,7 +5362,8 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base) {} } contract Final is Derived(4) { - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("m_i()"), encodeArgs(4)); } @@ -5346,7 +5383,8 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) function Derived(uint i) Base(i) {} } contract Final is Derived(4) { - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("m_i()"), encodeArgs(4)); } @@ -5357,7 +5395,8 @@ BOOST_AUTO_TEST_CASE(simple_constant_variables_test) contract Foo { function getX() returns (uint r) { return x; } uint constant x = 56; - })"; + } + )"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("getX()"), encodeArgs(56)); } @@ -5370,7 +5409,8 @@ BOOST_AUTO_TEST_CASE(constant_variables) enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } ActionChoices constant choices = ActionChoices.GoLeft; bytes32 constant st = "abc\x00\xff__"; - })"; + } + )"; compileAndRun(sourceCode); } @@ -7498,7 +7538,7 @@ BOOST_AUTO_TEST_CASE(short_strings) if (data1[0] != "1") return 10; if (data1[4] != "4") return 11; for (uint i = 0; i < data1.length; i ++) - data1[i] = byte(i * 3); + data1[i] = byte(uint8(i * 3)); if (data1[4] != 4 * 3) return 12; if (data1[67] != 67 * 3) return 13; // change length: long -> short @@ -8314,7 +8354,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_index_access) function g(bytes32 x) returns (uint) { data = [x[0], x[1], x[2]]; data[0] = "12345"; - return uint(data[0][4]); + return uint(uint8(data[0][4])); } } )"; @@ -8372,7 +8412,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_memory_access) function test() returns (bytes) { bytes memory x = new bytes(5); for (uint i = 0; i < x.length; ++i) - x[i] = byte(i + 1); + x[i] = byte(uint8(i + 1)); assembly { mstore(add(x, 32), "12345678901234567890123456789012") } return x; } @@ -8892,7 +8932,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types) function f(bytes2 a, uint16 x) returns (uint) { if (a != "ab") return 1; if (x != 0x0102) return 2; - if (bytes3(x) != 0x0102) return 3; + if (bytes3(uint24(x)) != 0x0102) return 3; return 0; } } |