Skip to content

Commit fd957c4

Browse files
committed
Merge branch 'master' of https://github.com/vittominacori/zeppelin-solidity into feature/token-recover
* 'master' of https://github.com/vittominacori/zeppelin-solidity: (98 commits) Renamed roles private variables to adhere to code style. (OpenZeppelin#1507) Remove extraneous quantity check, fixes OpenZeppelin#1454 (OpenZeppelin#1455) Remove redundant require statements (OpenZeppelin#1409) Add the step to delete the build dir to the RELEASE notes (OpenZeppelin#1467) add an address typecast to this per issue OpenZeppelin#1457 (OpenZeppelin#1471) add improvement in simpletoken example OpenZeppelin#1458 (OpenZeppelin#1473) SafeMath Test Coverage Improved (OpenZeppelin#1477) The beneficiary parameter of claimRefund is replaced with refundee (OpenZeppelin#1481) fix ERC20.sol#L174 and ERC20.sol#L187 should be casted to an address type. (OpenZeppelin#1470) Fix/add comment erc721 burnable OpenZeppelin#1464 (OpenZeppelin#1469) Release v2.0.0 Release candidate v2.0.0-rc.4 Improved some ERC721 internal shenanigans (OpenZeppelin#1450) Add warning about trading tokens before refundable crowdsale goal is met (OpenZeppelin#1452) Crowdsale.buyTokens is now nonReentrant. (OpenZeppelin#1438) InitialRate must be strictly larger than finalRate. (OpenZeppelin#1441) Fixed how allowance crowdsale checks remaining tokens. (OpenZeppelin#1449) Deleted unnecessary import. (OpenZeppelin#1437) Made SampleCrowdsale a bit clearer. (OpenZeppelin#1448) Now setting the finalized flag before doing finalization to prevent possbile reentrancy issues. (OpenZeppelin#1447) ...
2 parents a6ea985 + a833c4b commit fd957c4

15 files changed

+67
-41
lines changed

