Merge pull request #8843 from ethereum/deprecate-now

[BREAKING] Deprecate keyword now
This commit is contained in:
chriseth
2020-05-11 16:09:21 +02:00
committed by GitHub
34 changed files with 157 additions and 107 deletions
-23
View File
@@ -1025,29 +1025,6 @@ BOOST_AUTO_TEST_CASE(blockchain)
ABI_CHECK(callContractFunctionWithValue("someInfo()", 28), encodeArgs(28, u256("0x1212121212121212121212121212121212121212"), 7));
}
BOOST_AUTO_TEST_CASE(now)
{
char const* sourceCode = R"(
contract test {
function someInfo() public returns (bool equal, uint val) {
equal = block.timestamp == now;
val = now;
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
u256 startBlock = blockNumber();
size_t startTime = blockTimestamp(startBlock);
auto ret = callContractFunction("someInfo()");
u256 endBlock = blockNumber();
size_t endTime = blockTimestamp(endBlock);
BOOST_CHECK(startBlock != endBlock);
BOOST_CHECK(startTime != endTime);
ABI_CHECK(ret, encodeArgs(true, endTime));
)
}
BOOST_AUTO_TEST_CASE(send_ether)
{
char const* sourceCode = R"(
+2 -2
View File
@@ -346,9 +346,9 @@ BOOST_AUTO_TEST_CASE(incorrect_storage_access_bug)
mapping(uint => uint) data;
function f() public returns (uint)
{
if (data[now] == 0)
if (data[block.timestamp] == 0)
data[uint(-7)] = 5;
return data[now];
return data[block.timestamp];
}
}
)";
@@ -10,7 +10,7 @@ contract C
assert(tx.origin == msg.sender);
uint x = block.number;
assert(x + 2 > block.number);
assert(now > 10);
assert(block.timestamp > 10);
assert(gasleft() > 100);
}
}
@@ -22,5 +22,5 @@ contract C
// Warning: (244-275): Assertion violation happens here
// Warning: (311-316): Overflow (resulting value larger than 2**256 - 1) happens here
// Warning: (304-332): Assertion violation happens here
// Warning: (336-352): Assertion violation happens here
// Warning: (356-379): Assertion violation happens here
// Warning: (336-364): Assertion violation happens here
// Warning: (368-391): Assertion violation happens here
@@ -0,0 +1,7 @@
contract C {
function f() public {
now;
}
}
// ----
// TypeError: (38-41): "now" has been deprecated. Use "block.timestamp" instead.
@@ -0,0 +1,8 @@
contract C {
function f() public view {
uint now = block.timestamp;
now;
}
}
// ----
// Warning: (43-51): This declaration shadows a builtin symbol.
@@ -1,7 +1,7 @@
contract C {
uint x;
function g() pure public {}
function f() view public returns (uint) { return now; }
function f() view public returns (uint) { return block.timestamp; }
function h() public { x = 2; }
function i() payable public { x = 2; }
}