diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/liblll/EndToEndTest.cpp | 57 | ||||
-rw-r--r-- | test/libsolidity/ASTJSON.cpp | 30 | ||||
-rw-r--r-- | test/libsolidity/InlineAssembly.cpp | 12 | ||||
-rw-r--r-- | test/libsolidity/JSONCompiler.cpp | 10 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 11 | ||||
-rw-r--r-- | test/libsolidity/StandardCompiler.cpp | 2 |
7 files changed, 123 insertions, 7 deletions
diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index c8e7adf1..9021fa43 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -291,6 +291,63 @@ BOOST_AUTO_TEST_CASE(zeroarg_macro) BOOST_CHECK(callFallback() == encodeArgs(u256(0x1234))); } +BOOST_AUTO_TEST_CASE(keccak256_32bytes) +{ + char const* sourceCode = R"( + (returnlll + (seq + (mstore 0x00 0x01) + (return (keccak256 0x00 0x20)))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"))); +} + +BOOST_AUTO_TEST_CASE(sha3_two_args) +{ + char const* sourceCode = R"( + (returnlll + (seq + (mstore 0x00 0x01) + (return (sha3 0x00 0x20)))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"))); +} + +BOOST_AUTO_TEST_CASE(sha3_one_arg) +{ + char const* sourceCode = R"( + (returnlll + (return (sha3 0x01))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"))); +} + +BOOST_AUTO_TEST_CASE(shift_left) +{ + char const* sourceCode = R"( + (returnlll + (return (shl 1 8))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs(u256(256))); +} + +BOOST_AUTO_TEST_CASE(shift_right) +{ + char const* sourceCode = R"( + (returnlll + (return (shr 65536 8))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs(u256(256))); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index df7fac51..4fb4f20c 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -228,6 +228,36 @@ BOOST_AUTO_TEST_CASE(function_type) BOOST_CHECK_EQUAL(funType["attributes"]["visibility"], "external"); } +BOOST_AUTO_TEST_CASE(documentation) +{ + CompilerStack c; + c.addSource("a", "/**This contract is empty*/ contract C {}"); + c.addSource("b", + "/**This contract is empty" + " and has a line-breaking comment.*/" + "contract C {}" + ); + c.parseAndAnalyze(); + map<string, unsigned> sourceIndices; + sourceIndices["a"] = 0; + sourceIndices["b"] = 1; + Json::Value astJsonA = ASTJsonConverter(true, sourceIndices).toJson(c.ast("a")); + Json::Value documentationA = astJsonA["children"][0]["attributes"]["documentation"]; + BOOST_CHECK_EQUAL(documentationA, "This contract is empty"); + Json::Value astJsonB = ASTJsonConverter(true, sourceIndices).toJson(c.ast("b")); + Json::Value documentationB = astJsonB["children"][0]["attributes"]["documentation"]; + BOOST_CHECK_EQUAL(documentationB, "This contract is empty and has a line-breaking comment."); + //same tests for non-legacy mode + astJsonA = ASTJsonConverter(false, sourceIndices).toJson(c.ast("a")); + documentationA = astJsonA["nodes"][0]["documentation"]; + BOOST_CHECK_EQUAL(documentationA, "This contract is empty"); + astJsonB = ASTJsonConverter(false, sourceIndices).toJson(c.ast("b")); + documentationB = astJsonB["nodes"][0]["documentation"]; + BOOST_CHECK_EQUAL(documentationB, "This contract is empty and has a line-breaking comment."); + +} + + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 435c3dad..7876b7ee 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -213,6 +213,16 @@ BOOST_AUTO_TEST_CASE(functional) BOOST_CHECK(successParse("{ let x := 2 add(7, mul(6, x)) mul(7, 8) add =: x }")); } +BOOST_AUTO_TEST_CASE(functional_partial) +{ + CHECK_PARSE_ERROR("{ let x := byte }", ParserError, "Expected token \"(\""); +} + +BOOST_AUTO_TEST_CASE(functional_partial_success) +{ + BOOST_CHECK(successParse("{ let x := byte(1, 2) }")); +} + BOOST_AUTO_TEST_CASE(functional_assignment) { BOOST_CHECK(successParse("{ let x := 2 x := 7 }")); @@ -258,7 +268,7 @@ BOOST_AUTO_TEST_CASE(switch_duplicate_case) BOOST_AUTO_TEST_CASE(switch_invalid_expression) { CHECK_PARSE_ERROR("{ switch {} default {} }", ParserError, "Literal, identifier or instruction expected."); - CHECK_PARSE_ERROR("{ 1 2 switch mul default {} }", ParserError, "Instructions are not supported as expressions for switch."); + CHECK_PARSE_ERROR("{ switch calldatasize default {} }", ParserError, "Instructions are not supported as expressions for switch."); } BOOST_AUTO_TEST_CASE(switch_default_before_case) diff --git a/test/libsolidity/JSONCompiler.cpp b/test/libsolidity/JSONCompiler.cpp index 6aec59ab..f5154395 100644 --- a/test/libsolidity/JSONCompiler.cpp +++ b/test/libsolidity/JSONCompiler.cpp @@ -90,11 +90,11 @@ BOOST_AUTO_TEST_CASE(basic_compilation) BOOST_CHECK(result["sources"]["fileA"].isObject()); BOOST_CHECK(result["sources"]["fileA"]["AST"].isObject()); BOOST_CHECK(dev::jsonCompactPrint(result["sources"]["fileA"]["AST"]) == - "{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}}," - "\"children\":[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null]," - "\"contractKind\":\"contract\",\"fullyImplemented\":true,\"linearizedBaseContracts\":[1]," - "\"name\":\"A\",\"nodes\":[null],\"scope\":2},\"id\":1,\"name\":\"ContractDefinition\"," - "\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}"); + "{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}}," + "\"children\":[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null]," + "\"contractKind\":\"contract\",\"documentation\":null,\"fullyImplemented\":true,\"linearizedBaseContracts\":[1]," + "\"name\":\"A\",\"nodes\":[null],\"scope\":2},\"id\":1,\"name\":\"ContractDefinition\"," + "\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}"); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index dddb5dde..70934543 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5807,6 +5807,14 @@ BOOST_AUTO_TEST_CASE(returndatacopy_as_variable) CHECK_WARNING_ALLOW_MULTI(text, "Variable is shadowed in inline assembly by an instruction of the same name"); } +BOOST_AUTO_TEST_CASE(create2_as_variable) +{ + char const* text = R"( + contract c { function f() { uint create2; assembly { create2(0, 0, 0, 0) }}} + )"; + CHECK_WARNING_ALLOW_MULTI(text, "Variable is shadowed in inline assembly by an instruction of the same name"); +} + BOOST_AUTO_TEST_CASE(shadowing_warning_can_be_removed) { char const* text = R"( diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 31dfada9..27231b9b 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -199,6 +199,17 @@ BOOST_AUTO_TEST_CASE(missing_argument_in_named_args) CHECK_PARSE_ERROR(text, "Expected primary expression"); } +BOOST_AUTO_TEST_CASE(trailing_comma_in_named_args) +{ + char const* text = 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, }); } + } + )"; + CHECK_PARSE_ERROR(text, "Unexpected trailing comma"); +} + BOOST_AUTO_TEST_CASE(two_exact_functions) { char const* text = R"( diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index 050ca500..92bb471b 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE(basic_compilation) BOOST_CHECK(dev::jsonCompactPrint(result["sources"]["fileA"]["legacyAST"]) == "{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}},\"children\":" "[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null],\"contractKind\":\"contract\"," - "\"fullyImplemented\":true,\"linearizedBaseContracts\":[1],\"name\":\"A\",\"nodes\":[null],\"scope\":2}," + "\"documentation\":null,\"fullyImplemented\":true,\"linearizedBaseContracts\":[1],\"name\":\"A\",\"nodes\":[null],\"scope\":2}," "\"id\":1,\"name\":\"ContractDefinition\",\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}"); } |