mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds unit tests for moved function.
This commit is contained in:
parent
ed632025fe
commit
be35a65eb3
@ -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"(
|
||||
|
@ -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)});
|
||||
|
@ -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()
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user