Browse Source

Natspec method key is now the Canonical Signature

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
5b36d3c163
  1. 4
      libsolidity/InterfaceHandler.cpp
  2. 42
      test/SolidityNatspecJSON.cpp

4
libsolidity/InterfaceHandler.cpp

@ -106,7 +106,7 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(ContractDefi
if (!m_notice.empty()) if (!m_notice.empty())
{// since @notice is the only user tag if missing function should not appear {// since @notice is the only user tag if missing function should not appear
user["notice"] = Json::Value(m_notice); user["notice"] = Json::Value(m_notice);
methods[it.second->getName()] = user; methods[it.second->getCanonicalSignature()] = user;
} }
} }
} }
@ -162,7 +162,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
method["return"] = m_return; method["return"] = m_return;
if (!method.empty()) // add the function, only if we have any documentation to add if (!method.empty()) // add the function, only if we have any documentation to add
methods[it.second->getName()] = method; methods[it.second->getCanonicalSignature()] = method;
} }
} }
doc["methods"] = methods; doc["methods"] = methods;

42
test/SolidityNatspecJSON.cpp

@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(user_basic_test)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \"notice\": \"Multiplies `a` by 7\"}" " \"mul(uint256)\":{ \"notice\": \"Multiplies `a` by 7\"}"
"}}"; "}}";
checkNatspec(sourceCode, natspec, true); checkNatspec(sourceCode, natspec, true);
@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(dev_and_user_basic_test)
char const* devNatspec = "{" char const* devNatspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7\"\n" " \"details\": \"Multiplies a number by 7\"\n"
" }\n" " }\n"
" }\n" " }\n"
@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(dev_and_user_basic_test)
char const* userNatspec = "{" char const* userNatspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \"notice\": \"Multiplies `a` by 7\"}" " \"mul(uint256)\":{ \"notice\": \"Multiplies `a` by 7\"}"
"}}"; "}}";
checkNatspec(sourceCode, devNatspec, false); checkNatspec(sourceCode, devNatspec, false);
@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(user_multiline_comment)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul_and_add\":{ \"notice\": \"Multiplies `a` by 7 and then adds `b`\"}" " \"mul_and_add(uint256,uint256)\":{ \"notice\": \"Multiplies `a` by 7 and then adds `b`\"}"
"}}"; "}}";
checkNatspec(sourceCode, natspec, true); checkNatspec(sourceCode, natspec, true);
@ -157,9 +157,9 @@ BOOST_AUTO_TEST_CASE(user_multiple_functions)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul_and_add\":{ \"notice\": \"Multiplies `a` by 7 and then adds `b`\"}," " \"mul_and_add(uint256,uint256)\":{ \"notice\": \"Multiplies `a` by 7 and then adds `b`\"},"
" \"divide\":{ \"notice\": \"Divides `input` by `div`\"}," " \"divide(uint256,uint256)\":{ \"notice\": \"Divides `input` by `div`\"},"
" \"sub\":{ \"notice\": \"Subtracts 3 from `input`\"}" " \"sub(int256)\":{ \"notice\": \"Subtracts 3 from `input`\"}"
"}}"; "}}";
checkNatspec(sourceCode, natspec, true); checkNatspec(sourceCode, natspec, true);
@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(dev_desc_after_nl)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \" Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \" Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter\",\n" " \"a\": \"Documentation for the first parameter\",\n"
@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter\",\n" " \"a\": \"Documentation for the first parameter\",\n"
@ -252,7 +252,7 @@ BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n" " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
@ -289,21 +289,21 @@ BOOST_AUTO_TEST_CASE(dev_multiple_functions)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter\",\n" " \"a\": \"Documentation for the first parameter\",\n"
" \"second\": \"Documentation for the second parameter\"\n" " \"second\": \"Documentation for the second parameter\"\n"
" }\n" " }\n"
" },\n" " },\n"
" \"divide\":{ \n" " \"divide(uint256,uint256)\":{ \n"
" \"details\": \"Divides 2 numbers\",\n" " \"details\": \"Divides 2 numbers\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"input\": \"Documentation for the input parameter\",\n" " \"input\": \"Documentation for the input parameter\",\n"
" \"div\": \"Documentation for the div parameter\"\n" " \"div\": \"Documentation for the div parameter\"\n"
" }\n" " }\n"
" },\n" " },\n"
" \"sub\":{ \n" " \"sub(int256)\":{ \n"
" \"details\": \"Subtracts 3 from `input`\",\n" " \"details\": \"Subtracts 3 from `input`\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"input\": \"Documentation for the input parameter\"\n" " \"input\": \"Documentation for the input parameter\"\n"
@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(dev_return)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n" " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
@ -353,7 +353,7 @@ BOOST_AUTO_TEST_CASE(dev_return_desc_after_nl)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n" " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(dev_multiline_return)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n" " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
@ -410,7 +410,7 @@ BOOST_AUTO_TEST_CASE(dev_multiline_comment)
char const* natspec = "{" char const* natspec = "{"
"\"methods\":{" "\"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
" \"params\": {\n" " \"params\": {\n"
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n" " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
@ -432,7 +432,7 @@ BOOST_AUTO_TEST_CASE(dev_contract_no_doc)
char const* natspec = "{" char const* natspec = "{"
" \"methods\":{" " \"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Mul function\"\n" " \"details\": \"Mul function\"\n"
" }\n" " }\n"
" }\n" " }\n"
@ -454,7 +454,7 @@ BOOST_AUTO_TEST_CASE(dev_contract_doc)
" \"author\": \"Lefteris\"," " \"author\": \"Lefteris\","
" \"title\": \"Just a test contract\"," " \"title\": \"Just a test contract\","
" \"methods\":{" " \"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Mul function\"\n" " \"details\": \"Mul function\"\n"
" }\n" " }\n"
" }\n" " }\n"
@ -477,7 +477,7 @@ BOOST_AUTO_TEST_CASE(dev_author_at_function)
" \"author\": \"Lefteris\"," " \"author\": \"Lefteris\","
" \"title\": \"Just a test contract\"," " \"title\": \"Just a test contract\","
" \"methods\":{" " \"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Mul function\",\n" " \"details\": \"Mul function\",\n"
" \"author\": \"John Doe\",\n" " \"author\": \"John Doe\",\n"
" }\n" " }\n"
@ -501,7 +501,7 @@ BOOST_AUTO_TEST_CASE(dev_title_at_function_error)
" \"author\": \"Lefteris\"," " \"author\": \"Lefteris\","
" \"title\": \"Just a test contract\"," " \"title\": \"Just a test contract\","
" \"methods\":{" " \"methods\":{"
" \"mul\":{ \n" " \"mul(uint256,uint256)\":{ \n"
" \"details\": \"Mul function\"\n" " \"details\": \"Mul function\"\n"
" }\n" " }\n"
" }\n" " }\n"

Loading…
Cancel
Save