aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaweł Bylica <pawel.bylica@imapp.pl>2014-12-19 19:36:58 +0800
committerPaweł Bylica <pawel.bylica@imapp.pl>2014-12-19 19:36:58 +0800
commitfbd6d7e2bb16f907d46942fee0b222c79bd4f6fb (patch)
treecd10facbe85b9c0175df0d4736ece4e429114fb1
parent95f6627a53b76e820d7b23b47796adef07288c9c (diff)
parent7d7fa86697e07de2261d8b650be9eebf1c369469 (diff)
downloaddexon-solidity-fbd6d7e2bb16f907d46942fee0b222c79bd4f6fb.tar.gz
dexon-solidity-fbd6d7e2bb16f907d46942fee0b222c79bd4f6fb.tar.zst
dexon-solidity-fbd6d7e2bb16f907d46942fee0b222c79bd4f6fb.zip
Merge remote-tracking branch 'upstream/develop' into develop-evmcc
-rw-r--r--SolidityABIJSON.cpp (renamed from solidityJSONInterfaceTest.cpp)53
-rw-r--r--SolidityCompiler.cpp (renamed from solidityCompiler.cpp)0
-rw-r--r--SolidityEndToEndTest.cpp (renamed from solidityEndToEndTest.cpp)37
-rw-r--r--SolidityExpressionCompiler.cpp (renamed from solidityExpressionCompiler.cpp)0
-rw-r--r--SolidityNameAndTypeResolution.cpp (renamed from solidityNameAndTypeResolution.cpp)10
-rw-r--r--SolidityNatspecJSON.cpp (renamed from solidityNatspecJSON.cpp)29
-rw-r--r--SolidityOptimizer.cpp (renamed from solidityOptimizerTest.cpp)2
-rw-r--r--SolidityParser.cpp (renamed from solidityParser.cpp)14
-rw-r--r--SolidityScanner.cpp (renamed from solidityScanner.cpp)54
9 files changed, 188 insertions, 11 deletions
diff --git a/solidityJSONInterfaceTest.cpp b/SolidityABIJSON.cpp
index c734009c..62ab0458 100644
--- a/solidityJSONInterfaceTest.cpp
+++ b/SolidityABIJSON.cpp
@@ -76,6 +76,7 @@ BOOST_AUTO_TEST_CASE(basic_test)
char const* interface = R"([
{
"name": "f",
+ "const": false,
"inputs": [
{
"name": "a",
@@ -114,6 +115,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
char const* interface = R"([
{
"name": "f",
+ "const": false,
"inputs": [
{
"name": "a",
@@ -129,6 +131,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
},
{
"name": "g",
+ "const": false,
"inputs": [
{
"name": "b",
@@ -156,6 +159,7 @@ BOOST_AUTO_TEST_CASE(multiple_params)
char const* interface = R"([
{
"name": "f",
+ "const": false,
"inputs": [
{
"name": "a",
@@ -189,6 +193,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
char const* interface = R"([
{
"name": "c",
+ "const": false,
"inputs": [
{
"name": "b",
@@ -204,6 +209,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
},
{
"name": "f",
+ "const": false,
"inputs": [
{
"name": "a",
@@ -222,6 +228,53 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
checkInterface(sourceCode, interface);
}
+BOOST_AUTO_TEST_CASE(const_function)
+{
+ char const* sourceCode = "contract test {\n"
+ " function foo(uint a, uint b) returns(uint d) { return a + b; }\n"
+ " function boo(uint32 a) const returns(uint b) { return a * 4; }\n"
+ "}\n";
+
+ char const* interface = R"([
+ {
+ "name": "boo",
+ "const": true,
+ "inputs": [{
+ "name": "a",
+ "type": "uint32"
+ }],
+ "outputs": [
+ {
+ "name": "b",
+ "type": "uint256"
+ }
+ ]
+ },
+ {
+ "name": "foo",
+ "const": false,
+ "inputs": [
+ {
+ "name": "a",
+ "type": "uint256"
+ },
+ {
+ "name": "b",
+ "type": "uint256"
+ }
+ ],
+ "outputs": [
+ {
+ "name": "d",
+ "type": "uint256"
+ }
+ ]
+ }
+ ])";
+
+ checkInterface(sourceCode, interface);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/solidityCompiler.cpp b/SolidityCompiler.cpp
index 385a3e57..385a3e57 100644
--- a/solidityCompiler.cpp
+++ b/SolidityCompiler.cpp
diff --git a/solidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index 26f5528a..9559e370 100644
--- a/solidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -36,7 +36,7 @@ namespace solidity
namespace test
{
-BOOST_FIXTURE_TEST_SUITE(SolidityCompilerEndToEndTest, ExecutionFramework)
+BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, ExecutionFramework)
BOOST_AUTO_TEST_CASE(smoke_test)
{
@@ -504,6 +504,41 @@ BOOST_AUTO_TEST_CASE(state_smoke_test)
BOOST_CHECK(callContractFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0x3)));
}
+BOOST_AUTO_TEST_CASE(compound_assign)
+{
+ char const* sourceCode = "contract test {\n"
+ " uint value1;\n"
+ " uint value2;\n"
+ " function f(uint x, uint y) returns (uint w) {\n"
+ " uint value3 = y;"
+ " value1 += x;\n"
+ " value3 *= x;"
+ " value2 *= value3 + value1;\n"
+ " return value2 += 7;"
+ " }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+
+ u256 value1;
+ u256 value2;
+ auto f = [&](u256 const& _x, u256 const& _y) -> u256
+ {
+ u256 value3 = _y;
+ value1 += _x;
+ value3 *= _x;
+ value2 *= value3 + value1;
+ return value2 += 7;
+ };
+ testSolidityAgainstCpp(0, f, u256(0), u256(6));
+ testSolidityAgainstCpp(0, f, u256(1), u256(3));
+ testSolidityAgainstCpp(0, f, u256(2), u256(25));
+ testSolidityAgainstCpp(0, f, u256(3), u256(69));
+ testSolidityAgainstCpp(0, f, u256(4), u256(84));
+ testSolidityAgainstCpp(0, f, u256(5), u256(2));
+ testSolidityAgainstCpp(0, f, u256(6), u256(51));
+ testSolidityAgainstCpp(0, f, u256(7), u256(48));
+}
+
BOOST_AUTO_TEST_CASE(simple_mapping)
{
char const* sourceCode = "contract test {\n"
diff --git a/solidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp
index 9c375418..9c375418 100644
--- a/solidityExpressionCompiler.cpp
+++ b/SolidityExpressionCompiler.cpp
diff --git a/solidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
index 0bda0a1f..25bff71f 100644
--- a/solidityNameAndTypeResolution.cpp
+++ b/SolidityNameAndTypeResolution.cpp
@@ -311,6 +311,16 @@ BOOST_AUTO_TEST_CASE(forward_function_reference)
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
}
+BOOST_AUTO_TEST_CASE(comparison_bitop_precedence)
+{
+ char const* text = "contract First {\n"
+ " function fun() returns (bool ret) {\n"
+ " return 1 & 2 == 8 & 9 && 1 ^ 2 < 4 | 6;\n"
+ " }\n"
+ "}\n";
+ BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/solidityNatspecJSON.cpp b/SolidityNatspecJSON.cpp
index 2c3ded08..5b48a67c 100644
--- a/solidityNatspecJSON.cpp
+++ b/SolidityNatspecJSON.cpp
@@ -394,6 +394,35 @@ BOOST_AUTO_TEST_CASE(dev_multiline_return)
checkNatspec(sourceCode, natspec, false);
}
+BOOST_AUTO_TEST_CASE(dev_multiline_comment)
+{
+ char const* sourceCode = "contract test {\n"
+ " /**\n"
+ " * @dev Multiplies a number by 7 and adds second parameter\n"
+ " * @param a Documentation for the first parameter starts here.\n"
+ " * Since it's a really complicated parameter we need 2 lines\n"
+ " * @param second Documentation for the second parameter\n"
+ " * @return The result of the multiplication\n"
+ " * and cookies with nutella\n"
+ " */"
+ " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
+ "}\n";
+
+ char const* natspec = "{"
+ "\"methods\":{"
+ " \"mul\":{ \n"
+ " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
+ " \"params\": {\n"
+ " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
+ " \"second\": \"Documentation for the second parameter\"\n"
+ " },\n"
+ " \"return\": \"The result of the multiplication and cookies with nutella\"\n"
+ " }\n"
+ "}}";
+
+ checkNatspec(sourceCode, natspec, false);
+}
+
BOOST_AUTO_TEST_CASE(dev_contract_no_doc)
{
char const* sourceCode = "contract test {\n"
diff --git a/solidityOptimizerTest.cpp b/SolidityOptimizer.cpp
index 388e0579..ef5c6f9b 100644
--- a/solidityOptimizerTest.cpp
+++ b/SolidityOptimizer.cpp
@@ -71,7 +71,7 @@ protected:
Address m_nonOptimizedContract;
};
-BOOST_FIXTURE_TEST_SUITE(SolidityOptimizerTest, OptimizerTestFramework)
+BOOST_FIXTURE_TEST_SUITE(SolidityOptimizer, OptimizerTestFramework)
BOOST_AUTO_TEST_CASE(smoke_test)
{
diff --git a/solidityParser.cpp b/SolidityParser.cpp
index f978cdd9..c14c0512 100644
--- a/solidityParser.cpp
+++ b/SolidityParser.cpp
@@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation)
BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is a test function");
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is a test function");
}
BOOST_AUTO_TEST_CASE(function_normal_comments)
@@ -166,17 +166,17 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
auto functions = contract->getDefinedFunctions();
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is test function 1");
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 1");
BOOST_REQUIRE_NO_THROW(function = functions.at(1));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is test function 2");
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 2");
BOOST_REQUIRE_NO_THROW(function = functions.at(2));
BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr,
"Should not have gotten natspec comment for functionName3()");
BOOST_REQUIRE_NO_THROW(function = functions.at(3));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is test function 4");
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 4");
}
BOOST_AUTO_TEST_CASE(multiline_function_documentation)
@@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation)
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
BOOST_CHECK_EQUAL(*function->getDocumentation(),
- " This is a test function\n"
+ "This is a test function\n"
" and it has 2 lines");
}
@@ -220,11 +220,11 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
auto functions = contract->getDefinedFunctions();
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), " fun1 description");
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), "fun1 description");
BOOST_REQUIRE_NO_THROW(function = functions.at(1));
BOOST_CHECK_EQUAL(*function->getDocumentation(),
- " This is a test function\n"
+ "This is a test function\n"
" and it has 2 lines");
}
diff --git a/solidityScanner.cpp b/SolidityScanner.cpp
index 573affe6..355ea9e2 100644
--- a/solidityScanner.cpp
+++ b/SolidityScanner.cpp
@@ -157,7 +157,14 @@ BOOST_AUTO_TEST_CASE(documentation_comments_parsed_begin)
{
Scanner scanner(CharStream("/// Send $(value / 1000) chocolates to the user"));
BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), " Send $(value / 1000) chocolates to the user");
+ BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
+}
+
+BOOST_AUTO_TEST_CASE(multiline_documentation_comments_parsed_begin)
+{
+ Scanner scanner(CharStream("/** Send $(value / 1000) chocolates to the user*/"));
+ BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
+ BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
}
BOOST_AUTO_TEST_CASE(documentation_comments_parsed)
@@ -167,7 +174,43 @@ BOOST_AUTO_TEST_CASE(documentation_comments_parsed)
BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), " Send $(value / 1000) chocolates to the user");
+ BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
+}
+
+BOOST_AUTO_TEST_CASE(multiline_documentation_comments_parsed)
+{
+ Scanner scanner(CharStream("some other tokens /**\n"
+ "* Send $(value / 1000) chocolates to the user\n"
+ "*/"));
+ BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
+}
+
+BOOST_AUTO_TEST_CASE(multiline_documentation_no_stars)
+{
+ Scanner scanner(CharStream("some other tokens /**\n"
+ " Send $(value / 1000) chocolates to the user\n"
+ "*/"));
+ BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
+}
+
+BOOST_AUTO_TEST_CASE(multiline_documentation_whitespace_hell)
+{
+ Scanner scanner(CharStream("some other tokens /** \t \r \n"
+ "\t \r * Send $(value / 1000) chocolates to the user\n"
+ "*/"));
+ BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::IDENTIFIER);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
}
BOOST_AUTO_TEST_CASE(comment_before_eos)
@@ -184,6 +227,13 @@ BOOST_AUTO_TEST_CASE(documentation_comment_before_eos)
BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "");
}
+BOOST_AUTO_TEST_CASE(empty_multiline_documentation_comment_before_eos)
+{
+ Scanner scanner(CharStream("/***/"));
+ BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
+ BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "");
+}
+
BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence)
{
Scanner scanner(CharStream("hello_world ///documentation comment \n"