Docs, changelog and tests

This commit is contained in:
Harikrishnan Mulackal 2020-05-05 14:26:31 +05:30
parent b5612f96c9
commit a207613f17
11 changed files with 38 additions and 23 deletions

View File

@ -3,6 +3,7 @@
Breaking changes:
* Type Checker: Disallow virtual for library functions.
* Deprecated dot syntax for `value` and `gas`.
* Deprecated the identifier `now`.
Language Features:

View File

@ -67,7 +67,7 @@ The following is the order of precedence for operators, listed in order of evalu
| *15* | Comma operator | ``,`` |
+------------+-------------------------------------+--------------------------------------------+
.. index:: assert, block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, revert, require, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send
.. index:: assert, block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, gas price, origin, revert, require, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send
Global Variables
================
@ -91,7 +91,6 @@ Global Variables
- ``msg.data`` (``bytes``): complete calldata
- ``msg.sender`` (``address payable``): sender of the message (current call)
- ``msg.value`` (``uint``): number of wei sent with the message
- ``now`` (``uint``): current block timestamp (alias for ``block.timestamp``)
- ``tx.gasprice`` (``uint``): gas price of the transaction
- ``tx.origin`` (``address payable``): sender of the transaction (full call chain)
- ``assert(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for internal error)
@ -124,7 +123,7 @@ Global Variables
- ``type(I).interfaceId`` (``bytes4``): value containing the EIP-165 interface identifier of the given interface, see :ref:`Type Information<meta-type>`.
.. note::
Do not rely on ``block.timestamp``, ``now`` and ``blockhash`` as a source of randomness,
Do not rely on ``block.timestamp`` or ``blockhash`` as a source of randomness,
unless you know what you are doing.
Both the timestamp and the block hash can be influenced by miners to some degree.
@ -144,6 +143,8 @@ Global Variables
In version 0.5.0, the following aliases were removed: ``suicide`` as alias for ``selfdestruct``,
``msg.gas`` as alias for ``gasleft``, ``block.blockhash`` as alias for ``blockhash`` and
``sha3`` as alias for ``keccak256``.
.. note::
In version 0.7.0, the alias ``now`` (for ``block.timestamp``) was removed.
.. index:: visibility, public, private, external, internal

View File

@ -44,7 +44,7 @@ Constant
For ``constant`` variables, the value has to be a constant at compile time and it has to be
assigned where the variable is declared. Any expression
that accesses storage, blockchain data (e.g. ``now``, ``address(this).balance`` or
that accesses storage, blockchain data (e.g. ``block.timestamp``, ``address(this).balance`` or
``block.number``) or
execution data (``msg.value`` or ``gasleft()``) or makes calls to external contracts is disallowed. Expressions
that might have a side-effect on memory allocation are allowed, but those that

View File

@ -146,7 +146,7 @@ The following statements are considered modifying the state:
contract C {
function f(uint a, uint b) public view returns (uint) {
return a * (b + 42) + now;
return a * (b + 42) + block.timestamp;
}
}

View File

@ -61,7 +61,7 @@ to receive their money - contracts cannot activate themselves.
address payable _beneficiary
) public {
beneficiary = _beneficiary;
auctionEndTime = now + _biddingTime;
auctionEndTime = block.timestamp + _biddingTime;
}
/// Bid on the auction with the value sent
@ -78,7 +78,7 @@ to receive their money - contracts cannot activate themselves.
// Revert the call if the bidding
// period is over.
require(
now <= auctionEndTime,
block.timestamp <= auctionEndTime,
"Auction already ended."
);
@ -140,7 +140,7 @@ to receive their money - contracts cannot activate themselves.
// external contracts.
// 1. Conditions
require(now >= auctionEndTime, "Auction not yet ended.");
require(block.timestamp >= auctionEndTime, "Auction not yet ended.");
require(!ended, "auctionEnd has already been called.");
// 2. Effects
@ -211,8 +211,8 @@ invalid bids.
/// functions. `onlyBefore` is applied to `bid` below:
/// The new function body is the modifier's body where
/// `_` is replaced by the old function body.
modifier onlyBefore(uint _time) { require(now < _time); _; }
modifier onlyAfter(uint _time) { require(now > _time); _; }
modifier onlyBefore(uint _time) { require(block.timestamp < _time); _; }
modifier onlyAfter(uint _time) { require(block.timestamp > _time); _; }
constructor(
uint _biddingTime,
@ -220,7 +220,7 @@ invalid bids.
address payable _beneficiary
) public {
beneficiary = _beneficiary;
biddingEnd = now + _biddingTime;
biddingEnd = block.timestamp + _biddingTime;
revealEnd = biddingEnd + _revealTime;
}
@ -326,4 +326,4 @@ invalid bids.
highestBidder = bidder;
return true;
}
}
}

