From be35a65eb3966965e30b6b582f7722338e558013 Mon Sep 17 00:00:00 2001 From: bitshift Date: Mon, 5 Mar 2018 19:24:33 +0100 Subject: Adds unit tests for moved function. --- test/libsolidity/SolidityEndToEndTest.cpp | 29 ++++++++++++++++++++++ test/libsolidity/SolidityExpressionCompiler.cpp | 9 ++++--- test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 +++++++++ test/libsolidity/ViewPureChecker.cpp | 4 +-- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 44dc40f7..43d390f5 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1805,6 +1805,35 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash) BOOST_CHECK(result[0] != 0 || result[1] != 0 || result[2] != 0); } +BOOST_AUTO_TEST_CASE(blockhash_global_level) +{ + char const* sourceCode = R"( + contract Test { + function a() public returns (bytes32) { + return blockhash(0); + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(!callContractFunction("a()").empty()); +} + +BOOST_AUTO_TEST_CASE(blockhash_shadow) +{ + char const* sourceCode = R"( + contract Test { + function blockhash(uint256 blockNumber) public returns (bytes32) { + return "abc"; + } + function f() returns (bytes32) { + return blockhash(3); + } + } + )"; + compileAndRun(sourceCode); + BOOST_REQUIRE(callContractFunction("f()") != encodeArgs("abc")); +} + BOOST_AUTO_TEST_CASE(log0) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index c8adfc6e..90d8265c 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -503,12 +503,15 @@ BOOST_AUTO_TEST_CASE(blockhash) char const* sourceCode = R"( contract test { function f() { - block.blockhash(3); + blockhash(3); } } )"; - bytes code = compileFirstExpression(sourceCode, {}, {}, - {make_shared("block", make_shared(MagicType::Kind::Block))}); + + auto blockhashFun = make_shared(strings{"uint256"}, strings{"bytes32"}, + FunctionType::Kind::BlockHash, false, StateMutability::View); + + bytes code = compileFirstExpression(sourceCode, {}, {}, {make_shared("blockhash", blockhashFun)}); bytes expectation({byte(Instruction::PUSH1), 0x03, byte(Instruction::BLOCKHASH)}); diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 50ee2b2e..579fb239 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -8555,6 +8555,18 @@ BOOST_AUTO_TEST_CASE(require_visibility_specifiers) CHECK_ERROR(text, SyntaxError, "No visibility specified."); } +BOOST_AUTO_TEST_CASE(blockhash_not_available_in_block) +{ + char const* text = R"( + contract Test { + function a() public returns (bytes32) { + return block.blockhash(0); + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"blockhash\" not found or not visible after argument-dependent lookup in block"); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index a6ce6d91..de25cfcf 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -107,7 +107,6 @@ BOOST_AUTO_TEST_CASE(environment_access) vector view{ "block.coinbase", "block.timestamp", - "block.blockhash(7)", "block.difficulty", "block.number", "block.gaslimit", @@ -118,15 +117,16 @@ BOOST_AUTO_TEST_CASE(environment_access) "tx.origin", "tx.gasprice", "this", + "blockhash(7)", "address(1).balance" }; vector pure{ "msg.data", "msg.data[0]", "msg.sig", - "block.blockhash", // Not evaluating the function "msg", "block", + "blockhash", // Not evaluating the function "tx" }; for (string const& x: view) -- cgit v1.2.3