RELEASING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Draft the release notes in our [GitHub releases](https://github.com/OpenZeppelin
3636

3737
Before publishing on npm you need to generate the build artifacts. This is not done automatically at the moment because of a bug in Truffle. Since some of the contracts should not be included in the package, this is a _hairy_ process that you need to do with care.
3838

39-
1. Delete the `contracts/mocks` and `contracts/examples` directories.
39+
1. Delete the `contracts/mocks`, `contracts/examples` and `build` directories.
4040
2. Run `truffle compile`. (Note that the Truffle process may never exit and you will have to interrupt it.)
4141
3. Recover the directories using `git checkout`. It doesn't matter if you do this now or later.
4242

@@ -70,7 +70,7 @@ Draft the release notes in GitHub releases. Try to be consistent with our previo
7070

7171
Before publishing on npm you need to generate the build artifacts. This is not done automatically at the moment because of a bug in Truffle. Since some of the contracts should not be included in the package, this is a _hairy_ process that you need to do with care.
7272

73-
1. Delete the `contracts/mocks` and `contracts/examples` directories.
73+
1. Delete the `contracts/mocks`, `contracts/examples` and `build` directories.
7474
2. Run `truffle compile`. (Note that the Truffle process may never exit and you will have to interrupt it.)
7575
3. Recover the directories using `git checkout`. It doesn't matter if you do this now or later.
7676

contracts/access/roles/CapperRole.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contract CapperRole {
88
event CapperAdded(address indexed account);
99
event CapperRemoved(address indexed account);
1010

11-
Roles.Role private cappers;
11+
Roles.Role private _cappers;
1212

1313
constructor() internal {
1414
_addCapper(msg.sender);
@@ -20,7 +20,7 @@ contract CapperRole {
2020
}
2121

2222
function isCapper(address account) public view returns (bool) {
23-
return cappers.has(account);
23+
return _cappers.has(account);
2424
}
2525

2626
function addCapper(address account) public onlyCapper {
@@ -32,12 +32,12 @@ contract CapperRole {
3232
}
3333

3434
function _addCapper(address account) internal {
35-
cappers.add(account);
35+
_cappers.add(account);
3636
emit CapperAdded(account);
3737
}
3838

3939
function _removeCapper(address account) internal {
40-
cappers.remove(account);
40+
_cappers.remove(account);
4141
emit CapperRemoved(account);
4242
}
4343
}

contracts/access/roles/MinterRole.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contract MinterRole {
88
event MinterAdded(address indexed account);
99
event MinterRemoved(address indexed account);
1010

11-
Roles.Role private minters;
11+
Roles.Role private _minters;
1212

1313
constructor() internal {
1414
_addMinter(msg.sender);
@@ -20,7 +20,7 @@ contract MinterRole {
2020
}
2121

2222
function isMinter(address account) public view returns (bool) {
23-
return minters.has(account);
23+
return _minters.has(account);
2424
}
2525

2626
function addMinter(address account) public onlyMinter {
@@ -32,12 +32,12 @@ contract MinterRole {
3232
}
3333

3434
function _addMinter(address account) internal {
35-
minters.add(account);
35+
_minters.add(account);
3636
emit MinterAdded(account);
3737
}
3838

3939
function _removeMinter(address account) internal {
40-
minters.remove(account);
40+
_minters.remove(account);
4141
emit MinterRemoved(account);
4242
}
4343
}

contracts/access/roles/PauserRole.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contract PauserRole {
88
event PauserAdded(address indexed account);
99
event PauserRemoved(address indexed account);
1010

11-
Roles.Role private pausers;
11+
Roles.Role private _pausers;
1212

1313
constructor() internal {
1414
_addPauser(msg.sender);
@@ -20,7 +20,7 @@ contract PauserRole {
2020
}
2121

2222
function isPauser(address account) public view returns (bool) {
23-
return pausers.has(account);
23+
return _pausers.has(account);
2424
}
2525

2626
function addPauser(address account) public onlyPauser {
@@ -32,12 +32,12 @@ contract PauserRole {
3232
}
3333

3434
function _addPauser(address account) internal {
35-
pausers.add(account);
35+
_pausers.add(account);
3636
emit PauserAdded(account);
3737
}
3838

3939
function _removePauser(address account) internal {
40-
pausers.remove(account);
40+
_pausers.remove(account);
4141
emit PauserRemoved(account);
4242
}
4343
}

contracts/access/roles/SignerRole.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contract SignerRole {
88
event SignerAdded(address indexed account);
99
event SignerRemoved(address indexed account);
1010

11-
Roles.Role private signers;
11+
Roles.Role private _signers;
1212

1313
constructor() internal {
1414
_addSigner(msg.sender);
@@ -20,7 +20,7 @@ contract SignerRole {
2020
}
2121

2222
function isSigner(address account) public view returns (bool) {
23-
return signers.has(account);
23+
return _signers.has(account);
2424
}
2525

2626
function addSigner(address account) public onlySigner {
@@ -32,12 +32,12 @@ contract SignerRole {
3232
}
3333

3434
function _addSigner(address account) internal {
35-
signers.add(account);
35+
_signers.add(account);
3636
emit SignerAdded(account);
3737
}
3838

3939
function _removeSigner(address account) internal {
40-
signers.remove(account);
40+
_signers.remove(account);
4141
emit SignerRemoved(account);
4242
}
4343
}

contracts/crowdsale/distribution/RefundableCrowdsale.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
5050

5151
/**
5252
* @dev Investors can claim refunds here if crowdsale is unsuccessful
53-
* @param beneficiary Whose refund will be claimed.
53+
* @param refundee Whose refund will be claimed.
5454
*/
55-
function claimRefund(address beneficiary) public {
55+
function claimRefund(address refundee) public {
5656
require(finalized());
5757
require(!goalReached());
5858

59-
_escrow.withdraw(beneficiary);
59+
_escrow.withdraw(refundee);
6060
}
6161

6262
/**

contracts/drafts/TokenVesting.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ contract TokenVesting is Ownable {
161161
* @param token ERC20 token which is being vested
162162
*/
163163
function _vestedAmount(IERC20 token) private view returns (uint256) {
164-
uint256 currentBalance = token.balanceOf(this);
164+
uint256 currentBalance = token.balanceOf(address(this));
165165
uint256 totalBalance = currentBalance.add(_released[token]);
166166

167167
if (block.timestamp < _cliff) {

contracts/examples/SimpleToken.sol

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
pragma solidity ^0.4.24;
22

33
import "../token/ERC20/ERC20.sol";
4+
import "../token/ERC20/ERC20Detailed.sol";
45

56
/**
67
* @title SimpleToken
78
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
89
* Note they can later distribute these tokens as they wish using `transfer` and other
910
* `ERC20` functions.
1011
*/
11-
contract SimpleToken is ERC20 {
12+
contract SimpleToken is ERC20, ERC20Detailed {
1213

13-
string public constant name = "SimpleToken";
14-
string public constant symbol = "SIM";
15-
uint8 public constant decimals = 18;
16-
17-
uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals));
14+
uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals()));
1815

1916
/**
2017
* @dev Constructor that gives msg.sender all of existing tokens.
2118
*/
22-
constructor() public {
19+
constructor() public ERC20Detailed("SimpleToken", "SIM", 18) {
2320
_mint(msg.sender, INITIAL_SUPPLY);
2421
}
2522

contracts/token/ERC20/ERC20.sol

+3-8
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ contract ERC20 is IERC20 {
9393
public
9494
returns (bool)
9595
{
96-
require(value <= _allowed[from][msg.sender]);
97-
9896
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
9997
_transfer(from, to, value);
10098
return true;
@@ -155,7 +153,6 @@ contract ERC20 is IERC20 {
155153
* @param value The amount to be transferred.
156154
*/
157155
function _transfer(address from, address to, uint256 value) internal {
158-
require(value <= _balances[from]);
159156
require(to != address(0));
160157

161158
_balances[from] = _balances[from].sub(value);
@@ -171,7 +168,8 @@ contract ERC20 is IERC20 {
171168
* @param value The amount that will be created.
172169
*/
173170
function _mint(address account, uint256 value) internal {
174-
require(account != 0);
171+
require(account != address(0));
172+
175173
_totalSupply = _totalSupply.add(value);
176174
_balances[account] = _balances[account].add(value);
177175
emit Transfer(address(0), account, value);
@@ -184,8 +182,7 @@ contract ERC20 is IERC20 {
184182
* @param value The amount that will be burnt.
185183
*/
186184
function _burn(address account, uint256 value) internal {
187-
require(account != 0);
188-
require(value <= _balances[account]);
185+
require(account != address(0));
189186

190187
_totalSupply = _totalSupply.sub(value);
191188
_balances[account] = _balances[account].sub(value);
@@ -200,8 +197,6 @@ contract ERC20 is IERC20 {
200197
* @param value The amount that will be burnt.
201198
*/
202199
function _burnFrom(address account, uint256 value) internal {
203-
require(value <= _allowed[account][msg.sender]);
204-
205200
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
206201
// this function needs to emit an event with the updated approval.
207202
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub(

contracts/token/ERC721/ERC721Burnable.sol

+9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ pragma solidity ^0.4.24;
22

33
import "./ERC721.sol";
44

5+
/**
6+
* @title ERC721 Burnable Token
7+
* @dev ERC721 Token that can be irreversibly burned (destroyed).
8+
*/
59
contract ERC721Burnable is ERC721 {
10+
11+
/**
12+
* @dev Burns a specific ERC721 token.
13+
* @param tokenId uint256 id of the ERC721 token to be burned.
14+
*/
615
function burn(uint256 tokenId)
716
public
817
{

contracts/token/ERC721/ERC721Enumerable.sol

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import "./IERC721Enumerable.sol";
44
import "./ERC721.sol";
55
import "../../introspection/ERC165.sol";
66

7+
/**
8+
* @title ERC-721 Non-Fungible Token with optional enumeration extension logic
9+
* @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
10+
*/
711
contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable {
812
// Mapping from owner to list of owned token IDs
913
mapping(address => uint256[]) private _ownedTokens;

ethpm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"package_name": "zeppelin",
3-
"version": "2.0.0-rc.1",
3+
"version": "2.0.0",
44
"description": "Secure Smart Contract library for Solidity",
55
"authors": [
66
"OpenZeppelin Community <[email protected]>"

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openzeppelin-solidity",
3-
"version": "2.0.0-rc.1",
3+
"version": "2.0.0",
44
"description": "Secure Smart Contract library for Solidity",
55
"files": [
66
"build",

test/math/SafeMath.test.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,20 @@ contract('SafeMath', function () {
5353
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b));
5454
});
5555

56-
it('handles a zero product correctly', async function () {
56+
it('handles a zero product correctly (first number as zero)', async function () {
5757
const a = new BigNumber(0);
5858
const b = new BigNumber(5678);
5959

6060
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b));
6161
});
6262

63+
it('handles a zero product correctly (second number as zero)', async function () {
64+
const a = new BigNumber(5678);
65+
const b = new BigNumber(0);
66+
67+
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b));
68+
});
69+
6370
it('throws a revert error on multiplication overflow', async function () {
6471
const a = MAX_UINT256;
6572
const b = new BigNumber(2);
@@ -76,6 +83,20 @@ contract('SafeMath', function () {
7683
(await this.safeMath.div(a, b)).should.be.bignumber.equal(a.div(b));
7784
});
7885

86+
it('divides zero correctly', async function () {
87+
const a = new BigNumber(0);
88+
const b = new BigNumber(5678);
89+
90+
(await this.safeMath.div(a, b)).should.be.bignumber.equal(0);
91+
});
92+
93+
it('returns complete number result on non-even division', async function () {
94+
const a = new BigNumber(7000);
95+
const b = new BigNumber(5678);
96+
97+
(await this.safeMath.div(a, b)).should.be.bignumber.equal(1);
98+
});
99+
79100
it('throws a revert error on zero division', async function () {
80101
const a = new BigNumber(5678);
81102
const b = new BigNumber(0);

0 commit comments

Comments
 (0)