From adce9ca812bd0c8a79e1bc924ad70773bb9006b1 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 May 2018 15:52:24 +0200 Subject: Tidy up tests to always have closing braces on the proper line --- test/libsolidity/SolidityEndToEndTest.cpp | 57 ++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 1efcfde0..d00b174c 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))); @@ -2216,7 +2217,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 +2248,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 +2280,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 +2312,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 +2348,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 +2379,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 +2410,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 +2514,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 +2641,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")); @@ -3737,7 +3747,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 +4415,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 +4433,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 +4450,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)); @@ -5303,7 +5317,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 +5341,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 +5362,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 +5374,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 +5388,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); } -- cgit v1.2.3 From f5a49f679a1ec2b8aef466f41d85bbfa99b9a74a Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 11 May 2018 14:06:31 +0200 Subject: Adjust tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 1efcfde0..36840568 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1667,7 +1667,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 +1683,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 +1730,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 +1746,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)); } } )"; @@ -3128,7 +3128,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 +3525,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; @@ -4753,7 +4753,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 +4781,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 +4813,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 +4846,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 +5060,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 +5106,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 +5121,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 +5144,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]; @@ -7498,7 +7498,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 +8314,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 +8372,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 +8892,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; } } -- cgit v1.2.3 From f627dc77d01a9367b41d4a2e1654f045f9e4264a Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 14 May 2018 15:26:10 +0200 Subject: Fix continue inside do-while. --- test/libsolidity/SolidityEndToEndTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 36840568..88a1756b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -482,6 +482,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 -- cgit v1.2.3 From e9dcfb0b624e5443942451fc865c154a2c5a73d7 Mon Sep 17 00:00:00 2001 From: bitshift Date: Fri, 9 Mar 2018 17:46:24 +0100 Subject: Implements pop() for value type arrays. --- test/libsolidity/SolidityEndToEndTest.cpp | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 40962294..b4cf6950 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5111,6 +5111,72 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) ABI_CHECK(callContractFunction("test()"), encodeArgs(0)); } +BOOST_AUTO_TEST_CASE(array_pop) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public returns (uint x, uint y, uint l) { + data.push(7); + x = data.push(3); + data.pop(); + y = data.push(2); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 2, 2)); +} + +BOOST_AUTO_TEST_CASE(array_pop_empty) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public returns (bool) { + data.pop(); + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); +} + +BOOST_AUTO_TEST_CASE(bytearray_pop) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (uint x, uint y, uint l) { + data.push(7); + x = data.push(3); + data.pop(); + data.pop(); + y = data.push(2); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 1, 1)); +} + +BOOST_AUTO_TEST_CASE(bytearray_pop_empty) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bool) { + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit v1.2.3 From 7156a01acc822ab66c189435421564afc8b1c922 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 16 Mar 2018 17:06:38 +0100 Subject: Implements pop() for byte arrays. --- test/libsolidity/SolidityEndToEndTest.cpp | 87 ++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 6 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b4cf6950..41101223 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5115,21 +5115,23 @@ BOOST_AUTO_TEST_CASE(array_pop) { char const* sourceCode = R"( contract c { + uint256 a; uint[] data; - function test() public returns (uint x, uint y, uint l) { + function test() public returns (uint x, uint l) { data.push(7); x = data.push(3); data.pop(); - y = data.push(2); + x = data.length; + data.pop(); l = data.length; } } )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 2, 2)); + ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 0)); } -BOOST_AUTO_TEST_CASE(array_pop_empty) +BOOST_AUTO_TEST_CASE(array_pop_empty_exception) { char const* sourceCode = R"( contract c { @@ -5144,7 +5146,23 @@ BOOST_AUTO_TEST_CASE(array_pop_empty) ABI_CHECK(callContractFunction("test()"), encodeArgs()); } -BOOST_AUTO_TEST_CASE(bytearray_pop) +BOOST_AUTO_TEST_CASE(array_pop_storage_empty) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public { + data.push(7); + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop) { char const* sourceCode = R"( contract c { @@ -5163,13 +5181,31 @@ BOOST_AUTO_TEST_CASE(bytearray_pop) ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 1, 1)); } -BOOST_AUTO_TEST_CASE(bytearray_pop_empty) +BOOST_AUTO_TEST_CASE(byte_array_pop_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (uint l) { + for (uint i = 0; i < 33; i++) + data.push(byte(i)); + data.pop(); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(32)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_empty_exception) { char const* sourceCode = R"( contract c { bytes data; function test() public returns (bool) { data.pop(); + return true; } } )"; @@ -5177,6 +5213,45 @@ BOOST_AUTO_TEST_CASE(bytearray_pop_empty) ABI_CHECK(callContractFunction("test()"), encodeArgs()); } +BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public { + data.push(7); + data.push(5); + data.push(3); + data.pop(); + data.pop(); + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (uint l) { + for (uint i = 0; i < 33; i++) + data.push(3); + for (uint j = 0; j < 33; j++) + data.pop(); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(0)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit v1.2.3 From 34b5eca1f8d9a8f04db20139601c6e944532f4e4 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 4 Apr 2018 18:21:06 +0200 Subject: Improves assembly and adds more tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 125 +++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 41101223..b0ab15c8 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5115,7 +5115,6 @@ BOOST_AUTO_TEST_CASE(array_pop) { char const* sourceCode = R"( contract c { - uint256 a; uint[] data; function test() public returns (uint x, uint l) { data.push(7); @@ -5131,6 +5130,86 @@ BOOST_AUTO_TEST_CASE(array_pop) ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 0)); } +BOOST_AUTO_TEST_CASE(array_pop_uint16_transition) +{ + char const* sourceCode = R"( + contract c { + uint16[] data; + function test() public returns (uint16 x, uint16 y, uint16 z) { + for (uint i = 1; i <= 48; i++) + data.push(uint16(i)); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + z = data[data.length - 1]; + for (uint m = 1; m <= 18; m++) + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(38, 28, 18)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(array_pop_uint24_transition) +{ + char const* sourceCode = R"( + contract c { + uint24[] data; + function test() public returns (uint24 x, uint24 y) { + for (uint i = 1; i <= 30; i++) + data.push(uint24(i)); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(20, 10)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(array_pop_array_transition) +{ + char const* sourceCode = R"( + contract c { + uint16[] inner = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; + uint16[][] data; + function test() public returns (uint x, uint y, uint z) { + for (uint i = 1; i <= 48; i++) + data.push(inner); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1][0]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1][1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + z = data[data.length - 1][2]; + for (uint m = 1; m <= 18; m++) + data.pop(); + delete inner; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 2, 3)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + BOOST_AUTO_TEST_CASE(array_pop_empty_exception) { char const* sourceCode = R"( @@ -5252,6 +5331,50 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty_long) BOOST_CHECK(storageEmpty(m_contractAddress)); } +BOOST_AUTO_TEST_CASE(byte_array_pop_masking_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bytes) { + for (uint i = 0; i < 34; i++) + data.push(3); + data.pop(); + return data; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs( + u256(0x20), + u256(33), + asString(fromHex("0303030303030303030303030303030303030303030303030303030303030303")), + asString(fromHex("03")) + )); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_copy_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bytes) { + for (uint i = 0; i < 33; i++) + data.push(3); + for (uint j = 0; j < 4; j++) + data.pop(); + return data; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs( + u256(0x20), + u256(29), + asString(fromHex("0303030303030303030303030303030303030303030303030303030303")) + )); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit v1.2.3 From fea0d116f7d95e9a39f0c80c5156cb3656b03ce0 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Tue, 29 May 2018 11:25:13 +0200 Subject: Fixes assembly bug and adds tests to cover it. --- test/libsolidity/SolidityEndToEndTest.cpp | 68 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 23 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b0ab15c8..f1fac396 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5161,6 +5161,9 @@ BOOST_AUTO_TEST_CASE(array_pop_uint24_transition) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; uint24[] data; function test() public returns (uint24 x, uint24 y) { for (uint i = 1; i <= 30; i++) @@ -5185,6 +5188,9 @@ BOOST_AUTO_TEST_CASE(array_pop_array_transition) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; uint16[] inner = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; uint16[][] data; function test() public returns (uint x, uint y, uint z) { @@ -5260,27 +5266,13 @@ BOOST_AUTO_TEST_CASE(byte_array_pop) ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 1, 1)); } -BOOST_AUTO_TEST_CASE(byte_array_pop_long) -{ - char const* sourceCode = R"( - contract c { - bytes data; - function test() public returns (uint l) { - for (uint i = 0; i < 33; i++) - data.push(byte(i)); - data.pop(); - l = data.length; - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("test()"), encodeArgs(32)); -} - BOOST_AUTO_TEST_CASE(byte_array_pop_empty_exception) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; bytes data; function test() public returns (bool) { data.pop(); @@ -5312,22 +5304,52 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty) BOOST_CHECK(storageEmpty(m_contractAddress)); } -BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty_long) +BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; bytes data; - function test() public returns (uint l) { - for (uint i = 0; i < 33; i++) + function test() public returns (bool) { + for (uint8 i = 0; i <= 40; i++) + data.push(byte(i+1)); + for (int8 j = 40; j >= 0; j--) { + require(data[uint8(j)] == byte(j+1)); + require(data.length == uint8(j+1)); + data.pop(); + } + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(true)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty_garbage_ref) +{ + char const* sourceCode = R"( + contract c { + uint256 a; + uint256 b; + bytes data; + function test() public { + for (uint8 i = 0; i <= 40; i++) data.push(3); - for (uint j = 0; j < 33; j++) + for (uint8 j = 0; j <= 40; j++) { + assembly { + mstore(0, "garbage") + } data.pop(); - l = data.length; + } } } )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("test()"), encodeArgs(0)); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); BOOST_CHECK(storageEmpty(m_contractAddress)); } -- cgit v1.2.3 From 4b7e58f22fbac413b8f182cfdd5df9fdf1efd674 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 31 May 2018 15:01:45 +0200 Subject: Add test for pop on the stack. --- test/libsolidity/SolidityEndToEndTest.cpp | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f1fac396..649a1db6 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5397,6 +5397,40 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_copy_long) )); } +BOOST_AUTO_TEST_CASE(array_pop_isolated) +{ + char const* sourceCode = R"( + // This tests that the compiler knows the correct size of the function on the stack. + contract c { + uint[] data; + function test() public returns (uint x) { + x = 2; + data.pop; + x = 3; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(3)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_isolated) +{ + char const* sourceCode = R"( + // This tests that the compiler knows the correct size of the function on the stack. + contract c { + bytes data; + function test() public returns (uint x) { + x = 2; + data.pop; + x = 3; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(3)); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit v1.2.3 From 7de0d56aae3cf781d2ebeb54bddf93b3207b8f98 Mon Sep 17 00:00:00 2001 From: Jason Cobb Date: Mon, 16 Apr 2018 18:46:14 -0400 Subject: Remove sha3/suicide from assembly tests --- test/libsolidity/SolidityEndToEndTest.cpp | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f1fac396..91f59035 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8585,15 +8585,15 @@ BOOST_AUTO_TEST_CASE(inline_array_return) { char const* sourceCode = R"( contract C { - uint8[] tester; + uint8[] tester; function f() returns (uint8[5]) { return ([1,2,3,4,5]); } function test() returns (uint8, uint8, uint8, uint8, uint8) { - tester = f(); + tester = f(); return (tester[0], tester[1], tester[2], tester[3], tester[4]); } - + } )"; compileAndRun(sourceCode, 0, "C"); @@ -8617,13 +8617,13 @@ BOOST_AUTO_TEST_CASE(inline_array_singleton) BOOST_AUTO_TEST_CASE(inline_long_string_return) { char const* sourceCode = R"( - contract C { + contract C { function f() returns (string) { return (["somethingShort", "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"][1]); } } )"; - + string strLong = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeDyn(strLong)); @@ -11431,26 +11431,11 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly) =: ret } } - function h() pure returns (bytes32 ret) { - assembly { - ret := sha3(0, 0) - } - } - function i() pure returns (bytes32 ret) { - assembly { - 0 - 0 - sha3 - =: ret - } - } } )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); ABI_CHECK(callContractFunction("g()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); - ABI_CHECK(callContractFunction("h()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); - ABI_CHECK(callContractFunction("i()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); } BOOST_AUTO_TEST_CASE(multi_modifiers) -- cgit v1.2.3 From f33dc92cbd908a6d852368fa30144bda9e8da439 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 7 May 2018 19:09:52 +0200 Subject: Use proper SAR for signed right shifts and emulate on pre-constantinople. --- test/libsolidity/SolidityEndToEndTest.cpp | 172 ++++++++++++++++++++---------- 1 file changed, 115 insertions(+), 57 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b53a9294..3b3cc4f7 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10487,6 +10487,7 @@ BOOST_AUTO_TEST_CASE(shift_right) ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(0x4266), u256(8)), encodeArgs(u256(0x42))); ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(0x4266), u256(16)), encodeArgs(u256(0))); ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(0x4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(1)<<255, u256(5)), encodeArgs(u256(1)<<250)); } BOOST_AUTO_TEST_CASE(shift_right_garbled) @@ -10583,16 +10584,73 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(-1))); +} + +BOOST_AUTO_TEST_CASE(shift_right_negative_literal) +{ + char const* sourceCode = R"( + contract C { + function f1() pure returns (bool) { + return (-4266 >> 0) == -4266; + } + function f2() pure returns (bool) { + return (-4266 >> 1) == -2133; + } + function f3() pure returns (bool) { + return (-4266 >> 4) == -267; + } + function f4() pure returns (bool) { + return (-4266 >> 8) == -17; + } + function f5() pure returns (bool) { + return (-4266 >> 16) == -1; + } + function f6() pure returns (bool) { + return (-4266 >> 17) == -1; + } + function g1() pure returns (bool) { + return (-4267 >> 0) == -4267; + } + function g2() pure returns (bool) { + return (-4267 >> 1) == -2134; + } + function g3() pure returns (bool) { + return (-4267 >> 4) == -267; + } + function g4() pure returns (bool) { + return (-4267 >> 8) == -17; + } + function g5() pure returns (bool) { + return (-4267 >> 16) == -1; + } + function g6() pure returns (bool) { + return (-4267 >> 17) == -1; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f1()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f2()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f3()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f4()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f5()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f6()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g1()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g2()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g3()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g4()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g5()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g6()"), encodeArgs(true)); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int8) @@ -10607,16 +10665,16 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int8) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(0)), encodeArgs(u256(-66))); ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(1)), encodeArgs(u256(-33))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(4)), encodeArgs(u256(-4))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(8)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(4)), encodeArgs(u256(-5))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(8)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(0)), encodeArgs(u256(-67))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(1)), encodeArgs(u256(-33))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(4)), encodeArgs(u256(-4))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(8)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(1)), encodeArgs(u256(-34))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(4)), encodeArgs(u256(-5))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(8)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int8) @@ -10630,10 +10688,10 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int8) )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(0)), encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(1)), encodeArgs(u256(-51))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(2)), encodeArgs(u256(-25))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(4)), encodeArgs(u256(-6))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(8)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(1)), encodeArgs(u256(-52))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(2)), encodeArgs(u256(-26))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(4)), encodeArgs(u256(-7))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(8)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int16) @@ -10647,10 +10705,10 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int16) )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(0)), encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(1)), encodeArgs(u256(-51))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(2)), encodeArgs(u256(-25))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(4)), encodeArgs(u256(-6))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(8)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(1)), encodeArgs(u256(-52))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(2)), encodeArgs(u256(-26))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(4)), encodeArgs(u256(-7))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(8)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int32) @@ -10664,10 +10722,10 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int32) )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(0)), encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(1)), encodeArgs(u256(-51))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(2)), encodeArgs(u256(-25))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(4)), encodeArgs(u256(-6))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(8)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(1)), encodeArgs(u256(-52))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(2)), encodeArgs(u256(-26))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(4)), encodeArgs(u256(-7))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(8)), encodeArgs(u256(-1))); } @@ -10683,16 +10741,16 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int16) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int32) @@ -10707,16 +10765,16 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int32) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_assignment) @@ -10732,16 +10790,16 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_assignment) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_negative_rvalue) -- cgit v1.2.3 From 510f227bd78cda33181531141c88c6b948d72935 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 12 Jun 2018 15:53:15 +0200 Subject: Additional test and more explanation. --- test/libsolidity/SolidityEndToEndTest.cpp | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3b3cc4f7..a4c02888 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10508,6 +10508,39 @@ BOOST_AUTO_TEST_CASE(shift_right_garbled) ABI_CHECK(callContractFunction("f(uint8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(0xf))); } +BOOST_AUTO_TEST_CASE(shift_right_garbled_signed) +{ + char const* sourceCode = R"( + contract C { + function f(int8 a, uint8 b) returns (int) { + assembly { + a := 0xfffffff0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + function g(int8 a, uint8 b) returns (int) { + assembly { + a := 0xf0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1003)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1003)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(-1))); +} + BOOST_AUTO_TEST_CASE(shift_right_uint32) { char const* sourceCode = R"( -- cgit v1.2.3 From 9de45383d81c666deba27162ce163fc1c8c852dc Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 Jun 2018 17:06:47 +0100 Subject: Disallow sha3/suicide aliases --- test/libsolidity/SolidityEndToEndTest.cpp | 61 +------------------------------ 1 file changed, 2 insertions(+), 59 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a4c02888..2afb4e1c 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1971,25 +1971,6 @@ BOOST_AUTO_TEST_CASE(log_in_constructor) BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(u256(2))); } -BOOST_AUTO_TEST_CASE(suicide) -{ - char const* sourceCode = R"( - contract test { - function test() payable {} - function a(address receiver) returns (uint ret) { - suicide(receiver); - return 10; - } - } - )"; - u256 amount(130); - compileAndRun(sourceCode, amount); - u160 address(23); - ABI_CHECK(callContractFunction("a(address)", address), bytes()); - BOOST_CHECK(!addressHasCode(m_contractAddress)); - BOOST_CHECK_EQUAL(balanceAt(address), amount); -} - BOOST_AUTO_TEST_CASE(selfdestruct) { char const* sourceCode = R"( @@ -2028,23 +2009,6 @@ BOOST_AUTO_TEST_CASE(keccak256) testContractAgainstCpp("a(bytes32)", f, u256(-1)); } -BOOST_AUTO_TEST_CASE(sha3) -{ - char const* sourceCode = R"( - contract test { - // to confuse the optimiser - function b(bytes32 input) returns (bytes32) { - return sha3(input); - } - function a(bytes32 input) returns (bool) { - return keccak256(input) == b(input); - } - } - )"; - compileAndRun(sourceCode); - BOOST_REQUIRE(callContractFunction("a(bytes32)", u256(42)) == encodeArgs(true)); -} - BOOST_AUTO_TEST_CASE(sha256) { char const* sourceCode = R"( @@ -3760,27 +3724,6 @@ BOOST_AUTO_TEST_CASE(iterated_keccak256_with_bytes) )); } -BOOST_AUTO_TEST_CASE(sha3_multiple_arguments) -{ - char const* sourceCode = R"( - contract c { - function foo(uint a, uint b, uint c) returns (bytes32 d) - { - d = sha3(a, b, c); - } - } - )"; - compileAndRun(sourceCode); - - ABI_CHECK(callContractFunction("foo(uint256,uint256,uint256)", 10, 12, 13), encodeArgs( - dev::keccak256( - toBigEndian(u256(10)) + - toBigEndian(u256(12)) + - toBigEndian(u256(13)) - ) - )); -} - BOOST_AUTO_TEST_CASE(generic_call) { char const* sourceCode = R"**( @@ -11642,13 +11585,13 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value) return value; } function get_delegated() external returns (bool) { - return this.delegatecall(bytes4(sha3("get()"))); + return this.delegatecall(bytes4(keccak256("get()"))); } function assert0() external view { assert(value == 0); } function assert0_delegated() external returns (bool) { - return this.delegatecall(bytes4(sha3("assert0()"))); + return this.delegatecall(bytes4(keccak256("assert0()"))); } } )DELIMITER"; -- cgit v1.2.3 From 1dc28c065d91416caf778770ef57b73b30462b8d Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 7 May 2018 16:23:39 +0200 Subject: Properly pad data from calldata. --- test/libsolidity/SolidityEndToEndTest.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 2afb4e1c..236d83ef 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3457,7 +3457,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data) callContractFunction("deposit()"); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK_EQUAL(toHex(m_logs[0].data), toHex(encodeArgs(10, 0x60, 15, 4) + FixedHash<4>(dev::keccak256("deposit()")).asBytes())); + BOOST_CHECK_EQUAL(toHex(m_logs[0].data), toHex(encodeArgs(10, 0x60, 15, 4, asString(FixedHash<4>(dev::keccak256("deposit()")).asBytes())))); BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(uint256,bytes,uint256)"))); } @@ -3964,7 +3964,8 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) compileAndRun(sourceCode, 0, "sender"); // No additional data, just function selector - ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(0x20)); + // Should be this with 0.5.0: encodeArgs(4)); ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(0x20)); // Should be this with 0.5.0: encodeArgs(4)); ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(0x20)); @@ -3972,7 +3973,8 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) // Some additional unpadded data bytes unpadded = asBytes(string("abc")); - ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(0x20)); + // Should be this with 0.5.0: encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(0x20)); // Should be this with 0.5.0: encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(0x20)); -- cgit v1.2.3 From a211b8911885ded6ddcd4d7400994a85235fe8e4 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 6 Jun 2018 11:15:22 +0200 Subject: Enforce disallowing empty structs This patch enfoces an error when it encounters an empty struct, effectively eliminating the deprecation warning. Also adjust 419_interface_structs to explicitely test for (non-empty) structs, as this behaviour "may" change in the future. --- test/libsolidity/SolidityEndToEndTest.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 236d83ef..c80aa8ba 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1271,7 +1271,6 @@ BOOST_AUTO_TEST_CASE(deleteStruct) contract test { struct topStruct { nestedStruct nstr; - emptyStruct empty; uint topValue; mapping (uint => uint) topMapping; } @@ -1281,8 +1280,6 @@ BOOST_AUTO_TEST_CASE(deleteStruct) uint nestedValue; mapping (uint => bool) nestedMapping; } - struct emptyStruct{ - } function test(){ toDelete = 5; str.topValue = 1; -- cgit v1.2.3 From a17059573fe2ffce115b5368e798a87ce07dc1cd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 18 Jun 2018 16:06:23 +0100 Subject: Disallow raw callcode (was deprecated in 0.4.12) --- test/libsolidity/SolidityEndToEndTest.cpp | 36 ------------------------------- 1 file changed, 36 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c80aa8ba..2a24a1e3 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3745,38 +3745,6 @@ BOOST_AUTO_TEST_CASE(generic_call) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 50 - 2); } -BOOST_AUTO_TEST_CASE(generic_callcode) -{ - char const* sourceCode = R"**( - contract Receiver { - uint public received; - function receive(uint256 x) payable { received = x; } - } - contract Sender { - uint public received; - function Sender() payable { } - function doSend(address rec) returns (uint d) - { - bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); - rec.callcode.value(2)(signature, 23); - return Receiver(rec).received(); - } - } - )**"; - compileAndRun(sourceCode, 0, "Receiver"); - u160 const c_receiverAddress = m_contractAddress; - compileAndRun(sourceCode, 50, "Sender"); - u160 const c_senderAddress = m_contractAddress; - ABI_CHECK(callContractFunction("doSend(address)", c_receiverAddress), encodeArgs(0)); - ABI_CHECK(callContractFunction("received()"), encodeArgs(23)); - m_contractAddress = c_receiverAddress; - ABI_CHECK(callContractFunction("received()"), encodeArgs(0)); - BOOST_CHECK(storageEmpty(c_receiverAddress)); - BOOST_CHECK(!storageEmpty(c_senderAddress)); - BOOST_CHECK_EQUAL(balanceAt(c_receiverAddress), 0); - BOOST_CHECK_EQUAL(balanceAt(c_senderAddress), 50); -} - BOOST_AUTO_TEST_CASE(generic_delegatecall) { char const* sourceCode = R"**( @@ -11558,9 +11526,6 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address) function f() external returns (bool) { return address(0x4242).call(); } - function g() external returns (bool) { - return address(0x4242).callcode(); - } function h() external returns (bool) { return address(0x4242).delegatecall(); } @@ -11568,7 +11533,6 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address) )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(1))); ABI_CHECK(callContractFunction("h()"), encodeArgs(u256(1))); } -- cgit v1.2.3 From 8862b3092bcdbcb8314ec27e2b11bf25fcc6346a Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Fri, 15 Jun 2018 12:30:28 +0200 Subject: C99 scoping rules by default --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 2a24a1e3..65473f0d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5011,7 +5011,7 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) if (data.length != i) return 0x1000 + i; if (data[data.length - 1] != byte(i)) return i; } - for (i = 1; i < 40; i++) + for (uint8 i = 1; i < 40; i++) if (data[i - 1] != byte(i)) return 0x1000000 + i; return 0; } -- cgit v1.2.3 From 98c9ca257568e8f281a5d8857a45ef2c8aef2c77 Mon Sep 17 00:00:00 2001 From: Jason Cobb Date: Wed, 30 May 2018 17:02:47 -0400 Subject: Update tests for strict address literals --- test/libsolidity/SolidityEndToEndTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 65473f0d..42b5d417 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9460,8 +9460,8 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper) 0, // invalid v value 0x6944c77849b18048f6abe0db8084b0d0d0689cdddb53d2671c36967b58691ad4, 0xef4f06ba4f78319baafd0424365777241af4dfd3da840471b4b4b087b7750d0d, - 0xca35b7d915458ef540ade6068dfe2f44e8fa733c, - 0xca35b7d915458ef540ade6068dfe2f44e8fa733c + 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c, + 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c ); } function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s, uint blockExpired, bytes32 salt) -- cgit v1.2.3 From 312f422e100e63cb1980a2e09bc39a95f192aa09 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sun, 6 May 2018 15:23:20 +0200 Subject: Forwarding length check. --- test/libsolidity/SolidityEndToEndTest.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 42b5d417..f41d2665 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3931,19 +3931,15 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) // No additional data, just function selector ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(0x20)); // Should be this with 0.5.0: encodeArgs(4)); - ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(4)); - ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(4)); + ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4)); // Some additional unpadded data bytes unpadded = asBytes(string("abc")); ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(0x20)); // Should be this with 0.5.0: encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7)); } BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) -- cgit v1.2.3 From 86a720b96a45ce1b59ab1038e7bb465f9a566189 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 23 May 2018 15:39:26 +0200 Subject: Adjust tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 82 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f41d2665..1d10bf2a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1456,7 +1456,7 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) function test() { data = 8; name = "Celina"; - a_hash = keccak256(123); + a_hash = keccak256("\x7b"); an_address = address(0x1337); super_secret_data = 42; } @@ -1992,7 +1992,7 @@ BOOST_AUTO_TEST_CASE(keccak256) char const* sourceCode = R"( contract test { function a(bytes32 input) returns (bytes32 hash) { - return keccak256(input); + return keccak256(abi.encodePacked(input)); } } )"; @@ -2011,7 +2011,7 @@ BOOST_AUTO_TEST_CASE(sha256) char const* sourceCode = R"( contract test { function a(bytes32 input) returns (bytes32 sha256hash) { - return sha256(input); + return sha256(abi.encodePacked(input)); } } )"; @@ -2036,7 +2036,7 @@ BOOST_AUTO_TEST_CASE(ripemd) char const* sourceCode = R"( contract test { function a(bytes32 input) returns (bytes32 sha256hash) { - return ripemd160(input); + return ripemd160(abi.encodePacked(input)); } } )"; @@ -2063,7 +2063,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256) function a(bytes32 input) returns (bytes32 hash) { var b = 65536; uint c = 256; - return keccak256(8, input, b, input, c); + return keccak256(abi.encodePacked(8, input, b, input, c)); } } )"; @@ -2093,9 +2093,9 @@ BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types) x[0] = y[0] = uint120(-2); x[1] = y[1] = uint120(-3); x[2] = y[2] = uint120(-4); - hash1 = keccak256(x); - hash2 = keccak256(y); - hash3 = keccak256(this.f); + hash1 = keccak256(abi.encodePacked(x)); + hash2 = keccak256(abi.encodePacked(y)); + hash3 = keccak256(abi.encodePacked(this.f)); } } )"; @@ -2115,7 +2115,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256) function a(bytes32 input) returns (bytes32 hash) { var b = 65536; uint c = 256; - return sha256(8, input, b, input, c); + return sha256(abi.encodePacked(8, input, b, input, c)); } } )"; @@ -2142,7 +2142,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160) function a(bytes32 input) returns (bytes32 hash) { var b = 65536; uint c = 256; - return ripemd160(8, input, b, input, c); + return ripemd160(abi.encodePacked(8, input, b, input, c)); } } )"; @@ -3082,13 +3082,13 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) BOOST_AUTO_TEST_CASE(default_fallback_throws) { - char const* sourceCode = R"( + char const* sourceCode = R"YY( contract A { function f() returns (bool) { - return this.call(); + return this.call(""); } } - )"; + )YY"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("f()"), encodeArgs(0)); } @@ -3577,7 +3577,7 @@ BOOST_AUTO_TEST_CASE(sha256_empty) char const* sourceCode = R"( contract C { function f() returns (bytes32) { - return sha256(); + return sha256(""); } } )"; @@ -3590,7 +3590,7 @@ BOOST_AUTO_TEST_CASE(ripemd160_empty) char const* sourceCode = R"( contract C { function f() returns (bytes20) { - return ripemd160(); + return ripemd160(""); } } )"; @@ -3603,7 +3603,7 @@ BOOST_AUTO_TEST_CASE(keccak256_empty) char const* sourceCode = R"( contract C { function f() returns (bytes32) { - return keccak256(); + return keccak256(""); } } )"; @@ -3617,7 +3617,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments) contract c { function foo(uint a, uint b, uint c) returns (bytes32 d) { - d = keccak256(a, b, c); + d = keccak256(abi.encodePacked(a, b, c)); } } )"; @@ -3638,7 +3638,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals) contract c { function foo(uint a, uint16 b) returns (bytes32 d) { - d = keccak256(a, b, 145); + d = keccak256(abi.encodePacked(a, b, 145)); } } )"; @@ -3663,7 +3663,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals) } function bar(uint a, uint16 b) returns (bytes32 d) { - d = keccak256(a, b, 145, "foo"); + d = keccak256(abi.encodePacked(a, b, 145, "foo")); } } )"; @@ -3702,7 +3702,7 @@ BOOST_AUTO_TEST_CASE(keccak256_with_bytes) BOOST_AUTO_TEST_CASE(iterated_keccak256_with_bytes) { - char const* sourceCode = R"( + char const* sourceCode = R"ABC( contract c { bytes data; function foo() returns (bytes32) @@ -3711,10 +3711,10 @@ BOOST_AUTO_TEST_CASE(iterated_keccak256_with_bytes) data[0] = "x"; data[1] = "y"; data[2] = "z"; - return keccak256("b", keccak256(data), "a"); + return keccak256(abi.encodePacked("b", keccak256(data), "a")); } } - )"; + )ABC"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("foo()"), encodeArgs( u256(dev::keccak256(bytes{'b'} + dev::keccak256("xyz").asBytes() + bytes{'a'})) @@ -3733,7 +3733,7 @@ BOOST_AUTO_TEST_CASE(generic_call) function doSend(address rec) returns (uint d) { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); - rec.call.value(2)(signature, 23); + rec.call.value(2)(abi.encodeWithSelector(signature, 23)); return receiver(rec).received(); } } @@ -3763,7 +3763,7 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) function doSend(address rec) payable { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); - if (rec.delegatecall(signature, 23)) {} + if (rec.delegatecall(abi.encodeWithSelector(signature, 23))) {} } } )**"; @@ -3860,7 +3860,7 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) char const* sourceCode = R"( contract C { function f() returns (bytes32) { - return keccak256("abc", msg.data); + return keccak256(abi.encodePacked("abc", msg.data)); } } )"; @@ -3929,15 +3929,13 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) compileAndRun(sourceCode, 0, "sender"); // No additional data, just function selector - ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(4)); + ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4)); ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(4)); ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4)); // Some additional unpadded data bytes unpadded = asBytes(string("abc")); - ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7)); } @@ -6394,7 +6392,7 @@ BOOST_AUTO_TEST_CASE(reusing_memory) mapping(uint => uint) map; function f(uint x) returns (uint) { map[x] = x; - return (new Helper(uint(keccak256(this.g(map[x]))))).flag(); + return (new Helper(uint(keccak256(abi.encodePacked(this.g(map[x])))))).flag(); } function g(uint a) returns (uint) { @@ -9382,7 +9380,7 @@ BOOST_AUTO_TEST_CASE(mutex) // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) throw; - if (!msg.sender.call.value(amount)()) throw; + if (!msg.sender.call.value(amount)("")) throw; shares -= amount; return shares; } @@ -9390,7 +9388,7 @@ BOOST_AUTO_TEST_CASE(mutex) // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) throw; - if (!msg.sender.call.value(amount)()) throw; + if (!msg.sender.call.value(amount)("")) throw; shares -= amount; return shares; } @@ -9463,7 +9461,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper) function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s, uint blockExpired, bytes32 salt) returns (address) { - require(hash == keccak256(blockExpired, salt)); + require(hash == keccak256(abi.encodePacked(blockExpired, salt))); return ecrecover(hash, v, r, s); } } @@ -9495,7 +9493,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_asm) BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) { - char const* sourceCode = R"( + char const* sourceCode = R"YY( contract D { function g(); } contract C { D d = D(0x1212); @@ -9508,11 +9506,11 @@ BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) return 7; } function h() returns (uint) { - d.call(); // this does not throw (low-level) + d.call(""); // this does not throw (low-level) return 7; } } - )"; + )YY"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs()); ABI_CHECK(callContractFunction("g()"), encodeArgs()); @@ -11516,17 +11514,17 @@ BOOST_AUTO_TEST_CASE(inlineasm_empty_let) BOOST_AUTO_TEST_CASE(bare_call_invalid_address) { - char const* sourceCode = R"( + char const* sourceCode = R"YY( contract C { /// Calling into non-existant account is successful (creates the account) function f() external returns (bool) { - return address(0x4242).call(); + return address(0x4242).call(""); } function h() external returns (bool) { - return address(0x4242).delegatecall(); + return address(0x4242).delegatecall(""); } } - )"; + )YY"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); ABI_CHECK(callContractFunction("h()"), encodeArgs(u256(1))); @@ -11544,13 +11542,13 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value) return value; } function get_delegated() external returns (bool) { - return this.delegatecall(bytes4(keccak256("get()"))); + return this.delegatecall(abi.encodeWithSignature("get()")); } function assert0() external view { assert(value == 0); } function assert0_delegated() external returns (bool) { - return this.delegatecall(bytes4(keccak256("assert0()"))); + return this.delegatecall(abi.encodeWithSignature("assert0()")); } } )DELIMITER"; -- cgit v1.2.3 From 4e8883b63d26eb2bcfc5e1c18c8bab8236fff16b Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 27 Jun 2018 10:48:03 +0200 Subject: Add emit keyword to tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 106 +++++------------------------- 1 file changed, 16 insertions(+), 90 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 42b5d417..65a0a216 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3122,7 +3122,7 @@ BOOST_AUTO_TEST_CASE(event) bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f; log3(bytes32(msg.value), s, bytes32(uint256(msg.sender)), _id); } else { - Deposit(msg.sender, _id, msg.value); + emit Deposit(msg.sender, _id, msg.value); } } } @@ -3172,7 +3172,7 @@ BOOST_AUTO_TEST_CASE(event_no_arguments) contract ClientReceipt { event Deposit(); function deposit() { - Deposit(); + emit Deposit(); } } )"; @@ -3186,28 +3186,6 @@ BOOST_AUTO_TEST_CASE(event_no_arguments) BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit()"))); } -BOOST_AUTO_TEST_CASE(event_access_through_base_name) -{ - char const* sourceCode = R"( - contract A { - event x(); - } - contract B is A { - function f() returns (uint) { - A.x(); - return 1; - } - } - )"; - compileAndRun(sourceCode); - callContractFunction("f()"); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data.empty()); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("x()"))); -} - BOOST_AUTO_TEST_CASE(event_access_through_base_name_emit) { char const* sourceCode = R"( @@ -3238,67 +3216,15 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) event Deposit(address _addr); event Deposit(address _addr, uint _amount); function deposit() returns (uint) { - Deposit(); - return 1; - } - function deposit(address _addr) returns (uint) { - Deposit(_addr); - return 1; - } - function deposit(address _addr, uint _amount) returns (uint) { - Deposit(_addr, _amount); - return 1; - } - } - )"; - u160 const c_loggedAddress = m_contractAddress; - - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("deposit()"), encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data.empty()); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit()"))); - - ABI_CHECK(callContractFunction("deposit(address)", c_loggedAddress), encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data == encodeArgs(c_loggedAddress)); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address)"))); - - ABI_CHECK(callContractFunction("deposit(address,uint256)", c_loggedAddress, u256(100)), encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data == encodeArgs(c_loggedAddress, 100)); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address,uint256)"))); -} - -BOOST_AUTO_TEST_CASE(events_with_same_name_inherited) -{ - char const* sourceCode = R"( - contract A { - event Deposit(); - } - - contract B { - event Deposit(address _addr); - } - - contract ClientReceipt is A, B { - event Deposit(address _addr, uint _amount); - function deposit() returns (uint) { - Deposit(); + emit Deposit(); return 1; } function deposit(address _addr) returns (uint) { - Deposit(_addr); + emit Deposit(_addr); return 1; } function deposit(address _addr, uint _amount) returns (uint) { - Deposit(_addr, _amount); + emit Deposit(_addr, _amount); return 1; } } @@ -3386,7 +3312,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous) contract ClientReceipt { event Deposit() anonymous; function deposit() { - Deposit(); + emit Deposit(); } } )"; @@ -3401,7 +3327,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous_with_topics) contract ClientReceipt { event Deposit(address indexed _from, bytes32 indexed _id, uint indexed _value, uint indexed _value2, bytes32 data) anonymous; function deposit(bytes32 _id) payable { - Deposit(msg.sender, _id, msg.value, 2, "abc"); + emit Deposit(msg.sender, _id, msg.value, 2, "abc"); } } )"; @@ -3425,7 +3351,7 @@ BOOST_AUTO_TEST_CASE(event_lots_of_data) contract ClientReceipt { event Deposit(address _from, bytes32 _id, uint _value, bool _flag); function deposit(bytes32 _id) payable { - Deposit(msg.sender, _id, msg.value, true); + emit Deposit(msg.sender, _id, msg.value, true); } } )"; @@ -3446,7 +3372,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data) contract ClientReceipt { event Deposit(uint fixeda, bytes dynx, uint fixedb); function deposit() { - Deposit(10, msg.data, 15); + emit Deposit(10, msg.data, 15); } } )"; @@ -3470,7 +3396,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data_from_storage) x[0] = "A"; x[1] = "B"; x[2] = "C"; - Deposit(10, x, 15); + emit Deposit(10, x, 15); } } )"; @@ -3495,7 +3421,7 @@ BOOST_AUTO_TEST_CASE(event_really_really_lots_of_data_from_storage) x[1] = "B"; x[2] = "C"; x[30] = "Z"; - Deposit(10, x, 15); + emit Deposit(10, x, 15); } } )"; @@ -3523,7 +3449,7 @@ BOOST_AUTO_TEST_CASE(event_indexed_string) y[1] = 5; y[2] = 6; y[3] = 7; - E(x, y); + emit E(x, y); } } )"; @@ -4246,7 +4172,7 @@ BOOST_AUTO_TEST_CASE(storing_invalid_boolean) assembly { tmp := 5 } - Ev(tmp); + emit Ev(tmp); return 1; } } @@ -6034,12 +5960,12 @@ BOOST_AUTO_TEST_CASE(invalid_enum_logged) assembly { garbled := 5 } - Log(garbled); + emit Log(garbled); return 1; } function test_log_ok() returns (uint) { X x = X.A; - Log(x); + emit Log(x); return 1; } } @@ -11932,7 +11858,7 @@ BOOST_AUTO_TEST_CASE(snark) input[7] = 9643208548031422463313148630985736896287522941726746581856185889848792022807; input[8] = 18066496933330839731877828156604; if (verify(input, proof) == 0) { - Verified("Transaction successfully verified."); + emit Verified("Transaction successfully verified."); return true; } else { return false; -- cgit v1.2.3 From eeef82b2d77c6f956039c57b0598e684254ee6dd Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 28 Jun 2018 18:08:45 +0200 Subject: Fallback function has to be external: backwards-compatible changes. --- test/libsolidity/SolidityEndToEndTest.cpp | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 57204c61..b8c85a63 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1812,7 +1812,7 @@ BOOST_AUTO_TEST_CASE(transfer_ether) } contract C { - function () payable { + function () external payable { throw; } } @@ -2506,7 +2506,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) { char const* sourceCode = R"( contract helper { - function() payable { } // can receive ether + function() external payable { } // can receive ether } contract test { helper h; @@ -3054,7 +3054,7 @@ BOOST_AUTO_TEST_CASE(fallback_function) char const* sourceCode = R"( contract A { uint data; - function() { data = 1; } + function() external { data = 1; } function getData() returns (uint r) { return data; } } )"; @@ -3069,7 +3069,7 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) char const* sourceCode = R"( contract A { uint data; - function() { data = 1; } + function() external { data = 1; } function getData() returns (uint r) { return data; } } contract B is A {} @@ -3100,7 +3100,7 @@ BOOST_AUTO_TEST_CASE(short_data_calls_fallback) uint public x; // Signature is d88e0b00 function fow() { x = 3; } - function () { x = 2; } + function () external { x = 2; } } )"; compileAndRun(sourceCode); @@ -3802,11 +3802,11 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) contract receiver { uint public received; function receive(uint x) { received += x + 1; } - function() { received = 0x80; } + function() external { received = 0x80; } } contract sender { function sender() { rec = new receiver(); } - function() { savedData = msg.data; } + function() external { savedData = msg.data; } function forward() returns (bool) { !rec.call(savedData); return true; } function clear() returns (bool) { delete savedData; return true; } function val() returns (uint) { return rec.received(); } @@ -3830,7 +3830,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) char const* sourceCode = R"( contract receiver { uint public calledLength; - function() { calledLength = msg.data.length; } + function() external { calledLength = msg.data.length; } } contract sender { receiver rec; @@ -3872,11 +3872,11 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) contract receiver { uint public received; function receive(uint x) { received += x + 1; } - function() { received = 0x80; } + function() external { received = 0x80; } } contract sender { function sender() { rec = new receiver(); } - function() { savedData1 = savedData2 = msg.data; } + function() external { savedData1 = savedData2 = msg.data; } function forward(bool selector) returns (bool) { if (selector) { rec.call(savedData1); delete savedData1; } else { rec.call(savedData2); delete savedData2; } @@ -3903,7 +3903,7 @@ BOOST_AUTO_TEST_CASE(delete_removes_bytes_data) { char const* sourceCode = R"( contract c { - function() { data = msg.data; } + function() external { data = msg.data; } function del() returns (bool) { delete data; return true; } bytes data; } @@ -3920,7 +3920,7 @@ BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data) char const* sourceCode = R"( contract c { function set() returns (bool) { data = msg.data; return true; } - function() { data = msg.data; } + function() external { data = msg.data; } bytes data; } )"; @@ -6265,7 +6265,7 @@ BOOST_AUTO_TEST_CASE(failing_send) char const* sourceCode = R"( contract Helper { uint[] data; - function () { + function () external { data[9]; // trigger exception } } @@ -6289,7 +6289,7 @@ BOOST_AUTO_TEST_CASE(send_zero_ether) // (it previously did not because the gas stipend was not provided by the EVM) char const* sourceCode = R"( contract Receiver { - function () payable { + function () external payable { } } contract Main { @@ -7805,7 +7805,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) function f(address x) returns (bool) { return x.send(1); } - function () payable {} + function () external payable {} } )"; compileAndRun(sourceCode, 0, "lib"); @@ -9335,7 +9335,7 @@ BOOST_AUTO_TEST_CASE(mutex) else return fund.withdrawUnprotected(10); } - function() payable { + function() external payable { callDepth++; if (callDepth < 4) attackInternal(); @@ -9461,7 +9461,7 @@ BOOST_AUTO_TEST_CASE(payable_function) function f() payable returns (uint) { return msg.value; } - function() payable { + function() external payable { a = msg.value + 1; } } @@ -9500,7 +9500,7 @@ BOOST_AUTO_TEST_CASE(non_payable_throw) function f() returns (uint) { return msg.value; } - function() { + function() external { a = msg.value + 1; } } @@ -11189,7 +11189,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_transfer) { char const* sourceCode = R"( contract D { - function() public payable { + function() external payable { revert("message"); } function f() public { @@ -11340,7 +11340,7 @@ BOOST_AUTO_TEST_CASE(interface_contract) interface I { event A(); function f() returns (bool); - function() payable; + function() external payable; } contract A is I { @@ -11352,7 +11352,7 @@ BOOST_AUTO_TEST_CASE(interface_contract) return true; } - function() payable { + function() external payable { } } -- cgit v1.2.3 From 12c4eb769762d55a71ba05cf1b74b99797026f51 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 27 Jun 2018 13:22:33 +0200 Subject: Updates compiled unit tests to new constructor syntax. --- test/libsolidity/SolidityEndToEndTest.cpp | 178 +++++++++++++++--------------- 1 file changed, 89 insertions(+), 89 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b8c85a63..7ea6cf98 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1280,7 +1280,7 @@ BOOST_AUTO_TEST_CASE(deleteStruct) uint nestedValue; mapping (uint => bool) nestedMapping; } - function test(){ + constructor(){ toDelete = 5; str.topValue = 1; str.topMapping[0] = 1; @@ -1358,7 +1358,7 @@ BOOST_AUTO_TEST_CASE(constructor) char const* sourceCode = R"( contract test { mapping(uint => uint) data; - function test() { + constructor() { data[7] = 8; } function get(uint key) returns (uint value) { @@ -1382,7 +1382,7 @@ BOOST_AUTO_TEST_CASE(simple_accessor) char const* sourceCode = R"( contract test { uint256 public data; - function test() { + constructor() { data = 8; } } @@ -1401,7 +1401,7 @@ BOOST_AUTO_TEST_CASE(array_accessor) struct st { uint a; uint[] finalArray; } mapping(uint256 => mapping(uint256 => st[5])) public multiple_map; - function test() { + constructor() { data[0] = 8; dynamicData.length = 3; dynamicData[2] = 8; @@ -1431,7 +1431,7 @@ BOOST_AUTO_TEST_CASE(accessors_mapping_for_array) contract test { mapping(uint => uint[8]) public data; mapping(uint => uint[]) public dynamicData; - function test() { + constructor() { data[2][2] = 8; dynamicData[2].length = 3; dynamicData[2][2] = 8; @@ -1453,7 +1453,7 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) bytes6 public name; bytes32 public a_hash; address public an_address; - function test() { + constructor() { data = 8; name = "Celina"; a_hash = keccak256("\x7b"); @@ -1479,7 +1479,7 @@ BOOST_AUTO_TEST_CASE(complex_accessors) mapping(uint256 => bool) public to_bool_map; mapping(uint256 => uint256) public to_uint_map; mapping(uint256 => mapping(uint256 => uint256)) public to_multiple_map; - function test() { + constructor() { to_string_map[42] = "24"; to_bool_map[42] = false; to_uint_map[42] = 12; @@ -1500,7 +1500,7 @@ BOOST_AUTO_TEST_CASE(struct_accessor) contract test { struct Data { uint a; uint8 b; mapping(uint => uint) c; bool d; } mapping(uint => Data) public data; - function test() { + constructor() { data[7].a = 1; data[7].b = 2; data[7].c[0] = 3; @@ -1516,7 +1516,7 @@ BOOST_AUTO_TEST_CASE(balance) { char const* sourceCode = R"( contract test { - function test() payable {} + constructor() payable {} function getBalance() returns (uint256 balance) { return address(this).balance; } @@ -1530,7 +1530,7 @@ BOOST_AUTO_TEST_CASE(blockchain) { char const* sourceCode = R"( contract test { - function test() payable {} + constructor() payable {} function someInfo() payable returns (uint256 value, address coinbase, uint256 blockNumber) { value = msg.value; coinbase = block.coinbase; @@ -1780,7 +1780,7 @@ BOOST_AUTO_TEST_CASE(send_ether) { char const* sourceCode = R"( contract test { - function test() payable {} + constructor() payable {} function a(address addr, uint amount) returns (uint ret) { addr.send(amount); return address(this).balance; @@ -1798,7 +1798,7 @@ BOOST_AUTO_TEST_CASE(transfer_ether) { char const* sourceCode = R"( contract A { - function A() payable {} + constructor() payable {} function a(address addr, uint amount) returns (uint) { addr.transfer(amount); return this.balance; @@ -1955,7 +1955,7 @@ BOOST_AUTO_TEST_CASE(log_in_constructor) { char const* sourceCode = R"( contract test { - function test() { + constructor() { log1(1, 2); } } @@ -1972,7 +1972,7 @@ BOOST_AUTO_TEST_CASE(selfdestruct) { char const* sourceCode = R"( contract test { - function test() payable {} + constructor() payable {} function a(address receiver) returns (uint ret) { selfdestruct(receiver); return 10; @@ -2378,7 +2378,7 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_internal) bytes3 name; bool flag; - function Helper(bytes3 x, bool f) { + constructor(bytes3 x, bool f) { name = x; flag = f; } @@ -2387,7 +2387,7 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_internal) } contract Main { Helper h; - function Main() { + constructor() { h = new Helper("abc", true); } function getFlag() returns (bool ret) { return h.getFlag(); } @@ -2406,7 +2406,7 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_external) bytes3 name; bool flag; - function Main(bytes3 x, bool f) { + constructor(bytes3 x, bool f) { name = x; flag = f; } @@ -2426,7 +2426,7 @@ BOOST_AUTO_TEST_CASE(constructor_with_long_arguments) string public a; string public b; - function Main(string _a, string _b) { + constructor(string _a, string _b) { a = _a; b = _b; } @@ -2454,7 +2454,7 @@ BOOST_AUTO_TEST_CASE(constructor_static_array_argument) uint public a; uint[3] public b; - function C(uint _a, uint[3] _b) { + constructor(uint _a, uint[3] _b) { a = _a; b = _b; } @@ -2474,7 +2474,7 @@ BOOST_AUTO_TEST_CASE(constant_var_as_array_length) uint constant LEN = 3; uint[LEN] public a; - function C(uint[LEN] _a) { + constructor(uint[LEN] _a) { a = _a; } } @@ -2491,7 +2491,7 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) contract Test { bytes3 name; bool flag; - function Test() { + constructor() { setName("abc"); } function getName() returns (bytes3 ret) { return name; } @@ -2510,7 +2510,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } contract test { helper h; - function test() payable { h = new helper(); h.send(5); } + constructor() payable { h = new helper(); h.send(5); } function getBalance() returns (uint256 myBalance, uint256 helperBalance) { myBalance = this.balance; helperBalance = h.balance; @@ -2535,7 +2535,7 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic) } contract test { helper h; - function test() payable { h = new helper(); } + constructor() payable { h = new helper(); } function sendAmount(uint amount) payable returns (uint256 bal) { return h.getBalance.value(amount)(); } @@ -2566,7 +2566,7 @@ BOOST_AUTO_TEST_CASE(value_complex) } contract test { helper h; - function test() payable { h = new helper(); } + constructor() payable { h = new helper(); } function sendAmount(uint amount) payable returns (uint256 bal) { var x1 = h.getBalance.value(amount); uint someStackElement = 20; @@ -2589,7 +2589,7 @@ BOOST_AUTO_TEST_CASE(value_insane) } contract test { helper h; - function test() payable { h = new helper(); } + constructor() payable { h = new helper(); } function sendAmount(uint amount) returns (uint256 bal) { var x1 = h.getBalance.value; var x2 = x1(amount).gas; @@ -2608,7 +2608,7 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) contract Helper { bytes3 name; bool flag; - function Helper(bytes3 x, bool f) payable { + constructor(bytes3 x, bool f) payable { name = x; flag = f; } @@ -2617,7 +2617,7 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) } contract Main { Helper h; - function Main() payable { + constructor() payable { h = (new Helper).value(10)("abc", true); } function getFlag() returns (bool ret) { return h.getFlag(); } @@ -2711,12 +2711,12 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - function BaseBase(uint a) { + constructor(uint a) { m_a = a; } } contract Base is BaseBase(7) { - function Base() { + constructor() { m_a *= m_a; } } @@ -2733,7 +2733,7 @@ BOOST_AUTO_TEST_CASE(function_usage_in_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - function BaseBase(uint a) { + constructor(uint a) { m_a = a; } function g() returns (uint r) { return 2; } @@ -2753,7 +2753,7 @@ BOOST_AUTO_TEST_CASE(virtual_function_usage_in_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - function BaseBase(uint a) { + constructor(uint a) { m_a = a; } function overridden() returns (uint r) { return 1; } @@ -2775,7 +2775,7 @@ BOOST_AUTO_TEST_CASE(constructor_argument_overriding) char const* sourceCode = R"( contract BaseBase { uint m_a; - function BaseBase(uint a) { + constructor(uint a) { m_a = a; } } @@ -2792,7 +2792,7 @@ BOOST_AUTO_TEST_CASE(internal_constructor) { char const* sourceCode = R"( contract C { - function C() internal {} + constructor() internal {} } )"; BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "C").empty()); @@ -2885,7 +2885,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_calling_functions_in_creation_context) char const* sourceCode = R"( contract A { uint data; - function A() mod1 { f1(); } + constructor() mod1 { f1(); } function f1() mod2 { data |= 0x1; } function f2() { data |= 0x20; } function f3() { } @@ -2908,7 +2908,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_for_constructor) char const* sourceCode = R"( contract A { uint data; - function A() mod1 { data |= 2; } + constructor() mod1 { data |= 2; } modifier mod1 { data |= 1; _; } function getData() returns (uint r) { return data; } } @@ -3034,7 +3034,7 @@ BOOST_AUTO_TEST_CASE(super_in_constructor) contract A { function f() returns (uint r) { return 1; } } contract B is A { function f() returns (uint r) { return super.f() | 2; } } contract C is A { function f() returns (uint r) { return super.f() | 4; } } - contract D is B, C { uint data; function D() { data = super.f() | 8; } function f() returns (uint r) { return data; } } + contract D is B, C { uint data; constructor() { data = super.f() | 8; } function f() returns (uint r) { return data; } } )"; compileAndRun(sourceCode, 0, "D"); ABI_CHECK(callContractFunction("f()"), encodeArgs(1 | 2 | 4 | 8)); @@ -3655,7 +3655,7 @@ BOOST_AUTO_TEST_CASE(generic_call) function receive(uint256 x) payable { received = x; } } contract sender { - function sender() payable {} + constructor() payable {} function doSend(address rec) returns (uint d) { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); @@ -3678,14 +3678,14 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) uint public received; address public sender; uint public value; - function Receiver() payable {} + constructor() payable {} function receive(uint256 x) payable { received = x; sender = msg.sender; value = msg.value; } } contract Sender { uint public received; address public sender; uint public value; - function Sender() payable {} + constructor() payable {} function doSend(address rec) payable { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); @@ -3805,7 +3805,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) function() external { received = 0x80; } } contract sender { - function sender() { rec = new receiver(); } + constructor() { rec = new receiver(); } function() external { savedData = msg.data; } function forward() returns (bool) { !rec.call(savedData); return true; } function clear() returns (bool) { delete savedData; return true; } @@ -3875,7 +3875,7 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) function() external { received = 0x80; } } contract sender { - function sender() { rec = new receiver(); } + constructor() { rec = new receiver(); } function() external { savedData1 = savedData2 = msg.data; } function forward(bool selector) returns (bool) { if (selector) { rec.call(savedData1); delete savedData1; } @@ -4089,7 +4089,7 @@ BOOST_AUTO_TEST_CASE(using_enums) char const* sourceCode = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() + constructor() { choices = ActionChoices.GoStraight; } @@ -4109,7 +4109,7 @@ BOOST_AUTO_TEST_CASE(enum_explicit_overflow) char const* sourceCode = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoStraight } - function test() + constructor() { } function getChoiceExp(uint x) returns (uint d) @@ -4254,7 +4254,7 @@ BOOST_AUTO_TEST_CASE(inline_member_init) { char const* sourceCode = R"( contract test { - function test(){ + constructor(){ m_b = 6; m_c = 8; } @@ -4276,12 +4276,12 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence) { char const* sourceCode = R"( contract Base { - function Base(){} + constructor(){} uint m_base = 5; function getBMember() returns (uint i) { return m_base; } } contract Derived is Base { - function Derived(){} + constructor(){} uint m_derived = 6; function getDMember() returns (uint i) { return m_derived; } } @@ -5477,14 +5477,14 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base) { char const* sourceCode = R"( contract Base { - function Base(uint i) + constructor(uint i) { m_i = i; } uint public m_i; } contract Derived is Base { - function Derived(uint i) Base(i) + constructor(uint i) Base(i) {} } contract Final is Derived(4) { @@ -5498,17 +5498,17 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base) { char const* sourceCode = R"( contract Base { - function Base(uint j) + constructor(uint j) { m_i = j; } uint public m_i; } contract Base1 is Base { - function Base1(uint k) Base(k*k) {} + constructor(uint k) Base(k*k) {} } contract Derived is Base, Base1 { - function Derived(uint i) Base(i) Base1(i) + constructor(uint i) Base(i) Base1(i) {} } contract Final is Derived(4) { @@ -5522,7 +5522,7 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) { char const* sourceCode = R"( contract Base { - function Base(uint i) + constructor(uint i) { m_i = i; } @@ -5530,7 +5530,7 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) } contract Base1 is Base(3) {} contract Derived is Base, Base1 { - function Derived(uint i) Base(i) {} + constructor(uint i) Base(i) {} } contract Final is Derived(4) { } @@ -5893,7 +5893,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_signed) BOOST_AUTO_TEST_CASE(external_types_in_calls) { char const* sourceCode = R"( - contract C1 { C1 public bla; function C1(C1 x) { bla = x; } } + contract C1 { C1 public bla; constructor(C1 x) { bla = x; } } contract C { function test() returns (C1 x, C1 y) { C1 c = new C1(C1(9)); @@ -6106,7 +6106,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) testStruct data1; testStruct data2; testStruct data3; - function test() + constructor() { data1.m_value = 2; } @@ -6138,7 +6138,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) uint m_value; } testStruct data1; - function test() + constructor() { data1.m_value = 2; } @@ -6165,7 +6165,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) } mapping (uint => testStruct) campaigns; - function test() + constructor() { campaigns[0].m_value = 2; } @@ -6208,7 +6208,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( contract A { - function A() + constructor() { this.call("123"); } @@ -6234,7 +6234,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) contract A { uint public test = 1; uint[3] arr; - function A() + constructor() { uint index = 5; test = arr[index]; @@ -6270,7 +6270,7 @@ BOOST_AUTO_TEST_CASE(failing_send) } } contract Main { - function Main() payable {} + constructor() payable {} function callHelper(address _a) returns (bool r, uint bal) { r = !_a.send(5); bal = this.balance; @@ -6293,7 +6293,7 @@ BOOST_AUTO_TEST_CASE(send_zero_ether) } } contract Main { - function Main() payable {} + constructor() payable {} function s() returns (bool) { var r = new Receiver(); return r.send(0); @@ -6310,7 +6310,7 @@ BOOST_AUTO_TEST_CASE(reusing_memory) char const* sourceCode = R"( contract Helper { uint public flag; - function Helper(uint x) { + constructor(uint x) { flag = x; } } @@ -6541,7 +6541,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_unpacker) contract Test { uint public m_x; bytes public m_s; - function Test(uint x, bytes s) { + constructor(uint x, bytes s) { m_x = x; m_s = s; } @@ -6562,7 +6562,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) contract Base { uint public m_x; bytes m_s; - function Base(uint x, bytes s) { + constructor(uint x, bytes s) { m_x = x; m_s = s; } @@ -6571,7 +6571,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) } } contract Main is Base { - function Main(bytes s, uint x) Base(x, f(s)) {} + constructor(bytes s, uint x) Base(x, f(s)) {} function f(bytes s) returns (bytes) { return s; } @@ -6601,7 +6601,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors) contract Base { uint public m_x; address[] m_s; - function Base(uint x, address[] s) { + constructor(uint x, address[] s) { m_x = x; m_s = s; } @@ -6610,7 +6610,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors) } } contract Main is Base { - function Main(address[] s, uint x) Base(x, f(s)) {} + constructor(address[] s, uint x) Base(x, f(s)) {} function f(address[] s) returns (address[]) { return s; } @@ -6640,7 +6640,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_in_constructors) contract Creator { uint public r; address public ch; - function Creator(address[3] s, uint x) { + constructor(address[3] s, uint x) { r = x; ch = s[2]; } @@ -7060,7 +7060,7 @@ BOOST_AUTO_TEST_CASE(struct_constructor_nested) struct X { uint x1; uint x2; } struct S { uint s1; uint[3] s2; X s3; } S s; - function C() { + constructor() { uint[3] memory s2; s2[1] = 9; s = S(1, s2, X(4, 5)); @@ -7086,7 +7086,7 @@ BOOST_AUTO_TEST_CASE(struct_named_constructor) contract C { struct S { uint a; bool x; } S public s; - function C() { + constructor() { s = S({a: 1, x: true}); } } @@ -7368,7 +7368,7 @@ BOOST_AUTO_TEST_CASE(constant_string_literal) bytes32 constant public b = "abcdefghijklmnopq"; string constant public x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca"; - function Test() { + constructor() { var xx = x; var bb = b; } @@ -7501,7 +7501,7 @@ BOOST_AUTO_TEST_CASE(strings_in_struct) string last; } - function buggystruct(){ + constructor(){ bug = Buggy(10, 20, 30, "asdfghjkl"); } function getFirst() returns (uint) @@ -7776,7 +7776,7 @@ BOOST_AUTO_TEST_CASE(calldata_offset) { address[] _arr; string public last = "nd"; - function CB(address[] guardians) + constructor(address[] guardians) { _arr = guardians; } @@ -7801,7 +7801,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) char const* sourceCode = R"( library lib {} contract c { - function c() payable {} + constructor() payable {} function f(address x) returns (bool) { return x.send(1); } @@ -8222,7 +8222,7 @@ BOOST_AUTO_TEST_CASE(string_allocation_bug) { struct s { uint16 x; uint16 y; string a; string b;} s[2] public p; - function Sample() { + constructor() { s memory m; m.x = 0xbbbb; m.y = 0xcccc; @@ -9158,10 +9158,10 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs) BOOST_AUTO_TEST_CASE(failed_create) { char const* sourceCode = R"( - contract D { function D() payable {} } + contract D { constructor() payable {} } contract C { uint public x; - function C() payable {} + constructor() payable {} function f(uint amount) returns (address) { x++; return (new D).value(amount)(); @@ -9204,7 +9204,7 @@ BOOST_AUTO_TEST_CASE(correctly_initialize_memory_array_in_constructor) char const* sourceCode = R"( contract C { bool public success; - function C() public { + constructor() public { // Make memory dirty. assembly { for { let i := 0 } lt(i, 64) { i := add(i, 1) } { @@ -9301,7 +9301,7 @@ BOOST_AUTO_TEST_CASE(mutex) } contract Fund is mutexed { uint shares; - function Fund() payable { shares = msg.value; } + constructor() payable { shares = msg.value; } function withdraw(uint amount) protected returns (uint) { // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. @@ -9324,7 +9324,7 @@ BOOST_AUTO_TEST_CASE(mutex) uint callDepth; bool protected; function setProtected(bool _protected) { protected = _protected; } - function Attacker(Fund _fund) { fund = _fund; } + constructor(Fund _fund) { fund = _fund; } function attack() returns (uint) { callDepth = 0; return attackInternal(); @@ -9447,7 +9447,7 @@ BOOST_AUTO_TEST_CASE(payable_constructor) { char const* sourceCode = R"( contract C { - function C() payable { } + constructor() payable { } } )"; compileAndRun(sourceCode, 27, "C"); @@ -9729,7 +9729,7 @@ BOOST_AUTO_TEST_CASE(store_function_in_constructor) contract C { uint public result_in_constructor; function (uint) internal returns (uint) x; - function C () { + constructor() { x = double; result_in_constructor = use(2); } @@ -9754,7 +9754,7 @@ BOOST_AUTO_TEST_CASE(store_internal_unused_function_in_constructor) char const* sourceCode = R"( contract C { function () internal returns (uint) x; - function C () { + constructor() { x = unused; } function unused() internal returns (uint) { @@ -9776,7 +9776,7 @@ BOOST_AUTO_TEST_CASE(store_internal_unused_library_function_in_constructor) library L { function x() internal returns (uint) { return 7; } } contract C { function () internal returns (uint) x; - function C () { + constructor() { x = L.x; } function t() returns (uint) { @@ -9794,7 +9794,7 @@ BOOST_AUTO_TEST_CASE(same_function_in_construction_and_runtime) char const* sourceCode = R"( contract C { uint public initial; - function C() { + constructor() { initial = double(2); } function double(uint _arg) returns (uint _ret) { @@ -9816,7 +9816,7 @@ BOOST_AUTO_TEST_CASE(same_function_in_construction_and_runtime_equality_check) char const* sourceCode = R"( contract C { function (uint) internal returns (uint) x; - function C() { + constructor() { x = double; } function test() returns (bool) { @@ -9907,7 +9907,7 @@ BOOST_AUTO_TEST_CASE(mapping_of_functions) success = true; } - function Flow() { + constructor() { stages[msg.sender] = stage0; } @@ -10900,7 +10900,7 @@ BOOST_AUTO_TEST_CASE(include_creation_bytecode_only_once) contract D { bytes a = hex"1237651237125387136581271652831736512837126583171583712358126123765123712538713658127165283173651283712658317158371235812612376512371253871365812716528317365128371265831715837123581261237651237125387136581271652831736512837126583171583712358126"; bytes b = hex"1237651237125327136581271252831736512837126583171383712358126123765125712538713658127165253173651283712658357158371235812612376512371a5387136581271652a317365128371265a317158371235812612a765123712538a13658127165a83173651283712a58317158371235a126"; - function D(uint) {} + constructor(uint) {} } contract Double { function f() { @@ -11224,7 +11224,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_create) { char const* sourceCode = R"( contract E { - function E() { + constructor() { revert("message"); } } -- cgit v1.2.3 From 8747079746c1ca78dfabaca22bf1c011a342bb97 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 29 Jun 2018 12:14:36 +0200 Subject: Fix tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7ea6cf98..889c68b9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2770,24 +2770,6 @@ BOOST_AUTO_TEST_CASE(virtual_function_usage_in_constructor_arguments) ABI_CHECK(callContractFunction("getA()"), encodeArgs(2)); } -BOOST_AUTO_TEST_CASE(constructor_argument_overriding) -{ - char const* sourceCode = R"( - contract BaseBase { - uint m_a; - constructor(uint a) { - m_a = a; - } - } - contract Base is BaseBase(2) { } - contract Derived is BaseBase(3), Base { - function getA() returns (uint r) { return m_a; } - } - )"; - compileAndRun(sourceCode, 0, "Derived"); - ABI_CHECK(callContractFunction("getA()"), encodeArgs(3)); -} - BOOST_AUTO_TEST_CASE(internal_constructor) { char const* sourceCode = R"( @@ -5505,10 +5487,10 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base) uint public m_i; } contract Base1 is Base { - constructor(uint k) Base(k*k) {} + constructor(uint k) Base(k) {} } contract Derived is Base, Base1 { - constructor(uint i) Base(i) Base1(i) + constructor(uint i) Base1(i) {} } contract Final is Derived(4) { @@ -5528,9 +5510,11 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) } uint public m_i; } - contract Base1 is Base(3) {} + contract Base1 is Base { + constructor(uint k) {} + } contract Derived is Base, Base1 { - constructor(uint i) Base(i) {} + constructor(uint i) Base(i) Base1(7) {} } contract Final is Derived(4) { } -- cgit v1.2.3 From 334c023c7231810f28ca5ea04f14df3f722cea07 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 15 Jun 2018 12:18:00 +0200 Subject: Determine transaction status in RPC sessions. --- test/libsolidity/SolidityEndToEndTest.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7ea6cf98..ea90a5be 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -49,6 +49,25 @@ namespace test BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, SolidityExecutionFramework) +BOOST_AUTO_TEST_CASE(transaction_status) +{ + char const* sourceCode = R"( + contract test { + function f() { } + function g() { revert(); } + function h() { assert(false); } + } + )"; + compileAndRun(sourceCode); + callContractFunction("f()"); + BOOST_CHECK(m_transactionSuccessful); + callContractFunction("g()"); + BOOST_CHECK(!m_transactionSuccessful); + callContractFunction("h()"); + BOOST_CHECK(!m_transactionSuccessful); +} + + BOOST_AUTO_TEST_CASE(smoke_test) { char const* sourceCode = R"( @@ -3106,9 +3125,11 @@ BOOST_AUTO_TEST_CASE(short_data_calls_fallback) compileAndRun(sourceCode); // should call fallback sendMessage(asBytes("\xd8\x8e\x0b"), false, 0); + BOOST_CHECK(m_transactionSuccessful); ABI_CHECK(callContractFunction("x()"), encodeArgs(2)); // should call function sendMessage(asBytes(string("\xd8\x8e\x0b") + string(1, 0)), false, 0); + BOOST_CHECK(m_transactionSuccessful); ABI_CHECK(callContractFunction("x()"), encodeArgs(3)); } @@ -3793,6 +3814,7 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) compileAndRun(sourceCode); bytes calldata1 = FixedHash<4>(dev::keccak256("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12); sendMessage(calldata1, false); + BOOST_CHECK(m_transactionSuccessful); BOOST_CHECK(m_output == encodeArgs(dev::keccak256(bytes{'a', 'b', 'c'} + calldata1))); } @@ -3928,7 +3950,8 @@ BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data) ABI_CHECK(callContractFunction("set()", 1, 2, 3, 4, 5), encodeArgs(true)); BOOST_CHECK(!storageEmpty(m_contractAddress)); sendMessage(bytes(), false); - BOOST_CHECK(m_output == bytes()); + BOOST_CHECK(m_transactionSuccessful); + BOOST_CHECK(m_output.empty()); BOOST_CHECK(storageEmpty(m_contractAddress)); } @@ -6243,6 +6266,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) } )"; ABI_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A"), encodeArgs()); + BOOST_CHECK(!m_transactionSuccessful); } BOOST_AUTO_TEST_CASE(positive_integers_to_signed) -- cgit v1.2.3 From e251cdcf47667ad3e7c88446d8b26cb3ae1bd0f2 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Thu, 28 Jun 2018 15:19:53 +0200 Subject: test: ensure compiled tests do not use var-keyword in preparation of var-keyword removal --- test/libsolidity/SolidityEndToEndTest.cpp | 109 ++++++++++++++---------------- 1 file changed, 50 insertions(+), 59 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7ea6cf98..aca6a66b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_functions) function y() returns (uint) { return 2; } function f(bool cond) returns (uint) { - var z = cond ? x : y; + function () returns (uint) z = cond ? x : y; return z(); } } @@ -433,7 +433,7 @@ BOOST_AUTO_TEST_CASE(while_loop) contract test { function f(uint n) returns(uint nfac) { nfac = 1; - var i = 2; + uint i = 2; while (i <= n) nfac *= i++; } } @@ -460,7 +460,7 @@ BOOST_AUTO_TEST_CASE(do_while_loop) contract test { function f(uint n) returns(uint nfac) { nfac = 1; - var i = 2; + uint i = 2; do { nfac *= i++; } while (i <= n); } } @@ -561,7 +561,8 @@ BOOST_AUTO_TEST_CASE(for_loop) contract test { function f(uint n) returns(uint nfac) { nfac = 1; - for (var i = 2; i <= n; i++) + uint i; + for (i = 2; i <= n; i++) nfac *= i; } } @@ -735,7 +736,7 @@ BOOST_AUTO_TEST_CASE(many_local_variables) char const* sourceCode = R"( contract test { function run(uint x1, uint x2, uint x3) returns(uint y) { - var a = 0x1; var b = 0x10; var c = 0x100; + uint8 a = 0x1; uint8 b = 0x10; uint16 c = 0x100; y = a + b + c + x1 + x2 + x3; y += b + x2; } @@ -1252,7 +1253,7 @@ BOOST_AUTO_TEST_CASE(struct_reference) } function set() { data.z = 2; - var map = data.recursive; + mapping(uint8 => s2) map = data.recursive; s2 inner = map[0]; inner.z = 3; inner.recursive[0].z = inner.recursive[1].z + 1; @@ -1836,8 +1837,7 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash) contract C { function f() public view returns (bytes32) { - var x = block.blockhash; - return x(block.number - 1); + return (block.blockhash)(block.number - 1); } } )"; @@ -2061,7 +2061,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256) char const* sourceCode = R"( contract test { function a(bytes32 input) returns (bytes32 hash) { - var b = 65536; + uint24 b = 65536; uint c = 256; return keccak256(abi.encodePacked(8, input, b, input, c)); } @@ -2113,7 +2113,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256) char const* sourceCode = R"( contract test { function a(bytes32 input) returns (bytes32 hash) { - var b = 65536; + uint24 b = 65536; uint c = 256; return sha256(abi.encodePacked(8, input, b, input, c)); } @@ -2140,7 +2140,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160) char const* sourceCode = R"( contract test { function a(bytes32 input) returns (bytes32 hash) { - var b = 65536; + uint24 b = 65536; uint c = 256; return ripemd160(abi.encodePacked(8, input, b, input, c)); } @@ -2319,9 +2319,8 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) contract Main { Helper h; function callHelper(uint a, uint b) returns (uint c) { - var fu = h.multiply; - var y = 9; - var ret = fu(a, b); + uint8 y = 9; + uint256 ret = h.multiply(a, b); return ret + y; } function getHelper() returns (address haddress) { @@ -2568,10 +2567,8 @@ BOOST_AUTO_TEST_CASE(value_complex) helper h; constructor() payable { h = new helper(); } function sendAmount(uint amount) payable returns (uint256 bal) { - var x1 = h.getBalance.value(amount); uint someStackElement = 20; - var x2 = x1.gas(1000); - return x2.value(amount + 3)();// overwrite value + return h.getBalance.value(amount).gas(1000).value(amount + 3)(); } } )"; @@ -2591,10 +2588,7 @@ BOOST_AUTO_TEST_CASE(value_insane) helper h; constructor() payable { h = new helper(); } function sendAmount(uint amount) returns (uint256 bal) { - var x1 = h.getBalance.value; - var x2 = x1(amount).gas; - var x3 = x2(1000).value; - return x3(amount + 3)();// overwrite value + return h.getBalance.value(amount).gas(1000).value(amount + 3)();// overwrite value } } )"; @@ -2815,7 +2809,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_local_variables) { char const* sourceCode = R"( contract C { - modifier mod1 { var a = 1; var b = 2; _; } + modifier mod1 { uint8 a = 1; uint8 b = 2; _; } modifier mod2(bool a) { if (a) return; else _; } function f(bool a) mod1 mod2(a) returns (uint r) { return 3; } } @@ -2829,7 +2823,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_loop) { char const* sourceCode = R"( contract C { - modifier repeat(uint count) { for (var i = 0; i < count; ++i) _; } + modifier repeat(uint count) { uint i; for (i = 0; i < count; ++i) _; } function f() repeat(10) returns (uint r) { r += 1; } } )"; @@ -3007,8 +3001,7 @@ BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack) function f() returns (uint r) { uint; uint; uint; uint; int x = -7; - var a = uint; - return a(x); + return uint(x); } } )"; @@ -4074,7 +4067,7 @@ BOOST_AUTO_TEST_CASE(struct_copy_via_local) function test() returns (bool) { data1.a = 1; data1.b = 2; - var x = data1; + Struct memory x = data1; data2 = x; return data2.a == data1.a && data2.b == data1.b; } @@ -6295,7 +6288,7 @@ BOOST_AUTO_TEST_CASE(send_zero_ether) contract Main { constructor() payable {} function s() returns (bool) { - var r = new Receiver(); + Receiver r = new Receiver(); return r.send(0); } } @@ -6578,7 +6571,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) } contract Creator { function f(uint x, bytes s) returns (uint r, byte ch) { - var c = new Main(s, x); + Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); } @@ -6617,7 +6610,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors) } contract Creator { function f(uint x, address[] s) returns (uint r, address ch) { - var c = new Main(s, x); + Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); } @@ -7369,8 +7362,8 @@ BOOST_AUTO_TEST_CASE(constant_string_literal) string constant public x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca"; constructor() { - var xx = x; - var bb = b; + string memory xx = x; + bytes32 bb = b; } function getB() returns (bytes32) { return b; } function getX() returns (string) { return x; } @@ -7461,7 +7454,7 @@ BOOST_AUTO_TEST_CASE(cross_contract_types) contract Lib { struct S {uint a; uint b; } } contract Test { function f() returns (uint r) { - var x = Lib.S({a: 2, b: 3}); + Lib.S memory x = Lib.S({a: 2, b: 3}); r = x.b; } } @@ -7546,7 +7539,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) contract B { function f() returns (uint16[5] res, uint16[5] res2) { - var a = new A(); + A a = new A(); res = a.f(2); res2 = a.f(1000); } @@ -7829,13 +7822,13 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration) a = 1; b = 2; c = 3; } function f() returns (bool) { - var (x, y, z) = g(); + (uint x, uint y, uint z) = g(); if (x != 1 || y != 2 || z != 3) return false; - var (, a,) = g(); + (, uint a,) = g(); if (a != 2) return false; - var (b,) = g(); + (uint b,) = g(); if (b != 1) return false; - var (,c) = g(); + (, uint c) = g(); if (c != 3) return false; return true; } @@ -8037,11 +8030,11 @@ BOOST_AUTO_TEST_CASE(create_memory_array) contract C { struct S { uint[2] a; bytes b; } function f() returns (byte, uint, uint, byte) { - var x = new bytes(200); + bytes memory x = new bytes(200); x[199] = 'A'; - var y = new uint[2][](300); + uint[2][] memory y = new uint[2][](300); y[203][1] = 8; - var z = new S[](180); + S[] memory z = new S[](180); z[170].a[1] = 4; z[170].b = new bytes(102); z[170].b[99] = 'B'; @@ -8331,8 +8324,7 @@ BOOST_AUTO_TEST_CASE(bound_function_in_var) D.s public x; function f(uint a) returns (uint) { x.a = 6; - var g = x.mul; - return g({x: a}); + return (x.mul)({x: a}); } } )"; @@ -9120,7 +9112,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types) } function g() returns (uint, uint) { // Previous implementation "moved" b to the second place and did not skip. - var (a, _, b) = this.f(); + (uint a,, uint b) = this.f(); return (a, b); } } @@ -9146,7 +9138,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs) s.a = "abc"; s.b = [7, 8, 9]; s.y = 6; - var (x, a, y) = this.s(); + (uint x,, uint y) = this.s(); return (x, y); } } @@ -9188,7 +9180,7 @@ BOOST_AUTO_TEST_CASE(create_dynamic_array_with_zero_length) char const* sourceCode = R"( contract C { function f() returns (uint) { - var a = new uint[][](0); + uint[][] memory a = new uint[][](0); return 7; } } @@ -10039,7 +10031,7 @@ BOOST_AUTO_TEST_CASE(function_delete_stack) contract C { function a() returns (uint) { return 7; } function test() returns (uint) { - var y = a; + function () returns (uint) y = a; delete y; y(); } @@ -10077,7 +10069,7 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls) char const* sourceCode = R"( contract D { function f(function() external returns (function() external returns (uint))[] x) - returns (function() external returns (uint)[3] r) + public returns (function() external returns (uint)[3] r) { r[0] = x[0](); r[1] = x[1](); @@ -10085,23 +10077,23 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls) } } contract C { - function test() returns (uint, uint, uint) { + function test() public returns (uint, uint, uint) { function() external returns (function() external returns (uint))[] memory x = new function() external returns (function() external returns (uint))[](10); for (uint i = 0; i < x.length; i ++) x[i] = this.h; x[0] = this.htwo; - var y = (new D()).f(x); + function() external returns (uint)[3] memory y = (new D()).f(x); return (y[0](), y[1](), y[2]()); } - function e() returns (uint) { return 5; } - function f() returns (uint) { return 6; } - function g() returns (uint) { return 7; } + function e() public returns (uint) { return 5; } + function f() public returns (uint) { return 6; } + function g() public returns (uint) { return 7; } uint counter; - function h() returns (function() external returns (uint)) { + function h() public returns (function() external returns (uint)) { return counter++ == 0 ? this.f : this.g; } - function htwo() returns (function() external returns (uint)) { + function htwo() public returns (function() external returns (uint)) { return this.e; } } @@ -11230,7 +11222,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_create) } contract D { function f() public { - var x = new E(); + E x = new E(); } } contract C { @@ -11506,8 +11498,7 @@ BOOST_AUTO_TEST_CASE(function_types_sig) } function h() returns (bytes4) { function () pure external returns (bytes4) fun = this.f; - var funvar = fun; - return funvar.selector; + return fun.selector; } function i() pure returns (bytes4) { return this.x.selector; @@ -11739,8 +11730,8 @@ BOOST_AUTO_TEST_CASE(snark) Pairing.G1Point memory p2; p1.X = 1; p1.Y = 2; p2.X = 1; p2.Y = 2; - var explict_sum = Pairing.add(p1, p2); - var scalar_prod = Pairing.mul(p1, 2); + Pairing.G1Point memory explict_sum = Pairing.add(p1, p2); + Pairing.G1Point memory scalar_prod = Pairing.mul(p1, 2); return (explict_sum.X == scalar_prod.X && explict_sum.Y == scalar_prod.Y); } -- cgit v1.2.3 From f7a9c4203e35439de6ff4bdd94c7083c16b73e43 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 29 Jun 2018 17:41:59 +0200 Subject: Disallow packed encoding of literals. --- test/libsolidity/SolidityEndToEndTest.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 31842777..85848d88 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2082,7 +2082,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256) function a(bytes32 input) returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return keccak256(abi.encodePacked(8, input, b, input, c)); + return keccak256(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -2134,7 +2134,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256) function a(bytes32 input) returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return sha256(abi.encodePacked(8, input, b, input, c)); + return sha256(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -2161,7 +2161,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160) function a(bytes32 input) returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return ripemd160(abi.encodePacked(8, input, b, input, c)); + return ripemd160(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -3578,7 +3578,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals) contract c { function foo(uint a, uint16 b) returns (bytes32 d) { - d = keccak256(abi.encodePacked(a, b, 145)); + d = keccak256(abi.encodePacked(a, b, uint8(145))); } } )"; @@ -3603,7 +3603,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals) } function bar(uint a, uint16 b) returns (bytes32 d) { - d = keccak256(abi.encodePacked(a, b, 145, "foo")); + d = keccak256(abi.encodePacked(a, b, uint8(145), "foo")); } } )"; -- cgit v1.2.3 From 8202d512e0bd4e6b4a19ed483afff288514e75bd Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Wed, 4 Jul 2018 11:42:05 +0200 Subject: Enforcing error on msg.gas and block.blockhash() --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 9e6aa43d..9622de8c 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1856,7 +1856,7 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash) contract C { function f() public view returns (bytes32) { - return (block.blockhash)(block.number - 1); + return (blockhash)(block.number - 1); } } )"; -- cgit v1.2.3 From b42929975f7ac9729f795c416f922613c8ce3994 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 29 Jun 2018 16:04:16 +0200 Subject: Updates end-to-end tests to specify default visibility. --- test/libsolidity/SolidityEndToEndTest.cpp | 1574 ++++++++++++++--------------- 1 file changed, 787 insertions(+), 787 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 9622de8c..71c24796 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a * 7; } + function f(uint a) public returns(uint d) { return a * 7; } } )"; compileAndRun(sourceCode); @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(exp_operator) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return 2 ** a; } + function f(uint a) public returns(uint d) { return 2 ** a; } } )"; compileAndRun(sourceCode); @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(exp_operator_const) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { return 2 ** 3; } + function f() public returns(uint d) { return 2 ** 3; } } )"; compileAndRun(sourceCode); @@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed) { char const* sourceCode = R"( contract test { - function f() returns(int d) { return (-2) ** 3; } + function f() public returns(int d) { return (-2) ** 3; } } )"; compileAndRun(sourceCode); @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(exp_zero) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a ** 0; } + function f(uint a) public returns(uint d) { return a ** 0; } } )"; compileAndRun(sourceCode); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(exp_zero_literal) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { return 0 ** 0; } + function f() public returns(uint d) { return 0 ** 0; } } )"; compileAndRun(sourceCode); @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_true_literal) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { + function f() public returns(uint d) { return true ? 5 : 10; } } @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_false_literal) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { + function f() public returns(uint d) { return false ? 5 : 10; } } @@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_multiple) { char const* sourceCode = R"( contract test { - function f(uint x) returns(uint d) { + function f(uint x) public returns(uint d) { return x > 100 ? x > 1000 ? 1000 : 100 : @@ -193,7 +193,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_with_return_values) { char const* sourceCode = R"( contract test { - function f(bool cond, uint v) returns (uint a, uint b) { + function f(bool cond, uint v) public returns (uint a, uint b) { cond ? a = v : b = v; } } @@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory_1) char const* sourceCode = R"( contract test { bytes2[2] data1; - function f(bool cond) returns (uint) { + function f(bool cond) public returns (uint) { bytes2[2] memory x; x[0] = "aa"; bytes2[2] memory y; @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory_2) char const* sourceCode = R"( contract test { bytes2[2] data1; - function f(bool cond) returns (uint) { + function f(bool cond) public returns (uint) { data1[0] = "cc"; bytes2[2] memory x; @@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_different_types) { char const* sourceCode = R"( contract test { - function f(bool cond) returns (uint) { + function f(bool cond) public returns (uint) { uint8 x = 0xcd; uint16 y = 0xabab; return cond ? x : y; @@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_string_literal) { char const* sourceCode = R"( contract test { - function f(bool cond) returns (bytes32) { + function f(bool cond) public returns (bytes32) { return cond ? "true" : "false"; } } @@ -306,7 +306,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_tuples) { char const* sourceCode = R"( contract test { - function f(bool cond) returns (uint, uint) { + function f(bool cond) public returns (uint, uint) { return cond ? (1, 2) : (3, 4); } } @@ -320,10 +320,10 @@ BOOST_AUTO_TEST_CASE(conditional_expression_functions) { char const* sourceCode = R"( contract test { - function x() returns (uint) { return 1; } - function y() returns (uint) { return 2; } + function x() public returns (uint) { return 1; } + function y() public returns (uint) { return 2; } - function f(bool cond) returns (uint) { + function f(bool cond) public returns (uint) { function () returns (uint) z = cond ? x : y; return z(); } @@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(recursive_calls) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { if (n <= 1) return 1; else return n * f(n - 1); } @@ -408,10 +408,10 @@ BOOST_AUTO_TEST_CASE(multiple_functions) { char const* sourceCode = R"( contract test { - function a() returns(uint n) { return 0; } - function b() returns(uint n) { return 1; } - function c() returns(uint n) { return 2; } - function f() returns(uint n) { return 3; } + function a() public returns(uint n) { return 0; } + function b() public returns(uint n) { return 1; } + function c() public returns(uint n) { return 2; } + function f() public returns(uint n) { return 3; } } )"; compileAndRun(sourceCode); @@ -426,8 +426,8 @@ BOOST_AUTO_TEST_CASE(named_args) { char const* sourceCode = R"( contract test { - function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; } - function b() returns (uint r) { r = a({a: 1, b: 2, c: 3}); } + function a(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; } + function b() public returns (uint r) { r = a({a: 1, b: 2, c: 3}); } } )"; compileAndRun(sourceCode); @@ -438,8 +438,8 @@ BOOST_AUTO_TEST_CASE(disorder_named_args) { char const* sourceCode = R"( contract test { - function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; } - function b() returns (uint r) { r = a({c: 3, a: 1, b: 2}); } + function a(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; } + function b() public returns (uint r) { r = a({c: 3, a: 1, b: 2}); } } )"; compileAndRun(sourceCode); @@ -450,7 +450,7 @@ BOOST_AUTO_TEST_CASE(while_loop) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; uint i = 2; while (i <= n) nfac *= i++; @@ -477,7 +477,7 @@ BOOST_AUTO_TEST_CASE(do_while_loop) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; uint i = 2; do { nfac *= i++; } while (i <= n); @@ -528,7 +528,7 @@ BOOST_AUTO_TEST_CASE(nested_loops) // tests that break and continue statements in nested loops jump to the correct place char const* sourceCode = R"( contract test { - function f(uint x) returns(uint y) { + function f(uint x) public returns(uint y) { while (x > 1) { if (x == 10) break; while (x > 5) { @@ -578,7 +578,7 @@ BOOST_AUTO_TEST_CASE(for_loop) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; uint i; for (i = 2; i <= n; i++) @@ -603,7 +603,7 @@ BOOST_AUTO_TEST_CASE(for_loop_empty) { char const* sourceCode = R"( contract test { - function f() returns(uint ret) { + function f() public returns(uint ret) { ret = 1; for (;;) { ret += 1; @@ -632,7 +632,7 @@ BOOST_AUTO_TEST_CASE(for_loop_simple_init_expr) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; uint256 i; for (i = 2; i <= n; i++) @@ -658,7 +658,7 @@ BOOST_AUTO_TEST_CASE(for_loop_break_continue) { char const* sourceCode = R"( contract test { - function f(uint n) returns (uint r) + function f(uint n) public returns (uint r) { uint i = 1; uint k = 0; @@ -704,16 +704,16 @@ BOOST_AUTO_TEST_CASE(calling_other_functions) { char const* sourceCode = R"( contract collatz { - function run(uint x) returns(uint y) { + function run(uint x) public returns(uint y) { while ((y = x) > 1) { if (x % 2 == 0) x = evenStep(x); else x = oddStep(x); } } - function evenStep(uint x) returns(uint y) { + function evenStep(uint x) public returns(uint y) { return x / 2; } - function oddStep(uint x) returns(uint y) { + function oddStep(uint x) public returns(uint y) { return 3 * x + 1; } } @@ -754,7 +754,7 @@ BOOST_AUTO_TEST_CASE(many_local_variables) { char const* sourceCode = R"( contract test { - function run(uint x1, uint x2, uint x3) returns(uint y) { + function run(uint x1, uint x2, uint x3) public returns(uint y) { uint8 a = 0x1; uint8 b = 0x10; uint16 c = 0x100; y = a + b + c + x1 + x2 + x3; y += b + x2; @@ -777,7 +777,7 @@ BOOST_AUTO_TEST_CASE(packing_unpacking_types) { char const* sourceCode = R"( contract test { - function run(bool a, uint32 b, uint64 c) returns(uint256 y) { + function run(bool a, uint32 b, uint64 c) public returns(uint256 y) { if (a) y = 1; y = y * 0x100000000 | ~b; y = y * 0x10000000000000000 | ~c; @@ -795,7 +795,7 @@ BOOST_AUTO_TEST_CASE(packing_signed_types) { char const* sourceCode = R"( contract test { - function run() returns(int8 y) { + function run() public returns(int8 y) { uint8 x = 0xfa; return int8(x); } @@ -812,7 +812,7 @@ BOOST_AUTO_TEST_CASE(multiple_return_values) { char const* sourceCode = R"( contract test { - function run(bool x1, uint x2) returns(uint y1, bool y2, uint y3) { + function run(bool x1, uint x2) public returns(uint y1, bool y2, uint y3) { y1 = x2; y2 = x1; } } @@ -825,7 +825,7 @@ BOOST_AUTO_TEST_CASE(short_circuiting) { char const* sourceCode = R"( contract test { - function run(uint x) returns(uint y) { + function run(uint x) public returns(uint y) { x == 0 || ((x = 8) > 0); return x; } @@ -846,7 +846,7 @@ BOOST_AUTO_TEST_CASE(high_bits_cleaning) { char const* sourceCode = R"( contract test { - function run() returns(uint256 y) { + function run() public returns(uint256 y) { uint32 t = uint32(0xffffffff); uint32 x = t + 10; if (x >= 0xffffffff) return 0; @@ -870,7 +870,7 @@ BOOST_AUTO_TEST_CASE(sign_extension) { char const* sourceCode = R"( contract test { - function run() returns(uint256 y) { + function run() public returns(uint256 y) { int64 x = -int32(0xff); if (x >= 0xff) return 0; return -uint256(x); @@ -892,7 +892,7 @@ BOOST_AUTO_TEST_CASE(small_unsigned_types) { char const* sourceCode = R"( contract test { - function run() returns(uint256 y) { + function run() public returns(uint256 y) { uint32 t = uint32(0xffffff); uint32 x = t * 0xffffff; return x / 0x100; @@ -913,7 +913,7 @@ BOOST_AUTO_TEST_CASE(small_signed_types) { char const* sourceCode = R"( contract test { - function run() returns(int256 y) { + function run() public returns(int256 y) { return -int32(10) * -int64(20); } } @@ -930,10 +930,10 @@ BOOST_AUTO_TEST_CASE(strings) { char const* sourceCode = R"( contract test { - function fixedBytes() returns(bytes32 ret) { + function fixedBytes() public returns(bytes32 ret) { return "abc\x00\xff__"; } - function pipeThrough(bytes2 small, bool one) returns(bytes16 large, bool oneRet) { + function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) { oneRet = one; large = small; } @@ -950,7 +950,7 @@ BOOST_AUTO_TEST_CASE(inc_dec_operators) contract test { uint8 x; uint v; - function f() returns (uint r) { + function f() public returns (uint r) { uint a = 6; r = a; r += (a++) * 0x10; @@ -969,7 +969,7 @@ BOOST_AUTO_TEST_CASE(bytes_comparison) { char const* sourceCode = R"( contract test { - function f() returns (bool) { + function f() public returns (bool) { bytes2 a = "a"; bytes2 x = "aa"; bytes2 b = "b"; @@ -987,7 +987,7 @@ BOOST_AUTO_TEST_CASE(state_smoke_test) contract test { uint256 value1; uint256 value2; - function get(uint8 which) returns (uint256 value) { + function get(uint8 which) public returns (uint256 value) { if (which == 0) return value1; else return value2; } @@ -1014,7 +1014,7 @@ BOOST_AUTO_TEST_CASE(compound_assign) contract test { uint value1; uint value2; - function f(uint x, uint y) returns (uint w) { + function f(uint x, uint y) public returns (uint w) { uint value3 = y; value1 += x; value3 *= x; @@ -1050,7 +1050,7 @@ BOOST_AUTO_TEST_CASE(simple_mapping) char const* sourceCode = R"( contract test { mapping(uint8 => uint8) table; - function get(uint8 k) returns (uint8 v) { + function get(uint8 k) public returns (uint8 v) { return table[k]; } function set(uint8 k, uint8 v) { @@ -1084,13 +1084,13 @@ BOOST_AUTO_TEST_CASE(mapping_state) mapping(address => bool) canVote; mapping(address => uint) voteCount; mapping(address => bool) voted; - function getVoteCount(address addr) returns (uint retVoteCount) { + function getVoteCount(address addr) public returns (uint retVoteCount) { return voteCount[addr]; } function grantVoteRight(address addr) { canVote[addr] = true; } - function vote(address voter, address vote) returns (bool success) { + function vote(address voter, address vote) public returns (bool success) { if (!canVote[voter] || voted[voter]) return false; voted[voter] = true; voteCount[vote] = voteCount[vote] + 1; @@ -1160,7 +1160,7 @@ BOOST_AUTO_TEST_CASE(mapping_state_inc_dec) contract test { uint value; mapping(uint => uint) table; - function f(uint x) returns (uint y) { + function f(uint x) public returns (uint y) { value = x; if (x > 0) table[++value] = 8; if (x > 1) value--; @@ -1192,7 +1192,7 @@ BOOST_AUTO_TEST_CASE(multi_level_mapping) char const* sourceCode = R"( contract test { mapping(uint => mapping(uint => uint)) table; - function f(uint x, uint y, uint z) returns (uint w) { + function f(uint x, uint y, uint z) public returns (uint w) { if (z == 0) return table[x][y]; else return table[x][y] = z; } @@ -1230,7 +1230,7 @@ BOOST_AUTO_TEST_CASE(structs) mapping(uint8 => s2) recursive; } s2 data; - function check() returns (bool ok) { + function check() public returns (bool ok) { return data.z == 1 && data.s1data.x == 2 && data.s1data.y == true && data.recursive[3].recursive[4].z == 5 && @@ -1238,7 +1238,7 @@ BOOST_AUTO_TEST_CASE(structs) data.recursive[0].s1data.y == false && data.recursive[4].z == 9; } - function set() { + function set() public { data.z = 1; data.s1data.x = 2; data.s1data.y = true; @@ -1264,13 +1264,13 @@ BOOST_AUTO_TEST_CASE(struct_reference) mapping(uint8 => s2) recursive; } s2 data; - function check() returns (bool ok) { + function check() public returns (bool ok) { return data.z == 2 && data.recursive[0].z == 3 && data.recursive[0].recursive[1].z == 0 && data.recursive[0].recursive[0].z == 1; } - function set() { + function set() public { data.z = 2; mapping(uint8 => s2) map = data.recursive; s2 inner = map[0]; @@ -1312,19 +1312,19 @@ BOOST_AUTO_TEST_CASE(deleteStruct) delete str; delete toDelete; } - function getToDelete() returns (uint res){ + function getToDelete() public returns (uint res){ res = toDelete; } - function getTopValue() returns(uint topValue){ + function getTopValue() public returns(uint topValue){ topValue = str.topValue; } - function getNestedValue() returns(uint nestedValue){ + function getNestedValue() public returns(uint nestedValue){ nestedValue = str.nstr.nestedValue; } - function getTopMapping(uint index) returns(uint ret) { + function getTopMapping(uint index) public returns(uint ret) { ret = str.topMapping[index]; } - function getNestedMapping(uint index) returns(bool ret) { + function getNestedMapping(uint index) public returns(bool ret) { return str.nstr.nestedMapping[index]; } } @@ -1344,7 +1344,7 @@ BOOST_AUTO_TEST_CASE(deleteLocal) { char const* sourceCode = R"( contract test { - function delLocal() returns (uint res){ + function delLocal() public returns (uint res){ uint v = 5; delete v; res = v; @@ -1359,7 +1359,7 @@ BOOST_AUTO_TEST_CASE(deleteLocals) { char const* sourceCode = R"( contract test { - function delLocal() returns (uint res1, uint res2){ + function delLocal() public returns (uint res1, uint res2){ uint v = 5; uint w = 6; uint x = 7; @@ -1378,10 +1378,10 @@ BOOST_AUTO_TEST_CASE(constructor) char const* sourceCode = R"( contract test { mapping(uint => uint) data; - constructor() { + constructor() public { data[7] = 8; } - function get(uint key) returns (uint value) { + function get(uint key) public returns (uint value) { return data[key]; } } @@ -1402,7 +1402,7 @@ BOOST_AUTO_TEST_CASE(simple_accessor) char const* sourceCode = R"( contract test { uint256 public data; - constructor() { + constructor() public { data = 8; } } @@ -1421,7 +1421,7 @@ BOOST_AUTO_TEST_CASE(array_accessor) struct st { uint a; uint[] finalArray; } mapping(uint256 => mapping(uint256 => st[5])) public multiple_map; - constructor() { + constructor() public { data[0] = 8; dynamicData.length = 3; dynamicData[2] = 8; @@ -1451,7 +1451,7 @@ BOOST_AUTO_TEST_CASE(accessors_mapping_for_array) contract test { mapping(uint => uint[8]) public data; mapping(uint => uint[]) public dynamicData; - constructor() { + constructor() public { data[2][2] = 8; dynamicData[2].length = 3; dynamicData[2][2] = 8; @@ -1473,7 +1473,7 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) bytes6 public name; bytes32 public a_hash; address public an_address; - constructor() { + constructor() public { data = 8; name = "Celina"; a_hash = keccak256("\x7b"); @@ -1499,7 +1499,7 @@ BOOST_AUTO_TEST_CASE(complex_accessors) mapping(uint256 => bool) public to_bool_map; mapping(uint256 => uint256) public to_uint_map; mapping(uint256 => mapping(uint256 => uint256)) public to_multiple_map; - constructor() { + constructor() public { to_string_map[42] = "24"; to_bool_map[42] = false; to_uint_map[42] = 12; @@ -1520,7 +1520,7 @@ BOOST_AUTO_TEST_CASE(struct_accessor) contract test { struct Data { uint a; uint8 b; mapping(uint => uint) c; bool d; } mapping(uint => Data) public data; - constructor() { + constructor() public { data[7].a = 1; data[7].b = 2; data[7].c[0] = 3; @@ -1536,8 +1536,8 @@ BOOST_AUTO_TEST_CASE(balance) { char const* sourceCode = R"( contract test { - constructor() payable {} - function getBalance() returns (uint256 balance) { + constructor() public payable {} + function getBalance() public returns (uint256 balance) { return address(this).balance; } } @@ -1550,8 +1550,8 @@ BOOST_AUTO_TEST_CASE(blockchain) { char const* sourceCode = R"( contract test { - constructor() payable {} - function someInfo() payable returns (uint256 value, address coinbase, uint256 blockNumber) { + constructor() public payable {} + function someInfo() public payable returns (uint256 value, address coinbase, uint256 blockNumber) { value = msg.value; coinbase = block.coinbase; blockNumber = block.number; @@ -1568,7 +1568,7 @@ BOOST_AUTO_TEST_CASE(msg_sig) { char const* sourceCode = R"( contract test { - function foo(uint256 a) returns (bytes4 value) { + function foo(uint256 a) public returns (bytes4 value) { return msg.sig; } } @@ -1581,10 +1581,10 @@ BOOST_AUTO_TEST_CASE(msg_sig_after_internal_call_is_same) { char const* sourceCode = R"( contract test { - function boo() returns (bytes4 value) { + function boo() public returns (bytes4 value) { return msg.sig; } - function foo(uint256 a) returns (bytes4 value) { + function foo(uint256 a) public returns (bytes4 value) { return boo(); } } @@ -1597,7 +1597,7 @@ BOOST_AUTO_TEST_CASE(now) { char const* sourceCode = R"( contract test { - function someInfo() returns (bool equal, uint val) { + function someInfo() public returns (bool equal, uint val) { equal = block.timestamp == now; val = now; } @@ -1620,7 +1620,7 @@ BOOST_AUTO_TEST_CASE(type_conversions_cleanup) // integer should drop the first two bytes char const* sourceCode = R"( contract Test { - function test() returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); } + function test() public returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); } } )"; compileAndRun(sourceCode); @@ -1633,7 +1633,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_smaller_size) { char const* sourceCode = R"( contract Test { - function bytesToBytes(bytes4 input) returns (bytes2 ret) { + function bytesToBytes(bytes4 input) public returns (bytes2 ret) { return bytes2(input); } } @@ -1646,7 +1646,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_greater_size) { char const* sourceCode = R"( contract Test { - function bytesToBytes(bytes2 input) returns (bytes4 ret) { + function bytesToBytes(bytes2 input) public returns (bytes4 ret) { return bytes4(input); } } @@ -1659,7 +1659,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_same_size) { char const* sourceCode = R"( contract Test { - function bytesToBytes(bytes4 input) returns (bytes4 ret) { + function bytesToBytes(bytes4 input) public returns (bytes4 ret) { return bytes4(input); } } @@ -1673,7 +1673,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes32 s) returns (uint256 h) { + function bytesToUint(bytes32 s) public returns (uint256 h) { return uint(s); } } @@ -1689,7 +1689,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_min_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes1 s) returns (uint8 h) { + function bytesToUint(bytes1 s) public returns (uint8 h) { return uint8(s); } } @@ -1705,7 +1705,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) { + function bytesToUint(bytes4 s) public returns (uint16 h) { return uint16(uint32(s)); } } @@ -1721,7 +1721,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) { + function bytesToUint(bytes4 s) public returns (uint64 h) { return uint64(uint32(s)); } } @@ -1738,7 +1738,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_size) { char const* sourceCode = R"( contract Test { - function uintToBytes(uint256 h) returns (bytes32 s) { + function uintToBytes(uint256 h) public returns (bytes32 s) { return bytes32(h); } } @@ -1752,7 +1752,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_min_size) { char const* sourceCode = R"( contract Test { - function UintToBytes(uint8 h) returns (bytes1 s) { + function UintToBytes(uint8 h) public returns (bytes1 s) { return bytes1(h); } } @@ -1768,7 +1768,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) { + function uintToBytes(uint32 h) public returns (bytes2 s) { return bytes2(uint16(h)); } } @@ -1784,7 +1784,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) { + function UintToBytes(uint16 h) public returns (bytes8 s) { return bytes8(uint64(h)); } } @@ -1800,8 +1800,8 @@ BOOST_AUTO_TEST_CASE(send_ether) { char const* sourceCode = R"( contract test { - constructor() payable {} - function a(address addr, uint amount) returns (uint ret) { + constructor() payable public {} + function a(address addr, uint amount) public returns (uint ret) { addr.send(amount); return address(this).balance; } @@ -1818,8 +1818,8 @@ BOOST_AUTO_TEST_CASE(transfer_ether) { char const* sourceCode = R"( contract A { - constructor() payable {} - function a(address addr, uint amount) returns (uint) { + constructor() public payable {} + function a(address addr, uint amount) public returns (uint) { addr.transfer(amount); return this.balance; } @@ -1882,7 +1882,7 @@ BOOST_AUTO_TEST_CASE(log0) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log0(1); } } @@ -1899,7 +1899,7 @@ BOOST_AUTO_TEST_CASE(log1) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log1(1, 2); } } @@ -1917,7 +1917,7 @@ BOOST_AUTO_TEST_CASE(log2) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log2(1, 2, 3); } } @@ -1936,7 +1936,7 @@ BOOST_AUTO_TEST_CASE(log3) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log3(1, 2, 3, 4); } } @@ -1955,7 +1955,7 @@ BOOST_AUTO_TEST_CASE(log4) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log4(1, 2, 3, 4, 5); } } @@ -1974,7 +1974,7 @@ BOOST_AUTO_TEST_CASE(log_in_constructor) { char const* sourceCode = R"( contract test { - constructor() { + constructor() public { log1(1, 2); } } @@ -1991,8 +1991,8 @@ BOOST_AUTO_TEST_CASE(selfdestruct) { char const* sourceCode = R"( contract test { - constructor() payable {} - function a(address receiver) returns (uint ret) { + constructor() public payable {} + function a(address receiver) public returns (uint ret) { selfdestruct(receiver); return 10; } @@ -2010,7 +2010,7 @@ BOOST_AUTO_TEST_CASE(keccak256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { + function a(bytes32 input) public returns (bytes32 hash) { return keccak256(abi.encodePacked(input)); } } @@ -2029,7 +2029,7 @@ BOOST_AUTO_TEST_CASE(sha256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 sha256hash) { + function a(bytes32 input) public returns (bytes32 sha256hash) { return sha256(abi.encodePacked(input)); } } @@ -2054,7 +2054,7 @@ BOOST_AUTO_TEST_CASE(ripemd) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 sha256hash) { + function a(bytes32 input) public returns (bytes32 sha256hash) { return ripemd160(abi.encodePacked(input)); } } @@ -2079,7 +2079,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { + function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; return keccak256(abi.encodePacked(8, input, b, input, c)); @@ -2107,7 +2107,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types) char const* sourceCode = R"( contract test { uint120[3] x; - function f() returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) { + function f() public returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) { uint120[] memory y = new uint120[](3); x[0] = y[0] = uint120(-2); x[1] = y[1] = uint120(-3); @@ -2131,7 +2131,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { + function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; return sha256(abi.encodePacked(8, input, b, input, c)); @@ -2158,7 +2158,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { + function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; return ripemd160(abi.encodePacked(8, input, b, input, c)); @@ -2185,7 +2185,7 @@ BOOST_AUTO_TEST_CASE(ecrecover) { char const* sourceCode = R"( contract test { - function a(bytes32 h, uint8 v, bytes32 r, bytes32 s) returns (address addr) { + function a(bytes32 h, uint8 v, bytes32 r, bytes32 s) public returns (address addr) { return ecrecover(h, v, r, s); } } @@ -2203,16 +2203,16 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls) { char const* sourceCode = R"( contract Helper { - function multiply(uint a, uint b) returns (uint c) { + function multiply(uint a, uint b) public returns (uint c) { return a * b; } } contract Main { Helper h; - function callHelper(uint a, uint b) returns (uint c) { + function callHelper(uint a, uint b) public returns (uint c) { return h.multiply(a, b); } - function getHelper() returns (address haddress) { + function getHelper() public returns (address haddress) { return address(h); } function setHelper(address haddress) { @@ -2234,16 +2234,16 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_complex_parameters) { char const* sourceCode = R"( contract Helper { - function sel(uint a, bool select, uint b) returns (uint c) { + function sel(uint a, bool select, uint b) public returns (uint c) { if (select) return a; else return b; } } contract Main { Helper h; - function callHelper(uint a, bool select, uint b) returns (uint c) { + function callHelper(uint a, bool select, uint b) public returns (uint c) { return h.sel(a, select, b) * 3; } - function getHelper() returns (address haddress) { + function getHelper() public returns (address haddress) { return address(h); } function setHelper(address haddress) { @@ -2266,16 +2266,16 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_accessing_this) { char const* sourceCode = R"( contract Helper { - function getAddress() returns (address addr) { + function getAddress() public returns (address addr) { return address(this); } } contract Main { Helper h; - function callHelper() returns (address addr) { + function callHelper() public returns (address addr) { return h.getAddress(); } - function getHelper() returns (address addr) { + function getHelper() public returns (address addr) { return address(h); } function setHelper(address addr) { @@ -2295,19 +2295,19 @@ BOOST_AUTO_TEST_CASE(calls_to_this) { char const* sourceCode = R"( contract Helper { - function invoke(uint a, uint b) returns (uint c) { + function invoke(uint a, uint b) public returns (uint c) { return this.multiply(a, b, 10); } - function multiply(uint a, uint b, uint8 c) returns (uint ret) { + function multiply(uint a, uint b, uint8 c) public returns (uint ret) { return a * b + c; } } contract Main { Helper h; - function callHelper(uint a, uint b) returns (uint ret) { + function callHelper(uint a, uint b) public returns (uint ret) { return h.invoke(a, b); } - function getHelper() returns (address addr) { + function getHelper() public returns (address addr) { return address(h); } function setHelper(address addr) { @@ -2331,18 +2331,18 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) // so this tests correct stack slot allocation char const* sourceCode = R"( contract Helper { - function multiply(uint a, uint b) returns (uint c) { + function multiply(uint a, uint b) public returns (uint c) { return a * b; } } contract Main { Helper h; - function callHelper(uint a, uint b) returns (uint c) { + function callHelper(uint a, uint b) public returns (uint c) { uint8 y = 9; uint256 ret = h.multiply(a, b); return ret + y; } - function getHelper() returns (address haddress) { + function getHelper() public returns (address haddress) { return address(h); } function setHelper(address haddress) { @@ -2364,16 +2364,16 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_in_calls) { char const* sourceCode = R"( contract Helper { - function invoke(bytes3 x, bool stop) returns (bytes4 ret) { + function invoke(bytes3 x, bool stop) public returns (bytes4 ret) { return x; } } contract Main { Helper h; - function callHelper(bytes2 x, bool stop) returns (bytes5 ret) { + function callHelper(bytes2 x, bool stop) public returns (bytes5 ret) { return h.invoke(x, stop); } - function getHelper() returns (address addr) { + function getHelper() public returns (address addr) { return address(h); } function setHelper(address addr) { @@ -2396,20 +2396,20 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_internal) bytes3 name; bool flag; - constructor(bytes3 x, bool f) { + constructor(bytes3 x, bool f) public { name = x; flag = f; } - function getName() returns (bytes3 ret) { return name; } - function getFlag() returns (bool ret) { return flag; } + function getName() public returns (bytes3 ret) { return name; } + function getFlag() public returns (bool ret) { return flag; } } contract Main { Helper h; - constructor() { + constructor() public { h = new Helper("abc", true); } - function getFlag() returns (bool ret) { return h.getFlag(); } - function getName() returns (bytes3 ret) { return h.getName(); } + function getFlag() public returns (bool ret) { return h.getFlag(); } + function getName() public returns (bytes3 ret) { return h.getName(); } } )"; compileAndRun(sourceCode, 0, "Main"); @@ -2424,12 +2424,12 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_external) bytes3 name; bool flag; - constructor(bytes3 x, bool f) { + constructor(bytes3 x, bool f) public { name = x; flag = f; } - function getName() returns (bytes3 ret) { return name; } - function getFlag() returns (bool ret) { return flag; } + function getName() public returns (bytes3 ret) { return name; } + function getFlag() public returns (bool ret) { return flag; } } )"; compileAndRun(sourceCode, 0, "Main", encodeArgs("abc", true)); @@ -2444,7 +2444,7 @@ BOOST_AUTO_TEST_CASE(constructor_with_long_arguments) string public a; string public b; - constructor(string _a, string _b) { + constructor(string _a, string _b) public { a = _a; b = _b; } @@ -2472,7 +2472,7 @@ BOOST_AUTO_TEST_CASE(constructor_static_array_argument) uint public a; uint[3] public b; - constructor(uint _a, uint[3] _b) { + constructor(uint _a, uint[3] _b) public { a = _a; b = _b; } @@ -2492,7 +2492,7 @@ BOOST_AUTO_TEST_CASE(constant_var_as_array_length) uint constant LEN = 3; uint[LEN] public a; - constructor(uint[LEN] _a) { + constructor(uint[LEN] _a) public { a = _a; } } @@ -2509,10 +2509,10 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) contract Test { bytes3 name; bool flag; - constructor() { + constructor() public { setName("abc"); } - function getName() returns (bytes3 ret) { return name; } + function getName() public returns (bytes3 ret) { return name; } function setName(bytes3 _name) private { name = _name; } } )"; @@ -2528,8 +2528,8 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } contract test { helper h; - constructor() payable { h = new helper(); h.send(5); } - function getBalance() returns (uint256 myBalance, uint256 helperBalance) { + constructor() public payable { h = new helper(); h.send(5); } + function getBalance() public returns (uint256 myBalance, uint256 helperBalance) { myBalance = this.balance; helperBalance = h.balance; } @@ -2545,23 +2545,23 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic) char const* sourceCode = R"( contract helper { bool flag; - function getBalance() payable returns (uint256 myBalance) { + function getBalance() payable public returns (uint256 myBalance) { return this.balance; } - function setFlag() { flag = true; } - function getFlag() returns (bool fl) { return flag; } + function setFlag() public { flag = true; } + function getFlag() public returns (bool fl) { return flag; } } contract test { helper h; - constructor() payable { h = new helper(); } - function sendAmount(uint amount) payable returns (uint256 bal) { + constructor() public payable { h = new helper(); } + function sendAmount(uint amount) public payable returns (uint256 bal) { return h.getBalance.value(amount)(); } - function outOfGas() returns (bool ret) { + function outOfGas() public returns (bool ret) { h.setFlag.gas(2)(); // should fail due to OOG return true; } - function checkState() returns (bool flagAfter, uint myBal) { + function checkState() public returns (bool flagAfter, uint myBal) { flagAfter = h.getFlag(); myBal = this.balance; } @@ -2578,13 +2578,13 @@ BOOST_AUTO_TEST_CASE(value_complex) { char const* sourceCode = R"( contract helper { - function getBalance() payable returns (uint256 myBalance) { + function getBalance() payable public returns (uint256 myBalance) { return this.balance; } } contract test { helper h; - constructor() payable { h = new helper(); } + constructor() public payable { h = new helper(); } function sendAmount(uint amount) payable returns (uint256 bal) { uint someStackElement = 20; return h.getBalance.value(amount).gas(1000).value(amount + 3)(); @@ -2599,14 +2599,14 @@ BOOST_AUTO_TEST_CASE(value_insane) { char const* sourceCode = R"( contract helper { - function getBalance() payable returns (uint256 myBalance) { + function getBalance() payable public returns (uint256 myBalance) { return this.balance; } } contract test { helper h; - constructor() payable { h = new helper(); } - function sendAmount(uint amount) returns (uint256 bal) { + constructor() public payable { h = new helper(); } + function sendAmount(uint amount) public returns (uint256 bal) { return h.getBalance.value(amount).gas(1000).value(amount + 3)();// overwrite value } } @@ -2625,17 +2625,17 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) name = x; flag = f; } - function getName() returns (bytes3 ret) { return name; } - function getFlag() returns (bool ret) { return flag; } + function getName() public returns (bytes3 ret) { return name; } + function getFlag() public returns (bool ret) { return flag; } } contract Main { Helper h; constructor() payable { h = (new Helper).value(10)("abc", true); } - 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;} + function getFlag() public returns (bool ret) { return h.getFlag(); } + function getName() public returns (bytes3 ret) { return h.getName(); } + function getBalances() public returns (uint me, uint them) { me = this.balance; them = h.balance;} } )"; compileAndRun(sourceCode, 22, "Main"); @@ -2648,11 +2648,11 @@ BOOST_AUTO_TEST_CASE(virtual_function_calls) { char const* sourceCode = R"( contract Base { - function f() returns (uint i) { return g(); } - function g() returns (uint i) { return 1; } + function f() public returns (uint i) { return g(); } + function g() public returns (uint i) { return 1; } } contract Derived is Base { - function g() returns (uint i) { return 2; } + function g() public returns (uint i) { return 2; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2665,16 +2665,16 @@ BOOST_AUTO_TEST_CASE(access_base_storage) char const* sourceCode = R"( contract Base { uint dataBase; - function getViaBase() returns (uint i) { return dataBase; } + function getViaBase() public returns (uint i) { return dataBase; } } contract Derived is Base { uint dataDerived; - function setData(uint base, uint derived) returns (bool r) { + function setData(uint base, uint derived) public returns (bool r) { dataBase = base; dataDerived = derived; return true; } - function getViaDerived() returns (uint base, uint derived) { + function getViaDerived() public returns (uint base, uint derived) { base = dataBase; derived = dataDerived; } @@ -2692,10 +2692,10 @@ BOOST_AUTO_TEST_CASE(single_copy_with_multiple_inheritance) contract Base { uint data; function setData(uint i) { data = i; } - function getViaBase() returns (uint i) { return data; } + function getViaBase() public returns (uint i) { return data; } } contract A is Base { function setViaA(uint i) { setData(i); } } - contract B is Base { function getViaB() returns (uint i) { return getViaBase(); } } + contract B is Base { function getViaB() public returns (uint i) { return getViaBase(); } } contract Derived is Base, B, A { } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2707,11 +2707,11 @@ BOOST_AUTO_TEST_CASE(single_copy_with_multiple_inheritance) BOOST_AUTO_TEST_CASE(explicit_base_class) { char const* sourceCode = R"( - contract BaseBase { function g() returns (uint r) { return 1; } } - contract Base is BaseBase { function g() returns (uint r) { return 2; } } + contract BaseBase { function g() public returns (uint r) { return 1; } } + contract Base is BaseBase { function g() public returns (uint r) { return 2; } } contract Derived is Base { - function f() returns (uint r) { return BaseBase.g(); } - function g() returns (uint r) { return 3; } + function f() public returns (uint r) { return BaseBase.g(); } + function g() public returns (uint r) { return 3; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2724,17 +2724,17 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - constructor(uint a) { + constructor(uint a) public { m_a = a; } } contract Base is BaseBase(7) { - constructor() { + constructor() public { m_a *= m_a; } } - contract Derived is Base() { - function getA() returns (uint r) { return m_a; } + contract Derived is Base() public { + function getA() public returns (uint r) { return m_a; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2746,15 +2746,15 @@ BOOST_AUTO_TEST_CASE(function_usage_in_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - constructor(uint a) { + constructor(uint a) public { m_a = a; } - function g() returns (uint r) { return 2; } + function g() public returns (uint r) { return 2; } } contract Base is BaseBase(BaseBase.g()) { } - contract Derived is Base() { - function getA() returns (uint r) { return m_a; } + contract Derived is Base() public { + function getA() public returns (uint r) { return m_a; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2766,17 +2766,17 @@ BOOST_AUTO_TEST_CASE(virtual_function_usage_in_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - constructor(uint a) { + constructor(uint a) public { m_a = a; } - function overridden() returns (uint r) { return 1; } - function g() returns (uint r) { return overridden(); } + function overridden() public returns (uint r) { return 1; } + function g() public returns (uint r) { return overridden(); } } contract Base is BaseBase(BaseBase.g()) { } - contract Derived is Base() { - function getA() returns (uint r) { return m_a; } - function overridden() returns (uint r) { return 2; } + contract Derived is Base() public { + function getA() public returns (uint r) { return m_a; } + function overridden() public returns (uint r) { return 2; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2797,7 +2797,7 @@ BOOST_AUTO_TEST_CASE(function_modifier) { char const* sourceCode = R"( contract C { - function getOne() payable nonFree returns (uint r) { return 1; } + function getOne() payable nonFree public returns (uint r) { return 1; } modifier nonFree { if (msg.value > 0) _; } } )"; @@ -2812,7 +2812,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_local_variables) contract C { modifier mod1 { uint8 a = 1; uint8 b = 2; _; } modifier mod2(bool a) { if (a) return; else _; } - function f(bool a) mod1 mod2(a) returns (uint r) { return 3; } + function f(bool a) mod1 mod2(a) public returns (uint r) { return 3; } } )"; compileAndRun(sourceCode); @@ -2825,7 +2825,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_loop) char const* sourceCode = R"( contract C { modifier repeat(uint count) { uint i; for (i = 0; i < count; ++i) _; } - function f() repeat(10) returns (uint r) { r += 1; } + function f() repeat(10) public returns (uint r) { r += 1; } } )"; compileAndRun(sourceCode); @@ -2837,7 +2837,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multi_invocation) char const* sourceCode = R"( contract C { modifier repeat(bool twice) { if (twice) _; _; } - function f(bool twice) repeat(twice) returns (uint r) { r += 1; } + function f(bool twice) repeat(twice) public returns (uint r) { r += 1; } } )"; compileAndRun(sourceCode); @@ -2852,7 +2852,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multi_with_return) char const* sourceCode = R"( contract C { modifier repeat(bool twice) { if (twice) _; _; } - function f(bool twice) repeat(twice) returns (uint r) { r += 1; return r; } + function f(bool twice) repeat(twice) public returns (uint r) { r += 1; return r; } } )"; compileAndRun(sourceCode); @@ -2864,7 +2864,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_overriding) { char const* sourceCode = R"( contract A { - function f() mod returns (bool r) { return true; } + function f() mod public returns (bool r) { return true; } modifier mod { _; } } contract C is A { @@ -2880,18 +2880,18 @@ BOOST_AUTO_TEST_CASE(function_modifier_calling_functions_in_creation_context) char const* sourceCode = R"( contract A { uint data; - constructor() mod1 { f1(); } - function f1() mod2 { data |= 0x1; } - function f2() { data |= 0x20; } - function f3() { } + constructor() mod1 public { f1(); } + function f1() mod2 public { data |= 0x1; } + function f2() public { data |= 0x20; } + function f3() public { } modifier mod1 { f2(); _; } modifier mod2 { f3(); if (false) _; } - function getData() returns (uint r) { return data; } + function getData() public returns (uint r) { return data; } } contract C is A { modifier mod1 { f4(); _; } - function f3() { data |= 0x300; } - function f4() { data |= 0x4000; } + function f3() public { data |= 0x300; } + function f4() public { data |= 0x4000; } } )"; compileAndRun(sourceCode); @@ -2905,7 +2905,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_for_constructor) uint data; constructor() mod1 { data |= 2; } modifier mod1 { data |= 1; _; } - function getData() returns (uint r) { return data; } + function getData() public returns (uint r) { return data; } } contract C is A { modifier mod1 { data |= 4; _; } @@ -2921,7 +2921,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multiple_times) contract C { uint public a; modifier mod(uint x) { a += x; _; } - function f(uint x) mod(2) mod(5) mod(x) returns(uint) { return a; } + function f(uint x) mod(2) mod(5) mod(x) public returns(uint) { return a; } } )"; compileAndRun(sourceCode); @@ -2935,7 +2935,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multiple_times_local_vars) contract C { uint public a; modifier mod(uint x) { uint b = x; a += b; _; a -= b; assert(b == x); } - function f(uint x) mod(2) mod(5) mod(x) returns(uint) { return a; } + function f(uint x) mod(2) mod(5) mod(x) public returns(uint) { return a; } } )"; compileAndRun(sourceCode); @@ -2999,7 +2999,7 @@ BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack) { char const* sourceCode = R"( contract C { - function f() returns (uint r) { + function f() public returns (uint r) { uint; uint; uint; uint; int x = -7; return uint(x); @@ -3013,10 +3013,10 @@ BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack) BOOST_AUTO_TEST_CASE(super) { char const* sourceCode = R"( - contract A { function f() returns (uint r) { return 1; } } - contract B is A { function f() returns (uint r) { return super.f() | 2; } } - contract C is A { function f() returns (uint r) { return super.f() | 4; } } - contract D is B, C { function f() returns (uint r) { return super.f() | 8; } } + contract A { function f() public returns (uint r) { return 1; } } + contract B is A { function f() public returns (uint r) { return super.f() | 2; } } + contract C is A { function f() public returns (uint r) { return super.f() | 4; } } + contract D is B, C { function f() public returns (uint r) { return super.f() | 8; } } )"; compileAndRun(sourceCode, 0, "D"); ABI_CHECK(callContractFunction("f()"), encodeArgs(1 | 2 | 4 | 8)); @@ -3025,10 +3025,10 @@ BOOST_AUTO_TEST_CASE(super) BOOST_AUTO_TEST_CASE(super_in_constructor) { char const* sourceCode = R"( - contract A { function f() returns (uint r) { return 1; } } - contract B is A { function f() returns (uint r) { return super.f() | 2; } } - contract C is A { function f() returns (uint r) { return super.f() | 4; } } - contract D is B, C { uint data; constructor() { data = super.f() | 8; } function f() returns (uint r) { return data; } } + contract A { function f() public returns (uint r) { return 1; } } + contract B is A { function f() public returns (uint r) { return super.f() | 2; } } + contract C is A { function f() public returns (uint r) { return super.f() | 4; } } + contract D is B, C { uint data; function constructor() public { data = super.f() | 8; } function f() public returns (uint r) { return data; } } )"; compileAndRun(sourceCode, 0, "D"); ABI_CHECK(callContractFunction("f()"), encodeArgs(1 | 2 | 4 | 8)); @@ -3037,7 +3037,7 @@ BOOST_AUTO_TEST_CASE(super_in_constructor) BOOST_AUTO_TEST_CASE(super_alone) { char const* sourceCode = R"( - contract A { function f() { super; } } + contract A { function f() public { super; } } )"; compileAndRun(sourceCode, 0, "A"); ABI_CHECK(callContractFunction("f()"), encodeArgs()); @@ -3049,7 +3049,7 @@ BOOST_AUTO_TEST_CASE(fallback_function) contract A { uint data; function() external { data = 1; } - function getData() returns (uint r) { return data; } + function getData() public returns (uint r) { return data; } } )"; compileAndRun(sourceCode); @@ -3064,7 +3064,7 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) contract A { uint data; function() external { data = 1; } - function getData() returns (uint r) { return data; } + function getData() public returns (uint r) { return data; } } contract B is A {} )"; @@ -3078,7 +3078,7 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws) { char const* sourceCode = R"YY( contract A { - function f() returns (bool) { + function f() public returns (bool) { return this.call(""); } } @@ -3093,7 +3093,7 @@ BOOST_AUTO_TEST_CASE(short_data_calls_fallback) contract A { uint public x; // Signature is d88e0b00 - function fow() { x = 3; } + function fow() public { x = 3; } function () external { x = 2; } } )"; @@ -3167,7 +3167,7 @@ BOOST_AUTO_TEST_CASE(event_no_arguments) char const* sourceCode = R"( contract ClientReceipt { event Deposit(); - function deposit() { + function deposit() public { emit Deposit(); } } @@ -3189,7 +3189,7 @@ BOOST_AUTO_TEST_CASE(event_access_through_base_name_emit) event x(); } contract B is A { - function f() returns (uint) { + function f() public returns (uint) { emit A.x(); return 1; } @@ -3211,15 +3211,15 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) event Deposit(); event Deposit(address _addr); event Deposit(address _addr, uint _amount); - function deposit() returns (uint) { + function deposit() public returns (uint) { emit Deposit(); return 1; } - function deposit(address _addr) returns (uint) { + function deposit(address _addr) public returns (uint) { emit Deposit(_addr); return 1; } - function deposit(address _addr, uint _amount) returns (uint) { + function deposit(address _addr, uint _amount) public returns (uint) { emit Deposit(_addr, _amount); return 1; } @@ -3263,15 +3263,15 @@ BOOST_AUTO_TEST_CASE(events_with_same_name_inherited_emit) contract ClientReceipt is A, B { event Deposit(address _addr, uint _amount); - function deposit() returns (uint) { + function deposit() public returns (uint) { emit Deposit(); return 1; } - function deposit(address _addr) returns (uint) { + function deposit(address _addr) public returns (uint) { emit Deposit(_addr); return 1; } - function deposit(address _addr, uint _amount) returns (uint) { + function deposit(address _addr, uint _amount) public returns (uint) { emit Deposit(_addr, _amount); return 1; } @@ -3307,7 +3307,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous) char const* sourceCode = R"( contract ClientReceipt { event Deposit() anonymous; - function deposit() { + function deposit() public { emit Deposit(); } } @@ -3367,7 +3367,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data) char const* sourceCode = R"( contract ClientReceipt { event Deposit(uint fixeda, bytes dynx, uint fixedb); - function deposit() { + function deposit() public { emit Deposit(10, msg.data, 15); } } @@ -3387,7 +3387,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data_from_storage) contract ClientReceipt { bytes x; event Deposit(uint fixeda, bytes dynx, uint fixedb); - function deposit() { + function deposit() public { x.length = 3; x[0] = "A"; x[1] = "B"; @@ -3411,7 +3411,7 @@ BOOST_AUTO_TEST_CASE(event_really_really_lots_of_data_from_storage) contract ClientReceipt { bytes x; event Deposit(uint fixeda, bytes dynx, uint fixedb); - function deposit() { + function deposit() public { x.length = 31; x[0] = "A"; x[1] = "B"; @@ -3437,7 +3437,7 @@ BOOST_AUTO_TEST_CASE(event_indexed_string) string x; uint[4] y; event E(string indexed r, uint[4] indexed t); - function deposit() { + function deposit() public { bytes(x).length = 90; for (uint8 i = 0; i < 90; i++) bytes(x)[i] = byte(i); @@ -3469,7 +3469,7 @@ BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) { char const* sourceCode = R"( contract test { - function f(uint, uint k) returns(uint ret_k, uint ret_g){ + function f(uint, uint k) public returns(uint ret_k, uint ret_g){ uint g = 8; ret_k = k; ret_g = g; @@ -3485,7 +3485,7 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter) { char const* sourceCode = R"( contract test { - function f(uint k) returns(uint){ + function f(uint k) public returns(uint){ return k; } } @@ -3498,7 +3498,7 @@ BOOST_AUTO_TEST_CASE(sha256_empty) { char const* sourceCode = R"( contract C { - function f() returns (bytes32) { + function f() public returns (bytes32) { return sha256(""); } } @@ -3511,7 +3511,7 @@ BOOST_AUTO_TEST_CASE(ripemd160_empty) { char const* sourceCode = R"( contract C { - function f() returns (bytes20) { + function f() public returns (bytes20) { return ripemd160(""); } } @@ -3524,7 +3524,7 @@ BOOST_AUTO_TEST_CASE(keccak256_empty) { char const* sourceCode = R"( contract C { - function f() returns (bytes32) { + function f() public returns (bytes32) { return keccak256(""); } } @@ -3537,7 +3537,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments) { char const* sourceCode = R"( contract c { - function foo(uint a, uint b, uint c) returns (bytes32 d) + function foo(uint a, uint b, uint c) public returns (bytes32 d) { d = keccak256(abi.encodePacked(a, b, c)); } @@ -3558,7 +3558,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals) { char const* sourceCode = R"( contract c { - function foo(uint a, uint16 b) returns (bytes32 d) + function foo(uint a, uint16 b) public returns (bytes32 d) { d = keccak256(abi.encodePacked(a, b, 145)); } @@ -3579,11 +3579,11 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals) { char const* sourceCode = R"( contract c { - function foo() returns (bytes32 d) + function foo() public returns (bytes32 d) { d = keccak256("foo"); } - function bar(uint a, uint16 b) returns (bytes32 d) + function bar(uint a, uint16 b) public returns (bytes32 d) { d = keccak256(abi.encodePacked(a, b, 145, "foo")); } @@ -3608,7 +3608,7 @@ BOOST_AUTO_TEST_CASE(keccak256_with_bytes) char const* sourceCode = R"( contract c { bytes data; - function foo() returns (bool) + function foo() public returns (bool) { data.length = 3; data[0] = "f"; @@ -3627,7 +3627,7 @@ BOOST_AUTO_TEST_CASE(iterated_keccak256_with_bytes) char const* sourceCode = R"ABC( contract c { bytes data; - function foo() returns (bytes32) + function foo() public returns (bytes32) { data.length = 3; data[0] = "x"; @@ -3651,8 +3651,8 @@ BOOST_AUTO_TEST_CASE(generic_call) function receive(uint256 x) payable { received = x; } } contract sender { - constructor() payable {} - function doSend(address rec) returns (uint d) + constructor() public payable {} + function doSend(address rec) public returns (uint d) { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); rec.call.value(2)(abi.encodeWithSelector(signature, 23)); @@ -3711,10 +3711,10 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) BOOST_AUTO_TEST_CASE(library_call_in_homestead) { char const* sourceCode = R"( - library Lib { function m() returns (address) { return msg.sender; } } + library Lib { function m() public returns (address) { return msg.sender; } } contract Test { address public sender; - function f() { + function f() public { sender = Lib.m(); } } @@ -3763,7 +3763,7 @@ BOOST_AUTO_TEST_CASE(store_bytes) // this test just checks that the copy loop does not mess up the stack char const* sourceCode = R"( contract C { - function save() returns (uint r) { + function save() public returns (uint r) { r = 23; savedData = msg.data; r = 24; @@ -3781,7 +3781,7 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) { char const* sourceCode = R"( contract C { - function f() returns (bytes32) { + function f() public returns (bytes32) { return keccak256(abi.encodePacked("abc", msg.data)); } } @@ -3798,15 +3798,15 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) char const* sourceCode = R"( contract receiver { uint public received; - function receive(uint x) { received += x + 1; } + function receive(uint x) public { received += x + 1; } function() external { received = 0x80; } } contract sender { - constructor() { rec = new receiver(); } + constructor() public { rec = new receiver(); } function() external { savedData = msg.data; } - function forward() returns (bool) { !rec.call(savedData); return true; } - function clear() returns (bool) { delete savedData; return true; } - function val() returns (uint) { return rec.received(); } + function forward() public returns (bool) { !rec.call(savedData); return true; } + function clear() public returns (bool) { delete savedData; return true; } + function val() public returns (uint) { return rec.received(); } receiver rec; bytes savedData; } @@ -3831,18 +3831,18 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) } contract sender { receiver rec; - constructor() { rec = new receiver(); } - function viaCalldata() returns (uint) { + constructor() public { rec = new receiver(); } + function viaCalldata() public returns (uint) { require(rec.call(msg.data)); return rec.calledLength(); } - function viaMemory() returns (uint) { + function viaMemory() public returns (uint) { bytes memory x = msg.data; require(rec.call(x)); return rec.calledLength(); } bytes s; - function viaStorage() returns (uint) { + function viaStorage() public returns (uint) { s = msg.data; require(rec.call(s)); return rec.calledLength(); @@ -3872,14 +3872,14 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) function() external { received = 0x80; } } contract sender { - constructor() { rec = new receiver(); } + constructor() public { rec = new receiver(); } function() external { savedData1 = savedData2 = msg.data; } - function forward(bool selector) returns (bool) { + function forward(bool selector) public returns (bool) { if (selector) { rec.call(savedData1); delete savedData1; } else { rec.call(savedData2); delete savedData2; } return true; } - function val() returns (uint) { return rec.received(); } + function val() public returns (uint) { return rec.received(); } receiver rec; bytes savedData1; bytes savedData2; @@ -3901,7 +3901,7 @@ BOOST_AUTO_TEST_CASE(delete_removes_bytes_data) char const* sourceCode = R"( contract c { function() external { data = msg.data; } - function del() returns (bool) { delete data; return true; } + function del() public returns (bool) { delete data; return true; } bytes data; } )"; @@ -3916,7 +3916,7 @@ BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data) { char const* sourceCode = R"( contract c { - function set() returns (bool) { data = msg.data; return true; } + function set() public returns (bool) { data = msg.data; return true; } function() external { data = msg.data; } bytes data; } @@ -3934,8 +3934,8 @@ BOOST_AUTO_TEST_CASE(copy_removes_bytes_data) { char const* sourceCode = R"( contract c { - function set() returns (bool) { data1 = msg.data; return true; } - function reset() returns (bool) { data1 = data2; return true; } + function set() public returns (bool) { data1 = msg.data; return true; } + function reset() public returns (bool) { data1 = data2; return true; } bytes data1; bytes data2; } @@ -3951,8 +3951,8 @@ BOOST_AUTO_TEST_CASE(bytes_inside_mappings) { char const* sourceCode = R"( contract c { - function set(uint key) returns (bool) { data[key] = msg.data; return true; } - function copy(uint from, uint to) returns (bool) { data[to] = data[from]; return true; } + function set(uint key) public returns (bool) { data[key] = msg.data; return true; } + function copy(uint from, uint to) public returns (bool) { data[to] = data[from]; return true; } mapping(uint => bytes) data; } )"; @@ -3975,8 +3975,8 @@ BOOST_AUTO_TEST_CASE(bytes_length_member) { char const* sourceCode = R"( contract c { - function set() returns (bool) { data = msg.data; return true; } - function getLength() returns (uint) { return data.length; } + function set() public returns (bool) { data = msg.data; return true; } + function getLength() public returns (uint) { return data.length; } bytes data; } )"; @@ -3993,18 +3993,18 @@ BOOST_AUTO_TEST_CASE(struct_copy) struct Nested { uint x; uint y; } struct Struct { uint a; mapping(uint => Struct) b; Nested nested; uint c; } mapping(uint => Struct) data; - function set(uint k) returns (bool) { + function set(uint k) public returns (bool) { data[k].a = 1; data[k].nested.x = 3; data[k].nested.y = 4; data[k].c = 2; return true; } - function copy(uint from, uint to) returns (bool) { + function copy(uint from, uint to) public returns (bool) { data[to] = data[from]; return true; } - function retrieve(uint k) returns (uint a, uint x, uint y, uint c) + function retrieve(uint k) public returns (uint a, uint x, uint y, uint c) { a = data[k].a; x = data[k].nested.x; @@ -4039,11 +4039,11 @@ BOOST_AUTO_TEST_CASE(struct_containing_bytes_copy_and_delete) data1.data = _data; return true; } - function copy() returns (bool) { + function copy() public returns (bool) { data1 = data2; return true; } - function del() returns (bool) { + function del() public returns (bool) { delete data1; return true; } @@ -4069,7 +4069,7 @@ BOOST_AUTO_TEST_CASE(struct_copy_via_local) struct Struct { uint a; uint b; } Struct data1; Struct data2; - function test() returns (bool) { + function test() public returns (bool) { data1.a = 1; data1.b = 2; Struct memory x = data1; @@ -4091,7 +4091,7 @@ BOOST_AUTO_TEST_CASE(using_enums) { choices = ActionChoices.GoStraight; } - function getChoice() returns (uint d) + function getChoice() public returns (uint d) { d = uint256(choices); } @@ -4110,17 +4110,17 @@ BOOST_AUTO_TEST_CASE(enum_explicit_overflow) constructor() { } - function getChoiceExp(uint x) returns (uint d) + function getChoiceExp(uint x) public returns (uint d) { choice = ActionChoices(x); d = uint256(choice); } - function getChoiceFromSigned(int x) returns (uint d) + function getChoiceFromSigned(int x) public returns (uint d) { choice = ActionChoices(x); d = uint256(choice); } - function getChoiceFromNegativeLiteral() returns (uint d) + function getChoiceFromNegativeLiteral() public returns (uint d) { choice = ActionChoices(-1); d = uint256(choice); @@ -4144,7 +4144,7 @@ BOOST_AUTO_TEST_CASE(storing_invalid_boolean) contract C { event Ev(bool); bool public perm; - function set() returns(uint) { + function set() public returns(uint) { bool tmp; assembly { tmp := 5 @@ -4152,14 +4152,14 @@ BOOST_AUTO_TEST_CASE(storing_invalid_boolean) perm = tmp; return 1; } - function ret() returns(bool) { + function ret() public returns(bool) { bool tmp; assembly { tmp := 5 } return tmp; } - function ev() returns(uint) { + function ev() public returns(uint) { bool tmp; assembly { tmp := 5 @@ -4187,7 +4187,7 @@ BOOST_AUTO_TEST_CASE(using_contract_enums_with_explicit_contract_name) char const* sourceCode = R"( contract test { enum Choice { A, B, C } - function answer () returns (test.Choice _ret) + function answer () public returns (test.Choice _ret) { _ret = test.Choice.B; } @@ -4205,7 +4205,7 @@ BOOST_AUTO_TEST_CASE(using_inherited_enum) } contract test is base { - function answer () returns (Choice _ret) + function answer () public returns (Choice _ret) { _ret = Choice.B; } @@ -4223,7 +4223,7 @@ BOOST_AUTO_TEST_CASE(using_inherited_enum_excplicitly) } contract test is base { - function answer () returns (base.Choice _ret) + function answer () public returns (base.Choice _ret) { _ret = base.Choice.B; } @@ -4238,7 +4238,7 @@ BOOST_AUTO_TEST_CASE(constructing_enums_from_ints) char const* sourceCode = R"( contract c { enum Truth { False, True } - function test() returns (uint) + function test() public returns (uint) { return uint(Truth(uint8(0x701))); } @@ -4259,7 +4259,7 @@ BOOST_AUTO_TEST_CASE(inline_member_init) uint m_a = 5; uint m_b; uint m_c = 7; - function get() returns (uint a, uint b, uint c){ + function get() public returns (uint a, uint b, uint c){ a = m_a; b = m_b; c = m_c; @@ -4276,12 +4276,12 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence) contract Base { constructor(){} uint m_base = 5; - function getBMember() returns (uint i) { return m_base; } + function getBMember() public returns (uint i) { return m_base; } } contract Derived is Base { constructor(){} uint m_derived = 6; - function getDMember() returns (uint i) { return m_derived; } + function getDMember() public returns (uint i) { return m_derived; } } )"; compileAndRun(sourceCode); @@ -4294,11 +4294,11 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence_without_constructor) char const* sourceCode = R"( contract Base { uint m_base = 5; - function getBMember() returns (uint i) { return m_base; } + function getBMember() public returns (uint i) { return m_base; } } contract Derived is Base { uint m_derived = 6; - function getDMember() returns (uint i) { return m_derived; } + function getDMember() public returns (uint i) { return m_derived; } } )"; compileAndRun(sourceCode); @@ -4310,7 +4310,7 @@ BOOST_AUTO_TEST_CASE(external_function) { char const* sourceCode = R"( contract c { - function f(uint a) returns (uint) { return a; } + function f(uint a) public returns (uint) { return a; } function test(uint a, uint b) external returns (uint r_a, uint r_b) { r_a = f(a + 7); r_b = b; @@ -4362,9 +4362,9 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_in_storage) function setIDStatic(uint id) { ids[2] = id; } function setID(uint index, uint id) { ids[index] = id; } function setData(uint index, uint x, uint y) { data[index].x = x; data[index].y = y; } - function getID(uint index) returns (uint) { return ids[index]; } - function getData(uint index) returns (uint x, uint y) { x = data[index].x; y = data[index].y; } - function getLengths() returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } + function getID(uint index) public returns (uint) { return ids[index]; } + function getData(uint index) public returns (uint x, uint y) { x = data[index].x; y = data[index].y; } + function getLengths() public returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } } )"; compileAndRun(sourceCode); @@ -4389,9 +4389,9 @@ BOOST_AUTO_TEST_CASE(dynamic_arrays_in_storage) function setIDStatic(uint id) { ids[2] = id; } function setID(uint index, uint id) { ids[index] = id; } function setData(uint index, uint x, uint y) { data[index].x = x; data[index].y = y; } - function getID(uint index) returns (uint) { return ids[index]; } - function getData(uint index) returns (uint x, uint y) { x = data[index].x; y = data[index].y; } - function getLengths() returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } + function getID(uint index) public returns (uint) { return ids[index]; } + function getData(uint index) public returns (uint x, uint y) { x = data[index].x; y = data[index].y; } + function getLengths() public returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } function setLengths(uint l1, uint l2) { data.length = l1; ids.length = l2; } } )"; @@ -4414,9 +4414,9 @@ BOOST_AUTO_TEST_CASE(fixed_out_of_bounds_array_access) char const* sourceCode = R"( contract c { uint[4] data; - function set(uint index, uint value) returns (bool) { data[index] = value; return true; } - function get(uint index) returns (uint) { return data[index]; } - function length() returns (uint) { return data.length; } + function set(uint index, uint value) public returns (bool) { data[index] = value; return true; } + function get(uint index) public returns (uint) { return data[index]; } + function length() public returns (uint) { return data.length; } } )"; compileAndRun(sourceCode); @@ -4435,10 +4435,10 @@ BOOST_AUTO_TEST_CASE(dynamic_out_of_bounds_array_access) char const* sourceCode = R"( contract c { uint[] data; - function enlarge(uint amount) returns (uint) { return data.length += amount; } - function set(uint index, uint value) returns (bool) { data[index] = value; return true; } - function get(uint index) returns (uint) { return data[index]; } - function length() returns (uint) { return data.length; } + function enlarge(uint amount) public returns (uint) { return data.length += amount; } + function set(uint index, uint value) public returns (bool) { data[index] = value; return true; } + function get(uint index) public returns (uint) { return data[index]; } + function length() public returns (uint) { return data.length; } } )"; compileAndRun(sourceCode); @@ -4460,10 +4460,10 @@ BOOST_AUTO_TEST_CASE(fixed_array_cleanup) uint spacer1; uint spacer2; uint[20] data; - function fill() { + function fill() public { for (uint i = 0; i < data.length; ++i) data[i] = i+1; } - function clear() { delete data; } + function clear() public { delete data; } } )"; compileAndRun(sourceCode); @@ -4481,10 +4481,10 @@ BOOST_AUTO_TEST_CASE(short_fixed_array_cleanup) uint spacer1; uint spacer2; uint[3] data; - function fill() { + function fill() public { for (uint i = 0; i < data.length; ++i) data[i] = i+1; } - function clear() { delete data; } + function clear() public { delete data; } } )"; compileAndRun(sourceCode); @@ -4501,12 +4501,12 @@ BOOST_AUTO_TEST_CASE(dynamic_array_cleanup) contract c { uint[20] spacer; uint[] dynamic; - function fill() { + function fill() public { dynamic.length = 21; for (uint i = 0; i < dynamic.length; ++i) dynamic[i] = i+1; } - function halfClear() { dynamic.length = 5; } - function fullClear() { delete dynamic; } + function halfClear() public { dynamic.length = 5; } + function fullClear() public { delete dynamic; } } )"; compileAndRun(sourceCode); @@ -4525,14 +4525,14 @@ BOOST_AUTO_TEST_CASE(dynamic_multi_array_cleanup) contract c { struct s { uint[][] d; } s[] data; - function fill() returns (uint) { + function fill() public returns (uint) { data.length = 3; data[2].d.length = 4; data[2].d[3].length = 5; data[2].d[3][4] = 8; return data[2].d[3][4]; } - function clear() { delete data; } + function clear() public { delete data; } } )"; compileAndRun(sourceCode); @@ -4552,8 +4552,8 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_dyn_dyn) function setData1(uint length, uint index, uint value) { data1.length = length; if (index < length) data1[index] = value; } - function copyStorageStorage() { data2 = data1; } - function getData2(uint index) returns (uint len, uint val) { + function copyStorageStorage() public { data2 = data1; } + function getData2(uint index) public returns (uint len, uint val) { len = data2.length; if (index < len) val = data2[index]; } } @@ -4574,7 +4574,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_static_static) contract c { uint[40] data1; uint[20] data2; - function test() returns (uint x, uint y){ + function test() public returns (uint x, uint y){ data1[30] = 4; data1[2] = 7; data1[3] = 9; @@ -4595,7 +4595,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_static_dynamic) contract c { uint[9] data1; uint[] data2; - function test() returns (uint x, uint y){ + function test() public returns (uint x, uint y){ data1[8] = 4; data2 = data1; x = data2.length; @@ -4613,7 +4613,7 @@ BOOST_AUTO_TEST_CASE(array_copy_different_packing) contract c { bytes8[] data1; // 4 per slot bytes10[] data2; // 3 per slot - function test() returns (bytes10 a, bytes10 b, bytes10 c, bytes10 d, bytes10 e) { + function test() public 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(uint64(i)); @@ -4642,7 +4642,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_simple) contract c { bytes8[9] data1; // 4 per slot bytes17[10] data2; // 1 per slot, no offset counter - function test() returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) { + function test() public returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) { for (uint i = 0; i < data1.length; ++i) data1[i] = bytes8(uint64(i)); data2[8] = data2[9] = 2; @@ -4672,7 +4672,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover) contract c { byte[10] data1; bytes2[32] data2; - function test() returns (uint check, uint res1, uint res2) { + function test() public returns (uint check, uint res1, uint res2) { uint i; for (i = 0; i < data2.length; ++i) data2[i] = 0xffff; @@ -4703,7 +4703,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover2) contract c { bytes8[4] data1; // fits into one slot bytes10[6] data2; // 4 elements need two slots - function test() returns (bytes10 r1, bytes10 r2, bytes10 r3) { + function test() public returns (bytes10 r1, bytes10 r2, bytes10 r3) { data1[0] = 1; data1[1] = 2; data1[2] = 3; @@ -4732,7 +4732,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_struct) struct Data { uint x; uint y; } Data[] data1; Data[] data2; - function test() returns (uint x, uint y) { + function test() public returns (uint x, uint y) { data1.length = 9; data1[8].x = 4; data1[8].y = 5; @@ -4760,22 +4760,22 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi) uint16[] y; uint24[] z; uint24[][] w; - function test1() returns (uint8[]) { + function test1() public returns (uint8[]) { for (uint i = 0; i < 101; ++i) x.push(uint8(i)); return x; } - function test2() returns (uint16[]) { + function test2() public returns (uint16[]) { for (uint i = 0; i < 101; ++i) y.push(uint16(i)); return y; } - function test3() returns (uint24[]) { + function test3() public returns (uint24[]) { for (uint i = 0; i < 101; ++i) z.push(uint24(i)); return z; } - function test4() returns (uint24[][]) { + function test4() public returns (uint24[][]) { w.length = 5; for (uint i = 0; i < 5; ++i) for (uint j = 0; j < 101; ++j) @@ -4808,7 +4808,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi_signed) char const* sourceCode = R"( contract c { int16[] x; - function test() returns (int16[]) { + function test() public returns (int16[]) { x.push(int16(-1)); x.push(int16(-1)); x.push(int16(8)); @@ -4840,7 +4840,7 @@ BOOST_AUTO_TEST_CASE(array_push) char const* sourceCode = R"( contract c { uint[] data; - function test() returns (uint x, uint y, uint z, uint l) { + function test() public returns (uint x, uint y, uint z, uint l) { data.push(5); x = data[0]; data.push(4); @@ -4860,7 +4860,7 @@ BOOST_AUTO_TEST_CASE(array_push_struct) contract c { struct S { uint16 a; uint16 b; uint16[3] c; uint16[] d; } S[] data; - function test() returns (uint16, uint16, uint16, uint16) { + function test() public returns (uint16, uint16, uint16, uint16) { S memory s; s.a = 2; s.b = 3; @@ -4881,7 +4881,7 @@ BOOST_AUTO_TEST_CASE(array_push_packed_array) char const* sourceCode = R"( contract c { uint80[] x; - function test() returns (uint80, uint80, uint80, uint80) { + function test() public returns (uint80, uint80, uint80, uint80) { x.push(1); x.push(2); x.push(3); @@ -4901,7 +4901,7 @@ BOOST_AUTO_TEST_CASE(byte_array_push) char const* sourceCode = R"( contract c { bytes data; - function test() returns (bool x) { + function test() public returns (bool x) { if (data.push(5) != 1) return true; if (data[0] != 5) return true; data.push(4); @@ -4922,7 +4922,7 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) char const* sourceCode = R"( contract c { bytes data; - function test() returns (uint) { + function test() public returns (uint) { for (uint8 i = 1; i < 40; i++) { data.push(byte(i)); @@ -5352,7 +5352,7 @@ BOOST_AUTO_TEST_CASE(array_copy_calldata_storage) m_byte_data = b; return b[3][1]; // note that access and declaration are reversed to each other } - function retrieve() returns (uint a, uint b, uint c, uint d, uint e, uint f, uint g) { + function retrieve() public returns (uint a, uint b, uint c, uint d, uint e, uint f, uint g) { a = m_data.length; b = m_data[7]; c = m_data_dyn.length; @@ -5408,7 +5408,7 @@ BOOST_AUTO_TEST_CASE(array_copy_including_mapping) contract c { mapping(uint=>uint)[90][] large; mapping(uint=>uint)[3][] small; - function test() returns (uint r) { + function test() public returns (uint r) { large.length = small.length = 7; large[3][2][0] = 2; large[1] = large[3]; @@ -5422,7 +5422,7 @@ BOOST_AUTO_TEST_CASE(array_copy_including_mapping) delete small; delete large; } - function clear() returns (uint r) { + function clear() public returns (uint r) { large.length = small.length = 7; small[3][2][0] = 0; large[3][2][0] = 0; @@ -5451,11 +5451,11 @@ BOOST_AUTO_TEST_CASE(swap_in_storage_overwrite) struct S { uint a; uint b; } S public x; S public y; - function set() { + function set() public { x.a = 1; x.b = 2; y.a = 3; y.b = 4; } - function swap() { + function swap() public { (x, y) = (y, x); } } @@ -5496,17 +5496,17 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base) { char const* sourceCode = R"( contract Base { - constructor(uint j) + constructor(uint j) public { m_i = j; } uint public m_i; } contract Base1 is Base { - constructor(uint k) Base(k) {} + constructor(uint k) Base(k) public {} } contract Derived is Base, Base1 { - constructor(uint i) Base1(i) + constructor(uint i) Base1(i) public {} } contract Final is Derived(4) { @@ -5530,7 +5530,7 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) constructor(uint k) {} } contract Derived is Base, Base1 { - constructor(uint i) Base(i) Base1(7) {} + constructor(uint i) Base(i) Base1(7) public {} } contract Final is Derived(4) { } @@ -5543,7 +5543,7 @@ BOOST_AUTO_TEST_CASE(simple_constant_variables_test) { char const* sourceCode = R"( contract Foo { - function getX() returns (uint r) { return x; } + function getX() public returns (uint r) { return x; } uint constant x = 56; } )"; @@ -5569,7 +5569,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_expression) char const* sourceCode = R"( contract C { uint constant x = 0x123 + 0x456; - function f() returns (uint) { return x + 1; } + function f() public returns (uint) { return x + 1; } } )"; compileAndRun(sourceCode); @@ -5581,7 +5581,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) char const* sourceCode = R"( contract C { bytes32 constant x = keccak256("abc"); - function f() returns (bytes32) { return x; } + function f() public returns (bytes32) { return x; } } )"; compileAndRun(sourceCode); @@ -5595,7 +5595,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) // contract C { // uint[3] constant x = [uint(1), 2, 3]; // uint constant y = x[0] + x[1] + x[2]; -// function f() returns (uint) { return y; } +// function f() public returns (uint) { return y; } // } // )"; // compileAndRun(sourceCode); @@ -5609,7 +5609,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) // contract C { // struct S { uint x; uint[] y; } // S constant x = S(5, new uint[](4)); -// function f() returns (uint) { return x.x; } +// function f() public returns (uint) { return x.x; } // } // )"; // compileAndRun(sourceCode); @@ -5622,7 +5622,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_uint) contract C { struct str { uint8 a; uint16 b; uint248 c; } str data; - function test() returns (uint) { + function test() public returns (uint) { data.a = 2; if (data.a != 2) return 2; data.b = 0xabcd; @@ -5654,7 +5654,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_enum) enum larger { A, B, C, D, E} struct str { small a; small b; larger c; larger d; } str data; - function test() returns (uint) { + function test() public returns (uint) { data.a = small.B; if (data.a != small.B) return 2; data.b = small.C; @@ -5687,7 +5687,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_bytes) byte x; s2 data; byte y; - function test() returns (bool) { + function test() public returns (bool) { x = 1; data.a = 2; data.inner.a = 3; @@ -5716,7 +5716,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete) uint8 x; uint16 y; str data; - function test() returns (uint) { + function test() public returns (uint) { x = 1; y = 2; data.a = 2; @@ -5743,9 +5743,9 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_first) { char const* sourceCode = R"( contract test { - function f(uint k) returns(uint d) { return k; } - function f(uint a, uint b) returns(uint d) { return a + b; } - function g() returns(uint d) { return f(3); } + function f(uint k) public returns(uint d) { return k; } + function f(uint a, uint b) public returns(uint d) { return a + b; } + function g() public returns(uint d) { return f(3); } } )"; compileAndRun(sourceCode); @@ -5756,9 +5756,9 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_second) { char const* sourceCode = R"( contract test { - function f(uint a, uint b) returns(uint d) { return a + b; } - function f(uint k) returns(uint d) { return k; } - function g() returns(uint d) { return f(3, 7); } + function f(uint a, uint b) public returns(uint d) { return a + b; } + function f(uint k) public returns(uint d) { return k; } + function g() public returns(uint d) { return f(3, 7); } } )"; compileAndRun(sourceCode); @@ -5769,9 +5769,9 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_with_if_else) { char const* sourceCode = R"( contract test { - function f(uint a, uint b) returns(uint d) { return a + b; } - function f(uint k) returns(uint d) { return k; } - function g(bool flag) returns(uint d) { + function f(uint a, uint b) public returns(uint d) { return a + b; } + function f(uint k) public returns(uint d) { return k; } + function g(bool flag) public returns(uint d) { if (flag) return f(3); else @@ -5787,10 +5787,10 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_with_if_else) BOOST_AUTO_TEST_CASE(derived_overload_base_function_direct) { char const* sourceCode = R"( - contract B { function f() returns(uint) { return 10; } } + contract B { function f() public returns(uint) { return 10; } } contract C is B { - function f(uint i) returns(uint) { return 2 * i; } - function g() returns(uint) { return f(1); } + function f(uint i) public returns(uint) { return 2 * i; } + function g() public returns(uint) { return f(1); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5800,11 +5800,11 @@ BOOST_AUTO_TEST_CASE(derived_overload_base_function_direct) BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect) { char const* sourceCode = R"( - contract A { function f(uint a) returns(uint) { return 2 * a; } } - contract B { function f() returns(uint) { return 10; } } + contract A { function f(uint a) public returns(uint) { return 2 * a; } } + contract B { function f() public returns(uint) { return 10; } } contract C is A, B { - function g() returns(uint) { return f(); } - function h() returns(uint) { return f(1); } + function g() public returns(uint) { return f(); } + function h() public returns(uint) { return f(1); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5815,11 +5815,11 @@ BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect) BOOST_AUTO_TEST_CASE(super_overload) { char const* sourceCode = R"( - contract A { function f(uint a) returns(uint) { return 2 * a; } } - contract B { function f(bool b) returns(uint) { return 10; } } + contract A { function f(uint a) public returns(uint) { return 2 * a; } } + contract B { function f(bool b) public returns(uint) { return 10; } } contract C is A, B { - function g() returns(uint) { return super.f(true); } - function h() returns(uint) { return super.f(1); } + function g() public returns(uint) { return super.f(true); } + function h() public returns(uint) { return super.f(1); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5831,8 +5831,8 @@ BOOST_AUTO_TEST_CASE(gasleft_shadow_resolution) { char const* sourceCode = R"( contract C { - function gasleft() returns(uint256) { return 0; } - function f() returns(uint256) { return gasleft(); } + function gasleft() public returns(uint256) { return 0; } + function f() public returns(uint256) { return gasleft(); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5843,13 +5843,13 @@ BOOST_AUTO_TEST_CASE(bool_conversion) { char const* sourceCode = R"( contract C { - function f(bool _b) returns(uint) { + function f(bool _b) public returns(uint) { if (_b) return 1; else return 0; } - function g(bool _in) returns (bool _out) { + function g(bool _in) public returns (bool _out) { _out = _in; } } @@ -5875,7 +5875,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_signed) uint8 b; int8 c; uint8 d; - function test() returns (uint x1, uint x2, uint x3, uint x4) { + function test() public returns (uint x1, uint x2, uint x3, uint x4) { a = -2; b = -uint8(a) * 2; c = a * int8(120) * int8(121); @@ -5893,15 +5893,15 @@ BOOST_AUTO_TEST_CASE(packed_storage_signed) BOOST_AUTO_TEST_CASE(external_types_in_calls) { char const* sourceCode = R"( - contract C1 { C1 public bla; constructor(C1 x) { bla = x; } } + contract C1 { C1 public bla; constructor(C1 x) public { bla = x; } } contract C { - function test() returns (C1 x, C1 y) { + function test() public returns (C1 x, C1 y) { C1 c = new C1(C1(9)); x = c.bla(); y = this.t1(C1(7)); } - function t1(C1 a) returns (C1) { return a; } - function t2() returns (C1) { return C1(9); } + function t1(C1 a) public returns (C1) { return a; } + function t2() public returns (C1) { return C1(9); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5915,18 +5915,18 @@ BOOST_AUTO_TEST_CASE(invalid_enum_compared) contract C { enum X { A, B } - function test_eq() returns (bool) { + function test_eq() public returns (bool) { X garbled; assembly { garbled := 5 } return garbled == garbled; } - function test_eq_ok() returns (bool) { + function test_eq_ok() public returns (bool) { X garbled = X.A; return garbled == garbled; } - function test_neq() returns (bool) { + function test_neq() public returns (bool) { X garbled; assembly { garbled := 5 @@ -5949,7 +5949,7 @@ BOOST_AUTO_TEST_CASE(invalid_enum_logged) enum X { A, B } event Log(X); - function test_log() returns (uint) { + function test_log() public returns (uint) { X garbled = X.A; assembly { garbled := 5 @@ -5957,7 +5957,7 @@ BOOST_AUTO_TEST_CASE(invalid_enum_logged) emit Log(garbled); return 1; } - function test_log_ok() returns (uint) { + function test_log_ok() public returns (uint) { X x = X.A; emit Log(x); return 1; @@ -5983,7 +5983,7 @@ BOOST_AUTO_TEST_CASE(invalid_enum_stored) enum X { A, B } X public x; - function test_store() returns (uint) { + function test_store() public returns (uint) { X garbled = X.A; assembly { garbled := 5 @@ -5991,7 +5991,7 @@ BOOST_AUTO_TEST_CASE(invalid_enum_stored) x = garbled; return 1; } - function test_store_ok() returns (uint) { + function test_store_ok() public returns (uint) { x = X.A; return 1; } @@ -6011,19 +6011,19 @@ BOOST_AUTO_TEST_CASE(invalid_enum_as_external_ret) contract C { enum X { A, B } - function test_return() returns (X) { + function test_return() public returns (X) { X garbled; assembly { garbled := 5 } return garbled; } - function test_inline_assignment() returns (X _ret) { + function test_inline_assignment() public returns (X _ret) { assembly { _ret := 5 } } - function test_assignment() returns (X _ret) { + function test_assignment() public returns (X _ret) { X tmp; assembly { tmp := 5 @@ -6045,11 +6045,11 @@ BOOST_AUTO_TEST_CASE(invalid_enum_as_external_arg) contract C { enum X { A, B } - function tested (X x) returns (uint) { + function tested (X x) public returns (uint) { return 1; } - function test() returns (uint) { + function test() public returns (uint) { X garbled; assembly { @@ -6071,19 +6071,19 @@ BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes) // bug #1798 char const* sourceCode = R"( contract init { - function isOk() returns (bool) { return false; } + function isOk() public returns (bool) { return false; } bool public ok = false; } contract fix { - function isOk() returns (bool) { return true; } + function isOk() public returns (bool) { return true; } bool public ok = true; } contract init_fix is init, fix { - function checkOk() returns (bool) { return ok; } + function checkOk() public returns (bool) { return ok; } } contract fix_init is fix, init { - function checkOk() returns (bool) { return ok; } + function checkOk() public returns (bool) { return ok; } } )"; compileAndRun(sourceCode, 0, "init_fix"); @@ -6110,7 +6110,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) { data1.m_value = 2; } - function assign() returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) + function assign() public returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) { testStruct x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2 data2 = data1; // should copy data. data2.m_value == 2 @@ -6142,7 +6142,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) { data1.m_value = 2; } - function deleteMember() returns (uint ret_value) + function deleteMember() public returns (uint ret_value) { testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 x.m_value = 4; @@ -6169,7 +6169,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) { campaigns[0].m_value = 2; } - function deleteIt() returns (uint) + function deleteIt() public returns (uint) { delete campaigns[0]; return campaigns[0].m_value; @@ -6186,11 +6186,11 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_out_of_band_access) contract A { uint[3] arr; bool public test = false; - function getElement(uint i) returns (uint) + function getElement(uint i) public returns (uint) { return arr[i]; } - function testIt() returns (bool) + function testIt() public returns (bool) { uint i = this.getElement(5); test = true; @@ -6271,8 +6271,8 @@ BOOST_AUTO_TEST_CASE(failing_send) } } contract Main { - constructor() payable {} - function callHelper(address _a) returns (bool r, uint bal) { + constructor() public payable {} + function callHelper(address _a) public returns (bool r, uint bal) { r = !_a.send(5); bal = this.balance; } @@ -6294,8 +6294,8 @@ BOOST_AUTO_TEST_CASE(send_zero_ether) } } contract Main { - constructor() payable {} - function s() returns (bool) { + constructor() public payable {} + function s() public returns (bool) { Receiver r = new Receiver(); return r.send(0); } @@ -6311,17 +6311,17 @@ BOOST_AUTO_TEST_CASE(reusing_memory) char const* sourceCode = R"( contract Helper { uint public flag; - constructor(uint x) { + constructor(uint x) public { flag = x; } } contract Main { mapping(uint => uint) map; - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { map[x] = x; return (new Helper(uint(keccak256(abi.encodePacked(this.g(map[x])))))).flag(); } - function g(uint a) returns (uint) + function g(uint a) public returns (uint) { return map[a]; } @@ -6339,10 +6339,10 @@ BOOST_AUTO_TEST_CASE(return_string) function set(string _s) external { s = _s; } - function get1() returns (string r) { + function get1() public returns (string r) { return s; } - function get2() returns (string r) { + function get2() public returns (string r) { r = s; } } @@ -6367,7 +6367,7 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) s2 = _s2; return x; } - function get() returns (string r1, string r2) { + function get() public returns (string r1, string r2) { r1 = s1; r2 = s2; } @@ -6440,12 +6440,12 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) contract Main { string public s1; string public s2; - function set(string _s1, uint x, string _s2) returns (uint) { + function set(string _s1, uint x, string _s2) public returns (uint) { s1 = _s1; s2 = _s2; return x; } - function setIndirectFromMemory(string _s1, uint x, string _s2) returns (uint) { + function setIndirectFromMemory(string _s1, uint x, string _s2) public returns (uint) { return this.set(_s1, x, _s2); } function setIndirectFromCalldata(string _s1, uint x, string _s2) external returns (uint) { @@ -6485,7 +6485,7 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) char const* sourceCode = R"( contract Main { bytes s1; - function doSet(bytes _s1) returns (bytes _r1) { + function doSet(bytes _s1) public returns (bytes _r1) { s1 = _s1; _r1 = s1; } @@ -6513,15 +6513,15 @@ BOOST_AUTO_TEST_CASE(bytes_index_access_memory) { char const* sourceCode = R"( contract Main { - function f(bytes _s1, uint i1, uint i2, uint i3) returns (byte c1, byte c2, byte c3) { + function f(bytes _s1, uint i1, uint i2, uint i3) public returns (byte c1, byte c2, byte c3) { c1 = _s1[i1]; c2 = intern(_s1, i2); c3 = internIndirect(_s1)[i3]; } - function intern(bytes _s1, uint i) returns (byte c) { + function intern(bytes _s1, uint i) public returns (byte c) { return _s1[i]; } - function internIndirect(bytes _s1) returns (bytes) { + function internIndirect(bytes _s1) public returns (bytes) { return _s1; } } @@ -6542,7 +6542,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_unpacker) contract Test { uint public m_x; bytes public m_s; - constructor(uint x, bytes s) { + constructor(uint x, bytes s) public { m_x = x; m_s = s; } @@ -6563,22 +6563,22 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) contract Base { uint public m_x; bytes m_s; - constructor(uint x, bytes s) { + constructor(uint x, bytes s) public { m_x = x; m_s = s; } - function part(uint i) returns (byte) { + function part(uint i) public returns (byte) { return m_s[i]; } } contract Main is Base { - constructor(bytes s, uint x) Base(x, f(s)) {} - function f(bytes s) returns (bytes) { + constructor(bytes s, uint x) Base(x, f(s)) public {} + function f(bytes s) public returns (bytes) { return s; } } contract Creator { - function f(uint x, bytes s) returns (uint r, byte ch) { + function f(uint x, bytes s) public returns (uint r, byte ch) { Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); @@ -6602,22 +6602,22 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors) contract Base { uint public m_x; address[] m_s; - constructor(uint x, address[] s) { + constructor(uint x, address[] s) public { m_x = x; m_s = s; } - function part(uint i) returns (address) { + function part(uint i) public returns (address) { return m_s[i]; } } contract Main is Base { - constructor(address[] s, uint x) Base(x, f(s)) {} - function f(address[] s) returns (address[]) { + constructor(address[] s, uint x) Base(x, f(s)) public {} + function f(address[] s) public returns (address[]) { return s; } } contract Creator { - function f(uint x, address[] s) returns (uint r, address ch) { + function f(uint x, address[] s) public returns (uint r, address ch) { Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); @@ -6641,7 +6641,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_in_constructors) contract Creator { uint public r; address public ch; - constructor(address[3] s, uint x) { + constructor(address[3] s, uint x) public { r = x; ch = s[2]; } @@ -6657,11 +6657,11 @@ BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage) char const* sourceCode = R"( contract Test { uint24[] public data; - function set(uint24[] _data) returns (uint) { + function set(uint24[] _data) public returns (uint) { data = _data; return data.length; } - function get() returns (uint24[]) { + function get() public returns (uint24[]) { return data; } } @@ -6684,11 +6684,11 @@ BOOST_AUTO_TEST_CASE(arrays_complex_from_and_to_storage) char const* sourceCode = R"( contract Test { uint24[3][] public data; - function set(uint24[3][] _data) returns (uint) { + function set(uint24[3][] _data) public returns (uint) { data = _data; return data.length; } - function get() returns (uint24[3][]) { + function get() public returns (uint24[3][]) { return data; } } @@ -6710,7 +6710,7 @@ BOOST_AUTO_TEST_CASE(arrays_complex_memory_index_access) { char const* sourceCode = R"( contract Test { - function set(uint24[3][] _data, uint a, uint b) returns (uint l, uint e) { + function set(uint24[3][] _data, uint a, uint b) public returns (uint l, uint e) { l = _data.length; e = _data[a][b]; } @@ -6733,7 +6733,7 @@ BOOST_AUTO_TEST_CASE(bytes_memory_index_access) { char const* sourceCode = R"( contract Test { - function set(bytes _data, uint i) returns (uint l, byte c) { + function set(bytes _data, uint i) public returns (uint l, byte c) { l = _data.length; c = _data[i]; } @@ -6780,7 +6780,7 @@ BOOST_AUTO_TEST_CASE(storage_array_ref) data.length++; data[data.length - 1] = v; } - function find(uint v) returns (uint) { + function find(uint v) public returns (uint) { return find(data, v); } } @@ -6809,13 +6809,13 @@ BOOST_AUTO_TEST_CASE(memory_types_initialisation) char const* sourceCode = R"( contract Test { mapping(uint=>uint) data; - function stat() returns (uint[5]) + function stat() public returns (uint[5]) { data[2] = 3; // make sure to use some memory } - function dyn() returns (uint[]) { stat(); } - function nested() returns (uint[3][]) { stat(); } - function nestedStat() returns (uint[3][7]) { stat(); } + function dyn() public returns (uint[]) { stat(); } + function nested() public returns (uint[3][]) { stat(); } + function nestedStat() public returns (uint[3][7]) { stat(); } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -6830,7 +6830,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_delete) { char const* sourceCode = R"( contract Test { - function del() returns (uint24[3][4]) { + function del() public returns (uint24[3][4]) { uint24[3][4] memory x; for (uint24 i = 0; i < x.length; i ++) for (uint24 j = 0; j < x[i].length; j ++) @@ -6863,7 +6863,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write) x[2][2] = 1; x[3][2] = 7; } - function f() returns (uint24[3][4]){ + function f() public returns (uint24[3][4]){ uint24[3][4] memory data; set(data); return data; @@ -6888,7 +6888,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_dynamic_index_access_write) x[1][3][2] = 7; return x; } - function f() returns (uint24[3][]) { + function f() public returns (uint24[3][]) { data[1].length = 4; return set(data)[1]; } @@ -6908,7 +6908,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_read_write) contract Test { struct S { uint8 x; uint16 y; uint z; uint8[2] a; } S[5] data; - function testInit() returns (uint8 x, uint16 y, uint z, uint8 a, bool flag) { + function testInit() public returns (uint8 x, uint16 y, uint z, uint8 a, bool flag) { S[2] memory d; x = d[0].x; y = d[0].y; @@ -6916,7 +6916,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_read_write) a = d[0].a[1]; flag = true; } - function testCopyRead() returns (uint8 x, uint16 y, uint z, uint8 a) { + function testCopyRead() public returns (uint8 x, uint16 y, uint z, uint8 a) { data[2].x = 1; data[2].y = 2; data[2].z = 3; @@ -6927,7 +6927,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_read_write) z = s.z; a = s.a[1]; } - function testAssign() returns (uint8 x, uint16 y, uint z, uint8 a) { + function testAssign() public returns (uint8 x, uint16 y, uint z, uint8 a) { S memory s; s.x = 1; s.y = 2; @@ -6952,7 +6952,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_as_function_args) char const* sourceCode = R"( contract Test { struct S { uint8 x; uint16 y; uint z; } - function test() returns (uint x, uint y, uint z) { + function test() public returns (uint x, uint y, uint z) { S memory data = combine(1, 2, 3); x = extract(data, 0); y = extract(data, 1); @@ -6981,7 +6981,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_nested) contract Test { struct S { uint8 x; uint16 y; uint z; } struct X { uint8 x; S s; } - function test() returns (uint a, uint x, uint y, uint z) { + function test() public returns (uint a, uint x, uint y, uint z) { X memory d = combine(1, 2, 3, 4); a = extract(d, 0); x = extract(d, 1); @@ -7014,7 +7014,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_nested_load) struct S { uint8 x; uint16 y; uint z; } struct X { uint8 x; S s; uint8[2] a; } X m_x; - function load() returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { + function load() public returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { m_x.x = 1; m_x.s.x = 2; m_x.s.y = 3; @@ -7029,7 +7029,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_nested_load) a1 = d.a[0]; a2 = d.a[1]; } - function store() returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { + function store() public returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { X memory d; d.x = 1; d.s.x = 2; @@ -7061,12 +7061,12 @@ BOOST_AUTO_TEST_CASE(struct_constructor_nested) struct X { uint x1; uint x2; } struct S { uint s1; uint[3] s2; X s3; } S s; - constructor() { + constructor() public { uint[3] memory s2; s2[1] = 9; s = S(1, s2, X(4, 5)); } - function get() returns (uint s1, uint[3] s2, uint x1, uint x2) + function get() public returns (uint s1, uint[3] s2, uint x1, uint x2) { s1 = s.s1; s2 = s.s2; @@ -7087,7 +7087,7 @@ BOOST_AUTO_TEST_CASE(struct_named_constructor) contract C { struct S { uint a; bool x; } S public s; - constructor() { + constructor() public { s = S({a: 1, x: true}); } } @@ -7105,7 +7105,7 @@ BOOST_AUTO_TEST_CASE(literal_strings) string public medium; string public short; string public empty; - function f() returns (string) { + function f() public returns (string) { long = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; medium = "01234567890123456789012345678901234567890123456789012345678901234567890123456789"; short = "123"; @@ -7149,7 +7149,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_with_mappings) contract Test { struct S { uint8 a; mapping(uint => uint) b; uint8 c; } S s; - function f() returns (uint) { + function f() public returns (uint) { S memory x; if (x.a != 0 || x.c != 0) return 1; x.a = 4; x.c = 5; @@ -7172,12 +7172,12 @@ BOOST_AUTO_TEST_CASE(string_bytes_conversion) contract Test { string s; bytes b; - function f(string _s, uint n) returns (byte) { + function f(string _s, uint n) public returns (byte) { b = bytes(_s); s = string(b); return bytes(s)[n]; } - function l() returns (uint) { return bytes(s).length; } + function l() public returns (uint) { return bytes(s).length; } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -7197,7 +7197,7 @@ BOOST_AUTO_TEST_CASE(string_as_mapping_key) contract Test { mapping(string => uint) data; function set(string _s, uint _v) { data[_s] = _v; } - function get(string _s) returns (uint) { return data[_s]; } + function get(string _s) public returns (uint) { return data[_s]; } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -7254,7 +7254,7 @@ BOOST_AUTO_TEST_CASE(state_variable_under_contract_name) contract Scope { uint stateVar = 42; - function getStateVar() view returns (uint stateVar) { + function getStateVar() public view returns (uint stateVar) { stateVar = Scope.stateVar; } } @@ -7269,7 +7269,7 @@ BOOST_AUTO_TEST_CASE(state_variable_local_variable_mixture) contract A { uint x = 1; uint y = 2; - function a() returns (uint x) { + function a() public returns (uint x) { x = A.y; } } @@ -7284,7 +7284,7 @@ BOOST_AUTO_TEST_CASE(inherited_function) { contract A { function f() internal returns (uint) { return 1; } } contract B is A { function f() internal returns (uint) { return 2; } - function g() returns (uint) { + function g() public returns (uint) { return A.f(); } } @@ -7299,7 +7299,7 @@ BOOST_AUTO_TEST_CASE(inherited_function_from_a_library) { library A { function f() internal returns (uint) { return 1; } } contract B { function f() internal returns (uint) { return 2; } - function g() returns (uint) { + function g() public returns (uint) { return A.f(); } } @@ -7316,7 +7316,7 @@ BOOST_AUTO_TEST_CASE(inherited_constant_state_var) uint constant x = 7; } contract B is A { - function f() returns (uint) { + function f() public returns (uint) { return A.x; } } @@ -7336,17 +7336,17 @@ BOOST_AUTO_TEST_CASE(multiple_inherited_state_vars) uint x = 9; } contract C is A, B { - function a() returns (uint) { + function a() public returns (uint) { return A.x; } - function b() returns (uint) { + function b() public returns (uint) { return B.x; } - function a_set(uint _x) returns (uint) { + function a_set(uint _x) public returns (uint) { A.x = _x; return 1; } - function b_set(uint _x) returns (uint) { + function b_set(uint _x) public returns (uint) { B.x = _x; return 1; } @@ -7369,14 +7369,14 @@ BOOST_AUTO_TEST_CASE(constant_string_literal) bytes32 constant public b = "abcdefghijklmnopq"; string constant public x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca"; - constructor() { + constructor() public { string memory xx = x; bytes32 bb = b; } - function getB() returns (bytes32) { return b; } - function getX() returns (string) { return x; } - function getX2() returns (string r) { r = x; } - function unused() returns (uint) { + function getB() public returns (bytes32) { return b; } + function getX() public returns (string) { return x; } + function getX2() public returns (string r) { r = x; } + function unused() public returns (uint) { "unusedunusedunusedunusedunusedunusedunusedunusedunusedunusedunusedunused"; return 2; } @@ -7399,7 +7399,7 @@ BOOST_AUTO_TEST_CASE(storage_string_as_mapping_key_without_variable) char const* sourceCode = R"( contract Test { mapping(string => uint) data; - function f() returns (uint) { + function f() public returns (uint) { data["abc"] = 2; return data["abc"]; } @@ -7412,9 +7412,9 @@ BOOST_AUTO_TEST_CASE(storage_string_as_mapping_key_without_variable) BOOST_AUTO_TEST_CASE(library_call) { char const* sourceCode = R"( - library Lib { function m(uint x, uint y) returns (uint) { return x * y; } } + library Lib { function m(uint x, uint y) public returns (uint) { return x * y; } } contract Test { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { return Lib.m(x, 9); } } @@ -7442,9 +7442,9 @@ BOOST_AUTO_TEST_CASE(library_function_external) BOOST_AUTO_TEST_CASE(library_stray_values) { char const* sourceCode = R"( - library Lib { function m(uint x, uint y) returns (uint) { return x * y; } } + library Lib { function m(uint x, uint y) public returns (uint) { return x * y; } } contract Test { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { Lib; Lib.m; return x + 9; @@ -7461,7 +7461,7 @@ BOOST_AUTO_TEST_CASE(cross_contract_types) char const* sourceCode = R"( contract Lib { struct S {uint a; uint b; } } contract Test { - function f() returns (uint r) { + function f() public returns (uint r) { Lib.S memory x = Lib.S({a: 2, b: 3}); r = x.b; } @@ -7475,7 +7475,7 @@ BOOST_AUTO_TEST_CASE(simple_throw) { char const* sourceCode = R"( contract Test { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { if (x > 10) return x + 10; else @@ -7505,19 +7505,19 @@ BOOST_AUTO_TEST_CASE(strings_in_struct) constructor(){ bug = Buggy(10, 20, 30, "asdfghjkl"); } - function getFirst() returns (uint) + function getFirst() public returns (uint) { return bug.first; } - function getSecond() returns (uint) + function getSecond() public returns (uint) { return bug.second; } - function getThird() returns (uint) + function getThird() public returns (uint) { return bug.third; } - function getLast() returns (string) + function getLast() public returns (string) { return bug.last; } @@ -7535,7 +7535,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) { char const* sourceCode = R"( contract A { - function f(uint16 input) pure returns (uint16[5] arr) + function f(uint16 input) public pure returns (uint16[5] arr) { arr[0] = input; arr[1] = ++input; @@ -7545,7 +7545,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) } } contract B { - function f() returns (uint16[5] res, uint16[5] res2) + function f() public returns (uint16[5] res, uint16[5] res2) { A a = new A(); res = a.f(2); @@ -7564,7 +7564,7 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) { char const* sourceCode = R"( library Lib { - function find(uint16[] storage _haystack, uint16 _needle) view returns (uint) + function find(uint16[] storage _haystack, uint16 _needle) public view returns (uint) { for (uint i = 0; i < _haystack.length; ++i) if (_haystack[i] == _needle) @@ -7574,7 +7574,7 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) } contract Test { mapping(string => uint16[]) data; - function f() returns (uint a, uint b) + function f() public returns (uint a, uint b) { data["abc"].length = 20; data["abc"][4] = 9; @@ -7603,7 +7603,7 @@ BOOST_AUTO_TEST_CASE(using_library_structs) } contract Test { mapping(string => Lib.Data) data; - function f() returns (uint a, uint b) + function f() public returns (uint a, uint b) { Lib.set(data["abc"]); a = data["abc"].a; @@ -7627,7 +7627,7 @@ BOOST_AUTO_TEST_CASE(library_struct_as_an_expression) } contract Tsra { - function f() returns(uint) { + function f() public returns(uint) { Arst.Foo; return 1; } @@ -7648,7 +7648,7 @@ BOOST_AUTO_TEST_CASE(library_enum_as_an_expression) } contract Tsra { - function f() returns(uint) { + function f() public returns(uint) { Arst.Foo; return 1; } @@ -7666,7 +7666,7 @@ BOOST_AUTO_TEST_CASE(short_strings) contract A { bytes public data1 = "123"; bytes data2; - function lengthChange() returns (uint) + function lengthChange() public returns (uint) { // store constant in short and long string data1 = "123"; @@ -7708,7 +7708,7 @@ BOOST_AUTO_TEST_CASE(short_strings) data1.length = 0; data2.length = 0; } - function copy() returns (uint) { + function copy() public returns (uint) { bytes memory x = "123"; bytes memory y = "012345678901234567890123456789012345678901234567890123456789"; bytes memory z = "1234567"; @@ -7741,7 +7741,7 @@ BOOST_AUTO_TEST_CASE(short_strings) data1 = ""; data2 = ""; } - function deleteElements() returns (uint) { + function deleteElements() public returns (uint) { data1 = "01234"; delete data1[2]; if (data1[2] != 0) return 1; @@ -7790,9 +7790,9 @@ BOOST_AUTO_TEST_CASE(calldata_offset) BOOST_AUTO_TEST_CASE(contract_binary_dependencies) { char const* sourceCode = R"( - contract A { function f() { new B(); } } - contract B { function f() { } } - contract C { function f() { new B(); } } + contract A { function f() public { new B(); } } + contract B { function f() public { } } + contract C { function f() public { new B(); } } )"; compileAndRun(sourceCode); } @@ -7802,8 +7802,8 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) char const* sourceCode = R"( library lib {} contract c { - constructor() payable {} - function f(address x) returns (bool) { + constructor() public payable {} + function f(address x) public returns (bool) { return x.send(1); } function () external payable {} @@ -7826,10 +7826,10 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration) { char const* sourceCode = R"( contract C { - function g() returns (uint a, uint b, uint c) { + function g() public returns (uint a, uint b, uint c) { a = 1; b = 2; c = 3; } - function f() returns (bool) { + function f() public returns (bool) { (uint x, uint y, uint z) = g(); if (x != 1 || y != 2 || z != 3) return false; (, uint a,) = g(); @@ -7856,7 +7856,7 @@ BOOST_AUTO_TEST_CASE(typed_multi_variable_declaration) s.x = 7; return (1, s, 2); } - function f() returns (bool) { + function f() public returns (bool) { (uint x1, S storage y1, uint z1) = g(); if (x1 != 1 || y1.x != 7 || z1 != 2) return false; (, S storage y2,) = g(); @@ -7884,7 +7884,7 @@ BOOST_AUTO_TEST_CASE(tuples) function h() external returns (uint a, uint b) { return (5, 6); } - function f() returns (uint) { + function f() public returns (uint) { data.length = 1; data[0] = 3; uint a; uint b; @@ -7908,13 +7908,13 @@ BOOST_AUTO_TEST_CASE(string_tuples) { char const* sourceCode = R"( contract C { - function f() returns (string, uint) { + function f() public returns (string, uint) { return ("abc", 8); } - function g() returns (string, string) { + function g() public returns (string, string) { return (h(), "def"); } - function h() returns (string) { + function h() public returns (string) { return ("abc",); } } @@ -7928,7 +7928,7 @@ BOOST_AUTO_TEST_CASE(decayed_tuple) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { uint x = 1; (x) = 2; return x; @@ -7943,7 +7943,7 @@ BOOST_AUTO_TEST_CASE(inline_tuple_with_rational_numbers) { char const* sourceCode = R"( contract c { - function f() returns (int8) { + function f() public returns (int8) { int8[5] memory foo3 = [int8(1), -1, 0, 0, 0]; return foo3[0]; } @@ -7961,13 +7961,13 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment) bytes data; uint[] y; uint[] arrayData; - function returnsArray() returns (uint[]) { + function returnsArray() public returns (uint[]) { arrayData.length = 9; arrayData[2] = 5; arrayData[7] = 4; return arrayData; } - function f(bytes s) returns (uint) { + function f(bytes s) public returns (uint) { uint loc; uint[] memory memArray; (loc, x, y, data, arrayData[3]) = (8, 4, returnsArray(), s, 2); @@ -7996,7 +7996,7 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment_wildcard) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { uint a; uint b; uint c; @@ -8022,7 +8022,7 @@ BOOST_AUTO_TEST_CASE(lone_struct_array_type) char const* sourceCode = R"( contract C { struct s { uint a; uint b;} - function f() returns (uint) { + function f() public returns (uint) { s[7][]; // This is only the type, should not have any effect return 3; } @@ -8037,7 +8037,7 @@ BOOST_AUTO_TEST_CASE(create_memory_array) char const* sourceCode = R"( contract C { struct S { uint[2] a; bytes b; } - function f() returns (byte, uint, uint, byte) { + function f() public returns (byte, uint, uint, byte) { bytes memory x = new bytes(200); x[199] = 'A'; uint[2][] memory y = new uint[2][](300); @@ -8060,7 +8060,7 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) // multiple of 32 char const* sourceCode = R"( contract C { - function f() pure returns (uint d1, uint d2, uint d3) { + function f() public pure returns (uint d1, uint d2, uint d3) { bytes memory b1 = new bytes(31); bytes memory b2 = new bytes(32); bytes memory b3 = new bytes(256); @@ -8082,7 +8082,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes) // Computes binomial coefficients the chinese way char const* sourceCode = R"( contract C { - function f(uint n, uint k) returns (uint) { + function f(uint n, uint k) public returns (uint) { uint[][] memory rows = new uint[][](n + 1); for (uint i = 1; i <= n; i++) { rows[i] = new uint[](i); @@ -8103,7 +8103,7 @@ BOOST_AUTO_TEST_CASE(create_multiple_dynamic_arrays) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { uint[][] memory x = new uint[][](42); assert(x[0].length == 0); x[0] = new uint[](1); @@ -8138,7 +8138,7 @@ BOOST_AUTO_TEST_CASE(memory_overwrite) { char const* sourceCode = R"( contract C { - function f() returns (bytes x) { + function f() public returns (bytes x) { x = "12345"; x[3] = 0x61; x[0] = 0x62; @@ -8153,7 +8153,7 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod) { char const* sourceCode = R"( contract C { - function test() returns (uint) { + function test() public returns (uint) { // Note that this only works because computation on literals is done using // unbounded integers. if ((2**255 + 2**255) % 7 != addmod(2**255, 2**255, 7)) @@ -8172,15 +8172,15 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod_zero) { char const* sourceCode = R"( contract C { - function f(uint d) pure returns (uint) { + function f(uint d) public pure returns (uint) { addmod(1, 2, d); return 2; } - function g(uint d) pure returns (uint) { + function g(uint d) public pure returns (uint) { mulmod(1, 2, d); return 2; } - function h() pure returns (uint) { + function h() public pure returns (uint) { mulmod(0, 1, 2); mulmod(1, 0, 2); addmod(0, 1, 2); @@ -8199,10 +8199,10 @@ BOOST_AUTO_TEST_CASE(divisiod_by_zero) { char const* sourceCode = R"( contract C { - function div(uint a, uint b) returns (uint) { + function div(uint a, uint b) public returns (uint) { return a / b; } - function mod(uint a, uint b) returns (uint) { + function mod(uint a, uint b) public returns (uint) { return a % b; } } @@ -8223,7 +8223,7 @@ BOOST_AUTO_TEST_CASE(string_allocation_bug) { struct s { uint16 x; uint16 y; string a; string b;} s[2] public p; - constructor() { + constructor() public { s memory m; m.x = 0xbbbb; m.y = 0xcccc; @@ -8249,10 +8249,10 @@ BOOST_AUTO_TEST_CASE(string_allocation_bug) BOOST_AUTO_TEST_CASE(using_for_function_on_int) { char const* sourceCode = R"( - library D { function double(uint self) returns (uint) { return 2*self; } } + library D { function double(uint self) public returns (uint) { return 2*self; } } contract C { using D for uint; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { return a.double(); } } @@ -8265,11 +8265,11 @@ BOOST_AUTO_TEST_CASE(using_for_function_on_int) BOOST_AUTO_TEST_CASE(using_for_function_on_struct) { char const* sourceCode = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 3; return x.mul(a); } @@ -8286,13 +8286,13 @@ BOOST_AUTO_TEST_CASE(using_for_overload) char const* sourceCode = R"( library D { struct s { uint a; } - function mul(s storage self, uint x) returns (uint) { return self.a *= x; } - function mul(s storage self, bytes32 x) returns (bytes32) { } + function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } + function mul(s storage self, bytes32 x) public returns (bytes32) { } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 6; return x.mul(a); } @@ -8307,11 +8307,11 @@ BOOST_AUTO_TEST_CASE(using_for_overload) BOOST_AUTO_TEST_CASE(using_for_by_name) { char const* sourceCode = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 6; return x.mul({x: a}); } @@ -8326,11 +8326,11 @@ BOOST_AUTO_TEST_CASE(using_for_by_name) BOOST_AUTO_TEST_CASE(bound_function_in_var) { char const* sourceCode = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 6; return (x.mul)({x: a}); } @@ -8345,15 +8345,15 @@ BOOST_AUTO_TEST_CASE(bound_function_in_var) BOOST_AUTO_TEST_CASE(bound_function_to_string) { char const* sourceCode = R"( - library D { function length(string memory self) returns (uint) { return bytes(self).length; } } + library D { function length(string memory self) public returns (uint) { return bytes(self).length; } } contract C { using D for string; string x; - function f() returns (uint) { + function f() public returns (uint) { x = "abc"; return x.length(); } - function g() returns (uint) { + function g() public returns (uint) { string memory s = "abc"; return s.length(); } @@ -8370,7 +8370,7 @@ BOOST_AUTO_TEST_CASE(inline_array_storage_to_memory_conversion_strings) char const* sourceCode = R"( contract C { string s = "doh"; - function f() returns (string, string) { + function f() public returns (string, string) { string memory t = "ray"; string[3] memory x = [s, t, "mi"]; return (x[1], x[2]); @@ -8385,7 +8385,7 @@ BOOST_AUTO_TEST_CASE(inline_array_strings_from_document) { char const* sourceCode = R"( contract C { - function f(uint i) returns (string) { + function f(uint i) public returns (string) { string[4] memory x = ["This", "is", "an", "array"]; return (x[i]); } @@ -8402,7 +8402,7 @@ BOOST_AUTO_TEST_CASE(inline_array_storage_to_memory_conversion_ints) { char const* sourceCode = R"( contract C { - function f() returns (uint x, uint y) { + function f() public returns (uint x, uint y) { x = 3; y = 6; uint[2] memory z = [x, y]; @@ -8418,7 +8418,7 @@ BOOST_AUTO_TEST_CASE(inline_array_index_access_ints) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { return ([1, 2, 3, 4][2]); } } @@ -8432,10 +8432,10 @@ BOOST_AUTO_TEST_CASE(inline_array_index_access_strings) char const* sourceCode = R"( contract C { string public tester; - function f() returns (string) { + function f() public returns (string) { return (["abc", "def", "g"][0]); } - function test() { + function test() public { tester = f(); } } @@ -8450,10 +8450,10 @@ BOOST_AUTO_TEST_CASE(inline_array_return) char const* sourceCode = R"( contract C { uint8[] tester; - function f() returns (uint8[5]) { + function f() public returns (uint8[5]) { return ([1,2,3,4,5]); } - function test() returns (uint8, uint8, uint8, uint8, uint8) { + function test() public returns (uint8, uint8, uint8, uint8, uint8) { tester = f(); return (tester[0], tester[1], tester[2], tester[3], tester[4]); } @@ -8469,7 +8469,7 @@ BOOST_AUTO_TEST_CASE(inline_array_singleton) // This caused a failure since the type was not converted to its mobile type. char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { return [4][0]; } } @@ -8482,7 +8482,7 @@ BOOST_AUTO_TEST_CASE(inline_long_string_return) { char const* sourceCode = R"( contract C { - function f() returns (string) { + function f() public returns (string) { return (["somethingShort", "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"][1]); } } @@ -8498,10 +8498,10 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_index_access) char const* sourceCode = R"( contract C { bytes16[] public data; - function f(bytes32 x) returns (byte) { + function f(bytes32 x) public returns (byte) { return x[2]; } - function g(bytes32 x) returns (uint) { + function g(bytes32 x) public returns (uint) { data = [x[0], x[1], x[2]]; data[0] = "12345"; return uint(uint8(data[0][4])); @@ -8519,7 +8519,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_length_access) char const* sourceCode = R"( contract C { byte a; - function f(bytes32 x) returns (uint, uint, uint) { + function f(bytes32 x) public returns (uint, uint, uint) { return (x.length, bytes16(2).length, a.length + 7); } } @@ -8532,7 +8532,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_write_to_stack) { char const* sourceCode = R"( contract C { - function f() returns (uint r, bytes32 r2) { + function f() public returns (uint r, bytes32 r2) { assembly { r := 7 r2 := "abcdef" } } } @@ -8545,7 +8545,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_read_and_write_stack) { char const* sourceCode = R"( contract C { - function f() returns (uint r) { + function f() public returns (uint r) { for (uint x = 0; x < 10; ++x) assembly { r := add(r, x) } } @@ -8559,7 +8559,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_memory_access) { char const* sourceCode = R"( contract C { - function test() returns (bytes) { + function test() public returns (bytes) { bytes memory x = new bytes(5); for (uint i = 0; i < x.length; ++i) x[i] = byte(uint8(i + 1)); @@ -8579,7 +8579,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access) uint16 x; uint16 public y; uint public z; - function f() returns (bool) { + function f() public returns (bool) { uint off1; uint off2; assembly { @@ -8605,7 +8605,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_inside_function) uint16 x; uint16 public y; uint public z; - function f() returns (bool) { + function f() public returns (bool) { uint off1; uint off2; assembly { @@ -8633,7 +8633,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_via_pointer) uint public separator; Data public a; uint public separator2; - function f() returns (bool) { + function f() public returns (bool) { Data x = a; uint off; assembly { @@ -8656,7 +8656,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_jumps) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let n := calldataload(4) let a := 1 @@ -8702,7 +8702,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_call) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { function asmfun(a, b, c) -> x, y, z { x := a @@ -8726,7 +8726,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_call_assignment) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let a1, b1, c1 function asmfun(a, b, c) -> x, y, z { @@ -8751,7 +8751,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_call2) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let d := 0x10 function asmfun(a, b, c) -> x, y, z { @@ -8777,7 +8777,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_embedded_function_call) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let d := 0x10 function asmfun(a, b, c) -> x, y, z { @@ -8804,7 +8804,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_if) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { if gt(a, 1) { b := 2 } } @@ -8822,7 +8822,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_switch) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { switch a case 1 { b := 8 } @@ -8843,7 +8843,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_recursion) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { function fac(n) -> nf { switch n @@ -8868,7 +8868,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_for) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { function fac(n) -> nf { nf := 1 @@ -8894,7 +8894,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_for2) char const* sourceCode = R"( contract C { uint st; - function f(uint a) returns (uint b, uint c, uint d) { + function f(uint a) public returns (uint b, uint c, uint d) { st = 0; assembly { function sideeffect(r) -> x { sstore(0, add(sload(0), r)) x := 1} @@ -8918,7 +8918,7 @@ BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) // Test for a bug where higher order bits cleanup was not done for array index access. char const* sourceCode = R"( contract C { - function f(uint x) returns (uint[256] r){ + function f(uint x) public returns (uint[256] r){ r[uint8(x)] = 2; } } @@ -8936,7 +8936,7 @@ BOOST_AUTO_TEST_CASE(delete_on_array_of_structs) contract C { struct S { uint x; uint[] y; } S[] data; - function f() returns (bool) { + function f() public returns (bool) { data.length = 2; data[0].x = 2**200; data[1].x = 2**200; @@ -8963,7 +8963,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function) } } contract C { - function f() returns (uint) { + function f() public returns (uint) { uint[] memory x = new uint[](7); x[3] = 8; L.f(x); @@ -8991,7 +8991,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_calling_private) } } contract C { - function f() returns (uint) { + function f() public returns (uint) { uint[] memory x = new uint[](7); x[3] = 8; L.f(x); @@ -9015,7 +9015,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_bound) } contract C { using L for L.S; - function f() returns (uint) { + function f() public returns (uint) { L.S memory x; x.data = new uint[](7); x.data[3] = 8; @@ -9041,7 +9041,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_return_var_size) } contract C { using L for L.S; - function f() returns (uint) { + function f() public returns (uint) { L.S memory x; x.data = new uint[](7); x.data[3] = 8; @@ -9060,7 +9060,7 @@ BOOST_AUTO_TEST_CASE(iszero_bnot_correct) // "iszero" and "not". char const* sourceCode = R"( contract C { - function f() returns (bool) { + function f() public returns (bool) { bytes32 x = 1; assembly { x := not(x) } if (x != ~bytes32(1)) return false; @@ -9079,7 +9079,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types) // Checks that bytesXX types are properly cleaned before they are compared. char const* sourceCode = R"( contract C { - function f(bytes2 a, uint16 x) returns (uint) { + function f(bytes2 a, uint16 x) public returns (uint) { if (a != "ab") return 1; if (x != 0x0102) return 2; if (bytes3(uint24(x)) != 0x0102) return 3; @@ -9096,7 +9096,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types_shortening) { char const* sourceCode = R"( contract C { - function f() pure returns (bytes32 r) { + function f() public pure returns (bytes32 r) { bytes4 x = 0xffffffff; bytes2 y = bytes2(x); assembly { r := y } @@ -9115,10 +9115,10 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types) // The EVM cannot provide access to dynamically-sized return values, so we have to skip them. char const* sourceCode = R"( contract C { - function f() returns (uint, uint[], uint) { + function f() public returns (uint, uint[], uint) { return (7, new uint[](2), 8); } - function g() returns (uint, uint) { + function g() public returns (uint, uint) { // Previous implementation "moved" b to the second place and did not skip. (uint a,, uint b) = this.f(); return (a, b); @@ -9141,7 +9141,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs) uint y; } S public s; - function g() returns (uint, uint) { + function g() public returns (uint, uint) { s.x = 2; s.a = "abc"; s.b = [7, 8, 9]; @@ -9161,12 +9161,12 @@ BOOST_AUTO_TEST_CASE(failed_create) contract D { constructor() payable {} } contract C { uint public x; - constructor() payable {} - function f(uint amount) returns (address) { + constructor() public payable {} + function f(uint amount) public returns (address) { x++; return (new D).value(amount)(); } - function stack(uint depth) returns (address) { + function stack(uint depth) public returns (address) { if (depth < 1024) return this.stack(depth - 1); else @@ -9187,7 +9187,7 @@ BOOST_AUTO_TEST_CASE(create_dynamic_array_with_zero_length) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { uint[][] memory a = new uint[][](0); return 7; } @@ -9232,7 +9232,7 @@ BOOST_AUTO_TEST_CASE(return_does_not_skip_modifier) _; x = 9; } - function f() setsx returns (uint) { + function f() setsx public returns (uint) { return 2; } } @@ -9310,7 +9310,7 @@ BOOST_AUTO_TEST_CASE(mutex) shares -= amount; return shares; } - function withdrawUnprotected(uint amount) returns (uint) { + function withdrawUnprotected(uint amount) public returns (uint) { // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) throw; @@ -9324,8 +9324,8 @@ BOOST_AUTO_TEST_CASE(mutex) uint callDepth; bool protected; function setProtected(bool _protected) { protected = _protected; } - constructor(Fund _fund) { fund = _fund; } - function attack() returns (uint) { + constructor(Fund _fund) public { fund = _fund; } + function attack() public returns (uint) { callDepth = 0; return attackInternal(); } @@ -9361,7 +9361,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input) // Note that the precompile does not return zero but returns nothing. char const* sourceCode = R"( contract C { - function f() returns (address) { + function f() public returns (address) { return ecrecover(bytes32(uint(-1)), 1, 2, 3); } } @@ -9374,7 +9374,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper) { char const* sourceCode = R"( contract C { - function f() returns (address) { + function f() public returns (address) { return recover( 0x77e5189111eb6557e8a637b27ef8fbb15bc61d61c2f00cc48878f3a296e5e0ca, 0, // invalid v value @@ -9385,7 +9385,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper) ); } function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s, uint blockExpired, bytes32 salt) - returns (address) + public returns (address) { require(hash == keccak256(abi.encodePacked(blockExpired, salt))); return ecrecover(hash, v, r, s); @@ -9400,7 +9400,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_asm) { char const* sourceCode = R"( contract C { - function f() returns (address) { + function f() public returns (address) { assembly { mstore(mload(0x40), 0xca35b7d915458ef540ade6068dfe2f44e8fa733c) } @@ -9423,15 +9423,15 @@ BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) contract D { function g(); } contract C { D d = D(0x1212); - function f() returns (uint) { + function f() public returns (uint) { d.g(); return 7; } - function g() returns (uint) { + function g() public returns (uint) { d.g.gas(200)(); return 7; } - function h() returns (uint) { + function h() public returns (uint) { d.call(""); // this does not throw (low-level) return 7; } @@ -9458,7 +9458,7 @@ BOOST_AUTO_TEST_CASE(payable_function) char const* sourceCode = R"( contract C { uint public a; - function f() payable returns (uint) { + function f() payable public returns (uint) { return msg.value; } function() external payable { @@ -9479,10 +9479,10 @@ BOOST_AUTO_TEST_CASE(payable_function_calls_library) { char const* sourceCode = R"( library L { - function f() returns (uint) { return 7; } + function f() public returns (uint) { return 7; } } contract C { - function f() payable returns (uint) { + function f() payable public returns (uint) { return L.f(); } } @@ -9497,7 +9497,7 @@ BOOST_AUTO_TEST_CASE(non_payable_throw) char const* sourceCode = R"( contract C { uint public a; - function f() returns (uint) { + function f() public returns (uint) { return msg.value; } function() external { @@ -9524,7 +9524,7 @@ BOOST_AUTO_TEST_CASE(no_nonpayable_circumvention_by_modifier) modifier tryCircumvent { if (false) _; // avoid the function, we should still not accept ether } - function f() tryCircumvent returns (uint) { + function f() tryCircumvent public returns (uint) { return msg.value; } } @@ -9542,10 +9542,10 @@ BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call) // Tests that this also survives the optimizer. char const* sourceCode = R"( contract C { - function f() returns (uint[200]) {} + function f() public returns (uint[200]) {} } contract D { - function f(C c) returns (uint) { c.f(); return 7; } + function f(C c) public returns (uint) { c.f(); return 7; } } )"; @@ -9559,12 +9559,12 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function) { char const* sourceCode = R"( contract C { - function intern() returns (uint) { + function intern() public returns (uint) { function (uint) internal returns (uint) x; x(2); return 7; } - function extern() returns (uint) { + function extern() public returns (uint) { function (uint) external returns (uint) x; x(2); return 7; @@ -9584,7 +9584,7 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_in_detail) contract C { function() internal returns (uint) x; int mutex; - function t() returns (uint) { + function t() public returns (uint) { if (mutex > 0) { assembly { mstore(0, 7) return(0, 0x20) } } mutex = 1; @@ -9604,7 +9604,7 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_through_array) char const* sourceCode = R"( contract C { int mutex; - function t() returns (uint) { + function t() public returns (uint) { if (mutex > 0) { assembly { mstore(0, 7) return(0, 0x20) } } mutex = 1; @@ -9624,13 +9624,13 @@ BOOST_AUTO_TEST_CASE(pass_function_types_internally) { char const* sourceCode = R"( contract C { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { return eval(g, x); } - function eval(function(uint) returns (uint) x, uint a) internal returns (uint) { + function eval(function(uint) public returns (uint) x, uint a) internal returns (uint) { return x(a); } - function g(uint x) returns (uint) { return x + 1; } + function g(uint x) public returns (uint) { return x + 1; } } )"; @@ -9642,16 +9642,16 @@ BOOST_AUTO_TEST_CASE(pass_function_types_externally) { char const* sourceCode = R"( contract C { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { return this.eval(this.g, x); } - function f2(uint x) returns (uint) { + function f2(uint x) public returns (uint) { return eval(this.g, x); } - function eval(function(uint) external returns (uint) x, uint a) returns (uint) { + function eval(function(uint) external returns (uint) x, uint a) public returns (uint) { return x(a); } - function g(uint x) returns (uint) { return x + 1; } + function g(uint x) public returns (uint) { return x + 1; } } )"; @@ -9664,8 +9664,8 @@ BOOST_AUTO_TEST_CASE(receive_external_function_type) { char const* sourceCode = R"( contract C { - function g() returns (uint) { return 7; } - function f(function() external returns (uint) g) returns (uint) { + function g() public returns (uint) { return 7; } + function f(function() external returns (uint) g) public returns (uint) { return g(); } } @@ -9682,8 +9682,8 @@ BOOST_AUTO_TEST_CASE(return_external_function_type) { char const* sourceCode = R"( contract C { - function g() {} - function f() returns (function() external) { + function g() public {} + function f() public returns (function() external) { return this.g; } } @@ -9700,18 +9700,18 @@ BOOST_AUTO_TEST_CASE(store_function) { char const* sourceCode = R"( contract Other { - function addTwo(uint x) returns (uint) { return x + 2; } + function addTwo(uint x) public returns (uint) { return x + 2; } } contract C { - function (function (uint) external returns (uint)) returns (uint) ev; + function (function (uint) external returns (uint)) public returns (uint) ev; function (uint) external returns (uint) x; function store(function(uint) external returns (uint) y) { x = y; } - function eval(function(uint) external returns (uint) y) returns (uint) { + function eval(function(uint) external returns (uint) y) public returns (uint) { return y(7); } - function t() returns (uint) { + function t() public returns (uint) { ev = eval; this.store((new Other()).addTwo); return ev(x); @@ -9729,14 +9729,14 @@ BOOST_AUTO_TEST_CASE(store_function_in_constructor) contract C { uint public result_in_constructor; function (uint) internal returns (uint) x; - constructor() { + constructor() public { x = double; result_in_constructor = use(2); } - function double(uint _arg) returns (uint _ret) { + function double(uint _arg) public returns (uint _ret) { _ret = _arg * 2; } - function use(uint _arg) returns (uint) { + function use(uint _arg) public returns (uint) { return x(_arg); } } @@ -9754,13 +9754,13 @@ BOOST_AUTO_TEST_CASE(store_internal_unused_function_in_constructor) char const* sourceCode = R"( contract C { function () internal returns (uint) x; - constructor() { + constructor() public { x = unused; } function unused() internal returns (uint) { return 7; } - function t() returns (uint) { + function t() public returns (uint) { return x(); } } @@ -9776,10 +9776,10 @@ BOOST_AUTO_TEST_CASE(store_internal_unused_library_function_in_constructor) library L { function x() internal returns (uint) { return 7; } } contract C { function () internal returns (uint) x; - constructor() { + constructor() public { x = L.x; } - function t() returns (uint) { + function t() public returns (uint) { return x(); } } @@ -9794,13 +9794,13 @@ BOOST_AUTO_TEST_CASE(same_function_in_construction_and_runtime) char const* sourceCode = R"( contract C { uint public initial; - constructor() { + constructor() public { initial = double(2); } - function double(uint _arg) returns (uint _ret) { + function double(uint _arg) public returns (uint _ret) { _ret = _arg * 2; } - function runtime(uint _arg) returns (uint) { + function runtime(uint _arg) public returns (uint) { return double(_arg); } } @@ -9816,13 +9816,13 @@ BOOST_AUTO_TEST_CASE(same_function_in_construction_and_runtime_equality_check) char const* sourceCode = R"( contract C { function (uint) internal returns (uint) x; - constructor() { + constructor() public { x = double; } - function test() returns (bool) { + function test() public returns (bool) { return x == double; } - function double(uint _arg) returns (uint _ret) { + function double(uint _arg) public returns (uint _ret) { _ret = _arg * 2; } } @@ -9836,7 +9836,7 @@ BOOST_AUTO_TEST_CASE(function_type_library_internal) { char const* sourceCode = R"( library Utils { - function reduce(uint[] memory array, function(uint, uint) returns (uint) f, uint init) internal returns (uint) { + function reduce(uint[] memory array, function(uint, uint) public returns (uint) f, uint init) internal returns (uint) { for (uint i = 0; i < array.length; i++) { init = f(array[i], init); } @@ -9847,7 +9847,7 @@ BOOST_AUTO_TEST_CASE(function_type_library_internal) } } contract C { - function f(uint[] x) returns (uint) { + function f(uint[] x) public returns (uint) { return Utils.reduce(x, Utils.sum, 0); } } @@ -9862,21 +9862,21 @@ BOOST_AUTO_TEST_CASE(call_function_returning_function) { char const* sourceCode = R"( contract test { - function f0() returns (uint) { + function f0() public returns (uint) { return 2; } - function f1() internal returns (function() returns (uint)) { + function f1() internal returns (function() internal returns (uint)) { return f0; } - function f2() internal returns (function() returns (function () returns (uint))) { + function f2() internal returns (function() internal returns (function () internal returns (uint))) { return f1; } - function f3() internal returns (function() returns (function () returns (function () returns (uint)))) + function f3() internal returns (function() internal returns (function () internal returns (function () internal returns (uint)))) { return f2; } - function f() returns (uint) { - function() returns(function() returns(function() returns(function() returns(uint)))) x; + function f() public returns (uint) { + function() internal returns(function() internal returns(function() internal returns(function() internal returns(uint)))) x; x = f3; return x()()()(); } @@ -9907,11 +9907,11 @@ BOOST_AUTO_TEST_CASE(mapping_of_functions) success = true; } - constructor() { + constructor() public { stages[msg.sender] = stage0; } - function f() returns (uint) { + function f() public returns (uint) { stages[msg.sender](); return 7; } @@ -9932,35 +9932,35 @@ BOOST_AUTO_TEST_CASE(packed_functions) char const* sourceCode = R"( contract C { // these should take the same slot - function() returns (uint) a; + function() public returns (uint) a; function() external returns (uint) b; function() external returns (uint) c; - function() returns (uint) d; + function() public returns (uint) d; uint8 public x; - function set() { + function set() public { x = 2; d = g; c = this.h; b = this.h; a = g; } - function t1() returns (uint) { + function t1() public returns (uint) { return a(); } - function t2() returns (uint) { + function t2() public returns (uint) { return b(); } - function t3() returns (uint) { + function t3() public returns (uint) { return a(); } - function t4() returns (uint) { + function t4() public returns (uint) { return b(); } - function g() returns (uint) { + function g() public returns (uint) { return 7; } - function h() returns (uint) { + function h() public returns (uint) { return 8; } } @@ -9979,12 +9979,12 @@ BOOST_AUTO_TEST_CASE(function_memory_array) { char const* sourceCode = R"( contract C { - function a(uint x) returns (uint) { return x + 1; } - function b(uint x) returns (uint) { return x + 2; } - function c(uint x) returns (uint) { return x + 3; } - function d(uint x) returns (uint) { return x + 5; } - function e(uint x) returns (uint) { return x + 8; } - function test(uint x, uint i) returns (uint) { + function a(uint x) public returns (uint) { return x + 1; } + function b(uint x) public returns (uint) { return x + 2; } + function c(uint x) public returns (uint) { return x + 3; } + function d(uint x) public returns (uint) { return x + 5; } + function e(uint x) public returns (uint) { return x + 8; } + function test(uint x, uint i) public returns (uint) { function(uint) internal returns (uint)[] memory arr = new function(uint) internal returns (uint)[](10); arr[0] = a; @@ -10010,17 +10010,17 @@ BOOST_AUTO_TEST_CASE(function_delete_storage) { char const* sourceCode = R"( contract C { - function a() returns (uint) { return 7; } + function a() public returns (uint) { return 7; } function() internal returns (uint) y; - function set() returns (uint) { + function set() public returns (uint) { y = a; return y(); } - function d() returns (uint) { + function d() public returns (uint) { delete y; return 1; } - function ca() returns (uint) { + function ca() public returns (uint) { return y(); } } @@ -10037,8 +10037,8 @@ BOOST_AUTO_TEST_CASE(function_delete_stack) { char const* sourceCode = R"( contract C { - function a() returns (uint) { return 7; } - function test() returns (uint) { + function a() public returns (uint) { return 7; } + function test() public returns (uint) { function () returns (uint) y = a; delete y; y(); @@ -10056,13 +10056,13 @@ BOOST_AUTO_TEST_CASE(copy_function_storage_array) contract C { function() internal returns (uint)[] x; function() internal returns (uint)[] y; - function test() returns (uint) { + function test() public returns (uint) { x.length = 10; x[9] = a; y = x; return y[9](); } - function a() returns (uint) { + function a() public returns (uint) { return 7; } } @@ -10115,10 +10115,10 @@ BOOST_AUTO_TEST_CASE(external_function_to_address) { char const* sourceCode = R"( contract C { - function f() returns (bool) { + function f() public returns (bool) { return address(this.f) == address(this); } - function g(function() external cb) returns (address) { + function g(function() external cb) public returns (address) { return address(cb); } } @@ -10136,12 +10136,12 @@ BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage) contract C { function() internal returns (uint)[20] x; int mutex; - function one() returns (uint) { + function one() public returns (uint) { function() internal returns (uint)[20] xmem; x = xmem; return 3; } - function two() returns (uint) { + function two() public returns (uint) { if (mutex > 0) return 7; mutex = 1; @@ -10205,7 +10205,7 @@ BOOST_AUTO_TEST_CASE(shift_left) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { return a << b; } } @@ -10223,7 +10223,7 @@ BOOST_AUTO_TEST_CASE(shift_left_uint32) { char const* sourceCode = R"( contract C { - function f(uint32 a, uint32 b) returns (uint) { + function f(uint32 a, uint32 b) public returns (uint) { return a << b; } } @@ -10240,7 +10240,7 @@ BOOST_AUTO_TEST_CASE(shift_left_uint8) { char const* sourceCode = R"( contract C { - function f(uint8 a, uint8 b) returns (uint) { + function f(uint8 a, uint8 b) public returns (uint) { return a << b; } } @@ -10255,7 +10255,7 @@ BOOST_AUTO_TEST_CASE(shift_left_larger_type) // This basically tests proper cleanup and conversion. It should not convert x to int8. char const* sourceCode = R"( contract C { - function f() returns (int8) { + function f() public returns (int8) { uint8 x = 254; int8 y = 1; return y << x; @@ -10270,7 +10270,7 @@ BOOST_AUTO_TEST_CASE(shift_left_assignment) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { a <<= b; return a; } @@ -10289,7 +10289,7 @@ BOOST_AUTO_TEST_CASE(shift_left_assignment_different_type) { char const* sourceCode = R"( contract C { - function f(uint a, uint8 b) returns (uint) { + function f(uint a, uint8 b) public returns (uint) { a <<= b; return a; } @@ -10307,7 +10307,7 @@ BOOST_AUTO_TEST_CASE(shift_right) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { return a >> b; } } @@ -10324,7 +10324,7 @@ BOOST_AUTO_TEST_CASE(shift_right_garbled) { char const* sourceCode = R"( contract C { - function f(uint8 a, uint8 b) returns (uint) { + function f(uint8 a, uint8 b) public returns (uint) { assembly { a := 0xffffffff } @@ -10342,14 +10342,14 @@ BOOST_AUTO_TEST_CASE(shift_right_garbled_signed) { char const* sourceCode = R"( contract C { - function f(int8 a, uint8 b) returns (int) { + function f(int8 a, uint8 b) public returns (int) { assembly { a := 0xfffffff0 } // Higher bits should be signextended before the shift return a >> b; } - function g(int8 a, uint8 b) returns (int) { + function g(int8 a, uint8 b) public returns (int) { assembly { a := 0xf0 } @@ -10375,7 +10375,7 @@ BOOST_AUTO_TEST_CASE(shift_right_uint32) { char const* sourceCode = R"( contract C { - function f(uint32 a, uint32 b) returns (uint) { + function f(uint32 a, uint32 b) public returns (uint) { return a >> b; } } @@ -10391,7 +10391,7 @@ BOOST_AUTO_TEST_CASE(shift_right_uint8) { char const* sourceCode = R"( contract C { - function f(uint8 a, uint8 b) returns (uint) { + function f(uint8 a, uint8 b) public returns (uint) { return a >> b; } } @@ -10405,7 +10405,7 @@ BOOST_AUTO_TEST_CASE(shift_right_assignment) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { a >>= b; return a; } @@ -10422,7 +10422,7 @@ BOOST_AUTO_TEST_CASE(shift_right_assignment_signed) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { a >>= b; return a; } @@ -10439,7 +10439,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { return a >> b; } } @@ -10463,40 +10463,40 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_literal) { char const* sourceCode = R"( contract C { - function f1() pure returns (bool) { + function f1() public pure returns (bool) { return (-4266 >> 0) == -4266; } - function f2() pure returns (bool) { + function f2() public pure returns (bool) { return (-4266 >> 1) == -2133; } - function f3() pure returns (bool) { + function f3() public pure returns (bool) { return (-4266 >> 4) == -267; } - function f4() pure returns (bool) { + function f4() public pure returns (bool) { return (-4266 >> 8) == -17; } - function f5() pure returns (bool) { + function f5() public pure returns (bool) { return (-4266 >> 16) == -1; } - function f6() pure returns (bool) { + function f6() public pure returns (bool) { return (-4266 >> 17) == -1; } - function g1() pure returns (bool) { + function g1() public pure returns (bool) { return (-4267 >> 0) == -4267; } - function g2() pure returns (bool) { + function g2() public pure returns (bool) { return (-4267 >> 1) == -2134; } - function g3() pure returns (bool) { + function g3() public pure returns (bool) { return (-4267 >> 4) == -267; } - function g4() pure returns (bool) { + function g4() public pure returns (bool) { return (-4267 >> 8) == -17; } - function g5() pure returns (bool) { + function g5() public pure returns (bool) { return (-4267 >> 16) == -1; } - function g6() pure returns (bool) { + function g6() public pure returns (bool) { return (-4267 >> 17) == -1; } } @@ -10520,7 +10520,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int8) { char const* sourceCode = R"( contract C { - function f(int8 a, int8 b) returns (int) { + function f(int8 a, int8 b) public returns (int) { return a >> b; } } @@ -10544,7 +10544,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int8) { char const* sourceCode = R"( contract C { - function f(int8 a, int8 b) returns (int8) { + function f(int8 a, int8 b) public returns (int8) { return a >> b; } } @@ -10561,7 +10561,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int16) { char const* sourceCode = R"( contract C { - function f(int16 a, int16 b) returns (int16) { + function f(int16 a, int16 b) public returns (int16) { return a >> b; } } @@ -10578,7 +10578,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int32) { char const* sourceCode = R"( contract C { - function f(int32 a, int32 b) returns (int32) { + function f(int32 a, int32 b) public returns (int32) { return a >> b; } } @@ -10596,7 +10596,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int16) { char const* sourceCode = R"( contract C { - function f(int16 a, int16 b) returns (int) { + function f(int16 a, int16 b) public returns (int) { return a >> b; } } @@ -10620,7 +10620,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int32) { char const* sourceCode = R"( contract C { - function f(int32 a, int32 b) returns (int) { + function f(int32 a, int32 b) public returns (int) { return a >> b; } } @@ -10644,7 +10644,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_assignment) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { a >>= b; return a; } @@ -10669,10 +10669,10 @@ BOOST_AUTO_TEST_CASE(shift_negative_rvalue) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { return a << b; } - function g(int a, int b) returns (int) { + function g(int a, int b) public returns (int) { return a >> b; } } @@ -10686,11 +10686,11 @@ BOOST_AUTO_TEST_CASE(shift_negative_rvalue_assignment) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { a <<= b; return a; } - function g(int a, int b) returns (int) { + function g(int a, int b) public returns (int) { a >>= b; return a; } @@ -10705,7 +10705,7 @@ BOOST_AUTO_TEST_CASE(shift_constant_left_assignment) { char const* sourceCode = R"( contract C { - function f() returns (uint a) { + function f() public returns (uint a) { a = 0x42; a <<= 8; } @@ -10719,7 +10719,7 @@ BOOST_AUTO_TEST_CASE(shift_constant_right_assignment) { char const* sourceCode = R"( contract C { - function f() returns (uint a) { + function f() public returns (uint a) { a = 0x4200; a >>= 8; } @@ -10733,7 +10733,7 @@ BOOST_AUTO_TEST_CASE(shift_cleanup) { char const* sourceCode = R"( contract C { - function f() returns (uint16 x) { + function f() public returns (uint16 x) { x = 0xffff; x += 32; x <<= 8; @@ -10749,7 +10749,7 @@ BOOST_AUTO_TEST_CASE(shift_cleanup_garbled) { char const* sourceCode = R"( contract C { - function f() returns (uint8 x) { + function f() public returns (uint8 x) { assembly { x := 0xffff } @@ -10765,10 +10765,10 @@ BOOST_AUTO_TEST_CASE(shift_overflow) { char const* sourceCode = R"( contract C { - function leftU(uint8 x, uint8 y) returns (uint8) { + function leftU(uint8 x, uint8 y) public returns (uint8) { return x << y; } - function leftS(int8 x, int8 y) returns (int8) { + function leftS(int8 x, int8 y) public returns (int8) { return x << y; } } @@ -10787,10 +10787,10 @@ BOOST_AUTO_TEST_CASE(shift_bytes) { char const* sourceCode = R"( contract C { - function left(bytes20 x, uint8 y) returns (bytes20) { + function left(bytes20 x, uint8 y) public returns (bytes20) { return x << y; } - function right(bytes20 x, uint8 y) returns (bytes20) { + function right(bytes20 x, uint8 y) public returns (bytes20) { return x >> y; } } @@ -10804,12 +10804,12 @@ BOOST_AUTO_TEST_CASE(shift_bytes_cleanup) { char const* sourceCode = R"( contract C { - function left(uint8 y) returns (bytes20) { + function left(uint8 y) public returns (bytes20) { bytes20 x; assembly { x := "12345678901234567890abcde" } return x << y; } - function right(uint8 y) returns (bytes20) { + function right(uint8 y) public returns (bytes20) { bytes20 x; assembly { x := "12345678901234567890abcde" } return x >> y; @@ -10825,7 +10825,7 @@ BOOST_AUTO_TEST_CASE(cleanup_in_compound_assign) { char const* sourceCode = R"( contract C { - function test() returns (uint, uint) { + function test() public returns (uint, uint) { uint32 a = 0xffffffff; uint16 x = uint16(a); uint16 y = x; @@ -10852,7 +10852,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_in_modifiers) throw; _; } - function f() m returns (bool) { + function f() m public returns (bool) { return true; } } @@ -10868,7 +10868,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_overflow) uint16 x = 0x1234; uint16 a = 0xffff; uint16 b; - function f() returns (uint, uint, uint, uint) { + function f() public returns (uint, uint, uint, uint) { a++; uint c = b; delete b; @@ -10900,18 +10900,18 @@ BOOST_AUTO_TEST_CASE(include_creation_bytecode_only_once) contract D { bytes a = hex"1237651237125387136581271652831736512837126583171583712358126123765123712538713658127165283173651283712658317158371235812612376512371253871365812716528317365128371265831715837123581261237651237125387136581271652831736512837126583171583712358126"; bytes b = hex"1237651237125327136581271252831736512837126583171383712358126123765125712538713658127165253173651283712658357158371235812612376512371a5387136581271652a317365128371265a317158371235812612a765123712538a13658127165a83173651283712a58317158371235a126"; - constructor(uint) {} + constructor(uint) public {} } contract Double { - function f() { + function f() public { new D(2); } - function g() { + function g() public { new D(3); } } contract Single { - function f() { + function f() public { new D(2); } } @@ -10931,7 +10931,7 @@ BOOST_AUTO_TEST_CASE(recursive_structs) S[] x; } S sstorage; - function f() returns (uint) { + function f() public returns (uint) { S memory s; s.x = new S[](10); delete s; @@ -10949,7 +10949,7 @@ BOOST_AUTO_TEST_CASE(invalid_instruction) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { invalid } @@ -10964,14 +10964,14 @@ BOOST_AUTO_TEST_CASE(assert_require) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assert(false); } - function g(bool val) returns (bool) { + function g(bool val) public returns (bool) { assert(val == true); return true; } - function h(bool val) returns (bool) { + function h(bool val) public returns (bool) { require(val); return true; } @@ -10990,11 +10990,11 @@ BOOST_AUTO_TEST_CASE(revert) char const* sourceCode = R"( contract C { uint public a = 42; - function f() { + function f() public { a = 1; revert(); } - function g() { + function g() public { a = 1; assembly { revert(0, 0) @@ -11089,7 +11089,7 @@ BOOST_AUTO_TEST_CASE(require_with_message) bool flagCopy = flag; require(flagCopy == false, internalFun()); } - function internalFun() returns (string) { + function internalFun() public returns (string) { flag = true; return "only on second run"; } @@ -11224,7 +11224,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_create) { char const* sourceCode = R"( contract E { - constructor() { + constructor() public { revert("message"); } } @@ -11288,7 +11288,7 @@ BOOST_AUTO_TEST_CASE(literal_empty_string) x = _x; a = _a; } - function g() { + function g() public { this.f("", 2); } } @@ -11305,22 +11305,22 @@ BOOST_AUTO_TEST_CASE(scientific_notation) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { return 2e10 wei; } - function g() returns (uint) { + function g() public returns (uint) { return 200e-2 wei; } - function h() returns (uint) { + function h() public returns (uint) { return 2.5e1; } - function i() returns (int) { + function i() public returns (int) { return -2e10; } - function j() returns (int) { + function j() public returns (int) { return -200e-2; } - function k() returns (int) { + function k() public returns (int) { return -2.5e1; } } @@ -11339,16 +11339,16 @@ BOOST_AUTO_TEST_CASE(interface_contract) char const* sourceCode = R"( interface I { event A(); - function f() returns (bool); + function f() public returns (bool); function() external payable; } contract A is I { - function f() returns (bool) { + function f() public returns (bool) { return g(); } - function g() returns (bool) { + function g() public returns (bool) { return true; } @@ -11357,7 +11357,7 @@ BOOST_AUTO_TEST_CASE(interface_contract) } contract C { - function f(address _interfaceAddress) returns (bool) { + function f(address _interfaceAddress) public returns (bool) { I i = I(_interfaceAddress); return i.f(); } @@ -11373,12 +11373,12 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly) { char const* sourceCode = R"( contract C { - function f() pure returns (bytes32 ret) { + function f() public pure returns (bytes32 ret) { assembly { ret := keccak256(0, 0) } } - function g() pure returns (bytes32 ret) { + function g() public pure returns (bytes32 ret) { assembly { 0 0 @@ -11405,10 +11405,10 @@ BOOST_AUTO_TEST_CASE(multi_modifiers) x++; _; } - function f1() m1() { + function f1() m1() public { x += 7; } - function f2() m1() { + function f2() m1() public { x += 3; } } @@ -11424,7 +11424,7 @@ BOOST_AUTO_TEST_CASE(inlineasm_empty_let) { char const* sourceCode = R"( contract C { - function f() pure returns (uint a, uint b) { + function f() public pure returns (uint a, uint b) { assembly { let x let y, z @@ -11497,18 +11497,18 @@ BOOST_AUTO_TEST_CASE(function_types_sig) char const* sourceCode = R"( contract C { uint public x; - function f() pure returns (bytes4) { + function f() public pure returns (bytes4) { return this.f.selector; } - function g() returns (bytes4) { + function g() public returns (bytes4) { function () pure external returns (bytes4) fun = this.f; return fun.selector; } - function h() returns (bytes4) { + function h() public returns (bytes4) { function () pure external returns (bytes4) fun = this.f; return fun.selector; } - function i() pure returns (bytes4) { + function i() public pure returns (bytes4) { return this.x.selector; } } @@ -11527,13 +11527,13 @@ BOOST_AUTO_TEST_CASE(constant_string) bytes constant a = "\x03\x01\x02"; bytes constant b = hex"030102"; string constant c = "hello"; - function f() returns (bytes) { + function f() public returns (bytes) { return a; } - function g() returns (bytes) { + function g() public returns (bytes) { return b; } - function h() returns (bytes) { + function h() public returns (bytes) { return bytes(c); } } @@ -11548,18 +11548,18 @@ BOOST_AUTO_TEST_CASE(address_overload_resolution) { char const* sourceCode = R"( contract C { - function balance() returns (uint) { + function balance() public returns (uint) { return 1; } - function transfer(uint amount) returns (uint) { + function transfer(uint amount) public returns (uint) { return amount; } } contract D { - function f() returns (uint) { + function f() public returns (uint) { return (new C()).balance(); } - function g() returns (uint) { + function g() public returns (uint) { return (new C()).transfer(5); } } @@ -11733,7 +11733,7 @@ BOOST_AUTO_TEST_CASE(snark) Pairing.G1Point K; Pairing.G1Point H; } - function f() returns (bool) { + function f() public returns (bool) { Pairing.G1Point memory p1; Pairing.G1Point memory p2; p1.X = 1; p1.Y = 2; @@ -11743,12 +11743,12 @@ BOOST_AUTO_TEST_CASE(snark) return (explict_sum.X == scalar_prod.X && explict_sum.Y == scalar_prod.Y); } - function g() returns (bool) { + function g() public returns (bool) { Pairing.G1Point memory x = Pairing.add(Pairing.P1(), Pairing.negate(Pairing.P1())); // should be zero return (x.X == 0 && x.Y == 0); } - function testMul() returns (bool) { + function testMul() public returns (bool) { Pairing.G1Point memory p; // @TODO The points here are reported to be not well-formed p.X = 14125296762497065001182820090155008161146766663259912659363835465243039841726; @@ -11758,7 +11758,7 @@ BOOST_AUTO_TEST_CASE(snark) p.X == 18256332256630856740336504687838346961237861778318632856900758565550522381207 && p.Y == 6976682127058094634733239494758371323697222088503263230319702770853579280803; } - function pair() returns (bool) { + function pair() public returns (bool) { Pairing.G2Point memory fiveTimesP2 = Pairing.G2Point( [4540444681147253467785307942530223364530218361853237193970751657229138047649, 20954117799226682825035885491234530437475518021362091509513177301640194298072], [11631839690097995216017572651900167465857396346217730511548857041925508482915, 21508930868448350162258892668132814424284302804699005394342512102884055673846] @@ -11828,7 +11828,7 @@ BOOST_AUTO_TEST_CASE(snark) return 0; } event Verified(string); - function verifyTx() returns (bool) { + function verifyTx() public returns (bool) { uint[] memory input = new uint[](9); Proof memory proof; proof.A = Pairing.G1Point(12873740738727497448187997291915224677121726020054032516825496230827252793177, 21804419174137094775122804775419507726154084057848719988004616848382402162497); @@ -11874,17 +11874,17 @@ BOOST_AUTO_TEST_CASE(abi_encode) { char const* sourceCode = R"( contract C { - function f0() returns (bytes) { + function f0() public returns (bytes) { return abi.encode(); } - function f1() returns (bytes) { + function f1() public returns (bytes) { return abi.encode(1, 2); } - function f2() returns (bytes) { + function f2() public returns (bytes) { string memory x = "abc"; return abi.encode(1, x, 2); } - function f3() returns (bytes r) { + function f3() public returns (bytes r) { // test that memory is properly allocated string memory x = "abc"; r = abi.encode(1, x, 2); @@ -11893,7 +11893,7 @@ BOOST_AUTO_TEST_CASE(abi_encode) y[0] = "e"; require(y[0] == "e"); } - function f4() returns (bytes) { + function f4() public returns (bytes) { bytes4 x = "abcd"; return abi.encode(bytes2(x)); } @@ -12242,7 +12242,7 @@ BOOST_AUTO_TEST_CASE(swap_peephole_optimisation) { char const* sourceCode = R"( contract C { - function lt(uint a, uint b) returns (bool c) { + function lt(uint a, uint b) public returns (bool c) { assembly { a b @@ -12251,7 +12251,7 @@ BOOST_AUTO_TEST_CASE(swap_peephole_optimisation) =: c } } - function add(uint a, uint b) returns (uint c) { + function add(uint a, uint b) public returns (uint c) { assembly { a b @@ -12260,7 +12260,7 @@ BOOST_AUTO_TEST_CASE(swap_peephole_optimisation) =: c } } - function div(uint a, uint b) returns (uint c) { + function div(uint a, uint b) public returns (uint c) { assembly { a b @@ -12288,7 +12288,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) return; char const* sourceCode = R"( contract C { - function shl(uint a, uint b) returns (uint c) { + function shl(uint a, uint b) public returns (uint c) { assembly { a b @@ -12296,7 +12296,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) =: c } } - function shr(uint a, uint b) returns (uint c) { + function shr(uint a, uint b) public returns (uint c) { assembly { a b @@ -12304,7 +12304,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) =: c } } - function sar(uint a, uint b) returns (uint c) { + function sar(uint a, uint b) public returns (uint c) { assembly { a b @@ -12334,7 +12334,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) return; char const* sourceCode = R"( contract C { - function shl_1() returns (bool) { + function shl_1() public returns (bool) { uint c; assembly { 1 @@ -12345,7 +12345,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 4); return true; } - function shl_2() returns (bool) { + function shl_2() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff @@ -12356,7 +12356,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe); return true; } - function shl_3() returns (bool) { + function shl_3() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff @@ -12367,7 +12367,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 0); return true; } - function shr_1() returns (bool) { + function shr_1() public returns (bool) { uint c; assembly { 3 @@ -12378,7 +12378,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 1); return true; } - function shr_2() returns (bool) { + function shr_2() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff @@ -12389,7 +12389,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); return true; } - function shr_3() returns (bool) { + function shr_3() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -- cgit v1.2.3 From cbfe3766dbbaa14dce1db208460f319cf778a84b Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 29 Jun 2018 21:09:33 +0200 Subject: Fixes defects in end-to-end tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 71c24796..b4c496a7 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2733,7 +2733,7 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments) m_a *= m_a; } } - contract Derived is Base() public { + contract Derived is Base() { function getA() public returns (uint r) { return m_a; } } )"; @@ -2753,7 +2753,7 @@ BOOST_AUTO_TEST_CASE(function_usage_in_constructor_arguments) } contract Base is BaseBase(BaseBase.g()) { } - contract Derived is Base() public { + contract Derived is Base() { function getA() public returns (uint r) { return m_a; } } )"; @@ -2774,7 +2774,7 @@ BOOST_AUTO_TEST_CASE(virtual_function_usage_in_constructor_arguments) } contract Base is BaseBase(BaseBase.g()) { } - contract Derived is Base() public { + contract Derived is Base() { function getA() public returns (uint r) { return m_a; } function overridden() public returns (uint r) { return 2; } } @@ -9627,7 +9627,7 @@ BOOST_AUTO_TEST_CASE(pass_function_types_internally) function f(uint x) public returns (uint) { return eval(g, x); } - function eval(function(uint) public returns (uint) x, uint a) internal returns (uint) { + function eval(function(uint) internal returns (uint) x, uint a) internal returns (uint) { return x(a); } function g(uint x) public returns (uint) { return x + 1; } @@ -9703,7 +9703,7 @@ BOOST_AUTO_TEST_CASE(store_function) function addTwo(uint x) public returns (uint) { return x + 2; } } contract C { - function (function (uint) external returns (uint)) public returns (uint) ev; + function (function (uint) external returns (uint)) internal returns (uint) ev; function (uint) external returns (uint) x; function store(function(uint) external returns (uint) y) { x = y; @@ -9836,7 +9836,7 @@ BOOST_AUTO_TEST_CASE(function_type_library_internal) { char const* sourceCode = R"( library Utils { - function reduce(uint[] memory array, function(uint, uint) public returns (uint) f, uint init) internal returns (uint) { + function reduce(uint[] memory array, function(uint, uint) internal returns (uint) f, uint init) internal returns (uint) { for (uint i = 0; i < array.length; i++) { init = f(array[i], init); } @@ -9932,7 +9932,7 @@ BOOST_AUTO_TEST_CASE(packed_functions) char const* sourceCode = R"( contract C { // these should take the same slot - function() public returns (uint) a; + function() external returns (uint) a; function() external returns (uint) b; function() external returns (uint) c; function() public returns (uint) d; -- cgit v1.2.3 From 87ab7d18218dd404ed4a06c60b8ed435b0a3c90f Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 2 Jul 2018 11:53:47 +0200 Subject: Fixes compilation errors. --- test/libsolidity/SolidityEndToEndTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b4c496a7..4b1cb99b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3028,7 +3028,7 @@ BOOST_AUTO_TEST_CASE(super_in_constructor) contract A { function f() public returns (uint r) { return 1; } } contract B is A { function f() public returns (uint r) { return super.f() | 2; } } contract C is A { function f() public returns (uint r) { return super.f() | 4; } } - contract D is B, C { uint data; function constructor() public { data = super.f() | 8; } function f() public returns (uint r) { return data; } } + contract D is B, C { uint data; constructor() public { data = super.f() | 8; } function f() public returns (uint r) { return data; } } )"; compileAndRun(sourceCode, 0, "D"); ABI_CHECK(callContractFunction("f()"), encodeArgs(1 | 2 | 4 | 8)); @@ -9932,10 +9932,10 @@ BOOST_AUTO_TEST_CASE(packed_functions) char const* sourceCode = R"( contract C { // these should take the same slot - function() external returns (uint) a; + function() internal returns (uint) a; function() external returns (uint) b; function() external returns (uint) c; - function() public returns (uint) d; + function() internal returns (uint) d; uint8 public x; function set() public { -- cgit v1.2.3 From c8ac8618324d8d167c79a926880b2b5ab853f7f3 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 4 Jul 2018 11:23:51 +0200 Subject: Fix allocation of byte arrays. --- test/libsolidity/SolidityEndToEndTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 4b1cb99b..bc613868 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8060,7 +8060,7 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) // multiple of 32 char const* sourceCode = R"( contract C { - function f() public pure returns (uint d1, uint d2, uint d3) { + function f() public pure returns (uint d1, uint d2, uint d3, uint memsize) { bytes memory b1 = new bytes(31); bytes memory b2 = new bytes(32); bytes memory b3 = new bytes(256); @@ -8069,12 +8069,13 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) d1 := sub(b2, b1) d2 := sub(b3, b2) d3 := sub(b4, b3) + memsize := msize() } } } )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(0x40, 0x40, 0x20 + 256)); + ABI_CHECK(callContractFunction("f()"), encodeArgs(0x40, 0x40, 0x20 + 256, 0x260)); } BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes) -- cgit v1.2.3 From 46d6454b1f47e53c791d71aba26bb953ec667433 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 3 Jul 2018 15:10:39 +0200 Subject: Update tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bc613868..c3e90165 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7878,6 +7878,7 @@ BOOST_AUTO_TEST_CASE(tuples) char const* sourceCode = R"( contract C { uint[] data; + uint[] m_c; function g() internal returns (uint a, uint b, uint[] storage c) { return (1, 2, data); } @@ -7890,7 +7891,7 @@ BOOST_AUTO_TEST_CASE(tuples) uint a; uint b; (a, b) = this.h(); if (a != 5 || b != 6) return 1; - uint[] storage c; + uint[] storage c = m_c; (a, b, c) = g(); if (a != 1 || b != 2 || c[0] != 3) return 2; (a, b) = (b, a); @@ -9610,7 +9611,7 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_through_array) { assembly { mstore(0, 7) return(0, 0x20) } } mutex = 1; // Avoid re-executing this function if we jump somewhere. - function() internal returns (uint)[200] x; + function() internal returns (uint)[200] memory x; x[0](); return 2; } @@ -10138,7 +10139,7 @@ BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage) function() internal returns (uint)[20] x; int mutex; function one() public returns (uint) { - function() internal returns (uint)[20] xmem; + function() internal returns (uint)[20] memory xmem; x = xmem; return 3; } -- cgit v1.2.3 From afa5f528f5912e59abc75fea13c62fb627fc9399 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 10 Jul 2018 12:14:20 +0200 Subject: Update tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bc613868..ce00931b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7895,7 +7895,7 @@ BOOST_AUTO_TEST_CASE(tuples) if (a != 1 || b != 2 || c[0] != 3) return 2; (a, b) = (b, a); if (a != 2 || b != 1) return 3; - (a, , b, ) = (8, 9, 10, 11, 12); + (a, , b, , ) = (8, 9, 10, 11, 12); if (a != 8 || b != 10) return 4; } } @@ -7983,7 +7983,7 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment) if (loc != 3) return 9; if (memArray.length != arrayData.length) return 10; bytes memory memBytes; - (x, memBytes, y[2], ) = (456, s, 789, 101112, 131415); + (x, memBytes, y[2], , ) = (456, s, 789, 101112, 131415); if (x != 456 || memBytes.length != s.length || y[2] != 789) return 11; } } @@ -7992,31 +7992,6 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment) ABI_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), string("abcde")), encodeArgs(u256(0))); } -BOOST_AUTO_TEST_CASE(destructuring_assignment_wildcard) -{ - char const* sourceCode = R"( - contract C { - function f() public returns (uint) { - uint a; - uint b; - uint c; - (a,) = (1,); - if (a != 1) return 1; - (,b) = (2,3,4); - if (b != 4) return 2; - (, c,) = (5,6,7); - if (c != 6) return 3; - (a, b,) = (11, 12, 13); - if (a != 11 || b != 12) return 4; - (, a, b) = (11, 12, 13); - if (a != 12 || b != 13) return 5; - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0))); -} - BOOST_AUTO_TEST_CASE(lone_struct_array_type) { char const* sourceCode = R"( -- cgit v1.2.3 From 6d28278b3f2cc2b41928769d9de46e61799e167c Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 10 Jul 2018 15:53:48 +0200 Subject: Update end-to-end tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index ce00931b..1cab0d65 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7915,7 +7915,7 @@ BOOST_AUTO_TEST_CASE(string_tuples) return (h(), "def"); } function h() public returns (string) { - return ("abc",); + return ("abc"); } } )"; -- cgit v1.2.3 From 9d895e002d0e5e1e3435d03ac82277caa397bbec Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Wed, 4 Jul 2018 14:14:41 +0200 Subject: Added tests and review suggestions --- test/libsolidity/SolidityEndToEndTest.cpp | 154 ++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index fbc6a9c6..52fdfed7 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -523,6 +523,57 @@ BOOST_AUTO_TEST_CASE(do_while_loop_continue) ABI_CHECK(callContractFunction("f()"), encodeArgs(42)); } +BOOST_AUTO_TEST_CASE(do_while_loop_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint x) public pure returns(uint r) { + uint i = 0; + do + { + uint z = x * 2; + if (z < 4) break; + else { + uint k = z + 1; + if (k < 8) { + x++; + continue; + } + } + if (z > 12) return 0; + x++; + i++; + } while (true); + return 42; + } + } + )"; + compileAndRun(sourceCode); + + auto do_while = [](u256 n) -> u256 + { + u256 i = 0; + do + { + u256 z = n * 2; + if (z < 4) break; + else { + u256 k = z + 1; + if (k < 8) { + n++; + continue; + } + } + if (z > 12) return 0; + n++; + i++; + } while (true); + return 42; + }; + + testContractAgainstCppOnRange("f(uint256)", do_while, 0, 12); +} + BOOST_AUTO_TEST_CASE(nested_loops) { // tests that break and continue statements in nested loops jump to the correct place @@ -574,6 +625,109 @@ BOOST_AUTO_TEST_CASE(nested_loops) testContractAgainstCppOnRange("f(uint256)", nested_loops_cpp, 0, 12); } +BOOST_AUTO_TEST_CASE(nested_loops_multiple_local_vars) +{ + // tests that break and continue statements in nested loops jump to the correct place + char const* sourceCode = R"( + contract test { + function f(uint x) returns(uint y) { + while (x > 0) { + uint z = x + 10; + uint k = z + 1; + if (k > 20) break; + if (k > 15) { + x--; + continue; + } + while (k > 10) { + uint m = k - 1; + if (m == 10) return x; + return k; + } + x--; + break; + } + return x; + } + } + )"; + compileAndRun(sourceCode); + + auto nested_loops_cpp = [](u256 n) -> u256 + { + while (n > 0) + { + u256 z = n + 10; + u256 k = z + 1; + if (k > 20) break; + if (k > 15) { + n--; + continue; + } + while (k > 10) + { + u256 m = k - 1; + if (m == 10) return n; + return k; + } + n--; + break; + } + + return n; + }; + + testContractAgainstCppOnRange("f(uint256)", nested_loops_cpp, 0, 12); +} + +BOOST_AUTO_TEST_CASE(for_loop_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint x) public pure returns(uint r) { + for (uint i = 0; i < 12; i++) + { + uint z = x + 1; + if (z < 4) break; + else { + uint k = z * 2; + if (i + k < 10) { + x++; + continue; + } + } + if (z > 8) return 0; + x++; + } + return 42; + } + } + )"; + compileAndRun(sourceCode); + + auto for_loop = [](u256 n) -> u256 + { + for (u256 i = 0; i < 12; i++) + { + u256 z = n + 1; + if (z < 4) break; + else { + u256 k = z * 2; + if (i + k < 10) { + n++; + continue; + } + } + if (z > 8) return 0; + n++; + } + return 42; + }; + + testContractAgainstCppOnRange("f(uint256)", for_loop, 0, 12); +} + + BOOST_AUTO_TEST_CASE(for_loop) { char const* sourceCode = R"( -- cgit v1.2.3 From b750ca9741aba47cc8ba650a04dd620725ed4610 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Fri, 6 Jul 2018 09:56:27 +0200 Subject: Add more tests and assertions --- test/libsolidity/SolidityEndToEndTest.cpp | 154 +++++++++++++++++++++++++++++- 1 file changed, 153 insertions(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 52fdfed7..ae92810d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -523,6 +523,45 @@ BOOST_AUTO_TEST_CASE(do_while_loop_continue) ABI_CHECK(callContractFunction("f()"), encodeArgs(42)); } +BOOST_AUTO_TEST_CASE(array_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint256[] seq) public pure returns (uint256) { + uint i = 0; + uint sum = 0; + while (i < seq.length) + { + uint idx = i; + if (idx >= 10) break; + uint x = seq[idx]; + if (x >= 1000) { + uint n = i + 1; + i = n; + continue; + } + else { + uint y = sum + x; + sum = y; + } + if (sum >= 500) return sum; + i++; + } + return sum; + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("f(uint256[])", 32, 3, u256(1000), u256(1), u256(2)), encodeArgs(3)); + ABI_CHECK(callContractFunction("f(uint256[])", 32, 3, u256(100), u256(500), u256(300)), encodeArgs(600)); + ABI_CHECK(callContractFunction( + "f(uint256[])", 32, 11, + u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8), u256(9), u256(10), u256(111) + ), encodeArgs(55)); +} + + BOOST_AUTO_TEST_CASE(do_while_loop_multiple_local_vars) { char const* sourceCode = R"( @@ -628,21 +667,30 @@ BOOST_AUTO_TEST_CASE(nested_loops) BOOST_AUTO_TEST_CASE(nested_loops_multiple_local_vars) { // tests that break and continue statements in nested loops jump to the correct place + // and free local variables properly char const* sourceCode = R"( contract test { function f(uint x) returns(uint y) { while (x > 0) { uint z = x + 10; uint k = z + 1; - if (k > 20) break; + if (k > 20) { + break; + uint p = 100; + k += p; + } if (k > 15) { x--; continue; + uint t = 1000; + x += t; } while (k > 10) { uint m = k - 1; if (m == 10) return x; return k; + uint h = 10000; + z += h; } x--; break; @@ -727,6 +775,66 @@ BOOST_AUTO_TEST_CASE(for_loop_multiple_local_vars) testContractAgainstCppOnRange("f(uint256)", for_loop, 0, 12); } +BOOST_AUTO_TEST_CASE(nested_for_loop_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint x) public pure returns(uint r) { + for (uint i = 0; i < 5; i++) + { + uint z = x + 1; + if (z < 3) { + break; + uint p = z + 2; + } + for (uint j = 0; j < 5; j++) + { + uint k = z * 2; + if (j + k < 8) { + x++; + continue; + uint t = z * 3; + } + x++; + if (x > 20) { + return 84; + uint h = x + 42; + } + } + if (x > 30) { + return 42; + uint b = 0xcafe; + } + } + return 42; + } + } + )"; + compileAndRun(sourceCode); + + auto for_loop = [](u256 n) -> u256 + { + for (u256 i = 0; i < 5; i++) + { + u256 z = n + 1; + if (z < 3) break; + for (u256 j = 0; j < 5; j++) + { + u256 k = z * 2; + if (j + k < 8) { + n++; + continue; + } + n++; + if (n > 20) return 84; + } + if (n > 30) return 42; + } + return 42; + }; + + testContractAgainstCppOnRange("f(uint256)", for_loop, 0, 12); +} BOOST_AUTO_TEST_CASE(for_loop) { @@ -9396,6 +9504,50 @@ BOOST_AUTO_TEST_CASE(break_in_modifier) ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(1))); } +BOOST_AUTO_TEST_CASE(continue_in_modifier) +{ + char const* sourceCode = R"( + contract C { + uint public x; + modifier run() { + for (uint i = 0; i < 10; i++) { + if (i % 2 == 1) continue; + _; + } + } + function f() run { + x++; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f()"), encodeArgs()); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(5))); +} + +BOOST_AUTO_TEST_CASE(return_in_modifier) +{ + char const* sourceCode = R"( + contract C { + uint public x; + modifier run() { + for (uint i = 1; i < 10; i++) { + if (i == 5) return; + _; + } + } + function f() run { + x++; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f()"), encodeArgs()); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(4))); +} + BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers) { char const* sourceCode = R"( -- cgit v1.2.3 From 0c5e0e0d59dc55fcfe5b95a8c649a7a769ad3400 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Tue, 10 Jul 2018 18:39:26 +0200 Subject: Added assertion and tests suggestions --- test/libsolidity/SolidityEndToEndTest.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index ae92810d..d1466ea8 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -802,7 +802,7 @@ BOOST_AUTO_TEST_CASE(nested_for_loop_multiple_local_vars) } } if (x > 30) { - return 42; + return 42; uint b = 0xcafe; } } @@ -9494,7 +9494,9 @@ BOOST_AUTO_TEST_CASE(break_in_modifier) } } function f() run { - x++; + uint k = x; + uint t = k + 1; + x = t; } } )"; @@ -9516,7 +9518,9 @@ BOOST_AUTO_TEST_CASE(continue_in_modifier) } } function f() run { - x++; + uint k = x; + uint t = k + 1; + x = t; } } )"; @@ -9538,7 +9542,9 @@ BOOST_AUTO_TEST_CASE(return_in_modifier) } } function f() run { - x++; + uint k = x; + uint t = k + 1; + x = t; } } )"; @@ -9560,7 +9566,9 @@ BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers) } } function f() run { - x++; + uint k = x; + uint t = k + 1; + x = t; } } )"; -- cgit v1.2.3 From a18a475b1a6ba1ebcf235f322dec0e7ff3d3dcb0 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Tue, 10 Jul 2018 19:08:05 +0200 Subject: Change test from public to external --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index d1466ea8..29fc808b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -527,7 +527,7 @@ BOOST_AUTO_TEST_CASE(array_multiple_local_vars) { char const* sourceCode = R"( contract test { - function f(uint256[] seq) public pure returns (uint256) { + function f(uint256[] seq) external pure returns (uint256) { uint i = 0; uint sum = 0; while (i < seq.length) -- cgit v1.2.3 From 4116704442aff035acb5b707c6b211ac1f5524fe Mon Sep 17 00:00:00 2001 From: Cryptomental Date: Tue, 10 Jul 2018 09:18:19 +0200 Subject: test: Fix typos. Fix typos using codespell. Refs: #4442 --- test/libsolidity/SolidityEndToEndTest.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 822b8192..c6c11df5 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -6387,9 +6387,9 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" ); - vector lengthes{0, 30, 32, 63, 64, 65, 210, 300}; - for (auto l1: lengthes) - for (auto l2: lengthes) + vector lengths{0, 30, 32, 63, 64, 65, 210, 300}; + for (auto l1: lengths) + for (auto l2: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6456,9 +6456,9 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"); - vector lengthes{0, 31, 64, 65}; - for (auto l1: lengthes) - for (auto l2: lengthes) + vector lengths{0, 31, 64, 65}; + for (auto l1: lengths) + for (auto l2: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6497,8 +6497,8 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) )"; compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - vector lengthes{0, 31, 64, 65}; - for (auto l1: lengthes) + vector lengths{0, 31, 64, 65}; + for (auto l1: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes args1 = encodeArgs(u256(0x20)) + dyn1; -- cgit v1.2.3 From 38026d311443f5f0f8fb23a928839136b56c97bd Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Wed, 4 Jul 2018 16:29:52 +0200 Subject: Use STATICCALL for view and pure --- test/libsolidity/SolidityEndToEndTest.cpp | 38 ++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3cd3b9b7..0f314c2a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -12173,7 +12173,6 @@ BOOST_AUTO_TEST_CASE(abi_encode_call) BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure) { char const* sourceCode = R"( - pragma experimental "v0.5.0"; contract C { uint x; function f() public returns (uint) { @@ -12408,6 +12407,43 @@ BOOST_AUTO_TEST_CASE(senders_balance) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(27))); } +BOOST_AUTO_TEST_CASE(write_storage_external) +{ + char const* sourceCode = R"( + contract C { + uint public x; + function f(uint y) public payable { + x = y; + } + function g(uint y) external { + x = y; + } + function h() public { + this.g(12); + } + } + contract D { + C c = new C(); + function f() public payable returns (uint) { + c.g(3); + return c.x(); + } + function g() public returns (uint) { + c.g(8); + return c.x(); + } + function h() public returns (uint) { + c.h(); + return c.x(); + } + } + )"; + compileAndRun(sourceCode, 0, "D"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(8)); + ABI_CHECK(callContractFunction("h()"), encodeArgs(12)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 8b4b8bdbae2f67445178ebe3b12d23bb4f46f9d2 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 11 Jul 2018 13:23:33 +0200 Subject: Update test wrt requiring storage locations. --- test/libsolidity/SolidityEndToEndTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3cd3b9b7..dd20756f 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1273,7 +1273,7 @@ BOOST_AUTO_TEST_CASE(struct_reference) function set() public { data.z = 2; mapping(uint8 => s2) map = data.recursive; - s2 inner = map[0]; + s2 storage inner = map[0]; inner.z = 3; inner.recursive[0].z = inner.recursive[1].z + 1; } @@ -6112,7 +6112,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) } function assign() public returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) { - testStruct x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2 + testStruct storage x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2 data2 = data1; // should copy data. data2.m_value == 2 ret_local = x.m_value; // = 2 @@ -6144,7 +6144,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) } function deleteMember() public returns (uint ret_value) { - testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 + testStruct storage x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 x.m_value = 4; delete x.m_value; ret_value = data1.m_value; @@ -8611,7 +8611,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_via_pointer) Data public a; uint public separator2; function f() public returns (bool) { - Data x = a; + Data storage x = a; uint off; assembly { sstore(x_slot, 7) -- cgit v1.2.3 From 62645d530253c365ac09979135e9037f2bde2934 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 4 Jul 2018 18:35:01 +0200 Subject: Update tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index ad425d98..bee83007 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8091,17 +8091,36 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration) function g() public returns (uint a, uint b, uint c) { a = 1; b = 2; c = 3; } - function f() public returns (bool) { + function h() public returns (uint a, uint b, uint c, uint d) { + a = 1; b = 2; c = 3; d = 4; + } + function f1() public returns (bool) { (uint x, uint y, uint z) = g(); if (x != 1 || y != 2 || z != 3) return false; (, uint a,) = g(); if (a != 2) return false; - (uint b,) = g(); + (uint b, , ) = g(); if (b != 1) return false; - (, uint c) = g(); + (, , uint c) = g(); if (c != 3) return false; return true; } + function f2() public returns (bool) { + (uint a1, , uint a3, ) = h(); + if (a1 != 1 || a3 != 3) return false; + (uint b1, uint b2, , ) = h(); + if (b1 != 1 || b2 != 2) return false; + (, uint c2, uint c3, ) = h(); + if (c2 != 2 || c3 != 3) return false; + (, , uint d3, uint d4) = h(); + if (d3 != 3 || d4 != 4) return false; + (uint e1, , uint e3, uint e4) = h(); + if (e1 != 1 || e3 != 3 || e4 != 4) return false; + return true; + } + function f() public returns (bool) { + return f1() && f2(); + } } )"; compileAndRun(sourceCode); -- cgit v1.2.3 From 396bf118585d213a397be990b5118a47ac4753c1 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Thu, 12 Jul 2018 14:57:42 +0200 Subject: enforce interface-functions to be external-declared - libsolidity: Enforce interface-functions must be external-declared. - Changelog adapted to reflect changes wrt. functions in interfaces. - test: Adjustments according to prior interface-function changes. - tests: Adapting SolidityEndToEndTest to interface-function change. - docs: Adapted documentation to interface-function change. --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bee83007..1427826e 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -11649,7 +11649,7 @@ BOOST_AUTO_TEST_CASE(interface_contract) char const* sourceCode = R"( interface I { event A(); - function f() public returns (bool); + function f() external returns (bool); function() external payable; } -- cgit v1.2.3 From f48d01d0660747b0071e9d82a0261ce15bcc4c35 Mon Sep 17 00:00:00 2001 From: Chase McDermott Date: Wed, 11 Jul 2018 23:18:50 -0500 Subject: Added default data locations to parameters for end to end tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 318 +++++++++++++++--------------- 1 file changed, 159 insertions(+), 159 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bee83007..f76f1196 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2706,7 +2706,7 @@ BOOST_AUTO_TEST_CASE(constructor_with_long_arguments) string public a; string public b; - constructor(string _a, string _b) public { + constructor(string memory _a, string memory _b) public { a = _a; b = _b; } @@ -2734,7 +2734,7 @@ BOOST_AUTO_TEST_CASE(constructor_static_array_argument) uint public a; uint[3] public b; - constructor(uint _a, uint[3] _b) public { + constructor(uint _a, uint[3] memory _b) public { a = _a; b = _b; } @@ -2754,7 +2754,7 @@ BOOST_AUTO_TEST_CASE(constant_var_as_array_length) uint constant LEN = 3; uint[LEN] public a; - constructor(uint[LEN] _a) public { + constructor(uint[LEN] memory _a) public { a = _a; } } @@ -5022,22 +5022,22 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi) uint16[] y; uint24[] z; uint24[][] w; - function test1() public returns (uint8[]) { + function test1() public returns (uint8[] memory) { for (uint i = 0; i < 101; ++i) x.push(uint8(i)); return x; } - function test2() public returns (uint16[]) { + function test2() public returns (uint16[] memory) { for (uint i = 0; i < 101; ++i) y.push(uint16(i)); return y; } - function test3() public returns (uint24[]) { + function test3() public returns (uint24[] memory) { for (uint i = 0; i < 101; ++i) z.push(uint24(i)); return z; } - function test4() public returns (uint24[][]) { + function test4() public returns (uint24[][] memory) { w.length = 5; for (uint i = 0; i < 5; ++i) for (uint j = 0; j < 101; ++j) @@ -5070,7 +5070,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi_signed) char const* sourceCode = R"( contract c { int16[] x; - function test() public returns (int16[]) { + function test() public returns (int16[] memory) { x.push(int16(-1)); x.push(int16(-1)); x.push(int16(8)); @@ -5448,7 +5448,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_masking_long) char const* sourceCode = R"( contract c { bytes data; - function test() public returns (bytes) { + function test() public returns (bytes memory) { for (uint i = 0; i < 34; i++) data.push(3); data.pop(); @@ -5470,7 +5470,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_copy_long) char const* sourceCode = R"( contract c { bytes data; - function test() public returns (bytes) { + function test() public returns (bytes memory) { for (uint i = 0; i < 33; i++) data.push(3); for (uint j = 0; j < 4; j++) @@ -6601,10 +6601,10 @@ BOOST_AUTO_TEST_CASE(return_string) function set(string _s) external { s = _s; } - function get1() public returns (string r) { + function get1() public returns (string memory r) { return s; } - function get2() public returns (string r) { + function get2() public returns (string memory r) { r = s; } } @@ -6629,7 +6629,7 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) s2 = _s2; return x; } - function get() public returns (string r1, string r2) { + function get() public returns (string memory r1, string memory r2) { r1 = s1; r2 = s2; } @@ -6702,12 +6702,12 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) contract Main { string public s1; string public s2; - function set(string _s1, uint x, string _s2) public returns (uint) { + function set(string memory _s1, uint x, string memory _s2) public returns (uint) { s1 = _s1; s2 = _s2; return x; } - function setIndirectFromMemory(string _s1, uint x, string _s2) public returns (uint) { + function setIndirectFromMemory(string memory _s1, uint x, string memory _s2) public returns (uint) { return this.set(_s1, x, _s2); } function setIndirectFromCalldata(string _s1, uint x, string _s2) external returns (uint) { @@ -6747,11 +6747,11 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) char const* sourceCode = R"( contract Main { bytes s1; - function doSet(bytes _s1) public returns (bytes _r1) { + function doSet(bytes memory _s1) public returns (bytes memory _r1) { s1 = _s1; _r1 = s1; } - function set(bytes _s1) external returns (uint _r, bytes _r1) { + function set(bytes _s1) external returns (uint _r, bytes memory _r1) { _r1 = doSet(_s1); _r = _r1.length; } @@ -6775,15 +6775,15 @@ BOOST_AUTO_TEST_CASE(bytes_index_access_memory) { char const* sourceCode = R"( contract Main { - function f(bytes _s1, uint i1, uint i2, uint i3) public returns (byte c1, byte c2, byte c3) { + function f(bytes memory _s1, uint i1, uint i2, uint i3) public returns (byte c1, byte c2, byte c3) { c1 = _s1[i1]; c2 = intern(_s1, i2); c3 = internIndirect(_s1)[i3]; } - function intern(bytes _s1, uint i) public returns (byte c) { + function intern(bytes memory _s1, uint i) public returns (byte c) { return _s1[i]; } - function internIndirect(bytes _s1) public returns (bytes) { + function internIndirect(bytes memory _s1) public returns (bytes memory) { return _s1; } } @@ -6804,7 +6804,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_unpacker) contract Test { uint public m_x; bytes public m_s; - constructor(uint x, bytes s) public { + constructor(uint x, bytes memory s) public { m_x = x; m_s = s; } @@ -6825,7 +6825,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) contract Base { uint public m_x; bytes m_s; - constructor(uint x, bytes s) public { + constructor(uint x, bytes memory s) public { m_x = x; m_s = s; } @@ -6834,13 +6834,13 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) } } contract Main is Base { - constructor(bytes s, uint x) Base(x, f(s)) public {} - function f(bytes s) public returns (bytes) { + constructor(bytes memory s, uint x) Base(x, f(s)) public {} + function f(bytes memory s) public returns (bytes memory) { return s; } } contract Creator { - function f(uint x, bytes s) public returns (uint r, byte ch) { + function f(uint x, bytes memory s) public returns (uint r, byte ch) { Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); @@ -6864,7 +6864,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors) contract Base { uint public m_x; address[] m_s; - constructor(uint x, address[] s) public { + constructor(uint x, address[] memory s) public { m_x = x; m_s = s; } @@ -6873,13 +6873,13 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors) } } contract Main is Base { - constructor(address[] s, uint x) Base(x, f(s)) public {} - function f(address[] s) public returns (address[]) { + constructor(address[] memory s, uint x) Base(x, f(s)) public {} + function f(address[] memory s) public returns (address[] memory) { return s; } } contract Creator { - function f(uint x, address[] s) public returns (uint r, address ch) { + function f(uint x, address[] memory s) public returns (uint r, address ch) { Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); @@ -6903,7 +6903,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_in_constructors) contract Creator { uint public r; address public ch; - constructor(address[3] s, uint x) public { + constructor(address[3] memory s, uint x) public { r = x; ch = s[2]; } @@ -6919,11 +6919,11 @@ BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage) char const* sourceCode = R"( contract Test { uint24[] public data; - function set(uint24[] _data) public returns (uint) { + function set(uint24[] memory _data) public returns (uint) { data = _data; return data.length; } - function get() public returns (uint24[]) { + function get() public returns (uint24[] memory) { return data; } } @@ -6946,11 +6946,11 @@ BOOST_AUTO_TEST_CASE(arrays_complex_from_and_to_storage) char const* sourceCode = R"( contract Test { uint24[3][] public data; - function set(uint24[3][] _data) public returns (uint) { + function set(uint24[3][] memory _data) public returns (uint) { data = _data; return data.length; } - function get() public returns (uint24[3][]) { + function get() public returns (uint24[3][] memory) { return data; } } @@ -6972,7 +6972,7 @@ BOOST_AUTO_TEST_CASE(arrays_complex_memory_index_access) { char const* sourceCode = R"( contract Test { - function set(uint24[3][] _data, uint a, uint b) public returns (uint l, uint e) { + function set(uint24[3][] memory _data, uint a, uint b) public returns (uint l, uint e) { l = _data.length; e = _data[a][b]; } @@ -6995,7 +6995,7 @@ BOOST_AUTO_TEST_CASE(bytes_memory_index_access) { char const* sourceCode = R"( contract Test { - function set(bytes _data, uint i) public returns (uint l, byte c) { + function set(bytes memory _data, uint i) public returns (uint l, byte c) { l = _data.length; c = _data[i]; } @@ -7071,13 +7071,13 @@ BOOST_AUTO_TEST_CASE(memory_types_initialisation) char const* sourceCode = R"( contract Test { mapping(uint=>uint) data; - function stat() public returns (uint[5]) + function stat() public returns (uint[5] memory) { data[2] = 3; // make sure to use some memory } - function dyn() public returns (uint[]) { stat(); } - function nested() public returns (uint[3][]) { stat(); } - function nestedStat() public returns (uint[3][7]) { stat(); } + function dyn() public returns (uint[] memory) { stat(); } + function nested() public returns (uint[3][] memory) { stat(); } + function nestedStat() public returns (uint[3][7] memory) { stat(); } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -7092,7 +7092,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_delete) { char const* sourceCode = R"( contract Test { - function del() public returns (uint24[3][4]) { + function del() public returns (uint24[3][4] memory) { uint24[3][4] memory x; for (uint24 i = 0; i < x.length; i ++) for (uint24 j = 0; j < x[i].length; j ++) @@ -7121,11 +7121,11 @@ BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write) { char const* sourceCode = R"( contract Test { - function set(uint24[3][4] x) { + function set(uint24[3][4] memory x) { x[2][2] = 1; x[3][2] = 7; } - function f() public returns (uint24[3][4]){ + function f() public returns (uint24[3][4] memory){ uint24[3][4] memory data; set(data); return data; @@ -7145,12 +7145,12 @@ BOOST_AUTO_TEST_CASE(memory_arrays_dynamic_index_access_write) char const* sourceCode = R"( contract Test { uint24[3][][4] data; - function set(uint24[3][][4] x) internal returns (uint24[3][][4]) { + function set(uint24[3][][4] memory x) internal returns (uint24[3][][4] memory) { x[1][2][2] = 1; x[1][3][2] = 7; return x; } - function f() public returns (uint24[3][]) { + function f() public returns (uint24[3][] memory) { data[1].length = 4; return set(data)[1]; } @@ -7220,12 +7220,12 @@ BOOST_AUTO_TEST_CASE(memory_structs_as_function_args) y = extract(data, 1); z = extract(data, 2); } - function extract(S s, uint which) internal returns (uint x) { + function extract(S memory s, uint which) internal returns (uint x) { if (which == 0) return s.x; else if (which == 1) return s.y; else return s.z; } - function combine(uint8 x, uint16 y, uint z) internal returns (S s) { + function combine(uint8 x, uint16 y, uint z) internal returns (S memory s) { s.x = x; s.y = y; s.z = z; @@ -7250,13 +7250,13 @@ BOOST_AUTO_TEST_CASE(memory_structs_nested) y = extract(d, 2); z = extract(d, 3); } - function extract(X s, uint which) internal returns (uint x) { + function extract(X memory s, uint which) internal returns (uint x) { if (which == 0) return s.x; else if (which == 1) return s.s.x; else if (which == 2) return s.s.y; else return s.s.z; } - function combine(uint8 a, uint8 x, uint16 y, uint z) internal returns (X s) { + function combine(uint8 a, uint8 x, uint16 y, uint z) internal returns (X memory s) { s.x = a; s.s.x = x; s.s.y = y; @@ -7328,7 +7328,7 @@ BOOST_AUTO_TEST_CASE(struct_constructor_nested) s2[1] = 9; s = S(1, s2, X(4, 5)); } - function get() public returns (uint s1, uint[3] s2, uint x1, uint x2) + function get() public returns (uint s1, uint[3] memory s2, uint x1, uint x2) { s1 = s.s1; s2 = s.s2; @@ -7367,7 +7367,7 @@ BOOST_AUTO_TEST_CASE(literal_strings) string public medium; string public short; string public empty; - function f() public returns (string) { + function f() public returns (string memory) { long = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; medium = "01234567890123456789012345678901234567890123456789012345678901234567890123456789"; short = "123"; @@ -7434,7 +7434,7 @@ BOOST_AUTO_TEST_CASE(string_bytes_conversion) contract Test { string s; bytes b; - function f(string _s, uint n) public returns (byte) { + function f(string memory _s, uint n) public returns (byte) { b = bytes(_s); s = string(b); return bytes(s)[n]; @@ -7458,8 +7458,8 @@ BOOST_AUTO_TEST_CASE(string_as_mapping_key) char const* sourceCode = R"( contract Test { mapping(string => uint) data; - function set(string _s, uint _v) { data[_s] = _v; } - function get(string _s) public returns (uint) { return data[_s]; } + function set(string memory _s, uint _v) { data[_s] = _v; } + function get(string memory _s) public returns (uint) { return data[_s]; } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -7636,8 +7636,8 @@ BOOST_AUTO_TEST_CASE(constant_string_literal) bytes32 bb = b; } function getB() public returns (bytes32) { return b; } - function getX() public returns (string) { return x; } - function getX2() public returns (string r) { r = x; } + function getX() public returns (string memory) { return x; } + function getX2() public returns (string memory r) { r = x; } function unused() public returns (uint) { "unusedunusedunusedunusedunusedunusedunusedunusedunusedunusedunusedunused"; return 2; @@ -7691,7 +7691,7 @@ BOOST_AUTO_TEST_CASE(library_function_external) char const* sourceCode = R"( library Lib { function m(bytes b) external pure returns (byte) { return b[2]; } } contract Test { - function f(bytes b) public pure returns (byte) { + function f(bytes memory b) public pure returns (byte) { return Lib.m(b); } } @@ -7779,7 +7779,7 @@ BOOST_AUTO_TEST_CASE(strings_in_struct) { return bug.third; } - function getLast() public returns (string) + function getLast() public returns (string memory) { return bug.last; } @@ -7797,7 +7797,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) { char const* sourceCode = R"( contract A { - function f(uint16 input) public pure returns (uint16[5] arr) + function f(uint16 input) public pure returns (uint16[5] memory arr) { arr[0] = input; arr[1] = ++input; @@ -7807,7 +7807,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) } } contract B { - function f() public returns (uint16[5] res, uint16[5] res2) + function f() public returns (uint16[5] memory res, uint16[5] memory res2) { A a = new A(); res = a.f(2); @@ -8039,7 +8039,7 @@ BOOST_AUTO_TEST_CASE(calldata_offset) { address[] _arr; string public last = "nd"; - constructor(address[] guardians) + constructor(address[] memory guardians) { _arr = guardians; } @@ -8190,13 +8190,13 @@ BOOST_AUTO_TEST_CASE(string_tuples) { char const* sourceCode = R"( contract C { - function f() public returns (string, uint) { + function f() public returns (string memory, uint) { return ("abc", 8); } - function g() public returns (string, string) { + function g() public returns (string memory, string memory) { return (h(), "def"); } - function h() public returns (string) { + function h() public returns (string memory) { return ("abc"); } } @@ -8243,13 +8243,13 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment) bytes data; uint[] y; uint[] arrayData; - function returnsArray() public returns (uint[]) { + function returnsArray() public returns (uint[] memory) { arrayData.length = 9; arrayData[2] = 5; arrayData[7] = 4; return arrayData; } - function f(bytes s) public returns (uint) { + function f(bytes memory s) public returns (uint) { uint loc; uint[] memory memArray; (loc, x, y, data, arrayData[3]) = (8, 4, returnsArray(), s, 2); @@ -8396,7 +8396,7 @@ BOOST_AUTO_TEST_CASE(memory_overwrite) { char const* sourceCode = R"( contract C { - function f() public returns (bytes x) { + function f() public returns (bytes memory x) { x = "12345"; x[3] = 0x61; x[0] = 0x62; @@ -8628,7 +8628,7 @@ BOOST_AUTO_TEST_CASE(inline_array_storage_to_memory_conversion_strings) char const* sourceCode = R"( contract C { string s = "doh"; - function f() public returns (string, string) { + function f() public returns (string memory, string memory) { string memory t = "ray"; string[3] memory x = [s, t, "mi"]; return (x[1], x[2]); @@ -8643,7 +8643,7 @@ BOOST_AUTO_TEST_CASE(inline_array_strings_from_document) { char const* sourceCode = R"( contract C { - function f(uint i) public returns (string) { + function f(uint i) public returns (string memory) { string[4] memory x = ["This", "is", "an", "array"]; return (x[i]); } @@ -8690,7 +8690,7 @@ BOOST_AUTO_TEST_CASE(inline_array_index_access_strings) char const* sourceCode = R"( contract C { string public tester; - function f() public returns (string) { + function f() public returns (string memory) { return (["abc", "def", "g"][0]); } function test() public { @@ -8708,7 +8708,7 @@ BOOST_AUTO_TEST_CASE(inline_array_return) char const* sourceCode = R"( contract C { uint8[] tester; - function f() public returns (uint8[5]) { + function f() public returns (uint8[5] memory) { return ([1,2,3,4,5]); } function test() public returns (uint8, uint8, uint8, uint8, uint8) { @@ -8740,7 +8740,7 @@ BOOST_AUTO_TEST_CASE(inline_long_string_return) { char const* sourceCode = R"( contract C { - function f() public returns (string) { + function f() public returns (string memory) { return (["somethingShort", "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"][1]); } } @@ -8817,7 +8817,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_memory_access) { char const* sourceCode = R"( contract C { - function test() public returns (bytes) { + function test() public returns (bytes memory) { bytes memory x = new bytes(5); for (uint i = 0; i < x.length; ++i) x[i] = byte(uint8(i + 1)); @@ -9176,7 +9176,7 @@ BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) // Test for a bug where higher order bits cleanup was not done for array index access. char const* sourceCode = R"( contract C { - function f(uint x) public returns (uint[256] r){ + function f(uint x) public returns (uint[256] memory r){ r[uint8(x)] = 2; } } @@ -9216,7 +9216,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function) // and retain the same memory context (i.e. are pulled into the caller's code) char const* sourceCode = R"( library L { - function f(uint[] _data) internal { + function f(uint[] memory _data) internal { _data[3] = 2; } } @@ -9241,10 +9241,10 @@ BOOST_AUTO_TEST_CASE(internal_library_function_calling_private) // also has to be pulled into the caller's code) char const* sourceCode = R"( library L { - function g(uint[] _data) private { + function g(uint[] memory _data) private { _data[3] = 2; } - function f(uint[] _data) internal { + function f(uint[] memory _data) internal { g(_data); } } @@ -9267,7 +9267,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_bound) char const* sourceCode = R"( library L { struct S { uint[] data; } - function f(S _s) internal { + function f(S memory _s) internal { _s.data[3] = 2; } } @@ -9292,7 +9292,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_return_var_size) char const* sourceCode = R"( library L { struct S { uint[] data; } - function f(S _s) internal returns (uint[]) { + function f(S memory _s) internal returns (uint[] memory) { _s.data[3] = 2; return _s.data; } @@ -9373,7 +9373,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types) // The EVM cannot provide access to dynamically-sized return values, so we have to skip them. char const* sourceCode = R"( contract C { - function f() public returns (uint, uint[], uint) { + function f() public returns (uint, uint[] memory, uint) { return (7, new uint[](2), 8); } function g() public returns (uint, uint) { @@ -9852,7 +9852,7 @@ BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call) // Tests that this also survives the optimizer. char const* sourceCode = R"( contract C { - function f() public returns (uint[200]) {} + function f() public returns (uint[200] memory) {} } contract D { function f(C c) public returns (uint) { c.f(); return 7; } @@ -10157,7 +10157,7 @@ BOOST_AUTO_TEST_CASE(function_type_library_internal) } } contract C { - function f(uint[] x) public returns (uint) { + function f(uint[] memory x) public returns (uint) { return Utils.reduce(x, Utils.sum, 0); } } @@ -10386,8 +10386,8 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls) { char const* sourceCode = R"( contract D { - function f(function() external returns (function() external returns (uint))[] x) - public returns (function() external returns (uint)[3] r) + function f(function() external returns (function() external returns (uint))[] memory x) + public returns (function() external returns (uint)[3] memory r) { r[0] = x[0](); r[1] = x[1](); @@ -11344,7 +11344,7 @@ BOOST_AUTO_TEST_CASE(revert_with_cause) } contract C { D d = new D(); - function forward(address target, bytes data) internal returns (bool success, bytes retval) { + function forward(address target, bytes memory data) internal returns (bool success, bytes memory retval) { uint retsize; assembly { success := call(not(0), target, 0, add(data, 0x20), mload(data), 0, 0) @@ -11355,19 +11355,19 @@ BOOST_AUTO_TEST_CASE(revert_with_cause) returndatacopy(add(retval, 0x20), 0, returndatasize()) } } - function f() public returns (bool, bytes) { + function f() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function g() public returns (bool, bytes) { + function g() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function h() public returns (bool, bytes) { + function h() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function i() public returns (bool, bytes) { + function i() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function j() public returns (bool, bytes) { + function j() public returns (bool, bytes memory) { return forward(address(d), msg.data); } } @@ -11399,7 +11399,7 @@ BOOST_AUTO_TEST_CASE(require_with_message) bool flagCopy = flag; require(flagCopy == false, internalFun()); } - function internalFun() public returns (string) { + function internalFun() public returns (string memory) { flag = true; return "only on second run"; } @@ -11416,7 +11416,7 @@ BOOST_AUTO_TEST_CASE(require_with_message) } contract C { D d = new D(); - function forward(address target, bytes data) internal returns (bool success, bytes retval) { + function forward(address target, bytes memory data) internal returns (bool success, bytes memory retval) { uint retsize; assembly { success := call(not(0), target, 0, add(data, 0x20), mload(data), 0, 0) @@ -11427,19 +11427,19 @@ BOOST_AUTO_TEST_CASE(require_with_message) returndatacopy(add(retval, 0x20), 0, returndatasize()) } } - function f(uint x) public returns (bool, bytes) { + function f(uint x) public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function g() public returns (bool, bytes) { + function g() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function h() public returns (bool, bytes) { + function h() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function i() public returns (bool, bytes) { + function i() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function j() public returns (bool, bytes) { + function j() public returns (bool, bytes memory) { return forward(address(d), msg.data); } } @@ -11469,7 +11469,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages) } contract C { D d = new D(); - function forward(address target, bytes data) internal returns (bool success, bytes retval) { + function forward(address target, bytes memory data) internal returns (bool success, bytes memory retval) { uint retsize; assembly { success := call(not(0), target, 0, add(data, 0x20), mload(data), 0, 0) @@ -11480,10 +11480,10 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages) returndatacopy(add(retval, 0x20), 0, returndatasize()) } } - function f() public returns (bool, bytes) { + function f() public returns (bool, bytes memory) { return forward(address(d), msg.data); } - function g() public returns (bool, bytes) { + function g() public returns (bool, bytes memory) { return forward(address(d), msg.data); } } @@ -11508,7 +11508,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_transfer) } contract C { D d = new D(); - function forward(address target, bytes data) internal returns (bool success, bytes retval) { + function forward(address target, bytes memory data) internal returns (bool success, bytes memory retval) { uint retsize; assembly { success := call(not(0), target, 0, add(data, 0x20), mload(data), 0, 0) @@ -11519,7 +11519,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_transfer) returndatacopy(add(retval, 0x20), 0, returndatasize()) } } - function f() public returns (bool, bytes) { + function f() public returns (bool, bytes memory) { return forward(address(d), msg.data); } } @@ -11545,7 +11545,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_create) } contract C { D d = new D(); - function forward(address target, bytes data) internal returns (bool success, bytes retval) { + function forward(address target, bytes memory data) internal returns (bool success, bytes memory retval) { uint retsize; assembly { success := call(not(0), target, 0, add(data, 0x20), mload(data), 0, 0) @@ -11556,7 +11556,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_create) returndatacopy(add(retval, 0x20), 0, returndatasize()) } } - function f() public returns (bool, bytes) { + function f() public returns (bool, bytes memory) { return forward(address(d), msg.data); } } @@ -11580,9 +11580,9 @@ BOOST_AUTO_TEST_CASE(negative_stack_height) bool Aboolc; bool exists; } - function nredit(uint startindex) public pure returns(uint[500] CIDs, uint[500] dates, uint[500] RIDs, bool[500] Cboolas, uint[500] amounts){} - function return500InvoicesByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] AIDs, bool[500] Aboolas, uint[500] dates, bytes32[3][500] Abytesas, bytes32[3][500] bytesbs, bytes32[2][500] bytescs, uint[500] amounts, bool[500] Aboolbs, bool[500] Aboolcs){} - function return500PaymentsByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] BIDs, uint[500] dates, uint[500] RIDs, bool[500] Bboolas, bytes32[3][500] bytesbs,bytes32[2][500] bytescs, uint[500] amounts, bool[500] Bboolbs){} + function nredit(uint startindex) public pure returns(uint[500] memory CIDs, uint[500] memory dates, uint[500] memory RIDs, bool[500] memory Cboolas, uint[500] memory amounts){} + function return500InvoicesByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] memory AIDs, bool[500] memory Aboolas, uint[500] memory dates, bytes32[3][500] memory Abytesas, bytes32[3][500] memory bytesbs, bytes32[2][500] memory bytescs, uint[500] memory amounts, bool[500] memory Aboolbs, bool[500] memory Aboolcs){} + function return500PaymentsByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] memory BIDs, uint[500] memory dates, uint[500] memory RIDs, bool[500] memory Bboolas, bytes32[3][500] memory bytesbs,bytes32[2][500] memory bytescs, uint[500] memory amounts, bool[500] memory Bboolbs){} } )"; compileAndRun(sourceCode, 0, "C"); @@ -11837,13 +11837,13 @@ BOOST_AUTO_TEST_CASE(constant_string) bytes constant a = "\x03\x01\x02"; bytes constant b = hex"030102"; string constant c = "hello"; - function f() public returns (bytes) { + function f() public returns (bytes memory) { return a; } - function g() public returns (bytes) { + function g() public returns (bytes memory) { return b; } - function h() public returns (bytes) { + function h() public returns (bytes memory) { return bytes(c); } } @@ -11894,12 +11894,12 @@ BOOST_AUTO_TEST_CASE(snark) } /// @return the generator of G1 - function P1() internal returns (G1Point) { + function P1() internal returns (G1Point memory) { return G1Point(1, 2); } /// @return the generator of G2 - function P2() internal returns (G2Point) { + function P2() internal returns (G2Point memory) { return G2Point( [11559732032986387107991004021392285783925812861821192530917403151452391805634, 10857046999023057135944570762232829481370756359578518086990519993285655852781], @@ -11909,7 +11909,7 @@ BOOST_AUTO_TEST_CASE(snark) } /// @return the negation of p, i.e. p.add(p.negate()) should be zero. - function negate(G1Point p) internal returns (G1Point) { + function negate(G1Point memory p) internal returns (G1Point memory) { // The prime q in the base field F_q for G1 uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583; if (p.X == 0 && p.Y == 0) @@ -11918,7 +11918,7 @@ BOOST_AUTO_TEST_CASE(snark) } /// @return the sum of two points of G1 - function add(G1Point p1, G1Point p2) internal returns (G1Point r) { + function add(G1Point memory p1, G1Point memory p2) internal returns (G1Point memory r) { uint[4] memory input; input[0] = p1.X; input[1] = p1.Y; @@ -11935,7 +11935,7 @@ BOOST_AUTO_TEST_CASE(snark) /// @return the product of a point on G1 and a scalar, i.e. /// p == p.mul(1) and p.add(p) == p.mul(2) for all points p. - function mul(G1Point p, uint s) internal returns (G1Point r) { + function mul(G1Point memory p, uint s) internal returns (G1Point memory r) { uint[3] memory input; input[0] = p.X; input[1] = p.Y; @@ -11953,7 +11953,7 @@ BOOST_AUTO_TEST_CASE(snark) /// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1 /// For example pairing([P1(), P1().negate()], [P2(), P2()]) should /// return true. - function pairing(G1Point[] p1, G2Point[] p2) internal returns (bool) { + function pairing(G1Point[] memory p1, G2Point[] memory p2) internal returns (bool) { require(p1.length == p2.length); uint elements = p1.length; uint inputSize = p1.length * 6; @@ -11977,7 +11977,7 @@ BOOST_AUTO_TEST_CASE(snark) require(success); return out[0] != 0; } - function pairingProd2(G1Point a1, G2Point a2, G1Point b1, G2Point b2) internal returns (bool) { + function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal returns (bool) { G1Point[] memory p1 = new G1Point[](2); G2Point[] memory p2 = new G2Point[](2); p1[0] = a1; @@ -11987,9 +11987,9 @@ BOOST_AUTO_TEST_CASE(snark) return pairing(p1, p2); } function pairingProd3( - G1Point a1, G2Point a2, - G1Point b1, G2Point b2, - G1Point c1, G2Point c2 + G1Point memory a1, G2Point memory a2, + G1Point memory b1, G2Point memory b2, + G1Point memory c1, G2Point memory c2 ) internal returns (bool) { G1Point[] memory p1 = new G1Point[](3); G2Point[] memory p2 = new G2Point[](3); @@ -12002,10 +12002,10 @@ BOOST_AUTO_TEST_CASE(snark) return pairing(p1, p2); } function pairingProd4( - G1Point a1, G2Point a2, - G1Point b1, G2Point b2, - G1Point c1, G2Point c2, - G1Point d1, G2Point d2 + G1Point memory a1, G2Point memory a2, + G1Point memory b1, G2Point memory b2, + G1Point memory c1, G2Point memory c2, + G1Point memory d1, G2Point memory d2 ) internal returns (bool) { G1Point[] memory p1 = new G1Point[](4); G2Point[] memory p2 = new G2Point[](4); @@ -12094,7 +12094,7 @@ BOOST_AUTO_TEST_CASE(snark) return false; return true; } - function verifyingKey() internal returns (VerifyingKey vk) { + function verifyingKey() internal returns (VerifyingKey memory vk) { vk.A = Pairing.G2Point([0x209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf7, 0x04bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678], [0x2bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d, 0x120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550]); vk.B = Pairing.G1Point(0x2eca0c7238bf16e83e7a1e6c5d49540685ff51380f309842a98561558019fc02, 0x03d3260361bb8451de5ff5ecd17f010ff22f5c31cdf184e9020b06fa5997db84); vk.C = Pairing.G2Point([0x2e89718ad33c8bed92e210e81d1853435399a271913a6520736a4729cf0d51eb, 0x01a9e2ffa2e92599b68e44de5bcf354fa2642bd4f26b259daa6f7ce3ed57aeb3], [0x14a9a87b789a58af499b314e13c3d65bede56c07ea2d418d6874857b70763713, 0x178fb49a2d6cd347dc58973ff49613a20757d0fcc22079f9abd10c3baee24590]); @@ -12114,7 +12114,7 @@ BOOST_AUTO_TEST_CASE(snark) vk.IC[8] = Pairing.G1Point(0x0a6de0e2240aa253f46ce0da883b61976e3588146e01c9d8976548c145fe6e4a, 0x04fbaa3a4aed4bb77f30ebb07a3ec1c7d77a7f2edd75636babfeff97b1ea686e); vk.IC[9] = Pairing.G1Point(0x111e2e2a5f8828f80ddad08f9f74db56dac1cc16c1cb278036f79a84cf7a116f, 0x1d7d62e192b219b9808faa906c5ced871788f6339e8d91b83ac1343e20a16b30); } - function verify(uint[] input, Proof proof) internal returns (uint) { + function verify(uint[] memory input, Proof memory proof) internal returns (uint) { VerifyingKey memory vk = verifyingKey(); require(input.length + 1 == vk.IC.length); // Compute the linear combination vk_x @@ -12184,17 +12184,17 @@ BOOST_AUTO_TEST_CASE(abi_encode) { char const* sourceCode = R"( contract C { - function f0() public returns (bytes) { + function f0() public returns (bytes memory) { return abi.encode(); } - function f1() public returns (bytes) { + function f1() public returns (bytes memory) { return abi.encode(1, 2); } - function f2() public returns (bytes) { + function f2() public returns (bytes memory) { string memory x = "abc"; return abi.encode(1, x, 2); } - function f3() public returns (bytes r) { + function f3() public returns (bytes memory r) { // test that memory is properly allocated string memory x = "abc"; r = abi.encode(1, x, 2); @@ -12203,7 +12203,7 @@ BOOST_AUTO_TEST_CASE(abi_encode) y[0] = "e"; require(y[0] == "e"); } - function f4() public returns (bytes) { + function f4() public returns (bytes memory) { bytes4 x = "abcd"; return abi.encode(bytes2(x)); } @@ -12223,17 +12223,17 @@ BOOST_AUTO_TEST_CASE(abi_encode_v2) pragma experimental ABIEncoderV2; contract C { struct S { uint a; uint[] b; } - function f0() public pure returns (bytes) { + function f0() public pure returns (bytes memory) { return abi.encode(); } - function f1() public pure returns (bytes) { + function f1() public pure returns (bytes memory) { return abi.encode(1, 2); } - function f2() public pure returns (bytes) { + function f2() public pure returns (bytes memory) { string memory x = "abc"; return abi.encode(1, x, 2); } - function f3() public pure returns (bytes r) { + function f3() public pure returns (bytes memory r) { // test that memory is properly allocated string memory x = "abc"; r = abi.encode(1, x, 2); @@ -12243,7 +12243,7 @@ BOOST_AUTO_TEST_CASE(abi_encode_v2) require(y[0] == "e"); } S s; - function f4() public returns (bytes r) { + function f4() public returns (bytes memory r) { string memory x = "abc"; s.a = 7; s.b.push(2); @@ -12269,17 +12269,17 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked) { char const* sourceCode = R"( contract C { - function f0() public pure returns (bytes) { + function f0() public pure returns (bytes memory) { return abi.encodePacked(); } - function f1() public pure returns (bytes) { + function f1() public pure returns (bytes memory) { return abi.encodePacked(uint8(1), uint8(2)); } - function f2() public pure returns (bytes) { + function f2() public pure returns (bytes memory) { string memory x = "abc"; return abi.encodePacked(uint8(1), x, uint8(2)); } - function f3() public pure returns (bytes r) { + function f3() public pure returns (bytes memory r) { // test that memory is properly allocated string memory x = "abc"; r = abi.encodePacked(uint8(1), x, uint8(2)); @@ -12301,17 +12301,17 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_selector) { char const* sourceCode = R"( contract C { - function f0() public pure returns (bytes) { + function f0() public pure returns (bytes memory) { return abi.encodeWithSelector(0x12345678); } - function f1() public pure returns (bytes) { + function f1() public pure returns (bytes memory) { return abi.encodeWithSelector(0x12345678, "abc"); } - function f2() public pure returns (bytes) { + function f2() public pure returns (bytes memory) { bytes4 x = 0x12345678; return abi.encodeWithSelector(x, "abc"); } - function f3() public pure returns (bytes) { + function f3() public pure returns (bytes memory) { bytes4 x = 0x12345678; return abi.encodeWithSelector(x, uint(-1)); } @@ -12333,22 +12333,22 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_selectorv2) char const* sourceCode = R"( pragma experimental ABIEncoderV2; contract C { - function f0() public pure returns (bytes) { + function f0() public pure returns (bytes memory) { return abi.encodeWithSelector(0x12345678); } - function f1() public pure returns (bytes) { + function f1() public pure returns (bytes memory) { return abi.encodeWithSelector(0x12345678, "abc"); } - function f2() public pure returns (bytes) { + function f2() public pure returns (bytes memory) { bytes4 x = 0x12345678; return abi.encodeWithSelector(x, "abc"); } - function f3() public pure returns (bytes) { + function f3() public pure returns (bytes memory) { bytes4 x = 0x12345678; return abi.encodeWithSelector(x, uint(-1)); } struct S { uint a; string b; uint16 c; } - function f4() public pure returns (bytes) { + function f4() public pure returns (bytes memory) { bytes4 x = 0x12345678; S memory s; s.a = 0x1234567; @@ -12379,19 +12379,19 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_signature) { char const* sourceCode = R"T( contract C { - function f0() public pure returns (bytes) { + function f0() public pure returns (bytes memory) { return abi.encodeWithSignature("f(uint256)"); } - function f1() public pure returns (bytes) { + function f1() public pure returns (bytes memory) { string memory x = "f(uint256)"; return abi.encodeWithSignature(x, "abc"); } string xstor; - function f1s() public returns (bytes) { + function f1s() public returns (bytes memory) { xstor = "f(uint256)"; return abi.encodeWithSignature(xstor, "abc"); } - function f2() public pure returns (bytes r, uint[] ar) { + function f2() public pure returns (bytes memory r, uint[] memory ar) { string memory x = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; uint[] memory y = new uint[](4); y[0] = uint(-1); @@ -12423,19 +12423,19 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_signaturev2) char const* sourceCode = R"T( pragma experimental ABIEncoderV2; contract C { - function f0() public pure returns (bytes) { + function f0() public pure returns (bytes memory) { return abi.encodeWithSignature("f(uint256)"); } - function f1() public pure returns (bytes) { + function f1() public pure returns (bytes memory) { string memory x = "f(uint256)"; return abi.encodeWithSignature(x, "abc"); } string xstor; - function f1s() public returns (bytes) { + function f1s() public returns (bytes memory) { xstor = "f(uint256)"; return abi.encodeWithSignature(xstor, "abc"); } - function f2() public pure returns (bytes r, uint[] ar) { + function f2() public pure returns (bytes memory r, uint[] memory ar) { string memory x = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; uint[] memory y = new uint[](4); y[0] = uint(-1); @@ -12448,7 +12448,7 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_signaturev2) ar = new uint[](2); } struct S { uint a; string b; uint16 c; } - function f4() public pure returns (bytes) { + function f4() public pure returns (bytes memory) { bytes4 x = 0x12345678; S memory s; s.a = 0x1234567; @@ -12482,7 +12482,7 @@ BOOST_AUTO_TEST_CASE(abi_encode_call) char const* sourceCode = R"T( contract C { bool x; - function c(uint a, uint[] b) public { + function c(uint a, uint[] memory b) public { require(a == 5); require(b.length == 2); require(b[0] == 6); -- cgit v1.2.3 From 893f4cf092c98d13116741d1ebc19846f6873536 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 11 Jul 2018 15:57:07 +0200 Subject: Specifies visibility in unit tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 176 +++++++++++++++--------------- 1 file changed, 88 insertions(+), 88 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index be74c5ff..25c553e7 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -53,9 +53,9 @@ BOOST_AUTO_TEST_CASE(transaction_status) { char const* sourceCode = R"( contract test { - function f() { } - function g() { revert(); } - function h() { assert(false); } + function f() public { } + function g() public { revert(); } + function h() public { assert(false); } } )"; compileAndRun(sourceCode); @@ -1253,7 +1253,7 @@ BOOST_AUTO_TEST_CASE(state_smoke_test) if (which == 0) return value1; else return value2; } - function set(uint8 which, uint256 value) { + function set(uint8 which, uint256 value) public { if (which == 0) value1 = value; else value2 = value; } @@ -1315,7 +1315,7 @@ BOOST_AUTO_TEST_CASE(simple_mapping) function get(uint8 k) public returns (uint8 v) { return table[k]; } - function set(uint8 k, uint8 v) { + function set(uint8 k, uint8 v) public { table[k] = v; } } @@ -1349,7 +1349,7 @@ BOOST_AUTO_TEST_CASE(mapping_state) function getVoteCount(address addr) public returns (uint retVoteCount) { return voteCount[addr]; } - function grantVoteRight(address addr) { + function grantVoteRight(address addr) public { canVote[addr] = true; } function vote(address voter, address vote) public returns (bool success) { @@ -1562,7 +1562,7 @@ BOOST_AUTO_TEST_CASE(deleteStruct) uint nestedValue; mapping (uint => bool) nestedMapping; } - constructor(){ + constructor() public { toDelete = 5; str.topValue = 1; str.topMapping[0] = 1; @@ -2085,7 +2085,7 @@ BOOST_AUTO_TEST_CASE(transfer_ether) addr.transfer(amount); return this.balance; } - function b(address addr, uint amount) { + function b(address addr, uint amount) public { addr.transfer(amount); } } @@ -2344,7 +2344,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256) function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return keccak256(abi.encodePacked(uint8(8), input, b, input, c)); + return keccak256(abi.encodePacked(8, input, b, input, c)); } } )"; @@ -2396,7 +2396,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256) function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return sha256(abi.encodePacked(uint8(8), input, b, input, c)); + return sha256(abi.encodePacked(8, input, b, input, c)); } } )"; @@ -2423,7 +2423,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160) function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return ripemd160(abi.encodePacked(uint8(8), input, b, input, c)); + return ripemd160(abi.encodePacked(8, input, b, input, c)); } } )"; @@ -2477,7 +2477,7 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls) function getHelper() public returns (address haddress) { return address(h); } - function setHelper(address haddress) { + function setHelper(address haddress) public { h = Helper(haddress); } } @@ -2508,7 +2508,7 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_complex_parameters) function getHelper() public returns (address haddress) { return address(h); } - function setHelper(address haddress) { + function setHelper(address haddress) public { h = Helper(haddress); } } @@ -2540,7 +2540,7 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_accessing_this) function getHelper() public returns (address addr) { return address(h); } - function setHelper(address addr) { + function setHelper(address addr) public { h = Helper(addr); } } @@ -2572,7 +2572,7 @@ BOOST_AUTO_TEST_CASE(calls_to_this) function getHelper() public returns (address addr) { return address(h); } - function setHelper(address addr) { + function setHelper(address addr) public { h = Helper(addr); } } @@ -2607,7 +2607,7 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) function getHelper() public returns (address haddress) { return address(h); } - function setHelper(address haddress) { + function setHelper(address haddress) public { h = Helper(haddress); } } @@ -2638,7 +2638,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_in_calls) function getHelper() public returns (address addr) { return address(h); } - function setHelper(address addr) { + function setHelper(address addr) public { h = Helper(addr); } } @@ -2847,7 +2847,7 @@ BOOST_AUTO_TEST_CASE(value_complex) contract test { helper h; constructor() public payable { h = new helper(); } - function sendAmount(uint amount) payable returns (uint256 bal) { + function sendAmount(uint amount) public payable returns (uint256 bal) { uint someStackElement = 20; return h.getBalance.value(amount).gas(1000).value(amount + 3)(); } @@ -2883,7 +2883,7 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) contract Helper { bytes3 name; bool flag; - constructor(bytes3 x, bool f) payable { + constructor(bytes3 x, bool f) public payable { name = x; flag = f; } @@ -2892,7 +2892,7 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) } contract Main { Helper h; - constructor() payable { + constructor() public payable { h = (new Helper).value(10)("abc", true); } function getFlag() public returns (bool ret) { return h.getFlag(); } @@ -2953,10 +2953,10 @@ BOOST_AUTO_TEST_CASE(single_copy_with_multiple_inheritance) char const* sourceCode = R"( contract Base { uint data; - function setData(uint i) { data = i; } + function setData(uint i) public { data = i; } function getViaBase() public returns (uint i) { return data; } } - contract A is Base { function setViaA(uint i) { setData(i); } } + contract A is Base { function setViaA(uint i) public { setData(i); } } contract B is Base { function getViaB() public returns (uint i) { return getViaBase(); } } contract Derived is Base, B, A { } )"; @@ -3165,7 +3165,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_for_constructor) char const* sourceCode = R"( contract A { uint data; - constructor() mod1 { data |= 2; } + constructor() mod1 public { data |= 2; } modifier mod1 { data |= 1; _; } function getData() public returns (uint r) { return data; } } @@ -3375,7 +3375,7 @@ BOOST_AUTO_TEST_CASE(event) char const* sourceCode = R"( contract ClientReceipt { event Deposit(address indexed _from, bytes32 indexed _id, uint _value); - function deposit(bytes32 _id, bool _manually) payable { + function deposit(bytes32 _id, bool _manually) public payable { if (_manually) { bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f; log3(bytes32(msg.value), s, bytes32(uint256(msg.sender)), _id); @@ -3406,7 +3406,7 @@ BOOST_AUTO_TEST_CASE(event_emit) char const* sourceCode = R"( contract ClientReceipt { event Deposit(address indexed _from, bytes32 indexed _id, uint _value); - function deposit(bytes32 _id) payable { + function deposit(bytes32 _id) public payable { emit Deposit(msg.sender, _id, msg.value); } } @@ -3584,7 +3584,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous_with_topics) char const* sourceCode = R"( contract ClientReceipt { event Deposit(address indexed _from, bytes32 indexed _id, uint indexed _value, uint indexed _value2, bytes32 data) anonymous; - function deposit(bytes32 _id) payable { + function deposit(bytes32 _id) public payable { emit Deposit(msg.sender, _id, msg.value, 2, "abc"); } } @@ -3608,7 +3608,7 @@ BOOST_AUTO_TEST_CASE(event_lots_of_data) char const* sourceCode = R"( contract ClientReceipt { event Deposit(address _from, bytes32 _id, uint _value, bool _flag); - function deposit(bytes32 _id) payable { + function deposit(bytes32 _id) public payable { emit Deposit(msg.sender, _id, msg.value, true); } } @@ -3822,7 +3822,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals) contract c { function foo(uint a, uint16 b) public returns (bytes32 d) { - d = keccak256(abi.encodePacked(a, b, uint8(145))); + d = keccak256(abi.encodePacked(a, b, 145)); } } )"; @@ -3847,7 +3847,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals) } function bar(uint a, uint16 b) public returns (bytes32 d) { - d = keccak256(abi.encodePacked(a, b, uint8(145), "foo")); + d = keccak256(abi.encodePacked(a, b, 145, "foo")); } } )"; @@ -3910,7 +3910,7 @@ BOOST_AUTO_TEST_CASE(generic_call) char const* sourceCode = R"**( contract receiver { uint public received; - function receive(uint256 x) payable { received = x; } + function receive(uint256 x) public payable { received = x; } } contract sender { constructor() public payable {} @@ -3936,15 +3936,15 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) uint public received; address public sender; uint public value; - constructor() payable {} - function receive(uint256 x) payable { received = x; sender = msg.sender; value = msg.value; } + constructor() public payable {} + function receive(uint256 x) public payable { received = x; sender = msg.sender; value = msg.value; } } contract Sender { uint public received; address public sender; uint public value; - constructor() payable {} - function doSend(address rec) payable + constructor() public payable {} + function doSend(address rec) public payable { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); if (rec.delegatecall(abi.encodeWithSelector(signature, 23))) {} @@ -4130,7 +4130,7 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) char const* sourceCode = R"( contract receiver { uint public received; - function receive(uint x) { received += x + 1; } + function receive(uint x) public { received += x + 1; } function() external { received = 0x80; } } contract sender { @@ -4349,7 +4349,7 @@ BOOST_AUTO_TEST_CASE(using_enums) char const* sourceCode = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - constructor() + constructor() public { choices = ActionChoices.GoStraight; } @@ -4369,7 +4369,7 @@ BOOST_AUTO_TEST_CASE(enum_explicit_overflow) char const* sourceCode = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoStraight } - constructor() + constructor() public { } function getChoiceExp(uint x) public returns (uint d) @@ -4514,7 +4514,7 @@ BOOST_AUTO_TEST_CASE(inline_member_init) { char const* sourceCode = R"( contract test { - constructor(){ + constructor() public { m_b = 6; m_c = 8; } @@ -4536,12 +4536,12 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence) { char const* sourceCode = R"( contract Base { - constructor(){} + constructor() public {} uint m_base = 5; function getBMember() public returns (uint i) { return m_base; } } contract Derived is Base { - constructor(){} + constructor() public {} uint m_derived = 6; function getDMember() public returns (uint i) { return m_derived; } } @@ -4588,8 +4588,8 @@ BOOST_AUTO_TEST_CASE(bytes_in_arguments) char const* sourceCode = R"( contract c { uint result; - function f(uint a, uint b) { result += a + b; } - function g(uint a) { result *= a; } + function f(uint a, uint b) public { result += a + b; } + function g(uint a) public { result *= a; } function test(uint a, bytes data1, bytes data2, uint b) external returns (uint r_a, uint r, uint r_b, uint l) { r_a = a; this.call(data1); @@ -4621,9 +4621,9 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_in_storage) struct Data { uint x; uint y; } Data[2**10] data; uint[2**10 + 3] ids; - function setIDStatic(uint id) { ids[2] = id; } - function setID(uint index, uint id) { ids[index] = id; } - function setData(uint index, uint x, uint y) { data[index].x = x; data[index].y = y; } + function setIDStatic(uint id) public { ids[2] = id; } + function setID(uint index, uint id) public { ids[index] = id; } + function setData(uint index, uint x, uint y) public { data[index].x = x; data[index].y = y; } function getID(uint index) public returns (uint) { return ids[index]; } function getData(uint index) public returns (uint x, uint y) { x = data[index].x; y = data[index].y; } function getLengths() public returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } @@ -4648,13 +4648,13 @@ BOOST_AUTO_TEST_CASE(dynamic_arrays_in_storage) struct Data { uint x; uint y; } Data[] data; uint[] ids; - function setIDStatic(uint id) { ids[2] = id; } - function setID(uint index, uint id) { ids[index] = id; } - function setData(uint index, uint x, uint y) { data[index].x = x; data[index].y = y; } + function setIDStatic(uint id) public { ids[2] = id; } + function setID(uint index, uint id) public { ids[index] = id; } + function setData(uint index, uint x, uint y) public { data[index].x = x; data[index].y = y; } function getID(uint index) public returns (uint) { return ids[index]; } function getData(uint index) public returns (uint x, uint y) { x = data[index].x; y = data[index].y; } function getLengths() public returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } - function setLengths(uint l1, uint l2) { data.length = l1; ids.length = l2; } + function setLengths(uint l1, uint l2) public { data.length = l1; ids.length = l2; } } )"; compileAndRun(sourceCode); @@ -4811,7 +4811,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_dyn_dyn) contract c { uint[] data1; uint[] data2; - function setData1(uint length, uint index, uint value) { + function setData1(uint length, uint index, uint value) public { data1.length = length; if (index < length) data1[index] = value; } function copyStorageStorage() public { data2 = data1; } @@ -5737,14 +5737,14 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base) { char const* sourceCode = R"( contract Base { - constructor(uint i) + constructor(uint i) public { m_i = i; } uint public m_i; } contract Derived is Base { - constructor(uint i) Base(i) + constructor(uint i) Base(i) public {} } contract Final is Derived(4) { @@ -5782,14 +5782,14 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) { char const* sourceCode = R"( contract Base { - constructor(uint i) + constructor(uint i) public { m_i = i; } uint public m_i; } contract Base1 is Base { - constructor(uint k) {} + constructor(uint k) public {} } contract Derived is Base, Base1 { constructor(uint i) Base(i) Base1(7) public {} @@ -6368,7 +6368,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) testStruct data1; testStruct data2; testStruct data3; - constructor() + constructor() public { data1.m_value = 2; } @@ -6400,7 +6400,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) uint m_value; } testStruct data1; - constructor() + constructor() public { data1.m_value = 2; } @@ -6427,7 +6427,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) } mapping (uint => testStruct) campaigns; - constructor() + constructor() public { campaigns[0].m_value = 2; } @@ -6470,14 +6470,14 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( contract A { - constructor() + constructor() public { this.call("123"); } } contract B { uint public test = 1; - function testIt() + function testIt() public { A a = new A(); ++test; @@ -6496,7 +6496,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) contract A { uint public test = 1; uint[3] arr; - constructor() + constructor() public { uint index = 5; test = arr[index]; @@ -6649,9 +6649,9 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" ); - vector lengths{0, 30, 32, 63, 64, 65, 210, 300}; - for (auto l1: lengths) - for (auto l2: lengths) + vector lengthes{0, 30, 32, 63, 64, 65, 210, 300}; + for (auto l1: lengthes) + for (auto l2: lengthes) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6718,9 +6718,9 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"); - vector lengths{0, 31, 64, 65}; - for (auto l1: lengths) - for (auto l2: lengths) + vector lengthes{0, 31, 64, 65}; + for (auto l1: lengthes) + for (auto l2: lengthes) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6759,8 +6759,8 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) )"; compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - vector lengths{0, 31, 64, 65}; - for (auto l1: lengths) + vector lengthes{0, 31, 64, 65}; + for (auto l1: lengthes) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes args1 = encodeArgs(u256(0x20)) + dyn1; @@ -7038,7 +7038,7 @@ BOOST_AUTO_TEST_CASE(storage_array_ref) contract Store is BinarySearch { uint[] data; - function add(uint v) { + function add(uint v) public { data.length++; data[data.length - 1] = v; } @@ -7121,7 +7121,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write) { char const* sourceCode = R"( contract Test { - function set(uint24[3][4] memory x) { + function set(uint24[3][4] memory x) public { x[2][2] = 1; x[3][2] = 7; } @@ -7458,7 +7458,7 @@ BOOST_AUTO_TEST_CASE(string_as_mapping_key) char const* sourceCode = R"( contract Test { mapping(string => uint) data; - function set(string memory _s, uint _v) { data[_s] = _v; } + function set(string memory _s, uint _v) public { data[_s] = _v; } function get(string memory _s) public returns (uint) { return data[_s]; } } )"; @@ -7764,7 +7764,7 @@ BOOST_AUTO_TEST_CASE(strings_in_struct) string last; } - constructor(){ + constructor() public { bug = Buggy(10, 20, 30, "asdfghjkl"); } function getFirst() public returns (uint) @@ -7856,7 +7856,7 @@ BOOST_AUTO_TEST_CASE(using_library_structs) char const* sourceCode = R"( library Lib { struct Data { uint a; uint[] b; } - function set(Data storage _s) + function set(Data storage _s) public { _s.a = 7; _s.b.length = 20; @@ -8039,7 +8039,7 @@ BOOST_AUTO_TEST_CASE(calldata_offset) { address[] _arr; string public last = "nd"; - constructor(address[] memory guardians) + constructor(address[] memory guardians) public { _arr = guardians; } @@ -8941,8 +8941,8 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_access) char const* sourceCode = R"( contract C { uint public x; - function g(uint y) { x = 2 * y; assembly { stop } } - function f(uint _x) { + function g(uint y) public { x = 2 * y; assembly { stop } } + function f(uint _x) public { assembly { _x jump(g) @@ -9416,7 +9416,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs) BOOST_AUTO_TEST_CASE(failed_create) { char const* sourceCode = R"( - contract D { constructor() payable {} } + contract D { constructor() public payable {} } contract C { uint public x; constructor() public payable {} @@ -9512,7 +9512,7 @@ BOOST_AUTO_TEST_CASE(break_in_modifier) break; } } - function f() run { + function f() run public { uint k = x; uint t = k + 1; x = t; @@ -9584,7 +9584,7 @@ BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers) break; } } - function f() run { + function f() run public { uint k = x; uint t = k + 1; x = t; @@ -9611,8 +9611,8 @@ BOOST_AUTO_TEST_CASE(mutex) } contract Fund is mutexed { uint shares; - constructor() payable { shares = msg.value; } - function withdraw(uint amount) protected returns (uint) { + constructor() public payable { shares = msg.value; } + function withdraw(uint amount) public protected returns (uint) { // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) throw; @@ -9633,7 +9633,7 @@ BOOST_AUTO_TEST_CASE(mutex) Fund public fund; uint callDepth; bool protected; - function setProtected(bool _protected) { protected = _protected; } + function setProtected(bool _protected) public { protected = _protected; } constructor(Fund _fund) public { fund = _fund; } function attack() public returns (uint) { callDepth = 0; @@ -9730,7 +9730,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_asm) BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) { char const* sourceCode = R"YY( - contract D { function g(); } + contract D { function g() public; } contract C { D d = D(0x1212); function f() public returns (uint) { @@ -9757,7 +9757,7 @@ BOOST_AUTO_TEST_CASE(payable_constructor) { char const* sourceCode = R"( contract C { - constructor() payable { } + constructor() public payable { } } )"; compileAndRun(sourceCode, 27, "C"); @@ -9792,7 +9792,7 @@ BOOST_AUTO_TEST_CASE(payable_function_calls_library) function f() public returns (uint) { return 7; } } contract C { - function f() payable public returns (uint) { + function f() public payable returns (uint) { return L.f(); } } @@ -10015,7 +10015,7 @@ BOOST_AUTO_TEST_CASE(store_function) contract C { function (function (uint) external returns (uint)) internal returns (uint) ev; function (uint) external returns (uint) x; - function store(function(uint) external returns (uint) y) { + function store(function(uint) external returns (uint) y) public { x = y; } function eval(function(uint) external returns (uint) y) public returns (uint) { @@ -11594,7 +11594,7 @@ BOOST_AUTO_TEST_CASE(literal_empty_string) contract C { bytes32 public x; uint public a; - function f(bytes32 _x, uint _a) { + function f(bytes32 _x, uint _a) public { x = _x; a = _a; } @@ -12730,7 +12730,7 @@ BOOST_AUTO_TEST_CASE(senders_balance) } contract D { C c = new C(); - constructor() payable { } + constructor() public payable { } function f() public view returns (uint) { return c.f(); } -- cgit v1.2.3 From ed2aa3b8694f253edff8c0a4acefd4ba74bbd859 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 16 Jul 2018 12:23:06 +0200 Subject: Fixes end-to-end tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 25c553e7..ba6e864a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2344,7 +2344,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256) function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return keccak256(abi.encodePacked(8, input, b, input, c)); + return keccak256(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -2396,7 +2396,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256) function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return sha256(abi.encodePacked(8, input, b, input, c)); + return sha256(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -2423,7 +2423,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160) function a(bytes32 input) public returns (bytes32 hash) { uint24 b = 65536; uint c = 256; - return ripemd160(abi.encodePacked(8, input, b, input, c)); + return ripemd160(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -3822,7 +3822,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals) contract c { function foo(uint a, uint16 b) public returns (bytes32 d) { - d = keccak256(abi.encodePacked(a, b, 145)); + d = keccak256(abi.encodePacked(a, b, uint8(145))); } } )"; @@ -3847,7 +3847,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals) } function bar(uint a, uint16 b) public returns (bytes32 d) { - d = keccak256(abi.encodePacked(a, b, 145, "foo")); + d = keccak256(abi.encodePacked(a, b, uint8(145), "foo")); } } )"; @@ -6649,9 +6649,9 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" ); - vector lengthes{0, 30, 32, 63, 64, 65, 210, 300}; - for (auto l1: lengthes) - for (auto l2: lengthes) + vector lengths{0, 30, 32, 63, 64, 65, 210, 300}; + for (auto l1: lengths) + for (auto l2: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6718,9 +6718,9 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"); - vector lengthes{0, 31, 64, 65}; - for (auto l1: lengthes) - for (auto l2: lengthes) + vector lengths{0, 31, 64, 65}; + for (auto l1: lengths) + for (auto l2: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6759,8 +6759,8 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) )"; compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - vector lengthes{0, 31, 64, 65}; - for (auto l1: lengthes) + vector lengths{0, 31, 64, 65}; + for (auto l1: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes args1 = encodeArgs(u256(0x20)) + dyn1; -- cgit v1.2.3 From aa08460d94f0e3ac8e067f89786175fb5ebba73b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 12 Jul 2018 00:43:19 +0100 Subject: Replace throw with revert() in end-to-end tests --- test/libsolidity/SolidityEndToEndTest.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index be74c5ff..9317eedd 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2095,7 +2095,7 @@ BOOST_AUTO_TEST_CASE(transfer_ether) contract C { function () external payable { - throw; + revert(); } } )"; @@ -7741,7 +7741,7 @@ BOOST_AUTO_TEST_CASE(simple_throw) if (x > 10) return x + 10; else - throw; + revert(); return 2; } } @@ -9603,7 +9603,7 @@ BOOST_AUTO_TEST_CASE(mutex) contract mutexed { bool locked; modifier protected { - if (locked) throw; + if (locked) revert(); locked = true; _; locked = false; @@ -9615,16 +9615,16 @@ BOOST_AUTO_TEST_CASE(mutex) function withdraw(uint amount) protected returns (uint) { // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. - if (amount > shares) throw; - if (!msg.sender.call.value(amount)("")) throw; + if (amount > shares) revert(); + if (!msg.sender.call.value(amount)("")) revert(); shares -= amount; return shares; } function withdrawUnprotected(uint amount) public returns (uint) { // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. - if (amount > shares) throw; - if (!msg.sender.call.value(amount)("")) throw; + if (amount > shares) revert(); + if (!msg.sender.call.value(amount)("")) revert(); shares -= amount; return shares; } @@ -11159,7 +11159,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_in_modifiers) a := 2 } if (a != 2) - throw; + revert(); _; } function f() m public returns (bool) { -- cgit v1.2.3 From 0075f4239aca8c82cf110dc46ed333fdcd6dd572 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Thu, 5 Jul 2018 14:46:27 +0200 Subject: Address members not accessible by contract instance --- test/libsolidity/SolidityEndToEndTest.cpp | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 0fe21c4a..3f0e60f0 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2083,7 +2083,7 @@ BOOST_AUTO_TEST_CASE(transfer_ether) constructor() public payable {} function a(address addr, uint amount) public returns (uint) { addr.transfer(amount); - return this.balance; + return address(this).balance; } function b(address addr, uint amount) public { addr.transfer(amount); @@ -2790,10 +2790,10 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } contract test { helper h; - constructor() public payable { h = new helper(); h.send(5); } + constructor() public payable { h = new helper(); address(h).send(5); } function getBalance() public returns (uint256 myBalance, uint256 helperBalance) { - myBalance = this.balance; - helperBalance = h.balance; + myBalance = address(this).balance; + helperBalance = address(h).balance; } } )"; @@ -2808,7 +2808,7 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic) contract helper { bool flag; function getBalance() payable public returns (uint256 myBalance) { - return this.balance; + return address(this).balance; } function setFlag() public { flag = true; } function getFlag() public returns (bool fl) { return flag; } @@ -2825,7 +2825,7 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic) } function checkState() public returns (bool flagAfter, uint myBal) { flagAfter = h.getFlag(); - myBal = this.balance; + myBal = address(this).balance; } } )"; @@ -2841,7 +2841,7 @@ BOOST_AUTO_TEST_CASE(value_complex) char const* sourceCode = R"( contract helper { function getBalance() payable public returns (uint256 myBalance) { - return this.balance; + return address(this).balance; } } contract test { @@ -2862,7 +2862,7 @@ BOOST_AUTO_TEST_CASE(value_insane) char const* sourceCode = R"( contract helper { function getBalance() payable public returns (uint256 myBalance) { - return this.balance; + return address(this).balance; } } contract test { @@ -2897,7 +2897,7 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) } function getFlag() public returns (bool ret) { return h.getFlag(); } function getName() public returns (bytes3 ret) { return h.getName(); } - function getBalances() public returns (uint me, uint them) { me = this.balance; them = h.balance;} + function getBalances() public returns (uint me, uint them) { me = address(this).balance; them = address(h).balance;} } )"; compileAndRun(sourceCode, 22, "Main"); @@ -3341,7 +3341,7 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws) char const* sourceCode = R"YY( contract A { function f() public returns (bool) { - return this.call(""); + return address(this).call(""); } } )YY"; @@ -4066,7 +4066,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) contract sender { constructor() public { rec = new receiver(); } function() external { savedData = msg.data; } - function forward() public returns (bool) { !rec.call(savedData); return true; } + function forward() public returns (bool) { !address(rec).call(savedData); return true; } function clear() public returns (bool) { delete savedData; return true; } function val() public returns (uint) { return rec.received(); } receiver rec; @@ -4095,18 +4095,18 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) receiver rec; constructor() public { rec = new receiver(); } function viaCalldata() public returns (uint) { - require(rec.call(msg.data)); + require(address(rec).call(msg.data)); return rec.calledLength(); } function viaMemory() public returns (uint) { bytes memory x = msg.data; - require(rec.call(x)); + require(address(rec).call(x)); return rec.calledLength(); } bytes s; function viaStorage() public returns (uint) { s = msg.data; - require(rec.call(s)); + require(address(rec).call(s)); return rec.calledLength(); } } @@ -4137,8 +4137,8 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) constructor() public { rec = new receiver(); } function() external { savedData1 = savedData2 = msg.data; } function forward(bool selector) public returns (bool) { - if (selector) { rec.call(savedData1); delete savedData1; } - else { rec.call(savedData2); delete savedData2; } + if (selector) { address(rec).call(savedData1); delete savedData1; } + else { address(rec).call(savedData2); delete savedData2; } return true; } function val() public returns (uint) { return rec.received(); } @@ -4592,8 +4592,8 @@ BOOST_AUTO_TEST_CASE(bytes_in_arguments) function g(uint a) public { result *= a; } function test(uint a, bytes data1, bytes data2, uint b) external returns (uint r_a, uint r, uint r_b, uint l) { r_a = a; - this.call(data1); - this.call(data2); + address(this).call(data1); + address(this).call(data2); r = result; r_b = b; l = data1.length; @@ -6472,7 +6472,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) contract A { constructor() public { - this.call("123"); + address(this).call("123"); } } contract B { @@ -6536,7 +6536,7 @@ BOOST_AUTO_TEST_CASE(failing_send) constructor() public payable {} function callHelper(address _a) public returns (bool r, uint bal) { r = !_a.send(5); - bal = this.balance; + bal = address(this).balance; } } )"; @@ -6559,7 +6559,7 @@ BOOST_AUTO_TEST_CASE(send_zero_ether) constructor() public payable {} function s() public returns (bool) { Receiver r = new Receiver(); - return r.send(0); + return address(r).send(0); } } )"; @@ -9742,7 +9742,7 @@ BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) return 7; } function h() public returns (uint) { - d.call(""); // this does not throw (low-level) + address(d).call(""); // this does not throw (low-level) return 7; } } @@ -11503,7 +11503,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_transfer) revert("message"); } function f() public { - this.transfer(0); + address(this).transfer(0); } } contract C { @@ -11778,13 +11778,13 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value) return value; } function get_delegated() external returns (bool) { - return this.delegatecall(abi.encodeWithSignature("get()")); + return address(this).delegatecall(abi.encodeWithSignature("get()")); } function assert0() external view { assert(value == 0); } function assert0_delegated() external returns (bool) { - return this.delegatecall(abi.encodeWithSignature("assert0()")); + return address(this).delegatecall(abi.encodeWithSignature("assert0()")); } } )DELIMITER"; @@ -12494,7 +12494,7 @@ BOOST_AUTO_TEST_CASE(abi_encode_call) uint[] memory b = new uint[](2); b[0] = 6; b[1] = 7; - require(this.call(abi.encodeWithSignature("c(uint256,uint256[])", a, b))); + require(address(this).call(abi.encodeWithSignature("c(uint256,uint256[])", a, b))); return x; } } -- cgit v1.2.3 From 75bba5c9f02df281c667b77db01594c5c7eb823d Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Tue, 10 Jul 2018 12:48:09 +0200 Subject: Adjusts tests to expect type errors on default visibility. --- test/libsolidity/SolidityEndToEndTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 0fe21c4a..d8f2f531 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -670,7 +670,7 @@ BOOST_AUTO_TEST_CASE(nested_loops_multiple_local_vars) // and free local variables properly char const* sourceCode = R"( contract test { - function f(uint x) returns(uint y) { + function f(uint x) public returns(uint y) { while (x > 0) { uint z = x + 10; uint k = z + 1; @@ -9536,7 +9536,7 @@ BOOST_AUTO_TEST_CASE(continue_in_modifier) _; } } - function f() run { + function f() run public { uint k = x; uint t = k + 1; x = t; @@ -9560,7 +9560,7 @@ BOOST_AUTO_TEST_CASE(return_in_modifier) _; } } - function f() run { + function f() run public { uint k = x; uint t = k + 1; x = t; -- cgit v1.2.3 From c622a1e56c0a02b890b45fd15f1fb4cb9d119b3b Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 18 Jul 2018 17:20:26 +0200 Subject: Enforces data location of local mappings to storage. --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index d8f2f531..b9114b27 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1534,7 +1534,7 @@ BOOST_AUTO_TEST_CASE(struct_reference) } function set() public { data.z = 2; - mapping(uint8 => s2) map = data.recursive; + mapping(uint8 => s2) storage map = data.recursive; s2 storage inner = map[0]; inner.z = 3; inner.recursive[0].z = inner.recursive[1].z + 1; -- cgit v1.2.3 From c8232d9759458d5f6e1442533457d8529686eea7 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 19 Jun 2018 21:32:03 +0200 Subject: Disallow conversion between unrelated contract types. --- test/libsolidity/SolidityEndToEndTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 223250fa..f52d270d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9420,7 +9420,7 @@ BOOST_AUTO_TEST_CASE(failed_create) contract C { uint public x; constructor() public payable {} - function f(uint amount) public returns (address) { + function f(uint amount) public returns (D) { x++; return (new D).value(amount)(); } @@ -12524,10 +12524,10 @@ BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure) return (new C()).f(); } function fview() public returns (uint) { - return (CView(new C())).f(); + return (CView(address(new C()))).f(); } function fpure() public returns (uint) { - return (CPure(new C())).f(); + return (CPure(address(new C()))).f(); } } )"; -- cgit v1.2.3 From b800bfb02138f843538bca55a40d6a4e0d1be60f Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 12 Jul 2018 20:07:16 +0200 Subject: Fix tests regarding contract type conversion. --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f52d270d..e9e7c93b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9428,7 +9428,7 @@ BOOST_AUTO_TEST_CASE(failed_create) if (depth < 1024) return this.stack(depth - 1); else - return f(0); + return address(f(0)); } } )"; -- cgit v1.2.3 From 9b8a05ebfb34b0c4062cc6ab824b7281066424a6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 9 Jul 2018 15:04:27 +0200 Subject: Update tests to remove support for loose assembly --- test/libsolidity/SolidityEndToEndTest.cpp | 56 ++++++------------------------- 1 file changed, 10 insertions(+), 46 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e9e7c93b..0437c72f 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -11261,7 +11261,7 @@ BOOST_AUTO_TEST_CASE(invalid_instruction) contract C { function f() public { assembly { - invalid + invalid() } } } @@ -11688,19 +11688,10 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly) ret := keccak256(0, 0) } } - function g() public pure returns (bytes32 ret) { - assembly { - 0 - 0 - keccak256 - =: ret - } - } } )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); - ABI_CHECK(callContractFunction("g()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); } BOOST_AUTO_TEST_CASE(multi_modifiers) @@ -12599,26 +12590,17 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) contract C { function shl(uint a, uint b) public returns (uint c) { assembly { - a - b - shl - =: c + c := shl(b, a) } } function shr(uint a, uint b) public returns (uint c) { assembly { - a - b - shr - =: c + c := shr(b, a) } } function sar(uint a, uint b) public returns (uint c) { assembly { - a - b - sar - =: c + c := sar(b, a) } } } @@ -12646,10 +12628,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) function shl_1() public returns (bool) { uint c; assembly { - 1 - 2 - shl - =: c + c := shl(2, 1) } assert(c == 4); return true; @@ -12657,10 +12636,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) function shl_2() public returns (bool) { uint c; assembly { - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - 1 - shl - =: c + c := shl(1, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) } assert(c == 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe); return true; @@ -12668,10 +12644,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) function shl_3() public returns (bool) { uint c; assembly { - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - 256 - shl - =: c + c := shl(256, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) } assert(c == 0); return true; @@ -12679,10 +12652,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) function shr_1() public returns (bool) { uint c; assembly { - 3 - 1 - shr - =: c + c := shr(1, 3) } assert(c == 1); return true; @@ -12690,10 +12660,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) function shr_2() public returns (bool) { uint c; assembly { - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - 1 - shr - =: c + c := shr(1, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) } assert(c == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); return true; @@ -12701,10 +12668,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) function shr_3() public returns (bool) { uint c; assembly { - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - 256 - shr - =: c + c := shr(256, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) } assert(c == 0); return true; -- cgit v1.2.3 From a4ab305347c296e44e911765e4cd8c3243287e23 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Fri, 27 Jul 2018 13:40:07 +0200 Subject: Drop swap_peephole_optimization test from EndToEndTests Already covered by libevmasm/Optimiser: peephole_noncommutative_swap1, peephole_commutative_swap1 and peephole_swap_comparison --- test/libsolidity/SolidityEndToEndTest.cpp | 44 ------------------------------- 1 file changed, 44 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 0437c72f..d8b4b05d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -12538,50 +12538,6 @@ BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure) } } -BOOST_AUTO_TEST_CASE(swap_peephole_optimisation) -{ - char const* sourceCode = R"( - contract C { - function lt(uint a, uint b) public returns (bool c) { - assembly { - a - b - swap1 - lt - =: c - } - } - function add(uint a, uint b) public returns (uint c) { - assembly { - a - b - swap1 - add - =: c - } - } - function div(uint a, uint b) public returns (uint c) { - assembly { - a - b - swap1 - div - =: c - } - } - } - )"; - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("lt(uint256,uint256)", u256(1), u256(2)) == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("lt(uint256,uint256)", u256(2), u256(1)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("add(uint256,uint256)", u256(1), u256(2)) == encodeArgs(u256(3))); - BOOST_CHECK(callContractFunction("add(uint256,uint256)", u256(100), u256(200)) == encodeArgs(u256(300))); - BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(2), u256(1)) == encodeArgs(u256(2))); - BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(200), u256(10)) == encodeArgs(u256(20))); - BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(1), u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(0), u256(1)) == encodeArgs(u256(0))); -} - BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) { if (!dev::test::Options::get().evmVersion().hasBitwiseShifting()) -- cgit v1.2.3 From 43c01361f3bb1b2ffebbb82bb24ec7fecbb52d16 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Fri, 27 Jul 2018 13:40:25 +0200 Subject: Drops tests for inline assembly jumps and function access as both isn't possible anymore. --- test/libsolidity/SolidityEndToEndTest.cpp | 46 ------------------------------- 1 file changed, 46 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index d8b4b05d..45a56b22 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8910,52 +8910,6 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_via_pointer) ABI_CHECK(callContractFunction("separator2()"), encodeArgs(u256(0))); } -BOOST_AUTO_TEST_CASE(inline_assembly_jumps) -{ - char const* sourceCode = R"( - contract C { - function f() public { - assembly { - let n := calldataload(4) - let a := 1 - let b := a - loop: - jumpi(loopend, eq(n, 0)) - a add swap1 - n := sub(n, 1) - jump(loop) - loopend: - mstore(0, a) - return(0, 0x20) - } - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f()", u256(5)), encodeArgs(u256(13))); - ABI_CHECK(callContractFunction("f()", u256(7)), encodeArgs(u256(34))); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_function_access) -{ - char const* sourceCode = R"( - contract C { - uint public x; - function g(uint y) public { x = 2 * y; assembly { stop } } - function f(uint _x) public { - assembly { - _x - jump(g) - pop - } - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f(uint256)", u256(5)), encodeArgs()); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(10))); -} - BOOST_AUTO_TEST_CASE(inline_assembly_function_call) { char const* sourceCode = R"( -- cgit v1.2.3 From 1e4b5886d61328d951fc03dc88cfc3dd722a3a00 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 3 Aug 2018 16:22:03 +0200 Subject: Allow assignments to local variables of mapping types. --- test/libsolidity/SolidityEndToEndTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e9e7c93b..2ae13963 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1478,6 +1478,28 @@ BOOST_AUTO_TEST_CASE(multi_level_mapping) testContractAgainstCpp("f(uint256,uint256,uint256)", f, u256(5), u256(4), u256(0)); } +BOOST_AUTO_TEST_CASE(mapping_local_assignment) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8) m1; + mapping(uint8 => uint8) m2; + function f() public returns (uint8, uint8, uint8, uint8) { + mapping(uint8 => uint8) storage m = m1; + m[1] = 42; + + m = m2; + m[2] = 21; + + return (m1[1], m1[2], m2[1], m2[2]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); +} + BOOST_AUTO_TEST_CASE(structs) { char const* sourceCode = R"( -- cgit v1.2.3 From cbae02b514d7a9dd3845f2f731caec7defa29a66 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 3 Aug 2018 17:38:30 +0200 Subject: Additional semantics test cases. --- test/libsolidity/SolidityEndToEndTest.cpp | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 2ae13963..ccb60b32 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1500,6 +1500,51 @@ BOOST_AUTO_TEST_CASE(mapping_local_assignment) ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); } +BOOST_AUTO_TEST_CASE(mapping_local_tuple_assignment) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8) m1; + mapping(uint8 => uint8) m2; + function f() public returns (uint8, uint8, uint8, uint8) { + mapping(uint8 => uint8) storage m = m1; + m[1] = 42; + + uint8 v; + (m, v) = (m2, 21); + m[2] = v; + + return (m1[1], m1[2], m2[1], m2[2]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); +} + +BOOST_AUTO_TEST_CASE(mapping_local_compound_assignment) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8) m1; + mapping(uint8 => uint8) m2; + function f() public returns (uint8, uint8, uint8, uint8) { + mapping(uint8 => uint8) storage m = m1; + m[1] = 42; + + (m = m2)[2] = 21; + + return (m1[1], m1[2], m2[1], m2[2]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); +} + + BOOST_AUTO_TEST_CASE(structs) { char const* sourceCode = R"( -- cgit v1.2.3 From 3b5eee499862c8df0a751527d310f68c42f08edf Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 6 Aug 2018 16:57:10 +0200 Subject: Tests for deriving types for empty string. --- test/libsolidity/SolidityEndToEndTest.cpp | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 066e97e6..9c287e5e 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -12489,6 +12489,44 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_signaturev2) ABI_CHECK(callContractFunction("f4()"), expectation); } +BOOST_AUTO_TEST_CASE(abi_encode_empty_string) +{ + char const* sourceCode = R"( + // Tests that this will not end up using a "bytes0" type + // (which would assert) + contract C { + function f() public pure returns (bytes memory, bytes memory) { + return (abi.encode(""), abi.encodePacked("")); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs( + 0x40, 0xc0, + 0x60, 0x20, 0x00, 0x00, + 0x00 + )); +} + +BOOST_AUTO_TEST_CASE(abi_encode_empty_string_v2) +{ + char const* sourceCode = R"( + // Tests that this will not end up using a "bytes0" type + // (which would assert) + pragma experimental ABIEncoderV2; + contract C { + function f() public pure returns (bytes memory, bytes memory) { + return (abi.encode(""), abi.encodePacked("")); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs( + 0x40, 0xa0, + 0x40, 0x20, 0x00, + 0x00 + )); +} BOOST_AUTO_TEST_CASE(abi_encode_call) { char const* sourceCode = R"T( -- cgit v1.2.3 From 5298d818c4808377d3acb8980c2e763b9f86ada7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Aug 2018 10:52:01 +0100 Subject: Add test for abi.encode (negative) literals --- test/libsolidity/SolidityEndToEndTest.cpp | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 9c287e5e..bd1d9de7 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -12527,6 +12527,42 @@ BOOST_AUTO_TEST_CASE(abi_encode_empty_string_v2) 0x00 )); } + +BOOST_AUTO_TEST_CASE(abi_encode_rational) +{ + char const* sourceCode = R"( + // Tests that rational numbers (even negative ones) are encoded properly. + contract C { + function f() public pure returns (bytes memory) { + return abi.encode(1, -2); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs( + 0x20, + 0x40, u256(1), u256(-2) + )); +} + +BOOST_AUTO_TEST_CASE(abi_encode_rational_v2) +{ + char const* sourceCode = R"( + // Tests that rational numbers (even negative ones) are encoded properly. + pragma experimental ABIEncoderV2; + contract C { + function f() public pure returns (bytes memory) { + return abi.encode(1, -2); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs( + 0x20, + 0x40, u256(1), u256(-2) + )); +} + BOOST_AUTO_TEST_CASE(abi_encode_call) { char const* sourceCode = R"T( -- cgit v1.2.3 From 34a711a14daf9874061a83401bf28a57b3abf1b1 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Aug 2018 13:43:12 +0100 Subject: Add endToEnd test for referencing enums --- test/libsolidity/SolidityEndToEndTest.cpp | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 9c287e5e..c291c6d6 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4577,6 +4577,50 @@ BOOST_AUTO_TEST_CASE(constructing_enums_from_ints) ABI_CHECK(callContractFunction("test()"), encodeArgs(1)); } +BOOST_AUTO_TEST_CASE(enum_referencing) +{ + char const* sourceCode = R"( + interface I { + enum Direction { A, B, Left, Right } + } + library L { + enum Direction { Left, Right } + function f() public pure returns (Direction) { + return Direction.Right; + } + function g() public pure returns (I.Direction) { + return I.Direction.Right; + } + } + contract C is I { + function f() public pure returns (Direction) { + return Direction.Right; + } + function g() public pure returns (I.Direction) { + return I.Direction.Right; + } + function h() public pure returns (L.Direction) { + return L.Direction.Right; + } + function x() public pure returns (L.Direction) { + return L.f(); + } + function y() public pure returns (I.Direction) { + return L.g(); + } + } + )"; + compileAndRun(sourceCode, 0, "L"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("h()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("x()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("y()"), encodeArgs(3)); +} + BOOST_AUTO_TEST_CASE(inline_member_init) { char const* sourceCode = R"( -- cgit v1.2.3 From 09a36cba0223c16248335703412cee019c7aa59f Mon Sep 17 00:00:00 2001 From: Balajiganapathi S Date: Wed, 25 Oct 2017 13:42:07 +0530 Subject: Add stricter hex underscore rules --- test/libsolidity/SolidityEndToEndTest.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a6c1372b..12da1fa1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -12836,6 +12836,22 @@ BOOST_AUTO_TEST_CASE(write_storage_external) ABI_CHECK(callContractFunction("h()"), encodeArgs(12)); } +BOOST_AUTO_TEST_CASE(test_underscore_in_hex) +{ + char const* sourceCode = R"( + contract test { + function f(bool cond) returns (uint) { + uint32 x = 0x1234_ab; + uint y = 0x1234_abcd_1234; + return cond ? x : y; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f(bool)", true), encodeArgs(u256(0x1234ab))); + ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(u256(0x1234abcd1234))); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From b9222808f61e00833f8c11cd196cafb50ec9e1b9 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Fri, 3 Aug 2018 16:13:52 +0200 Subject: Cleanup & polish numbers-with-underscores parsing, also improving tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 12da1fa1..3fd610a0 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -12840,7 +12840,7 @@ BOOST_AUTO_TEST_CASE(test_underscore_in_hex) { char const* sourceCode = R"( contract test { - function f(bool cond) returns (uint) { + function f(bool cond) public pure returns (uint) { uint32 x = 0x1234_ab; uint y = 0x1234_abcd_1234; return cond ? x : y; -- cgit v1.2.3 From 1bfb841771bae7461540e5372ccf528b5508bb10 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Aug 2018 14:05:36 +0100 Subject: Remove experimental 0.5.0 pragma --- test/libsolidity/SolidityEndToEndTest.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a6c1372b..9f7602d1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -334,10 +334,9 @@ BOOST_AUTO_TEST_CASE(conditional_expression_functions) ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(u256(2))); } -BOOST_AUTO_TEST_CASE(C99_scoping_activation) +BOOST_AUTO_TEST_CASE(c99_scoping_activation) { char const* sourceCode = R"( - pragma experimental "v0.5.0"; contract test { function f() pure public returns (uint) { uint x = 7; -- cgit v1.2.3 From 7d7abeb1496dddfab7eb8705dbfc3d06284cf25d Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 6 Aug 2018 14:59:37 +0200 Subject: Disallow ambiguous conversions between number literals and bytesXX types. --- test/libsolidity/SolidityEndToEndTest.cpp | 106 +++++++++++++++--------------- 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e487f0ae..2c7e3947 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2211,7 +2211,7 @@ BOOST_AUTO_TEST_CASE(log0) char const* sourceCode = R"( contract test { function a() public { - log0(1); + log0(bytes32(uint256(1))); } } )"; @@ -2228,7 +2228,7 @@ BOOST_AUTO_TEST_CASE(log1) char const* sourceCode = R"( contract test { function a() public { - log1(1, 2); + log1(bytes32(uint256(1)), bytes32(uint256(2))); } } )"; @@ -2246,7 +2246,7 @@ BOOST_AUTO_TEST_CASE(log2) char const* sourceCode = R"( contract test { function a() public { - log2(1, 2, 3); + log2(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3))); } } )"; @@ -2265,7 +2265,7 @@ BOOST_AUTO_TEST_CASE(log3) char const* sourceCode = R"( contract test { function a() public { - log3(1, 2, 3, 4); + log3(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)), bytes32(uint256(4))); } } )"; @@ -2284,7 +2284,7 @@ BOOST_AUTO_TEST_CASE(log4) char const* sourceCode = R"( contract test { function a() public { - log4(1, 2, 3, 4, 5); + log4(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)), bytes32(uint256(4)), bytes32(uint256(5))); } } )"; @@ -2303,7 +2303,7 @@ BOOST_AUTO_TEST_CASE(log_in_constructor) char const* sourceCode = R"( contract test { constructor() public { - log1(1, 2); + log1(bytes32(uint256(1)), bytes32(uint256(2))); } } )"; @@ -5017,7 +5017,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_simple) function test() public returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) { for (uint i = 0; i < data1.length; ++i) data1[i] = bytes8(uint64(i)); - data2[8] = data2[9] = 2; + data2[8] = data2[9] = bytes8(uint64(2)); data2 = data1; a = data2[1]; b = data2[2]; @@ -5076,10 +5076,10 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover2) bytes8[4] data1; // fits into one slot bytes10[6] data2; // 4 elements need two slots function test() public returns (bytes10 r1, bytes10 r2, bytes10 r3) { - data1[0] = 1; - data1[1] = 2; - data1[2] = 3; - data1[3] = 4; + data1[0] = bytes8(uint64(1)); + data1[1] = bytes8(uint64(2)); + data1[2] = bytes8(uint64(3)); + data1[3] = bytes8(uint64(4)); for (uint i = 0; i < data2.length; ++i) data2[i] = bytes10(uint80(0xffff00 | (1 + i))); data2 = data1; @@ -5274,13 +5274,13 @@ BOOST_AUTO_TEST_CASE(byte_array_push) contract c { bytes data; function test() public returns (bool x) { - if (data.push(5) != 1) return true; - if (data[0] != 5) return true; - data.push(4); - if (data[1] != 4) return true; - uint l = data.push(3); - if (data[2] != 3) return true; - if (l != 3) return true; + if (data.push(0x05) != 1) return true; + if (data[0] != 0x05) return true; + data.push(0x04); + if (data[1] != 0x04) return true; + uint l = data.push(0x03); + if (data[2] != 0x03) return true; + if (l != 0x03) return true; } } )"; @@ -5453,11 +5453,11 @@ BOOST_AUTO_TEST_CASE(byte_array_pop) contract c { bytes data; function test() public returns (uint x, uint y, uint l) { - data.push(7); - x = data.push(3); + data.push(0x07); + x = data.push(0x03); data.pop(); data.pop(); - y = data.push(2); + y = data.push(0x02); l = data.length; } } @@ -5490,9 +5490,9 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty) contract c { bytes data; function test() public { - data.push(7); - data.push(5); - data.push(3); + data.push(0x07); + data.push(0x05); + data.push(0x03); data.pop(); data.pop(); data.pop(); @@ -5538,7 +5538,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty_garbage_ref) bytes data; function test() public { for (uint8 i = 0; i <= 40; i++) - data.push(3); + data.push(0x03); for (uint8 j = 0; j <= 40; j++) { assembly { mstore(0, "garbage") @@ -5560,7 +5560,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_masking_long) bytes data; function test() public returns (bytes memory) { for (uint i = 0; i < 34; i++) - data.push(3); + data.push(0x03); data.pop(); return data; } @@ -5582,7 +5582,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_copy_long) bytes data; function test() public returns (bytes memory) { for (uint i = 0; i < 33; i++) - data.push(3); + data.push(0x03); for (uint j = 0; j < 4; j++) data.pop(); return data; @@ -5672,10 +5672,10 @@ BOOST_AUTO_TEST_CASE(bytes_index_access) data[31] = 0x77; data[32] = 0x14; - data[31] = 1; - data[31] |= 8; - data[30] = 1; - data[32] = 3; + data[31] = 0x01; + data[31] |= 0x08; + data[30] = 0x01; + data[32] = 0x03; return uint(uint8(data[30])) * 0x100 | uint(uint8(data[31])) * 0x10 | uint(uint8(data[32])); } } @@ -5703,7 +5703,7 @@ BOOST_AUTO_TEST_CASE(bytes_delete_element) delete data[94]; delete data[96]; delete data[98]; - return data[94] == 0 && data[95] == 95 && data[96] == 0 && data[97] == 97; + return data[94] == 0 && uint8(data[95]) == 95 && data[96] == 0 && uint8(data[97]) == 97; } } )"; @@ -6060,19 +6060,19 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_bytes) s2 data; byte y; function test() public returns (bool) { - x = 1; - data.a = 2; - data.inner.a = 3; - data.inner.b = 4; + x = 0x01; + data.a = 0x02; + data.inner.a = 0x03; + data.inner.b = 0x04; data.inner.c = "1234567890"; data.inner.d = "123456789"; data.inner.e = "abcdefghij"; - data.b = 5; - data.c = 6; - y = 7; - return x == 1 && data.a == 2 && data.inner.a == 3 && data.inner.b == 4 && + data.b = 0x05; + data.c = byte(0x06); + y = 0x07; + return x == 0x01 && data.a == 0x02 && data.inner.a == 0x03 && data.inner.b == 0x04 && data.inner.c == "1234567890" && data.inner.d == "123456789" && - data.inner.e == "abcdefghij" && data.b == 5 && data.c == 6 && y == 7; + data.inner.e == "abcdefghij" && data.b == 0x05 && data.c == byte(0x06) && y == 0x07; } } )"; @@ -8062,17 +8062,17 @@ BOOST_AUTO_TEST_CASE(short_strings) if (data1[4] != "4") return 11; for (uint i = 0; i < data1.length; i ++) data1[i] = byte(uint8(i * 3)); - if (data1[4] != 4 * 3) return 12; - if (data1[67] != 67 * 3) return 13; + if (uint8(data1[4]) != 4 * 3) return 12; + if (uint8(data1[67]) != 67 * 3) return 13; // change length: long -> short data1.length = 22; if (data1.length != 22) return 14; - if (data1[21] != byte(21 * 3)) return 15; - if (data1[2] != 2 * 3) return 16; + if (uint8(data1[21]) != 21 * 3) return 15; + if (uint8(data1[2]) != 2 * 3) return 16; // change length: short -> shorter data1.length = 19; if (data1.length != 19) return 17; - if (data1[7] != byte(7 * 3)) return 18; + if (uint8(data1[7]) != 7 * 3) return 18; // and now again to original size data1.length = 22; if (data1.length != 22) return 19; @@ -8888,7 +8888,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_length_access) contract C { byte a; function f(bytes32 x) public returns (uint, uint, uint) { - return (x.length, bytes16(2).length, a.length + 7); + return (x.length, bytes16(uint128(2)).length, a.length + 7); } } )"; @@ -9383,9 +9383,9 @@ BOOST_AUTO_TEST_CASE(iszero_bnot_correct) char const* sourceCode = R"( contract C { function f() public returns (bool) { - bytes32 x = 1; + bytes32 x = bytes32(uint256(1)); assembly { x := not(x) } - if (x != ~bytes32(1)) return false; + if (x != ~bytes32(uint256(1))) return false; assembly { x := iszero(x) } if (x != bytes32(0)) return false; return true; @@ -9404,7 +9404,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types) function f(bytes2 a, uint16 x) public returns (uint) { if (a != "ab") return 1; if (x != 0x0102) return 2; - if (bytes3(uint24(x)) != 0x0102) return 3; + if (bytes3(uint24(x)) != 0x000102) return 3; return 0; } } @@ -9736,7 +9736,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input) char const* sourceCode = R"( contract C { function f() public returns (address) { - return ecrecover(bytes32(uint(-1)), 1, 2, 3); + return ecrecover(bytes32(uint(-1)), 1, bytes32(uint(2)), bytes32(uint(3))); } } )"; @@ -9754,8 +9754,8 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper) 0, // invalid v value 0x6944c77849b18048f6abe0db8084b0d0d0689cdddb53d2671c36967b58691ad4, 0xef4f06ba4f78319baafd0424365777241af4dfd3da840471b4b4b087b7750d0d, - 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c, - 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c + 0x000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c, + 0x000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c ); } function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s, uint blockExpired, bytes32 salt) -- cgit v1.2.3 From 57ada1d69e311f847b4581a0e487aebd1b0e468f Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 10 Aug 2018 15:13:12 +0200 Subject: Allow mapping arguments and return values in internal library functions. --- test/libsolidity/SolidityEndToEndTest.cpp | 156 ++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e487f0ae..cc89a307 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7961,6 +7961,162 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(4), u256(17))); } +BOOST_AUTO_TEST_CASE(mapping_arguments_in_library) +{ + char const* sourceCode = R"( + library Lib { + function set(mapping(uint => uint) storage m, uint key, uint value) internal + { + m[key] = value; + } + function get(mapping(uint => uint) storage m, uint key) internal view returns (uint) + { + return m[key]; + } + } + contract Test { + mapping(uint => uint) m; + function set(uint256 key, uint256 value) public returns (uint) + { + uint oldValue = Lib.get(m, key); + Lib.set(m, key, value); + return oldValue; + } + function get(uint256 key) public view returns (uint) { + return Lib.get(m, key); + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(42)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(84)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(7)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(21)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(42)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(14)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(21))); + ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(14))); +} + +BOOST_AUTO_TEST_CASE(mapping_returns_in_library) +{ + char const* sourceCode = R"( + library Lib { + function choose_mapping(mapping(uint => uint) storage a, mapping(uint => uint) storage b, bool c) internal pure returns(mapping(uint=>uint) storage) + { + return c ? a : b; + } + } + contract Test { + mapping(uint => uint) a; + mapping(uint => uint) b; + function set(bool choice, uint256 key, uint256 value) public returns (uint) + { + mapping(uint => uint) storage m = Lib.choose_mapping(a, b, choice); + uint oldValue = m[key]; + m[key] = value; + return oldValue; + } + function get(bool choice, uint256 key) public view returns (uint) { + return Lib.choose_mapping(a, b, choice)[key]; + } + function get_a(uint256 key) public view returns (uint) { + return a[key]; + } + function get_b(uint256 key) public view returns (uint) { + return b[key]; + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(42)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(84)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(7)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(10)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(11)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(12)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(10))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(11))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(12))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(10))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(11))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(12))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(21)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(42)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(14)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(30)), encodeArgs(u256(10))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(31)), encodeArgs(u256(11))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(32)), encodeArgs(u256(12))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(21))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(14))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(21))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(14))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(30))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(31))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(32))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(30))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(31))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(32))); +} + +BOOST_AUTO_TEST_CASE(mapping_returns_in_library_named) +{ + char const* sourceCode = R"( + library Lib { + function f(mapping(uint => uint) storage a, mapping(uint => uint) storage b) internal returns(mapping(uint=>uint) storage r) + { + r = a; + r[1] = 42; + r = b; + r[1] = 21; + } + } + contract Test { + mapping(uint => uint) a; + mapping(uint => uint) b; + function f() public returns (uint, uint, uint, uint, uint, uint) + { + Lib.f(a, b)[2] = 84; + return (a[0], a[1], a[2], b[0], b[1], b[2]); + } + function g() public returns (uint, uint, uint, uint, uint, uint) + { + mapping(uint => uint) storage m = Lib.f(a, b); + m[2] = 17; + return (a[0], a[1], a[2], b[0], b[1], b[2]); + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(84))); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(17))); +} + BOOST_AUTO_TEST_CASE(using_library_structs) { char const* sourceCode = R"( -- cgit v1.2.3 From a9f31da41146221c674356d5678030616110d471 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 10 Aug 2018 15:56:29 +0200 Subject: Allow mapping arguments and return values in all internal functions. --- test/libsolidity/SolidityEndToEndTest.cpp | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index cc89a307..09e94028 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1543,6 +1543,62 @@ BOOST_AUTO_TEST_CASE(mapping_local_compound_assignment) ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); } +BOOST_AUTO_TEST_CASE(mapping_internal_argument) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8) a; + mapping(uint8 => uint8) b; + function set_internal(mapping(uint8 => uint8) storage m, uint8 key, uint8 value) internal returns (uint8) { + uint8 oldValue = m[key]; + m[key] = value; + return oldValue; + } + function set(uint8 key, uint8 value_a, uint8 value_b) public returns (uint8 old_a, uint8 old_b) { + old_a = set_internal(a, key, value_a); + old_b = set_internal(b, key, value_b); + } + function get(uint8 key) public returns (uint8, uint8) { + return (a[key], b[key]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(21), byte(42)), encodeArgs(byte(0), byte(0))); + ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(42))); + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(10), byte(11)), encodeArgs(byte(21), byte(42))); + ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(11))); +} + +BOOST_AUTO_TEST_CASE(mapping_internal_return) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8) a; + mapping(uint8 => uint8) b; + function f() internal returns (mapping(uint8 => uint8) storage r) { + r = a; + r[1] = 42; + r = b; + r[1] = 84; + } + function g() public returns (uint8, uint8, uint8, uint8, uint8, uint8) { + f()[2] = 21; + return (a[0], a[1], a[2], b[0], b[1], b[2]); + } + function h() public returns (uint8, uint8, uint8, uint8, uint8, uint8) { + mapping(uint8 => uint8) storage m = f(); + m[2] = 17; + return (a[0], a[1], a[2], b[0], b[1], b[2]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("g()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (21))); + ABI_CHECK(callContractFunction("h()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (17))); +} BOOST_AUTO_TEST_CASE(structs) { -- cgit v1.2.3 From 341128962f001eb78e5e3e3a83beadbef8d697b0 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 13 Aug 2018 16:25:28 +0200 Subject: Allow mappings of arrays as arguments and return values of internal functions. --- test/libsolidity/SolidityEndToEndTest.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 09e94028..a978a654 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1571,6 +1571,36 @@ BOOST_AUTO_TEST_CASE(mapping_internal_argument) ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(11))); } +BOOST_AUTO_TEST_CASE(mapping_array_internal_argument) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8)[2] a; + mapping(uint8 => uint8)[2] b; + function set_internal(mapping(uint8 => uint8)[2] storage m, uint8 key, uint8 value1, uint8 value2) internal returns (uint8, uint8) { + uint8 oldValue1 = m[0][key]; + uint8 oldValue2 = m[1][key]; + m[0][key] = value1; + m[1][key] = value2; + return (oldValue1, oldValue2); + } + function set(uint8 key, uint8 value_a1, uint8 value_a2, uint8 value_b1, uint8 value_b2) public returns (uint8 old_a1, uint8 old_a2, uint8 old_b1, uint8 old_b2) { + (old_a1, old_a2) = set_internal(a, key, value_a1, value_a2); + (old_b1, old_b2) = set_internal(b, key, value_b1, value_b2); + } + function get(uint8 key) public returns (uint8, uint8, uint8, uint8) { + return (a[0][key], a[1][key], b[0][key], b[1][key]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(21), byte(22), byte(42), byte(43)), encodeArgs(byte(0), byte(0), byte(0), byte(0))); + ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(22), byte(42), byte(43))); + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(10), byte(30), byte(11), byte(31)), encodeArgs(byte(21), byte(22), byte(42), byte(43))); + ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(30), byte(11), byte(31))); +} + BOOST_AUTO_TEST_CASE(mapping_internal_return) { char const* sourceCode = R"( -- cgit v1.2.3 From 06b7edfdcfd960e5d4012c7d20913efab0516ca1 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 10 Aug 2018 19:19:21 +0200 Subject: Add missing tests for ``gasleft()``, ``blockhash()`` ``tx.gasprice`` and ``block.gaslimit``. --- test/libsolidity/SolidityEndToEndTest.cpp | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 5ffdf6af..15cd3f1d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2988,6 +2988,86 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic) BOOST_REQUIRE(callContractFunction("checkState()") == encodeArgs(false, 20 - 5)); } +BOOST_AUTO_TEST_CASE(gasleft_decrease) +{ + char const* sourceCode = R"( + contract C { + uint v; + function f() public returns (bool) { + uint startGas = gasleft(); + v++; + assert(startGas > gasleft()); + return true; + } + function g() public returns (bool) { + uint startGas = gasleft(); + assert(startGas > gasleft()); + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(true)); +} + +BOOST_AUTO_TEST_CASE(gaslimit) +{ + char const* sourceCode = R"( + contract C { + function f() public returns (uint) { + return block.gaslimit; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(gasLimit())); +} + +BOOST_AUTO_TEST_CASE(gasprice) +{ + char const* sourceCode = R"( + contract C { + function f() public returns (uint) { + return tx.gasprice; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(gasPrice())); +} + +BOOST_AUTO_TEST_CASE(blockhash) +{ + char const* sourceCode = R"( + contract C { + uint256 counter; + function g() public returns (bool) { counter++; return true; } + function f() public returns (bytes32[] memory r) { + r = new bytes32[](259); + for (uint i = 0; i < 259; i++) + r[i] = blockhash(block.number - 257 + i); + } + } + )"; + compileAndRun(sourceCode); + // generate a sufficient amount of blocks + while (blockNumber() < u256(255)) + ABI_CHECK(callContractFunction("g()"), encodeArgs(true)); + + vector hashes; + hashes.reserve(259); + // ``blockhash()`` is only valid for the last 256 blocks, otherwise zero + hashes.emplace_back(0); + for (u256 i = blockNumber() - u256(255); i <= blockNumber(); i++) + hashes.emplace_back(blockHash(i)); + // the current block hash is not yet known at execution time and therefore zero + hashes.emplace_back(0); + // future block hashes are zero + hashes.emplace_back(0); + ABI_CHECK(callContractFunction("f()"), encodeDyn(hashes)); +} + BOOST_AUTO_TEST_CASE(value_complex) { char const* sourceCode = R"( -- cgit v1.2.3 From b325a70d59baf1afc4e284cc8738d71069ec97c2 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 13 Aug 2018 14:55:51 +0200 Subject: Fix tests for constantinople (expect zero for the time being). --- test/libsolidity/SolidityEndToEndTest.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 15cd3f1d..d8e95ad2 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3056,15 +3056,28 @@ BOOST_AUTO_TEST_CASE(blockhash) ABI_CHECK(callContractFunction("g()"), encodeArgs(true)); vector hashes; - hashes.reserve(259); - // ``blockhash()`` is only valid for the last 256 blocks, otherwise zero - hashes.emplace_back(0); - for (u256 i = blockNumber() - u256(255); i <= blockNumber(); i++) - hashes.emplace_back(blockHash(i)); - // the current block hash is not yet known at execution time and therefore zero - hashes.emplace_back(0); - // future block hashes are zero - hashes.emplace_back(0); + // currently the test only works for pre-constantinople + if (Options::get().evmVersion() < EVMVersion::constantinople()) + { + // ``blockhash()`` is only valid for the last 256 blocks, otherwise zero + hashes.emplace_back(0); + for (u256 i = blockNumber() - u256(255); i <= blockNumber(); i++) + hashes.emplace_back(blockHash(i)); + // the current block hash is not yet known at execution time and therefore zero + hashes.emplace_back(0); + // future block hashes are zero + hashes.emplace_back(0); + } + else + // TODO: Starting from constantinople blockhash always seems to return zero. + // The blockhash contract introduced in EIP96 seems to break in our setup of + // aleth (setting the constantinople fork block to zero and resetting the chain + // to block zero before each test run). Pre-deploying the blockchain contract + // during genesis seems to help, but currently causes problems with other tests. + // Set the expectation to zero for now, so that this test tracks changes in this + // behavior. + hashes.assign(259, 0); + ABI_CHECK(callContractFunction("f()"), encodeDyn(hashes)); } -- cgit v1.2.3 From 81faafe7f233f185b5efd9340ccb0185baf226e4 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Fri, 10 Aug 2018 11:51:41 +0200 Subject: Adds support for structs in interfaces. Closes #4733. --- test/libsolidity/SolidityEndToEndTest.cpp | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index d8e95ad2..7b56fa9d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4755,6 +4755,68 @@ BOOST_AUTO_TEST_CASE(constructing_enums_from_ints) ABI_CHECK(callContractFunction("test()"), encodeArgs(1)); } +BOOST_AUTO_TEST_CASE(struct_referencing) +{ + static char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + interface I { + struct S { uint a; } + } + library L { + struct S { uint b; uint a; } + function f() public pure returns (S) { + S memory s; + s.a = 3; + return s; + } + function g() public pure returns (I.S) { + I.S memory s; + s.a = 4; + return s; + } + // argument-dependant lookup tests + function a(I.S memory) public pure returns (uint) { return 1; } + function a(S memory) public pure returns (uint) { return 2; } + } + contract C is I { + function f() public pure returns (S) { + S memory s; + s.a = 1; + return s; + } + function g() public pure returns (I.S) { + I.S memory s; + s.a = 2; + return s; + } + function h() public pure returns (L.S) { + L.S memory s; + s.a = 5; + return s; + } + function x() public pure returns (L.S) { + return L.f(); + } + function y() public pure returns (I.S) { + return L.g(); + } + function a1() public pure returns (uint) { S memory s; return L.a(s); } + function a2() public pure returns (uint) { L.S memory s; return L.a(s); } + } + )"; + compileAndRun(sourceCode, 0, "L"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 3)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(4)); + compileAndRun(sourceCode, 0, "C", bytes(), map{ {"L", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(2)); + ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 5)); + ABI_CHECK(callContractFunction("x()"), encodeArgs(0, 3)); + ABI_CHECK(callContractFunction("y()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("a1()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("a2()"), encodeArgs(2)); +} + BOOST_AUTO_TEST_CASE(enum_referencing) { char const* sourceCode = R"( -- cgit v1.2.3 From b000a022f2d7c1057ade755ed1ea8c70380688a5 Mon Sep 17 00:00:00 2001 From: Chase McDermott Date: Tue, 7 Aug 2018 15:19:50 +0200 Subject: Update tests --- test/libsolidity/SolidityEndToEndTest.cpp | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7b56fa9d..af2b3485 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -526,7 +526,7 @@ BOOST_AUTO_TEST_CASE(array_multiple_local_vars) { char const* sourceCode = R"( contract test { - function f(uint256[] seq) external pure returns (uint256) { + function f(uint256[] calldata seq) external pure returns (uint256) { uint i = 0; uint sum = 0; while (i < seq.length) @@ -4540,7 +4540,7 @@ BOOST_AUTO_TEST_CASE(struct_containing_bytes_copy_and_delete) struct Struct { uint a; bytes data; uint b; } Struct data1; Struct data2; - function set(uint _a, bytes _data, uint _b) external returns (bool) { + function set(uint _a, bytes calldata _data, uint _b) external returns (bool) { data1.a = _a; data1.b = _b; data1.data = _data; @@ -4764,12 +4764,12 @@ BOOST_AUTO_TEST_CASE(struct_referencing) } library L { struct S { uint b; uint a; } - function f() public pure returns (S) { + function f() public pure returns (S memory) { S memory s; s.a = 3; return s; } - function g() public pure returns (I.S) { + function g() public pure returns (I.S memory) { I.S memory s; s.a = 4; return s; @@ -4779,25 +4779,25 @@ BOOST_AUTO_TEST_CASE(struct_referencing) function a(S memory) public pure returns (uint) { return 2; } } contract C is I { - function f() public pure returns (S) { + function f() public pure returns (S memory) { S memory s; s.a = 1; return s; } - function g() public pure returns (I.S) { + function g() public pure returns (I.S memory) { I.S memory s; s.a = 2; return s; } - function h() public pure returns (L.S) { + function h() public pure returns (L.S memory) { L.S memory s; s.a = 5; return s; } - function x() public pure returns (L.S) { + function x() public pure returns (L.S memory) { return L.f(); } - function y() public pure returns (I.S) { + function y() public pure returns (I.S memory) { return L.g(); } function a1() public pure returns (uint) { S memory s; return L.a(s); } @@ -4941,7 +4941,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_arguments) uint result; function f(uint a, uint b) public { result += a + b; } function g(uint a) public { result *= a; } - function test(uint a, bytes data1, bytes data2, uint b) external returns (uint r_a, uint r, uint r_b, uint l) { + function test(uint a, bytes calldata data1, bytes calldata data2, uint b) external returns (uint r_a, uint r, uint r_b, uint l) { r_a = a; address(this).call(data1); address(this).call(data2); @@ -5876,7 +5876,7 @@ BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( contract c { - function test(uint[8] a, uint[] b, uint[5] c, uint a_index, uint b_index, uint c_index) + function test(uint[8] calldata a, uint[] calldata b, uint[5] calldata c, uint a_index, uint b_index, uint c_index) external returns (uint av, uint bv, uint cv) { av = a[a_index]; bv = b[b_index]; @@ -5901,10 +5901,10 @@ BOOST_AUTO_TEST_CASE(bytes_index_access) char const* sourceCode = R"( contract c { bytes data; - function direct(bytes arg, uint index) external returns (uint) { + function direct(bytes calldata arg, uint index) external returns (uint) { return uint(uint8(arg[index])); } - function storageCopyRead(bytes arg, uint index) external returns (uint) { + function storageCopyRead(bytes calldata arg, uint index) external returns (uint) { data = arg; return uint(uint8(data[index])); } @@ -5959,7 +5959,7 @@ BOOST_AUTO_TEST_CASE(array_copy_calldata_storage) uint[9] m_data; uint[] m_data_dyn; uint8[][] m_byte_data; - function store(uint[9] a, uint8[3][] b) external returns (uint8) { + function store(uint[9] calldata a, uint8[3][] calldata b) external returns (uint8) { m_data = a; m_data_dyn = a; m_byte_data = b; @@ -5998,7 +5998,7 @@ BOOST_AUTO_TEST_CASE(array_copy_nested_array) uint[4][] a; uint[10][] b; uint[][] c; - function test(uint[2][] d) external returns (uint) { + function test(uint[2][] calldata d) external returns (uint) { a = d; b = a; c = b; @@ -6949,7 +6949,7 @@ BOOST_AUTO_TEST_CASE(return_string) char const* sourceCode = R"( contract Main { string public s; - function set(string _s) external { + function set(string calldata _s) external { s = _s; } function get1() public returns (string memory r) { @@ -6975,7 +6975,7 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) contract Main { string public s1; string public s2; - function set(string _s1, uint x, string _s2) external returns (uint) { + function set(string calldata _s1, uint x, string calldata _s2) external returns (uint) { s1 = _s1; s2 = _s2; return x; @@ -7024,7 +7024,7 @@ BOOST_AUTO_TEST_CASE(accessor_involving_strings) contract Main { struct stringData { string a; uint b; string c; } mapping(uint => stringData[]) public data; - function set(uint x, uint y, string a, uint b, string c) external returns (bool) { + function set(uint x, uint y, string calldata a, uint b, string calldata c) external returns (bool) { data[x].length = y + 1; data[x][y].a = a; data[x][y].b = b; @@ -7061,7 +7061,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) function setIndirectFromMemory(string memory _s1, uint x, string memory _s2) public returns (uint) { return this.set(_s1, x, _s2); } - function setIndirectFromCalldata(string _s1, uint x, string _s2) external returns (uint) { + function setIndirectFromCalldata(string calldata _s1, uint x, string calldata _s2) external returns (uint) { return this.set(_s1, x, _s2); } } @@ -7102,7 +7102,7 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) s1 = _s1; _r1 = s1; } - function set(bytes _s1) external returns (uint _r, bytes memory _r1) { + function set(bytes calldata _s1) external returns (uint _r, bytes memory _r1) { _r1 = doSet(_s1); _r = _r1.length; } @@ -8040,7 +8040,7 @@ BOOST_AUTO_TEST_CASE(library_call) BOOST_AUTO_TEST_CASE(library_function_external) { char const* sourceCode = R"( - library Lib { function m(bytes b) external pure returns (byte) { return b[2]; } } + library Lib { function m(bytes calldata b) external pure returns (byte) { return b[2]; } } contract Test { function f(bytes memory b) public pure returns (byte) { return Lib.m(b); -- cgit v1.2.3 From 9328ea4c3c023950e59405941cfc25ec4c0ed1b4 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sat, 30 Jun 2018 18:09:13 +0200 Subject: Add abi.decode(bytes data, (...)) --- test/libsolidity/SolidityEndToEndTest.cpp | 197 ++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index af2b3485..8a334e5e 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -13195,6 +13195,203 @@ BOOST_AUTO_TEST_CASE(senders_balance) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(27))); } +BOOST_AUTO_TEST_CASE(abi_decode_trivial) +{ + char const* sourceCode = R"( + contract C { + function f(bytes memory data) public pure returns (uint) { + return abi.decode(data, (uint)); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f(bytes)", 0x20, 0x20, 33), encodeArgs(u256(33))); +} + +BOOST_AUTO_TEST_CASE(abi_encode_decode_simple) +{ + char const* sourceCode = R"XX( + contract C { + function f() public pure returns (uint, bytes memory) { + bytes memory arg = "abcdefg"; + return abi.decode(abi.encode(uint(33), arg), (uint, bytes)); + } + } + )XX"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f()"), + encodeArgs(33, 0x40, 7, "abcdefg") + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_simple) +{ + char const* sourceCode = R"( + contract C { + function f(bytes memory data) public pure returns (uint, bytes memory) { + return abi.decode(data, (uint, bytes)); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f(bytes)", 0x20, 0x20 * 4, 33, 0x40, 7, "abcdefg"), + encodeArgs(33, 0x40, 7, "abcdefg") + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + struct S { uint a; uint[] b; } + function f() public pure returns (S memory) { + S memory s; + s.a = 8; + s.b = new uint[](3); + s.b[0] = 9; + s.b[1] = 10; + s.b[2] = 11; + return abi.decode(abi.encode(s), (S)); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f()"), + encodeArgs(0x20, 8, 0x40, 3, 9, 10, 11) + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_simple_storage) +{ + char const* sourceCode = R"( + contract C { + bytes data; + function f(bytes memory _data) public returns (uint, bytes memory) { + data = _data; + return abi.decode(data, (uint, bytes)); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f(bytes)", 0x20, 0x20 * 4, 33, 0x40, 7, "abcdefg"), + encodeArgs(33, 0x40, 7, "abcdefg") + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_v2_storage) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + bytes data; + struct S { uint a; uint[] b; } + function f() public returns (S memory) { + S memory s; + s.a = 8; + s.b = new uint[](3); + s.b[0] = 9; + s.b[1] = 10; + s.b[2] = 11; + data = abi.encode(s); + return abi.decode(data, (S)); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f()"), + encodeArgs(0x20, 8, 0x40, 3, 9, 10, 11) + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_calldata) +{ + char const* sourceCode = R"( + contract C { + function f(bytes calldata data) external pure returns (uint, bytes memory r) { + return abi.decode(data, (uint, bytes)); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f(bytes)", 0x20, 0x20 * 4, 33, 0x40, 7, "abcdefg"), + encodeArgs(33, 0x40, 7, "abcdefg") + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_v2_calldata) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + struct S { uint a; uint[] b; } + function f(bytes calldata data) external pure returns (S memory) { + return abi.decode(data, (S)); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f(bytes)", 0x20, 0x20 * 7, 0x20, 33, 0x40, 3, 10, 11, 12), + encodeArgs(0x20, 33, 0x40, 3, 10, 11, 12) + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_static_array) +{ + char const* sourceCode = R"( + contract C { + function f(bytes calldata data) external pure returns (uint[2][3] memory) { + return abi.decode(data, (uint[2][3])); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f(bytes)", 0x20, 6 * 0x20, 1, 2, 3, 4, 5, 6), + encodeArgs(1, 2, 3, 4, 5, 6) + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_static_array_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + function f(bytes calldata data) external pure returns (uint[2][3] memory) { + return abi.decode(data, (uint[2][3])); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f(bytes)", 0x20, 6 * 0x20, 1, 2, 3, 4, 5, 6), + encodeArgs(1, 2, 3, 4, 5, 6) + ); +} + +BOOST_AUTO_TEST_CASE(abi_decode_dynamic_array) +{ + char const* sourceCode = R"( + contract C { + function f(bytes calldata data) external pure returns (uint[] memory) { + return abi.decode(data, (uint[])); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK( + callContractFunction("f(bytes)", 0x20, 6 * 0x20, 0x20, 4, 3, 4, 5, 6), + encodeArgs(0x20, 4, 3, 4, 5, 6) + ); +} + BOOST_AUTO_TEST_CASE(write_storage_external) { char const* sourceCode = R"( -- cgit v1.2.3 From 7ca0aaaf6f62aafd0fe36ae6b7dc777361ae40e3 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 15 Aug 2018 14:40:20 +0200 Subject: Add ``staticcall`` to ``address``. --- test/libsolidity/SolidityEndToEndTest.cpp | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8a334e5e..b3618ad9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3592,6 +3592,19 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws) )YY"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("f()"), encodeArgs(0)); + + if (dev::test::Options::get().evmVersion().hasStaticCall()) + { + char const* sourceCode = R"YY( + contract A { + function f() public returns (bool) { + return address(this).staticcall(""); + } + } + )YY"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(0)); + } } BOOST_AUTO_TEST_CASE(short_data_calls_fallback) @@ -4215,6 +4228,49 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) BOOST_CHECK_EQUAL(balanceAt(c_senderAddress), 50 + 11); } +BOOST_AUTO_TEST_CASE(generic_staticcall) +{ + if (dev::test::Options::get().evmVersion().hasStaticCall()) + { + char const* sourceCode = R"**( + contract A { + uint public x; + constructor() public { x = 42; } + function pureFunction(uint256 p) public pure returns (uint256) { return p; } + function viewFunction(uint256 p) public view returns (uint256) { return p + x; } + function nonpayableFunction(uint256 p) public returns (uint256) { x = p; return x; } + function assertFunction(uint256 p) public view returns (uint256) { assert(x == p); return x; } + } + contract C { + function f(address a) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("pureFunction(uint256)", 23)); + } + function g(address a) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("viewFunction(uint256)", 23)); + } + function h(address a) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("nonpayableFunction(uint256)", 23)); + } + function i(address a, uint256 v) public view returns (bool) + { + return a.staticcall(abi.encodeWithSignature("assertFunction(uint256)", v)); + } + } + )**"; + compileAndRun(sourceCode, 0, "A"); + u160 const c_addressA = m_contractAddress; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f(address)", c_addressA), encodeArgs(true)); + ABI_CHECK(callContractFunction("g(address)", c_addressA), encodeArgs(true)); + ABI_CHECK(callContractFunction("h(address)", c_addressA), encodeArgs(false)); + ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 42), encodeArgs(true)); + ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 23), encodeArgs(false)); + } +} + BOOST_AUTO_TEST_CASE(library_call_in_homestead) { char const* sourceCode = R"( @@ -12216,6 +12272,19 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); ABI_CHECK(callContractFunction("h()"), encodeArgs(u256(1))); + + if (dev::test::Options::get().evmVersion().hasStaticCall()) + { + char const* sourceCode = R"YY( + contract C { + function f() external returns (bool) { + return address(0x4242).staticcall(""); + } + } + )YY"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); + } } BOOST_AUTO_TEST_CASE(delegatecall_return_value) -- cgit v1.2.3 From c3d3ae80fa59df3a134141ed75f4d195984960fd Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Wed, 15 Aug 2018 16:54:13 +0200 Subject: Add end to end tests --- test/libsolidity/SolidityEndToEndTest.cpp | 203 ++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8a334e5e..ce3c4324 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3937,6 +3937,209 @@ BOOST_AUTO_TEST_CASE(event_really_really_lots_of_data_from_storage) BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(uint256,bytes,uint256)"))); } +BOOST_AUTO_TEST_CASE(event_struct_memory_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + struct S { uint a; } + event E(S); + function createEvent(uint x) public { + emit E(S(x)); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(x)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E((uint256))"))); +} + +BOOST_AUTO_TEST_CASE(event_struct_storage_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + struct S { uint a; } + event E(S); + S s; + function createEvent(uint x) public { + s.a = x; + emit E(s); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(x)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E((uint256))"))); +} + +BOOST_AUTO_TEST_CASE(event_dynamic_array_memory) +{ + char const* sourceCode = R"( + contract C { + event E(uint[]); + function createEvent(uint x) public { + uint[] memory arr = new uint[](3); + arr[0] = x; + arr[1] = x + 1; + arr[2] = x + 2; + emit E(arr); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])"))); +} + +BOOST_AUTO_TEST_CASE(event_dynamic_array_memory_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + event E(uint[]); + function createEvent(uint x) public { + uint[] memory arr = new uint[](3); + arr[0] = x; + arr[1] = x + 1; + arr[2] = x + 2; + emit E(arr); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])"))); +} + +BOOST_AUTO_TEST_CASE(event_dynamic_nested_array_memory_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + event E(uint[][]); + function createEvent(uint x) public { + uint[][] memory arr = new uint[][](2); + arr[0] = new uint[](2); + arr[1] = new uint[](2); + arr[0][0] = x; + arr[0][1] = x + 1; + arr[1][0] = x + 2; + arr[1][1] = x + 3; + emit E(arr); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 2, 0x40, 0xa0, 2, x, x + 1, 2, x + 2, x + 3)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[][])"))); +} + +BOOST_AUTO_TEST_CASE(event_dynamic_array_storage) +{ + char const* sourceCode = R"( + contract C { + event E(uint[]); + uint[] arr; + function createEvent(uint x) public { + arr.length = 3; + arr[0] = x; + arr[1] = x + 1; + arr[2] = x + 2; + emit E(arr); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])"))); +} + +BOOST_AUTO_TEST_CASE(event_dynamic_array_storage_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + event E(uint[]); + uint[] arr; + function createEvent(uint x) public { + arr.length = 3; + arr[0] = x; + arr[1] = x + 1; + arr[2] = x + 2; + emit E(arr); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])"))); +} + +BOOST_AUTO_TEST_CASE(event_dynamic_nested_array_storage_v2) +{ + char const* sourceCode = R"( + pragma experimental ABIEncoderV2; + contract C { + event E(uint[][]); + uint[][] arr; + function createEvent(uint x) public { + arr.length = 2; + arr[0].length = 2; + arr[1].length = 2; + arr[0][0] = x; + arr[0][1] = x + 1; + arr[1][0] = x + 2; + arr[1][1] = x + 3; + emit E(arr); + } + } + )"; + compileAndRun(sourceCode); + u256 x(42); + callContractFunction("createEvent(uint256)", x); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 2, 0x40, 0xa0, 2, x, x + 1, 2, x + 2, x + 3)); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[][])"))); +} + BOOST_AUTO_TEST_CASE(event_indexed_string) { char const* sourceCode = R"( -- cgit v1.2.3 From b7c6e53d3d74b649ee6275254d30162aef403e17 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Mon, 20 Aug 2018 15:13:38 +0200 Subject: Fix endToEnd test --- test/libsolidity/SolidityEndToEndTest.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 2bf20126..f058458d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10528,11 +10528,18 @@ BOOST_AUTO_TEST_CASE(non_payable_throw) contract C { uint public a; function f() public returns (uint) { + return msgvalue(); + } + function msgvalue() internal returns (uint) { return msg.value; } function() external { + update(); + } + function update() internal { a = msg.value + 1; } + } )"; compileAndRun(sourceCode, 0, "C"); @@ -10555,6 +10562,9 @@ BOOST_AUTO_TEST_CASE(no_nonpayable_circumvention_by_modifier) if (false) _; // avoid the function, we should still not accept ether } function f() tryCircumvent public returns (uint) { + return msgvalue(); + } + function msgvalue() internal returns (uint) { return msg.value; } } -- cgit v1.2.3 From 82f512a7d40a3bd6a13dd799be66dd164fded077 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 15 Aug 2018 23:30:09 +0200 Subject: Add return data to bare calls. --- test/libsolidity/SolidityEndToEndTest.cpp | 158 ++++++++++++++++++++---------- 1 file changed, 105 insertions(+), 53 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 2bf20126..922f0fb6 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3586,7 +3586,8 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws) char const* sourceCode = R"YY( contract A { function f() public returns (bool) { - return address(this).call(""); + (bool success,) = address(this).call(""); + return success; } } )YY"; @@ -3598,7 +3599,9 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws) char const* sourceCode = R"YY( contract A { function f() public returns (bool) { - return address(this).staticcall(""); + (bool success, bytes memory data) = address(this).staticcall(""); + assert(data.length == 0); + return success; } } )YY"; @@ -4408,7 +4411,8 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) function doSend(address rec) public payable { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); - if (rec.delegatecall(abi.encodeWithSelector(signature, 23))) {} + (bool success,) = rec.delegatecall(abi.encodeWithSelector(signature, 23)); + success; } } )**"; @@ -4445,19 +4449,19 @@ BOOST_AUTO_TEST_CASE(generic_staticcall) function assertFunction(uint256 p) public view returns (uint256) { assert(x == p); return x; } } contract C { - function f(address a) public view returns (bool) + function f(address a) public view returns (bool, bytes memory) { return a.staticcall(abi.encodeWithSignature("pureFunction(uint256)", 23)); } - function g(address a) public view returns (bool) + function g(address a) public view returns (bool, bytes memory) { return a.staticcall(abi.encodeWithSignature("viewFunction(uint256)", 23)); } - function h(address a) public view returns (bool) + function h(address a) public view returns (bool, bytes memory) { return a.staticcall(abi.encodeWithSignature("nonpayableFunction(uint256)", 23)); } - function i(address a, uint256 v) public view returns (bool) + function i(address a, uint256 v) public view returns (bool, bytes memory) { return a.staticcall(abi.encodeWithSignature("assertFunction(uint256)", v)); } @@ -4466,11 +4470,11 @@ BOOST_AUTO_TEST_CASE(generic_staticcall) compileAndRun(sourceCode, 0, "A"); u160 const c_addressA = m_contractAddress; compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f(address)", c_addressA), encodeArgs(true)); - ABI_CHECK(callContractFunction("g(address)", c_addressA), encodeArgs(true)); - ABI_CHECK(callContractFunction("h(address)", c_addressA), encodeArgs(false)); - ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 42), encodeArgs(true)); - ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 23), encodeArgs(false)); + ABI_CHECK(callContractFunction("f(address)", c_addressA), encodeArgs(true, 0x40, 0x20, 23)); + ABI_CHECK(callContractFunction("g(address)", c_addressA), encodeArgs(true, 0x40, 0x20, 23 + 42)); + ABI_CHECK(callContractFunction("h(address)", c_addressA), encodeArgs(false, 0x40, 0x00)); + ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 42), encodeArgs(true, 0x40, 0x20, 42)); + ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 23), encodeArgs(false, 0x40, 0x00)); } } @@ -4570,7 +4574,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) contract sender { constructor() public { rec = new receiver(); } function() external { savedData = msg.data; } - function forward() public returns (bool) { !address(rec).call(savedData); return true; } + function forward() public returns (bool) { address(rec).call(savedData); return true; } function clear() public returns (bool) { delete savedData; return true; } function val() public returns (uint) { return rec.received(); } receiver rec; @@ -4599,18 +4603,21 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) receiver rec; constructor() public { rec = new receiver(); } function viaCalldata() public returns (uint) { - require(address(rec).call(msg.data)); + (bool success,) = address(rec).call(msg.data); + require(success); return rec.calledLength(); } function viaMemory() public returns (uint) { bytes memory x = msg.data; - require(address(rec).call(x)); + (bool success,) = address(rec).call(x); + require(success); return rec.calledLength(); } bytes s; function viaStorage() public returns (uint) { s = msg.data; - require(address(rec).call(s)); + (bool success,) = address(rec).call(s); + require(success); return rec.calledLength(); } } @@ -10336,7 +10343,8 @@ BOOST_AUTO_TEST_CASE(mutex) // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) revert(); - if (!msg.sender.call.value(amount)("")) revert(); + (bool success,) = msg.sender.call.value(amount)(""); + require(success); shares -= amount; return shares; } @@ -10344,7 +10352,8 @@ BOOST_AUTO_TEST_CASE(mutex) // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) revert(); - if (!msg.sender.call.value(amount)("")) revert(); + (bool success,) = msg.sender.call.value(amount)(""); + require(success); shares -= amount; return shares; } @@ -12465,10 +12474,12 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address) contract C { /// Calling into non-existant account is successful (creates the account) function f() external returns (bool) { - return address(0x4242).call(""); + (bool success,) = address(0x4242).call(""); + return success; } function h() external returns (bool) { - return address(0x4242).delegatecall(""); + (bool success,) = address(0x4242).delegatecall(""); + return success; } } )YY"; @@ -12480,50 +12491,90 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address) { char const* sourceCode = R"YY( contract C { - function f() external returns (bool) { + function f() external returns (bool, bytes memory) { return address(0x4242).staticcall(""); } } )YY"; compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), 0x40, 0x00)); } } BOOST_AUTO_TEST_CASE(delegatecall_return_value) { - char const* sourceCode = R"DELIMITER( - contract C { - uint value; - function set(uint _value) external { - value = _value; - } - function get() external view returns (uint) { - return value; - } - function get_delegated() external returns (bool) { - return address(this).delegatecall(abi.encodeWithSignature("get()")); - } - function assert0() external view { - assert(value == 0); + if (dev::test::Options::get().evmVersion().supportsReturndata()) + { + char const* sourceCode = R"DELIMITER( + contract C { + uint value; + function set(uint _value) external { + value = _value; + } + function get() external view returns (uint) { + return value; + } + function get_delegated() external returns (bool, bytes memory) { + return address(this).delegatecall(abi.encodeWithSignature("get()")); + } + function assert0() external view { + assert(value == 0); + } + function assert0_delegated() external returns (bool, bytes memory) { + return address(this).delegatecall(abi.encodeWithSignature("assert0()")); + } } - function assert0_delegated() external returns (bool) { - return address(this).delegatecall(abi.encodeWithSignature("assert0()")); + )DELIMITER"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(1), 0x40, 0x00)); + ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1), 0x40, 0x20, 0x00)); + ABI_CHECK(callContractFunction("set(uint256)", u256(1)), encodeArgs()); + ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0), 0x40, 0x00)); + ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1), 0x40, 0x20, 1)); + ABI_CHECK(callContractFunction("set(uint256)", u256(42)), encodeArgs()); + ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0), 0x40, 0x00)); + ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1), 0x40, 0x20, 42)); + } + else + { + char const* sourceCode = R"DELIMITER( + contract C { + uint value; + function set(uint _value) external { + value = _value; + } + function get() external view returns (uint) { + return value; + } + function get_delegated() external returns (bool) { + (bool success,) = address(this).delegatecall(abi.encodeWithSignature("get()")); + return success; + } + function assert0() external view { + assert(value == 0); + } + function assert0_delegated() external returns (bool) { + (bool success,) = address(this).delegatecall(abi.encodeWithSignature("assert0()")); + return success; + } } - } - )DELIMITER"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("set(uint256)", u256(1)), encodeArgs()); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("set(uint256)", u256(42)), encodeArgs()); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); + )DELIMITER"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunction("set(uint256)", u256(1)), encodeArgs()); + ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunction("set(uint256)", u256(42)), encodeArgs()); + ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); + } } BOOST_AUTO_TEST_CASE(function_types_sig) @@ -13292,7 +13343,8 @@ BOOST_AUTO_TEST_CASE(abi_encode_call) uint[] memory b = new uint[](2); b[0] = 6; b[1] = 7; - require(address(this).call(abi.encodeWithSignature("c(uint256,uint256[])", a, b))); + (bool success,) = address(this).call(abi.encodeWithSignature("c(uint256,uint256[])", a, b)); + require(success); return x; } } -- cgit v1.2.3 From e3097b30dace9bbd88a5a74e6507baad0bc12cc4 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 4 Sep 2018 15:03:06 +0200 Subject: Add another end-to-end test. --- test/libsolidity/SolidityEndToEndTest.cpp | 127 ++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 922f0fb6..63067b3c 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -12501,6 +12501,133 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address) } } +BOOST_AUTO_TEST_CASE(bare_call_return_data) +{ + if (dev::test::Options::get().evmVersion().supportsReturndata()) + { + vector calltypes = {"call", "delegatecall"}; + if (dev::test::Options::get().evmVersion().hasStaticCall()) + calltypes.emplace_back("staticcall"); + for (string const& calltype: calltypes) + { + string sourceCode = R"DELIMITER( + contract A { + constructor() public { + } + function return_bool() public pure returns(bool) { + return true; + } + function return_int32() public pure returns(int32) { + return -32; + } + function return_uint32() public pure returns(uint32) { + return 0x3232; + } + function return_int256() public pure returns(int256) { + return -256; + } + function return_uint256() public pure returns(uint256) { + return 0x256256; + } + function return_bytes4() public pure returns(bytes4) { + return 0xabcd0012; + } + function return_multi() public pure returns(bool, uint32, bytes4) { + return (false, 0x3232, 0xabcd0012); + } + function return_bytes() public pure returns(bytes memory b) { + b = new bytes(2); + b[0] = 0x42; + b[1] = 0x21; + } + } + contract C { + A addr; + constructor() public { + addr = new A(); + } + function f(string memory signature) public returns (bool, bytes memory) { + return address(addr).)DELIMITER" + calltype + R"DELIMITER((abi.encodeWithSignature(signature)); + } + function check_bool() external returns (bool) { + (bool success, bytes memory data) = f("return_bool()"); + assert(success); + bool a = abi.decode(data, (bool)); + assert(a); + return true; + } + function check_int32() external returns (bool) { + (bool success, bytes memory data) = f("return_int32()"); + assert(success); + int32 a = abi.decode(data, (int32)); + assert(a == -32); + return true; + } + function check_uint32() external returns (bool) { + (bool success, bytes memory data) = f("return_uint32()"); + assert(success); + uint32 a = abi.decode(data, (uint32)); + assert(a == 0x3232); + return true; + } + function check_int256() external returns (bool) { + (bool success, bytes memory data) = f("return_int256()"); + assert(success); + int256 a = abi.decode(data, (int256)); + assert(a == -256); + return true; + } + function check_uint256() external returns (bool) { + (bool success, bytes memory data) = f("return_uint256()"); + assert(success); + uint256 a = abi.decode(data, (uint256)); + assert(a == 0x256256); + return true; + } + function check_bytes4() external returns (bool) { + (bool success, bytes memory data) = f("return_bytes4()"); + assert(success); + bytes4 a = abi.decode(data, (bytes4)); + assert(a == 0xabcd0012); + return true; + } + function check_multi() external returns (bool) { + (bool success, bytes memory data) = f("return_multi()"); + assert(success); + (bool a, uint32 b, bytes4 c) = abi.decode(data, (bool, uint32, bytes4)); + assert(a == false && b == 0x3232 && c == 0xabcd0012); + return true; + } + function check_bytes() external returns (bool) { + (bool success, bytes memory data) = f("return_bytes()"); + assert(success); + (bytes memory d) = abi.decode(data, (bytes)); + assert(d.length == 2 && d[0] == 0x42 && d[1] == 0x21); + return true; + } + } + )DELIMITER"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_bool()"))), encodeArgs(true, 0x40, 0x20, true)); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_int32()"))), encodeArgs(true, 0x40, 0x20, u256(-32))); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_uint32()"))), encodeArgs(true, 0x40, 0x20, u256(0x3232))); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_int256()"))), encodeArgs(true, 0x40, 0x20, u256(-256))); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_uint256()"))), encodeArgs(true, 0x40, 0x20, u256(0x256256))); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_bytes4()"))), encodeArgs(true, 0x40, 0x20, u256(0xabcd0012) << (28*8))); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_multi()"))), encodeArgs(true, 0x40, 0x60, false, u256(0x3232), u256(0xabcd0012) << (28*8))); + ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_bytes()"))), encodeArgs(true, 0x40, 0x60, 0x20, 0x02, encode(bytes{0x42,0x21}, false))); + ABI_CHECK(callContractFunction("check_bool()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("check_int32()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("check_uint32()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("check_int256()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("check_uint256()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("check_bytes4()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("check_multi()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("check_bytes()"), encodeArgs(true)); + } + } +} + BOOST_AUTO_TEST_CASE(delegatecall_return_value) { if (dev::test::Options::get().evmVersion().supportsReturndata()) -- cgit v1.2.3 From 7118f5397485d42f38e66e98b163d7396e373a4e Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Sep 2018 16:51:17 +0200 Subject: Tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 85582ece..6be9d95b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -11870,6 +11870,46 @@ BOOST_AUTO_TEST_CASE(shift_bytes_cleanup) ABI_CHECK(callContractFunction("right(uint8)", 8 * 8), encodeArgs(string(8, 0) + "123456789012")); } +BOOST_AUTO_TEST_CASE(exp_cleanup) +{ + char const* sourceCode = R"( + contract C { + function f() public pure returns (uint8 x) { + uint8 y = uint8(2) ** uint8(8); + return 0 ** y; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0x1))); +} + +BOOST_AUTO_TEST_CASE(exp_cleanup_direct) +{ + char const* sourceCode = R"( + contract C { + function f() public pure returns (uint8 x) { + return uint8(0) ** uint8(uint8(2) ** uint8(8)); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0x1))); +} + +BOOST_AUTO_TEST_CASE(exp_cleanup_nonzero_base) +{ + char const* sourceCode = R"( + contract C { + function f() public pure returns (uint8 x) { + return uint8(0x166) ** uint8(uint8(2) ** uint8(8)); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0x1))); +} + BOOST_AUTO_TEST_CASE(cleanup_in_compound_assign) { char const* sourceCode = R"( -- cgit v1.2.3 From 879251a78b2d4e26dc71299d2d7ca989d0855d61 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 12 Sep 2018 16:21:43 +0200 Subject: Update test suite to use address payable. --- test/libsolidity/SolidityEndToEndTest.cpp | 62 +++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 7 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 6be9d95b..642c9929 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2215,7 +2215,7 @@ BOOST_AUTO_TEST_CASE(send_ether) char const* sourceCode = R"( contract test { constructor() payable public {} - function a(address addr, uint amount) public returns (uint ret) { + function a(address payable addr, uint amount) public returns (uint ret) { addr.send(amount); return address(this).balance; } @@ -2233,11 +2233,11 @@ BOOST_AUTO_TEST_CASE(transfer_ether) char const* sourceCode = R"( contract A { constructor() public payable {} - function a(address addr, uint amount) public returns (uint) { + function a(address payable addr, uint amount) public returns (uint) { addr.transfer(amount); return address(this).balance; } - function b(address addr, uint amount) public { + function b(address payable addr, uint amount) public { addr.transfer(amount); } } @@ -2406,7 +2406,7 @@ BOOST_AUTO_TEST_CASE(selfdestruct) char const* sourceCode = R"( contract test { constructor() public payable {} - function a(address receiver) public returns (uint ret) { + function a(address payable receiver) public returns (uint ret) { selfdestruct(receiver); return 10; } @@ -7151,7 +7151,7 @@ BOOST_AUTO_TEST_CASE(failing_send) } contract Main { constructor() public payable {} - function callHelper(address _a) public returns (bool r, uint bal) { + function callHelper(address payable _a) public returns (bool r, uint bal) { r = !_a.send(5); bal = address(this).balance; } @@ -8838,7 +8838,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) library lib {} contract c { constructor() public payable {} - function f(address x) public returns (bool) { + function f(address payable x) public returns (bool) { return x.send(1); } function () external payable {} @@ -10095,6 +10095,54 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types_shortening) ABI_CHECK(callContractFunction("f()"), encodeArgs("\xff\xff\xff\xff")); } +BOOST_AUTO_TEST_CASE(cleanup_address_types) +{ + // Checks that address types are properly cleaned before they are compared. + char const* sourceCode = R"( + contract C { + function f(address a) public returns (uint) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } + function g(address payable a) public returns (uint) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + // We input longer data on purpose. + ABI_CHECK(callContractFunction("f(address)", u256("0xFFFF1234567890123456789012345678901234567890")), encodeArgs(0)); + ABI_CHECK(callContractFunction("g(address)", u256("0xFFFF1234567890123456789012345678901234567890")), encodeArgs(0)); +} + +BOOST_AUTO_TEST_CASE(cleanup_address_types_shortening) +{ + char const* sourceCode = R"( + contract C { + function f() public pure returns (address r) { + bytes21 x = 0x1122334455667788990011223344556677889900ff; + bytes20 y; + assembly { y := x } + address z = address(y); + assembly { r := z } + require(z == 0x1122334455667788990011223344556677889900); + } + function g() public pure returns (address payable r) { + bytes21 x = 0x1122334455667788990011223344556677889900ff; + bytes20 y; + assembly { y := x } + address payable z = address(y); + assembly { r := z } + require(z == 0x1122334455667788990011223344556677889900); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256("0x1122334455667788990011223344556677889900"))); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256("0x1122334455667788990011223344556677889900"))); +} + BOOST_AUTO_TEST_CASE(skip_dynamic_types) { // The EVM cannot provide access to dynamically-sized return values, so we have to skip them. @@ -12446,7 +12494,7 @@ BOOST_AUTO_TEST_CASE(interface_contract) } contract C { - function f(address _interfaceAddress) public returns (bool) { + function f(address payable _interfaceAddress) public returns (bool) { I i = I(_interfaceAddress); return i.f(); } -- cgit v1.2.3 From 3e55aa3fa2ce0f7fa0d28fb6de1ef361d500181d Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 13 Sep 2018 17:18:42 +0200 Subject: Disable blockhash test for constantinople due to changes between aleth versions. --- test/libsolidity/SolidityEndToEndTest.cpp | 49 +++++++++++++------------------ 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 642c9929..f65c8b27 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3039,26 +3039,26 @@ BOOST_AUTO_TEST_CASE(gasprice) BOOST_AUTO_TEST_CASE(blockhash) { - char const* sourceCode = R"( - contract C { - uint256 counter; - function g() public returns (bool) { counter++; return true; } - function f() public returns (bytes32[] memory r) { - r = new bytes32[](259); - for (uint i = 0; i < 259; i++) - r[i] = blockhash(block.number - 257 + i); - } - } - )"; - compileAndRun(sourceCode); - // generate a sufficient amount of blocks - while (blockNumber() < u256(255)) - ABI_CHECK(callContractFunction("g()"), encodeArgs(true)); - - vector hashes; - // currently the test only works for pre-constantinople + // depending on the aleth version, this test only works for pre-constantinople if (Options::get().evmVersion() < EVMVersion::constantinople()) { + char const* sourceCode = R"( + contract C { + uint256 counter; + function g() public returns (bool) { counter++; return true; } + function f() public returns (bytes32[] memory r) { + r = new bytes32[](259); + for (uint i = 0; i < 259; i++) + r[i] = blockhash(block.number - 257 + i); + } + } + )"; + compileAndRun(sourceCode); + // generate a sufficient amount of blocks + while (blockNumber() < u256(255)) + ABI_CHECK(callContractFunction("g()"), encodeArgs(true)); + + vector hashes; // ``blockhash()`` is only valid for the last 256 blocks, otherwise zero hashes.emplace_back(0); for (u256 i = blockNumber() - u256(255); i <= blockNumber(); i++) @@ -3067,18 +3067,9 @@ BOOST_AUTO_TEST_CASE(blockhash) hashes.emplace_back(0); // future block hashes are zero hashes.emplace_back(0); + + ABI_CHECK(callContractFunction("f()"), encodeDyn(hashes)); } - else - // TODO: Starting from constantinople blockhash always seems to return zero. - // The blockhash contract introduced in EIP96 seems to break in our setup of - // aleth (setting the constantinople fork block to zero and resetting the chain - // to block zero before each test run). Pre-deploying the blockchain contract - // during genesis seems to help, but currently causes problems with other tests. - // Set the expectation to zero for now, so that this test tracks changes in this - // behavior. - hashes.assign(259, 0); - - ABI_CHECK(callContractFunction("f()"), encodeDyn(hashes)); } BOOST_AUTO_TEST_CASE(value_complex) -- cgit v1.2.3 From 4beabf6686c59fbe4ac6d4a4a158eca41a0b682a Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 10 Oct 2018 12:28:24 +0200 Subject: Documents library view functions and adds unit test. --- test/libsolidity/SolidityEndToEndTest.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f65c8b27..7a496e64 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4519,6 +4519,31 @@ BOOST_AUTO_TEST_CASE(library_call_protection) ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); } + +BOOST_AUTO_TEST_CASE(library_staticcall_delegatecall) +{ + char const* sourceCode = R"( + library Lib { + function x() public view returns (uint) { + return 1; + } + } + contract Test { + uint t; + function f() public returns (uint) { + t = 2; + return this.g(); + } + function g() public view returns (uint) { + return Lib.x(); + } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); +} + BOOST_AUTO_TEST_CASE(store_bytes) { // this test just checks that the copy loop does not mess up the stack -- cgit v1.2.3 From 134f5cb7985965c9fb5756979b4912153f043062 Mon Sep 17 00:00:00 2001 From: mordax Date: Sat, 13 Oct 2018 20:22:39 -0400 Subject: Added test for flipping signs on signed type edge case --- test/libsolidity/SolidityEndToEndTest.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7a496e64..133387c8 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -14010,6 +14010,21 @@ BOOST_AUTO_TEST_CASE(test_underscore_in_hex) ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(u256(0x1234abcd1234))); } +BOOST_AUTO_TEST_CASE(flipping_sign_tests) +{ + char const* sourceCode = R"( + contract test { + function f() public returns (bool){ + int x = -2**255; + assert(-x == x); + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(true)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 56425bb2b1cb9937b7c7a6baaee5ddcdd1f2e3d1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 17 Oct 2018 22:07:05 +0200 Subject: Add a test for delete x.length --- test/libsolidity/SolidityEndToEndTest.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7a496e64..7f865aa1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1787,6 +1787,24 @@ BOOST_AUTO_TEST_CASE(deleteLocals) ABI_CHECK(callContractFunction("delLocal()"), encodeArgs(6, 7)); } +BOOST_AUTO_TEST_CASE(deleteLength) +{ + char const* sourceCode = R"( + contract test { + uint[] x; + function f() public returns (uint){ + x.length = 1; + x[0] = 1; + delete x.length; + return x.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(0)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + BOOST_AUTO_TEST_CASE(constructor) { char const* sourceCode = R"( -- cgit v1.2.3 From ab0de38f16a9eff13ee5a32a3408b890d87941f6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 7 Nov 2018 12:04:46 +0100 Subject: Eliminate `byte`-typedef and use `uint8_t` in all their places instead. This change is made to (easily) be forward compatible with future C++ standards, in order to allow compiling the code with newer standards at some point in the future. * Removed the `using byte = uint8_t;` line from Common.h * Mechanically change all uses of `byte` to `uint8_t`. Tested with GCC 7.3 in C++11/14/17 modes :-) --- test/libsolidity/SolidityEndToEndTest.cpp | 76 +++++++++++++++---------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8d17e56f..87646737 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1259,14 +1259,14 @@ BOOST_AUTO_TEST_CASE(state_smoke_test) } )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x00)), encodeArgs(0)); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x01)), encodeArgs(0)); - ABI_CHECK(callContractFunction("set(uint8,uint256)", byte(0x00), 0x1234), encodeArgs()); - ABI_CHECK(callContractFunction("set(uint8,uint256)", byte(0x01), 0x8765), encodeArgs()); - ABI_CHECK(callContractFunction("get(uint8)", byte( 0x00)), encodeArgs(0x1234)); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x01)), encodeArgs(0x8765)); - ABI_CHECK(callContractFunction("set(uint8,uint256)", byte(0x00), 0x3), encodeArgs()); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x00)), encodeArgs(0x3)); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(0)); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(0)); + ABI_CHECK(callContractFunction("set(uint8,uint256)", uint8_t(0x00), 0x1234), encodeArgs()); + ABI_CHECK(callContractFunction("set(uint8,uint256)", uint8_t(0x01), 0x8765), encodeArgs()); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t( 0x00)), encodeArgs(0x1234)); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(0x8765)); + ABI_CHECK(callContractFunction("set(uint8,uint256)", uint8_t(0x00), 0x3), encodeArgs()); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(0x3)); } BOOST_AUTO_TEST_CASE(compound_assign) @@ -1321,21 +1321,21 @@ BOOST_AUTO_TEST_CASE(simple_mapping) )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("get(uint8)", byte(0)), encodeArgs(byte(0x00))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x01)), encodeArgs(byte(0x00))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0xa7)), encodeArgs(byte(0x00))); - callContractFunction("set(uint8,uint8)", byte(0x01), byte(0xa1)); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x00)), encodeArgs(byte(0x00))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x01)), encodeArgs(byte(0xa1))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0xa7)), encodeArgs(byte(0x00))); - callContractFunction("set(uint8,uint8)", byte(0x00), byte(0xef)); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x00)), encodeArgs(byte(0xef))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x01)), encodeArgs(byte(0xa1))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0xa7)), encodeArgs(byte(0x00))); - callContractFunction("set(uint8,uint8)", byte(0x01), byte(0x05)); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x00)), encodeArgs(byte(0xef))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0x01)), encodeArgs(byte(0x05))); - ABI_CHECK(callContractFunction("get(uint8)", byte(0xa7)), encodeArgs(byte(0x00))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0)), encodeArgs(uint8_t(0x00))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x00))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00))); + callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0xa1)); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0x00))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00))); + callContractFunction("set(uint8,uint8)", uint8_t(0x00), uint8_t(0xef)); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00))); + callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0x05)); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x05))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00))); } BOOST_AUTO_TEST_CASE(mapping_state) @@ -1496,7 +1496,7 @@ BOOST_AUTO_TEST_CASE(mapping_local_assignment) )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); + ABI_CHECK(callContractFunction("f()"), encodeArgs(uint8_t(42), uint8_t(0), uint8_t(0), uint8_t(21))); } BOOST_AUTO_TEST_CASE(mapping_local_tuple_assignment) @@ -1519,7 +1519,7 @@ BOOST_AUTO_TEST_CASE(mapping_local_tuple_assignment) )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); + ABI_CHECK(callContractFunction("f()"), encodeArgs(uint8_t(42), uint8_t(0), uint8_t(0), uint8_t(21))); } BOOST_AUTO_TEST_CASE(mapping_local_compound_assignment) @@ -1540,7 +1540,7 @@ BOOST_AUTO_TEST_CASE(mapping_local_compound_assignment) )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); + ABI_CHECK(callContractFunction("f()"), encodeArgs(uint8_t(42), uint8_t(0), uint8_t(0), uint8_t(21))); } BOOST_AUTO_TEST_CASE(mapping_internal_argument) @@ -1565,10 +1565,10 @@ BOOST_AUTO_TEST_CASE(mapping_internal_argument) )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(21), byte(42)), encodeArgs(byte(0), byte(0))); - ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(42))); - ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(10), byte(11)), encodeArgs(byte(21), byte(42))); - ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(11))); + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", uint8_t(1), uint8_t(21), uint8_t(42)), encodeArgs(uint8_t(0), uint8_t(0))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(1)), encodeArgs(uint8_t(21), uint8_t(42))); + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", uint8_t(1), uint8_t(10), uint8_t(11)), encodeArgs(uint8_t(21), uint8_t(42))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(1)), encodeArgs(uint8_t(10), uint8_t(11))); } BOOST_AUTO_TEST_CASE(mapping_array_internal_argument) @@ -1595,10 +1595,10 @@ BOOST_AUTO_TEST_CASE(mapping_array_internal_argument) )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(21), byte(22), byte(42), byte(43)), encodeArgs(byte(0), byte(0), byte(0), byte(0))); - ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(22), byte(42), byte(43))); - ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(10), byte(30), byte(11), byte(31)), encodeArgs(byte(21), byte(22), byte(42), byte(43))); - ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(30), byte(11), byte(31))); + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", uint8_t(1), uint8_t(21), uint8_t(22), uint8_t(42), uint8_t(43)), encodeArgs(uint8_t(0), uint8_t(0), uint8_t(0), uint8_t(0))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(1)), encodeArgs(uint8_t(21), uint8_t(22), uint8_t(42), uint8_t(43))); + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", uint8_t(1), uint8_t(10), uint8_t(30), uint8_t(11), uint8_t(31)), encodeArgs(uint8_t(21), uint8_t(22), uint8_t(42), uint8_t(43))); + ABI_CHECK(callContractFunction("get(uint8)", uint8_t(1)), encodeArgs(uint8_t(10), uint8_t(30), uint8_t(11), uint8_t(31))); } BOOST_AUTO_TEST_CASE(mapping_internal_return) @@ -1626,8 +1626,8 @@ BOOST_AUTO_TEST_CASE(mapping_internal_return) )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("g()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (21))); - ABI_CHECK(callContractFunction("h()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (17))); + ABI_CHECK(callContractFunction("g()"), encodeArgs(uint8_t(0), uint8_t(42), uint8_t(0), uint8_t(0), uint8_t(84), uint8_t (21))); + ABI_CHECK(callContractFunction("h()"), encodeArgs(uint8_t(0), uint8_t(42), uint8_t(0), uint8_t(0), uint8_t(84), uint8_t (17))); } BOOST_AUTO_TEST_CASE(structs) @@ -1819,7 +1819,7 @@ BOOST_AUTO_TEST_CASE(constructor) } )"; compileAndRun(sourceCode); - map data; + map data; data[7] = 8; auto get = [&](u256 const& _x) -> u256 { @@ -2624,7 +2624,7 @@ BOOST_AUTO_TEST_CASE(ecrecover) )"; compileAndRun(sourceCode); u256 h("0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c"); - byte v = 28; + uint8_t v = 28; u256 r("0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f"); u256 s("0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549"); u160 addr("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"); -- cgit v1.2.3