diff options
author | bitshift <bitshift@posteo.org> | 2018-03-06 02:24:33 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-03-27 10:30:03 +0800 |
commit | be35a65eb3966965e30b6b582f7722338e558013 (patch) | |
tree | 4784a52616f22bf96a388af7591ead908bad4617 | |
parent | ed632025fe5995d093472b1e7660087e943f2ca6 (diff) | |
download | dexon-solidity-be35a65eb3966965e30b6b582f7722338e558013.tar.gz dexon-solidity-be35a65eb3966965e30b6b582f7722338e558013.tar.zst dexon-solidity-be35a65eb3966965e30b6b582f7722338e558013.zip |
Adds unit tests for moved function.
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 29 | ||||
-rw-r--r-- | test/libsolidity/SolidityExpressionCompiler.cpp | 9 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 | ||||
-rw-r--r-- | 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<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block))}); + + auto blockhashFun = make_shared<FunctionType>(strings{"uint256"}, strings{"bytes32"}, + FunctionType::Kind::BlockHash, false, StateMutability::View); + + bytes code = compileFirstExpression(sourceCode, {}, {}, {make_shared<MagicVariableDeclaration>("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<string> 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<string> 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) |