View File

@ -351,7 +351,7 @@ The full contract
{
sender = msg.sender;
recipient = _recipient;
expiration = now + duration;
expiration = block.timestamp + duration;
}
/// the recipient can close the channel at any time by presenting a
@ -376,7 +376,7 @@ The full contract
/// if the timeout is reached without the recipient closing the channel,
/// then the Ether is released back to the sender.
function claimTimeout() public {
require(now >= expiration);
require(block.timestamp >= expiration);
selfdestruct(sender);
}

View File

@ -47,7 +47,7 @@ These suffixes cannot be applied to variables. For example, if you want to
interpret a function parameter in days, you can in the following way::
function f(uint start, uint daysAfter) public {
if (now >= start + daysAfter * 1 days) {
if (block.timestamp >= start + daysAfter * 1 days) {
// ...
}
}
@ -61,7 +61,7 @@ There are special variables and functions which always exist in the global
namespace and are mainly used to provide information about the blockchain
or are general-use utility functions.
.. index:: abi, block, coinbase, difficulty, encode, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin
.. index:: abi, block, coinbase, difficulty, encode, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, gas price, origin
Block and Transaction Properties
@ -78,7 +78,6 @@ Block and Transaction Properties
- ``msg.sender`` (``address payable``): sender of the message (current call)
- ``msg.sig`` (``bytes4``): first four bytes of the calldata (i.e. function identifier)
- ``msg.value`` (``uint``): number of wei sent with the message
- ``now`` (``uint``): current block timestamp (alias for ``block.timestamp``)
- ``tx.gasprice`` (``uint``): gas price of the transaction
- ``tx.origin`` (``address payable``): sender of the transaction (full call chain)
@ -88,7 +87,7 @@ Block and Transaction Properties
This includes calls to library functions.
.. note::
Do not rely on ``block.timestamp``, ``now`` and ``blockhash`` as a source of randomness,
Do not rely on ``block.timestamp`` or ``blockhash`` as a source of randomness,
unless you know what you are doing.
Both the timestamp and the block hash can be influenced by miners to some degree.
@ -327,4 +326,3 @@ for an interface type ``I``:
A ``bytes4`` value containing the `EIP-165 <https://eips.ethereum.org/EIPS/eip-165>`_
interface identifier of the given interface ``I``. This identifier is defined as the ``XOR`` of all
function selectors defined within the interface itself - excluding all inherited functions.

View File

@ -69,8 +69,8 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet {
internal
returns (bool)
{
if (now > lastDay + 24 hours) {
lastDay = now;
if (block.timestamp > lastDay + 24 hours) {
lastDay = block.timestamp;
spentToday = 0;
}
if (spentToday + amount > dailyLimit || spentToday + amount < spentToday)
@ -88,7 +88,7 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet {
view
returns (uint)
{
if (now > lastDay + 24 hours)
if (block.timestamp > lastDay + 24 hours)
return dailyLimit;
if (dailyLimit < spentToday)
return 0;

View File

@ -0,0 +1,7 @@
contract C {
function f() public {
now;
}
}
// ----
// TypeError: (38-41): "now" has been deprecated. Use "block.timestamp" instead.

View File

@ -0,0 +1,8 @@
contract C {
function f() public view {
uint now = block.timestamp;
now;
}
}
// ----
// Warning: (43-51): This declaration shadows a builtin symbol.

View File

@ -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; }
}