diff options
author | Gav Wood <g@ethdev.com> | 2015-01-07 23:32:13 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-01-07 23:32:13 +0800 |
commit | ec661c9938f7a53b86cc020506a18e5eaae23475 (patch) | |
tree | 620bfb66bae022db22633fdea2fd3579f38a52c6 | |
parent | 2d8771620482a76ad37e565ee268a97eeb02ba1f (diff) | |
parent | deb137f2c41f7011883fec796b63bbe52f5957c1 (diff) | |
download | dexon-solidity-ec661c9938f7a53b86cc020506a18e5eaae23475.tar.gz dexon-solidity-ec661c9938f7a53b86cc020506a18e5eaae23475.tar.zst dexon-solidity-ec661c9938f7a53b86cc020506a18e5eaae23475.zip |
Merge pull request #738 from LefterisJP/sol_abiFunctionHash
Canonical Function signature creation in solidity
-rw-r--r-- | SolidityNameAndTypeResolution.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 25bff71f..94271b1f 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -38,7 +38,7 @@ namespace test namespace { -void parseTextAndResolveNames(std::string const& _source) +ASTPointer<SourceUnit> parseTextAndResolveNames(std::string const& _source) { Parser parser; ASTPointer<SourceUnit> sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source))); @@ -50,6 +50,8 @@ void parseTextAndResolveNames(std::string const& _source) for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) resolver.checkTypeRequirements(*contract); + + return sourceUnit; } } @@ -321,6 +323,40 @@ BOOST_AUTO_TEST_CASE(comparison_bitop_precedence) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } +BOOST_AUTO_TEST_CASE(function_canonical_signature) +{ + ASTPointer<SourceUnit> sourceUnit; + char const* text = "contract Test {\n" + " function foo(uint256 arg1, uint64 arg2, bool arg3) returns (uint256 ret) {\n" + " ret = arg1 + arg2;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text)); + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + auto functions = contract->getDefinedFunctions(); + BOOST_CHECK_EQUAL("foo(uint256,uint64,bool)", functions[0]->getCanonicalSignature()); + } +} + +BOOST_AUTO_TEST_CASE(function_canonical_signature_type_aliases) +{ + ASTPointer<SourceUnit> sourceUnit; + char const* text = "contract Test {\n" + " function boo(uint arg1, hash arg2, address arg3) returns (uint ret) {\n" + " ret = 5;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text)); + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + auto functions = contract->getDefinedFunctions(); + BOOST_CHECK_EQUAL("boo(uint256,hash256,address)", functions[0]->getCanonicalSignature()); + } +} + BOOST_AUTO_TEST_SUITE_END() } |