diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-23 23:37:06 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-29 04:46:16 +0800 |
commit | 1aa77295e563472724c886df6c92c6646b2e4a45 (patch) | |
tree | 491dfd3694d7e73d78a9fadf1a222113b5dbbbe7 /SolidityNameAndTypeResolution.cpp | |
parent | 9e8fa8b08a1a322efbd099b17af603dca5401fba (diff) | |
download | dexon-solidity-1aa77295e563472724c886df6c92c6646b2e4a45.tar.gz dexon-solidity-1aa77295e563472724c886df6c92c6646b2e4a45.tar.zst dexon-solidity-1aa77295e563472724c886df6c92c6646b2e4a45.zip |
State variable accessors code is now more organized
- FunctionDescription is the abstraction of what should describe a
function. It can either be a VariableDeclaration of a
FunctionDefinition.
- ParamDescription is what FunctionDescription uses to describe its
parameters for outside use purposes with a pair of (name, type)
strings
- Modified code around Solidity and especially interface handler to
adapt to this change
Diffstat (limited to 'SolidityNameAndTypeResolution.cpp')
-rw-r--r-- | SolidityNameAndTypeResolution.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 7728414d..dbb95cf7 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -30,6 +30,8 @@ #include <libsolidity/Exceptions.h> #include <boost/test/unit_test.hpp> +using namespace std; + namespace dev { namespace solidity @@ -39,6 +41,7 @@ namespace test namespace { + ASTPointer<SourceUnit> parseTextAndResolveNames(std::string const& _source) { Parser parser; @@ -90,8 +93,8 @@ static ContractDefinition const* retrieveContract(ASTPointer<SourceUnit> _source return NULL; } -static FunctionDefinition const* retrieveFunctionBySignature(ContractDefinition const* _contract, - std::string const& _signature) +static FunctionDescription const& retrieveFunctionBySignature(ContractDefinition const* _contract, + std::string const& _signature) { FixedHash<4> hash(dev::sha3(_signature)); return _contract->getInterfaceFunctions()[hash]; @@ -629,19 +632,40 @@ BOOST_AUTO_TEST_CASE(modifier_returns_value) BOOST_AUTO_TEST_CASE(state_variable_accessors) { - char const* text = "contract base {\n" + char const* text = "contract test {\n" + " function fun() {\n" + " uint64(2);\n" + " }\n" + "uint256 foo;\n" + "}\n"; + + ASTPointer<SourceUnit> source; + ContractDefinition const* contract; + BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); + BOOST_CHECK((contract = retrieveContract(source, 0)) != nullptr); + FunctionDescription function = retrieveFunctionBySignature(contract, "foo()"); + BOOST_CHECK_MESSAGE(function.getDeclaration() != nullptr, "Could not find the accessor function"); + // vector<ParamDescription> const expected({ParamDescription("", "uint256")}); + // BOOST_CHECK_EQUAL_COLLECTIONS(function.getReturnParameters().begin(), function.getReturnParameters().end(), + // expected.begin(), expected.end()); +} + +BOOST_AUTO_TEST_CASE(private_state_variable) +{ + char const* text = "contract test {\n" " function fun() {\n" " uint64(2);\n" " }\n" + "private:\n" "uint256 foo;\n" "}\n"; ASTPointer<SourceUnit> source; ContractDefinition const* contract; - FunctionDefinition const* function; BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); BOOST_CHECK((contract = retrieveContract(source, 0)) != nullptr); - BOOST_CHECK((function = retrieveFunctionBySignature(contract, "foo()")) != nullptr); + FunctionDescription function = retrieveFunctionBySignature(contract, "foo()"); + BOOST_CHECK_MESSAGE(function.getDeclaration() == nullptr, "Accessor function of a private variable should not exist"); } BOOST_AUTO_TEST_SUITE_END() |