aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-03-03 00:58:27 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2018-03-05 18:18:04 +0800
commitc633c0eacba12e940b12c6ff58b5c6c55dc0122c (patch)
tree9b54278c28df1c2fb97916c9ec7e263faea1b97d /test/libsolidity
parent5982869e94965e48ec680fd32e6f80b8211fc34c (diff)
downloaddexon-solidity-c633c0eacba12e940b12c6ff58b5c6c55dc0122c.tar
dexon-solidity-c633c0eacba12e940b12c6ff58b5c6c55dc0122c.tar.gz
dexon-solidity-c633c0eacba12e940b12c6ff58b5c6c55dc0122c.tar.bz2
dexon-solidity-c633c0eacba12e940b12c6ff58b5c6c55dc0122c.tar.lz
dexon-solidity-c633c0eacba12e940b12c6ff58b5c6c55dc0122c.tar.xz
dexon-solidity-c633c0eacba12e940b12c6ff58b5c6c55dc0122c.tar.zst
dexon-solidity-c633c0eacba12e940b12c6ff58b5c6c55dc0122c.zip
Move msg.gas to global function gasleft(). Closes #2971.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp19
-rw-r--r--test/libsolidity/SolidityExpressionCompiler.cpp33
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp25
-rw-r--r--test/libsolidity/ViewPureChecker.cpp1
4 files changed, 78 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index c352a2c2..e61afb0e 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2481,6 +2481,25 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic)
BOOST_REQUIRE(callContractFunction("checkState()") == encodeArgs(false, 20 - 5));
}
+BOOST_AUTO_TEST_CASE(gas_left)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function getGasLeft() public returns (uint256 val) { return msg.gas; }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_REQUIRE(callContractFunction("getGasLeft()") == encodeArgs(99978604));
+
+ sourceCode = R"(
+ contract test {
+ function getGasLeft() public returns (uint256 val) { return gasleft(); }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_REQUIRE(callContractFunction("getGasLeft()") == encodeArgs(99978604));
+}
+
BOOST_AUTO_TEST_CASE(value_complex)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp
index e2a0c3cd..83129ba1 100644
--- a/test/libsolidity/SolidityExpressionCompiler.cpp
+++ b/test/libsolidity/SolidityExpressionCompiler.cpp
@@ -515,6 +515,39 @@ BOOST_AUTO_TEST_CASE(blockhash)
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
}
+BOOST_AUTO_TEST_CASE(gas_left)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f() returns (uint256 val) {
+ return msg.gas;
+ }
+ }
+ )";
+ bytes code = compileFirstExpression(
+ sourceCode, {}, {},
+ {make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::Message))}
+ );
+
+ bytes expectation({byte(Instruction::GAS)});
+ BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
+
+ sourceCode = R"(
+ contract test {
+ function f() returns (uint256 val) {
+ return gasleft();
+ }
+ }
+ )";
+ code = compileFirstExpression(
+ sourceCode, {}, {},
+ {make_shared<MagicVariableDeclaration>("gasleft", make_shared<FunctionType>(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft))}
+ );
+
+ expectation = bytes({byte(Instruction::GAS)});
+ BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index eeefe818..469211d3 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -7409,6 +7409,31 @@ BOOST_AUTO_TEST_CASE(builtin_reject_gas)
CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup");
}
+BOOST_AUTO_TEST_CASE(gas_left)
+{
+ char const* text = R"(
+ contract C {
+ function f() public returns (uint256 val) { return msg.gas; }
+ }
+ )";
+ CHECK_SUCCESS(text);
+
+ text = R"(
+ contract C {
+ function f() public returns (uint256 val) { return gasleft(); }
+ }
+ )";
+ CHECK_SUCCESS(text);
+
+ text = R"(
+ pragma experimental "v0.5.0";
+ contract C {
+ function f() public returns (uint256 val) { return msg.gas; }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup in msg");
+}
+
BOOST_AUTO_TEST_CASE(builtin_reject_value)
{
char const* text = R"(
diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp
index 2599ca28..609a0154 100644
--- a/test/libsolidity/ViewPureChecker.cpp
+++ b/test/libsolidity/ViewPureChecker.cpp
@@ -109,6 +109,7 @@ BOOST_AUTO_TEST_CASE(environment_access)
"block.difficulty",
"block.number",
"block.gaslimit",
+ "gasleft()",
"msg.gas",
"msg.value",
"msg.sender",