diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/contracts/LLL_ENS.cpp | 2 | ||||
-rw-r--r-- | test/contracts/LLL_ERC20.cpp | 2 | ||||
-rw-r--r-- | test/liblll/EndToEndTest.cpp | 50 | ||||
-rw-r--r-- | test/libsolidity/GasMeter.cpp | 5 | ||||
-rw-r--r-- | test/libsolidity/JSONCompiler.cpp | 15 | ||||
-rw-r--r-- | test/libsolidity/Metadata.cpp | 5 | ||||
-rw-r--r-- | test/libsolidity/SolidityABIJSON.cpp | 4 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 249 | ||||
-rw-r--r-- | test/libsolidity/SolidityNatspecJSON.cpp | 4 |
9 files changed, 215 insertions, 121 deletions
diff --git a/test/contracts/LLL_ENS.cpp b/test/contracts/LLL_ENS.cpp index 3df1546d..c5fe8a82 100644 --- a/test/contracts/LLL_ENS.cpp +++ b/test/contracts/LLL_ENS.cpp @@ -345,7 +345,7 @@ protected: if (!s_compiledEns) { vector<string> errors; - s_compiledEns.reset(new bytes(compileLLL(ensCode, false, &errors))); + s_compiledEns.reset(new bytes(compileLLL(ensCode, dev::test::Options::get().optimize, &errors))); BOOST_REQUIRE(errors.empty()); } sendMessage(*s_compiledEns, true); diff --git a/test/contracts/LLL_ERC20.cpp b/test/contracts/LLL_ERC20.cpp index 3ee1aa98..25665d64 100644 --- a/test/contracts/LLL_ERC20.cpp +++ b/test/contracts/LLL_ERC20.cpp @@ -396,7 +396,7 @@ protected: if (!s_compiledErc20) { vector<string> errors; - s_compiledErc20.reset(new bytes(compileLLL(erc20Code, false, &errors))); + s_compiledErc20.reset(new bytes(compileLLL(erc20Code, dev::test::Options::get().optimize, &errors))); BOOST_REQUIRE(errors.empty()); } sendMessage(*s_compiledErc20, true); diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 4e896fd0..9292d963 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -165,6 +165,56 @@ BOOST_AUTO_TEST_CASE(conditional_seq) BOOST_CHECK(callFallback() == toBigEndian(u256(1))); } +BOOST_AUTO_TEST_CASE(conditional_nested_else) +{ + char const* sourceCode = R"( + (returnlll + (seq + (def 'input (calldataload 0x04)) + ;; Calculates width in bytes of utf-8 characters. + (return + (if (< input 0x80) 1 + (if (< input 0xE0) 2 + (if (< input 0xF0) 3 + (if (< input 0xF8) 4 + (if (< input 0xFC) 5 + 6)))))))) + + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()", 0x00) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("test()", 0x80) == encodeArgs(u256(2))); + BOOST_CHECK(callContractFunction("test()", 0xe0) == encodeArgs(u256(3))); + BOOST_CHECK(callContractFunction("test()", 0xf0) == encodeArgs(u256(4))); + BOOST_CHECK(callContractFunction("test()", 0xf8) == encodeArgs(u256(5))); + BOOST_CHECK(callContractFunction("test()", 0xfc) == encodeArgs(u256(6))); +} + +BOOST_AUTO_TEST_CASE(conditional_nested_then) +{ + char const* sourceCode = R"( + (returnlll + (seq + (def 'input (calldataload 0x04)) + ;; Calculates width in bytes of utf-8 characters. + (return + (if (>= input 0x80) + (if (>= input 0xE0) + (if (>= input 0xF0) + (if (>= input 0xF8) + (if (>= input 0xFC) + 6 5) 4) 3) 2) 1)))) + + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()", 0x00) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("test()", 0x80) == encodeArgs(u256(2))); + BOOST_CHECK(callContractFunction("test()", 0xe0) == encodeArgs(u256(3))); + BOOST_CHECK(callContractFunction("test()", 0xf0) == encodeArgs(u256(4))); + BOOST_CHECK(callContractFunction("test()", 0xf8) == encodeArgs(u256(5))); + BOOST_CHECK(callContractFunction("test()", 0xfc) == encodeArgs(u256(6))); +} + BOOST_AUTO_TEST_CASE(exp_operator_const) { char const* sourceCode = R"( diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp index ef560b12..8b41e1db 100644 --- a/test/libsolidity/GasMeter.cpp +++ b/test/libsolidity/GasMeter.cpp @@ -47,8 +47,9 @@ public: GasMeterTestFramework() { } void compile(string const& _sourceCode) { - m_compiler.setSource("pragma solidity >= 0.0;" + _sourceCode); - ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(), "Compiling contract failed"); + m_compiler.reset(false); + m_compiler.addSource("", "pragma solidity >=0.0;\n" + _sourceCode); + ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(dev::test::Options::get().optimize), "Compiling contract failed"); AssemblyItems const* items = m_compiler.runtimeAssemblyItems(""); ASTNode const& sourceUnit = m_compiler.ast(); diff --git a/test/libsolidity/JSONCompiler.cpp b/test/libsolidity/JSONCompiler.cpp index aa690f0b..a6a7bc5b 100644 --- a/test/libsolidity/JSONCompiler.cpp +++ b/test/libsolidity/JSONCompiler.cpp @@ -24,6 +24,7 @@ #include <regex> #include <boost/test/unit_test.hpp> #include <libdevcore/JSON.h> +#include <libsolidity/interface/Version.h> #include "../Metadata.h" #include "../TestHelper.h" @@ -32,6 +33,8 @@ using namespace std; extern "C" { +extern char const* version(); +extern char const* license(); extern char const* compileJSONMulti(char const* _input, bool _optimize); } @@ -57,6 +60,18 @@ Json::Value compile(string const& _input) BOOST_AUTO_TEST_SUITE(JSONCompiler) +BOOST_AUTO_TEST_CASE(read_version) +{ + string output(version()); + BOOST_CHECK(output.find(VersionString) == 0); +} + +BOOST_AUTO_TEST_CASE(read_license) +{ + string output(license()); + BOOST_CHECK(output.find("GNU GENERAL PUBLIC LICENSE") != string::npos); +} + BOOST_AUTO_TEST_CASE(basic_compilation) { char const* input = R"( diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp index 60bb2e4e..ce1a7b18 100644 --- a/test/libsolidity/Metadata.cpp +++ b/test/libsolidity/Metadata.cpp @@ -43,9 +43,10 @@ BOOST_AUTO_TEST_CASE(metadata_stamp) } )"; CompilerStack compilerStack; - BOOST_REQUIRE(compilerStack.compile(std::string(sourceCode))); + compilerStack.addSource("", std::string(sourceCode)); + ETH_TEST_REQUIRE_NO_THROW(compilerStack.compile(dev::test::Options::get().optimize), "Compiling contract failed"); bytes const& bytecode = compilerStack.runtimeObject("test").bytecode; - std::string const& metadata = compilerStack.onChainMetadata("test"); + std::string const& metadata = compilerStack.metadata("test"); BOOST_CHECK(dev::test::isValidMetadata(metadata)); bytes hash = dev::swarmHash(metadata).asBytes(); BOOST_REQUIRE(hash.size() == 32); diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index f87390e1..452a2662 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -42,7 +42,9 @@ public: void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString) { - ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parseAndAnalyze("pragma solidity >=0.0;\n" + _code), "Parsing contract failed"); + m_compilerStack.reset(false); + m_compilerStack.addSource("", "pragma solidity >=0.0;\n" + _code); + ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parseAndAnalyze(), "Parsing contract failed"); Json::Value generatedInterface = m_compilerStack.contractABI(""); Json::Value expectedInterface; diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index cb39101e..4b29243a 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -112,7 +112,14 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false, ) { if (error && !_allowMultipleErrors) - BOOST_FAIL("Multiple errors found"); + { + string message("Multiple errors found: "); + for (auto const& e: errorReporter.errors()) + if (string const* description = boost::get_error_info<errinfo_comment>(*e)) + message += *description + ", "; + + BOOST_FAIL(message); + } if (!error) error = currentError; } @@ -2283,6 +2290,9 @@ BOOST_AUTO_TEST_CASE(test_fromElementaryTypeName) BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 30, 0)) == *make_shared<FixedBytesType>(30)); BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 31, 0)) == *make_shared<FixedBytesType>(31)); BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 32, 0)) == *make_shared<FixedBytesType>(32)); + + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Fixed, 0, 0)) == *make_shared<FixedPointType>(128, 19, FixedPointType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixed, 0, 0)) == *make_shared<FixedPointType>(128, 19, FixedPointType::Modifier::Unsigned)); } BOOST_AUTO_TEST_CASE(test_byte_is_alias_of_byte1) @@ -4026,7 +4036,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_types_0x7_mxn) fixed0x7 a = .3; } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(invalid_fixed_types_long_invalid_identifier) @@ -4036,7 +4046,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_types_long_invalid_identifier) fixed99999999999999999999999999999999999999x7 b = 9.5; } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(invalid_fixed_types_7x8_mxn) @@ -4046,7 +4056,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_types_7x8_mxn) fixed7x8 c = 3.12345678; } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(library_instances_cannot_be_used) @@ -4060,7 +4070,7 @@ BOOST_AUTO_TEST_CASE(library_instances_cannot_be_used) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Member \"l\" not found or not visible after argument-dependent lookup in library L"); } BOOST_AUTO_TEST_CASE(invalid_fixed_type_long) @@ -4072,7 +4082,7 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_type_long) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, DeclarationError, "Identifier not found"); } BOOST_AUTO_TEST_CASE(fixed_type_int_conversion) @@ -4080,8 +4090,8 @@ BOOST_AUTO_TEST_CASE(fixed_type_int_conversion) char const* text = R"( contract test { function f() { - uint128 a = 3; - int128 b = 4; + uint64 a = 3; + int64 b = 4; fixed c = b; ufixed d = a; c; d; @@ -4130,7 +4140,7 @@ BOOST_AUTO_TEST_CASE(invalid_int_implicit_conversion_from_fixed) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Type fixed128x19 is not implicitly convertible to expected type int256"); } BOOST_AUTO_TEST_CASE(rational_unary_operation) @@ -4138,10 +4148,9 @@ BOOST_AUTO_TEST_CASE(rational_unary_operation) char const* text = R"( contract test { function f() { - ufixed8x16 a = 3.25; - fixed8x16 b = -3.25; - a; - b; + ufixed16x2 a = 3.25; + fixed16x2 b = -3.25; + a; b; } } )"; @@ -4149,13 +4158,13 @@ BOOST_AUTO_TEST_CASE(rational_unary_operation) text = R"( contract test { function f() { - ufixed8x16 a = +3.25; - fixed8x16 b = -3.25; + ufixed16x2 a = +3.25; + fixed16x2 b = -3.25; a; b; } } )"; - CHECK_WARNING(text,"Use of unary + is deprecated"); + CHECK_WARNING(text, "Use of unary + is deprecated"); text = R"( contract test { function f(uint x) { @@ -4172,10 +4181,10 @@ BOOST_AUTO_TEST_CASE(leading_zero_rationals_convert) char const* text = R"( contract A { function f() { - ufixed0x8 a = 0.5; - ufixed0x56 b = 0.0000000000000006661338147750939242541790008544921875; - fixed0x8 c = -0.5; - fixed0x56 d = -0.0000000000000006661338147750939242541790008544921875; + ufixed16x2 a = 0.5; + ufixed256x52 b = 0.0000000000000006661338147750939242541790008544921875; + fixed16x2 c = -0.5; + fixed256x52 d = -0.0000000000000006661338147750939242541790008544921875; a; b; c; d; } } @@ -4188,12 +4197,12 @@ BOOST_AUTO_TEST_CASE(size_capabilities_of_fixed_point_types) char const* text = R"( contract test { function f() { - ufixed248x8 a = 123456781234567979695948382928485849359686494864095409282048094275023098123.5; - ufixed0x256 b = 0.920890746623327805482905058466021565416131529487595827354393978494366605267637829135688384325135165352082715782143655824815685807141335814463015972119819459298455224338812271036061391763384038070334798471324635050876128428143374549108557403087615966796875; - ufixed0x256 c = 0.0000000000015198847363997979984922685411315294875958273543939784943666052676464653042434787697605517039455161817147718251801220885263595179331845639229818863564267318422845592626219390573301877339317935702714669975697814319204326238832436501979827880859375; - fixed248x8 d = -123456781234567979695948382928485849359686494864095409282048094275023098123.5; - fixed0x256 e = -0.93322335481643744342575580035176794825198893968114429702091846411734101080123092162893656820177312738451291806995868682861328125; - fixed0x256 g = -0.00011788606643744342575580035176794825198893968114429702091846411734101080123092162893656820177312738451291806995868682861328125; + ufixed256x1 a = 123456781234567979695948382928485849359686494864095409282048094275023098123.5; + ufixed256x77 b = 0.920890746623327805482905058466021565416131529487595827354393978494366605267637; + ufixed224x78 c = 0.000000000001519884736399797998492268541131529487595827354393978494366605267646; + fixed256x1 d = -123456781234567979695948382928485849359686494864095409282048094275023098123.5; + fixed256x76 e = -0.93322335481643744342575580035176794825198893968114429702091846411734101080123; + fixed256x79 g = -0.0001178860664374434257558003517679482519889396811442970209184641173410108012309; a; b; c; d; e; g; } } @@ -4201,17 +4210,30 @@ BOOST_AUTO_TEST_CASE(size_capabilities_of_fixed_point_types) CHECK_SUCCESS(text); } +BOOST_AUTO_TEST_CASE(zero_handling) +{ + char const* text = R"( + contract test { + function f() { + fixed16x2 a = 0; a; + ufixed32x1 b = 0; b; + } + } + )"; + CHECK_SUCCESS(text); +} + BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_size) { char const* text = R"( contract test { function f() { ufixed a = 11/4; - ufixed248x8 b = a; + ufixed248x8 b = a; b; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Type ufixed128x19 is not implicitly convertible to expected type ufixed248x8"); } BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_lost_data) @@ -4219,11 +4241,11 @@ BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_lost_data) char const* text = R"( contract test { function f() { - ufixed0x256 a = 1/3; + ufixed256x1 a = 1/3; a; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type ufixed256x1"); } BOOST_AUTO_TEST_CASE(fixed_type_valid_explicit_conversions) @@ -4231,10 +4253,9 @@ BOOST_AUTO_TEST_CASE(fixed_type_valid_explicit_conversions) char const* text = R"( contract test { function f() { - ufixed0x256 a = ufixed0x256(1/3); - ufixed0x248 b = ufixed0x248(1/3); - ufixed0x8 c = ufixed0x8(1/3); - a; b; c; + ufixed256x80 a = ufixed256x80(1/3); a; + ufixed248x80 b = ufixed248x80(1/3); b; + ufixed8x1 c = ufixed8x1(1/3); c; } } )"; @@ -4246,23 +4267,35 @@ BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_rational) char const* text = R"( contract test { function f() { - uint[3.5] a; + uint[3.5] a; a; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal"); } -BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_fixed_type) +BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_signed_fixed_type) { char const* text = R"( contract test { function f() { - uint[fixed(3.5)] a; + uint[fixed(3.5)] a; a; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal"); +} + +BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_unsigned_fixed_type) +{ + char const* text = R"( + contract test { + function f() { + uint[ufixed(3.5)] a; a; + } + } + )"; + CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal"); } BOOST_AUTO_TEST_CASE(rational_to_bytes_implicit_conversion) @@ -4270,11 +4303,11 @@ BOOST_AUTO_TEST_CASE(rational_to_bytes_implicit_conversion) char const* text = R"( contract test { function f() { - bytes32 c = 3.2; + bytes32 c = 3.2; c; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type bytes32"); } BOOST_AUTO_TEST_CASE(fixed_to_bytes_implicit_conversion) @@ -4283,18 +4316,18 @@ BOOST_AUTO_TEST_CASE(fixed_to_bytes_implicit_conversion) contract test { function f() { fixed a = 3.25; - bytes32 c = a; + bytes32 c = a; c; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "fixed128x19 is not implicitly convertible to expected type bytes32"); } BOOST_AUTO_TEST_CASE(mapping_with_fixed_literal) { char const* text = R"( contract test { - mapping(ufixed8x248 => string) fixedString; + mapping(ufixed8x1 => string) fixedString; function f() { fixedString[0.5] = "Half"; } @@ -4334,7 +4367,7 @@ BOOST_AUTO_TEST_CASE(inline_array_rationals) char const* text = R"( contract test { function f() { - ufixed8x8[4] memory a = [3.5, 4.125, 2.5, 4.0]; + ufixed128x3[4] memory a = [ufixed128x3(3.5), 4.125, 2.5, 4.0]; } } )"; @@ -4351,7 +4384,7 @@ BOOST_AUTO_TEST_CASE(rational_index_access) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "rational_const 1/2 is not implicitly convertible to expected type uint256"); } BOOST_AUTO_TEST_CASE(rational_to_fixed_literal_expression) @@ -4359,12 +4392,12 @@ BOOST_AUTO_TEST_CASE(rational_to_fixed_literal_expression) char const* text = R"( contract test { function f() { - ufixed8x8 a = 3.5 * 3; - ufixed8x8 b = 4 - 2.5; - ufixed8x8 c = 11 / 4; - ufixed16x240 d = 599 + 0.21875; - ufixed8x248 e = ufixed8x248(35.245 % 12.9); - ufixed8x248 f = ufixed8x248(1.2 % 2); + ufixed64x8 a = 3.5 * 3; + ufixed64x8 b = 4 - 2.5; + ufixed64x8 c = 11 / 4; + ufixed240x5 d = 599 + 0.21875; + ufixed256x80 e = ufixed256x80(35.245 % 12.9); + ufixed256x80 f = ufixed256x80(1.2 % 2); fixed g = 2 ** -2; a; b; c; d; e; f; g; } @@ -4373,7 +4406,7 @@ BOOST_AUTO_TEST_CASE(rational_to_fixed_literal_expression) CHECK_SUCCESS(text); } -BOOST_AUTO_TEST_CASE(rational_as_exponent_value_neg_decimal) +BOOST_AUTO_TEST_CASE(rational_as_exponent_value_signed) { char const* text = R"( contract test { @@ -4382,10 +4415,10 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_value_neg_decimal) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } -BOOST_AUTO_TEST_CASE(rational_as_exponent_value_pos_decimal) +BOOST_AUTO_TEST_CASE(rational_as_exponent_value_unsigned) { char const* text = R"( contract test { @@ -4394,7 +4427,7 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_value_pos_decimal) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_as_exponent_half) @@ -4402,11 +4435,11 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_half) char const* text = R"( contract test { function f() { - ufixed24x24 b = 2 ** (1/2); + 2 ** (1/2); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_as_exponent_value_neg_quarter) @@ -4414,11 +4447,11 @@ BOOST_AUTO_TEST_CASE(rational_as_exponent_value_neg_quarter) char const* text = R"( contract test { function f() { - fixed40x40 c = 42 ** (-1/4); + 42 ** (-1/4); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_15) @@ -4426,23 +4459,11 @@ BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_15) char const* text = R"( contract test { function f() { - ufixed a = 3 ** ufixed(1.5); - } - } - )"; - BOOST_CHECK(!success(text)); -} - -BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_half) -{ - char const* text = R"( - contract test { - function f() { - ufixed b = 2 ** ufixed(1/2); + var a = 3 ** ufixed(1.5); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_neg) @@ -4450,23 +4471,11 @@ BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_neg) char const* text = R"( contract test { function f() { - fixed c = 42 ** fixed(-1/4); - } - } - )"; - BOOST_CHECK(!success(text)); -} - -BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_neg_decimal) -{ - char const* text = R"( - contract test { - function f() { - fixed d = 16 ** fixed(-0.5); + var c = 42 ** fixed(-1/4); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(var_capable_of_holding_constant_rationals) @@ -4506,7 +4515,7 @@ BOOST_AUTO_TEST_CASE(var_handle_divided_integers) } } )"; - CHECK_SUCCESS(text); + CHECK_SUCCESS(text); } BOOST_AUTO_TEST_CASE(rational_bitnot_unary_operation) @@ -4514,11 +4523,11 @@ BOOST_AUTO_TEST_CASE(rational_bitnot_unary_operation) char const* text = R"( contract test { function f() { - fixed a = ~3.5; + ~fixed(3.5); } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "cannot be applied"); } BOOST_AUTO_TEST_CASE(rational_bitor_binary_operation) @@ -4526,11 +4535,11 @@ BOOST_AUTO_TEST_CASE(rational_bitor_binary_operation) char const* text = R"( contract test { function f() { - fixed a = 1.5 | 3; + fixed(1.5) | 3; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_bitxor_binary_operation) @@ -4538,11 +4547,11 @@ BOOST_AUTO_TEST_CASE(rational_bitxor_binary_operation) char const* text = R"( contract test { function f() { - fixed a = 1.75 ^ 3; + fixed(1.75) ^ 3; } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(rational_bitand_binary_operation) @@ -4550,25 +4559,11 @@ BOOST_AUTO_TEST_CASE(rational_bitand_binary_operation) char const* text = R"( contract test { function f() { - fixed a = 1.75 & 3; + fixed(1.75) & 3; } } )"; - BOOST_CHECK(!success(text)); -} - -BOOST_AUTO_TEST_CASE(zero_handling) -{ - char const* text = R"( - contract test { - function f() { - fixed8x8 a = 0; - ufixed8x8 b = 0; - a; b; - } - } - )"; - CHECK_SUCCESS(text); + CHECK_ERROR(text, TypeError, "not compatible with types"); } BOOST_AUTO_TEST_CASE(missing_bool_conversion) @@ -4588,7 +4583,7 @@ BOOST_AUTO_TEST_CASE(integer_and_fixed_interaction) char const* text = R"( contract test { function f() { - ufixed a = uint128(1) + ufixed(2); + ufixed a = uint64(1) + ufixed(2); } } )"; @@ -4618,7 +4613,7 @@ BOOST_AUTO_TEST_CASE(one_divided_by_three_integer_conversion) } } )"; - BOOST_CHECK(!success(text)); + CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type uint256. Try converting to type ufixed256x77"); } BOOST_AUTO_TEST_CASE(unused_return_value) @@ -6359,6 +6354,34 @@ BOOST_AUTO_TEST_CASE(explicit_literal_to_storage_string) CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed from \"literal_string \"abc\"\" to \"string storage pointer\""); } +BOOST_AUTO_TEST_CASE(modifiers_access_storage_pointer) +{ + char const* text = R"( + contract C { + struct S { } + modifier m(S storage x) { + x; + _; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + +BOOST_AUTO_TEST_CASE(using_this_in_constructor) +{ + char const* text = R"( + contract C { + function C() { + this.f(); + } + function f() { + } + } + )"; + CHECK_WARNING(text, "\"this\" used in constructor"); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp index 2a7376b9..aa343561 100644 --- a/test/libsolidity/SolidityNatspecJSON.cpp +++ b/test/libsolidity/SolidityNatspecJSON.cpp @@ -45,7 +45,9 @@ public: bool _userDocumentation ) { - ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parseAndAnalyze("pragma solidity >=0.0;\n" + _code), "Parsing failed"); + m_compilerStack.reset(false); + m_compilerStack.addSource("", "pragma solidity >=0.0;\n" + _code); + ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parseAndAnalyze(), "Parsing contract failed"); Json::Value generatedDocumentation; if (_userDocumentation) |