diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-20 00:00:23 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-20 00:13:18 +0800 |
commit | ab4178941b1f1d99bf266cd0a27d79a27162513a (patch) | |
tree | d1bcc1c293e9a551f41495eda567a2b3b10243fc /SolidityExpressionCompiler.cpp | |
parent | 933d65e9863e4f1d57500ccba85e6cde116d962a (diff) | |
download | dexon-solidity-ab4178941b1f1d99bf266cd0a27d79a27162513a.tar.gz dexon-solidity-ab4178941b1f1d99bf266cd0a27d79a27162513a.tar.zst dexon-solidity-ab4178941b1f1d99bf266cd0a27d79a27162513a.zip |
Adding blockhash test in Solidity ExpressionCompiler
Diffstat (limited to 'SolidityExpressionCompiler.cpp')
-rw-r--r-- | SolidityExpressionCompiler.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp index 579af5bb..d50dc253 100644 --- a/SolidityExpressionCompiler.cpp +++ b/SolidityExpressionCompiler.cpp @@ -86,13 +86,19 @@ Declaration const& resolveDeclaration(vector<string> const& _namespacedName, } bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _functions = {}, - vector<vector<string>> _localVariables = {}) + vector<vector<string>> _localVariables = {}, vector<shared_ptr<MagicVariableDeclaration const>> _globalDeclarations = {}) { Parser parser; ASTPointer<SourceUnit> sourceUnit; BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); - NameAndTypeResolver resolver({}); + + vector<Declaration const*> declarations; + declarations.reserve(_globalDeclarations.size() + 1); + for (ASTPointer<Declaration const> const& variable: _globalDeclarations) + declarations.push_back(variable.get()); + NameAndTypeResolver resolver(declarations); resolver.registerDeclarations(*sourceUnit); + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) { @@ -390,6 +396,21 @@ BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } +BOOST_AUTO_TEST_CASE(blockhash) +{ + char const* sourceCode = "contract test {\n" + " function f() {\n" + " block.blockhash(3);\n" + " }\n" + "}\n"; + bytes code = compileFirstExpression(sourceCode, {}, {}, + {make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::BLOCK))}); + + bytes expectation({byte(eth::Instruction::PUSH1), 0x03, + byte(eth::Instruction::BLOCKHASH)}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + BOOST_AUTO_TEST_SUITE_END() } |