Skip to content

Commit d8e7c25

Browse files
authored
MintableToken using Roles (#1236)
* Minor test style improvements (#1219) * Changed .eq to .equal * Changed equal(bool) to .to.be.bool * Changed be.bool to equal(bool), disallowed unused expressions. * Add ERC165Query library (#1086) * Add ERC165Query library * Address PR Comments * Add tests and mocks from #1024 and refactor code slightly * Fix javascript and solidity linting errors * Split supportsInterface into three methods as discussed in #1086 * Change InterfaceId_ERC165 comment to match style in the rest of the repo * Fix max-len lint issue on ERC165Checker.sol * Conditionally ignore the asserts during solidity-coverage test * Switch to abi.encodeWithSelector and add test for account addresses * Switch to supportsInterfaces API as suggested by @frangio * Adding ERC165InterfacesSupported.sol * Fix style issues * Add test for supportsInterfaces returning false * Add ERC165Checker.sol newline * feat: fix coverage implementation * fix: solidity linting error * fix: revert to using boolean tests instead of require statements * fix: make supportsERC165Interface private again * rename SupportsInterfaceWithLookupMock to avoid name clashing * Added mint and burn tests for zero amounts. (#1230) * Changed .eq to .equal. (#1231) * ERC721 pausable token (#1154) * ERC721 pausable token * Reuse of ERC721 Basic behavior for Pausable, split view checks in paused state & style fixes * [~] paused token behavior * Add some detail to releasing steps (#1190) * add note about pulling upstream changes to release branch * add comment about upstream changes in merging section * Increase test coverage (#1237) * Fixed a SplitPayment test * Deleted unnecessary function. * Improved PostDeliveryCrowdsale tests. * Improved RefundableCrowdsale tests. * Improved MintedCrowdsale tests. * Improved IncreasingPriceCrowdsale tests. * Fixed a CappedCrowdsale test. * Improved TimedCrowdsale tests. * Improved descriptions of added tests. * ci: trigger docs update on tag (#1186) * MintableToken now uses Roles. * Fixed FinalizableCrowdsale test. * Roles can now be transfered. * Fixed tests related to MintableToken. * Removed Roles.check. * Renamed transferMintPermission. * Moved MinterRole * Fixed RBAC. * Adressed review comments. * Addressed review comments * Fixed linter errors. * Added Events tests of Pausable contract (#1207) * Fixed roles tests. * Rename events to past-tense (#1181) * fix: refactor sign.js and related tests (#1243) * fix: refactor sign.js and related tests * fix: remove unused dep * fix: update package.json correctly * Added "_" sufix to internal variables (#1171) * Added PublicRole test. * Fixed crowdsale tests. * Rename ERC interfaces to I prefix (#1252) * rename ERC20 to IERC20 * move ERC20.sol to IERC20.sol * rename StandardToken to ERC20 * rename StandardTokenMock to ERC20Mock * move StandardToken.sol to ERC20.sol, likewise test and mock files * rename MintableToken to ERC20Mintable * move MintableToken.sol to ERC20Mintable.sol, likewise test and mock files * rename BurnableToken to ERC20Burnable * move BurnableToken.sol to ERC20Burnable.sol, likewise for related files * rename CappedToken to ERC20Capped * move CappedToken.sol to ERC20Capped.sol, likewise for related files * rename PausableToken to ERC20Pausable * move PausableToken.sol to ERC20Pausable.sol, likewise for related files * rename DetailedERC20 to ERC20Detailed * move DetailedERC20.sol to ERC20Detailed.sol, likewise for related files * rename ERC721 to IERC721, and likewise for other related interfaces * move ERC721.sol to IERC721.sol, likewise for other 721 interfaces * rename ERC721Token to ERC721 * move ERC721Token.sol to ERC721.sol, likewise for related files * rename ERC721BasicToken to ERC721Basic * move ERC721BasicToken.sol to ERC721Basic.sol, likewise for related files * rename ERC721PausableToken to ERC721Pausable * move ERC721PausableToken.sol to ERC721Pausable.sol * rename ERC165 to IERC165 * move ERC165.sol to IERC165.sol * amend comment that ERC20 is based on FirstBlood * fix comments mentioning IERC721Receiver * added explicit visibility (#1261) * Remove underscores from event parameters. (#1258) * Remove underscores from event parameters. Fixes #1175 * Add comment about ERC * Move contracts to subdirectories (#1253) * Move contracts to subdirectories Fixes #1177. This Change also removes the LimitBalance contract. * fix import * move MerkleProof to cryptography * Fix import * Remove HasNoEther, HasNoTokens, HasNoContracts, and NoOwner (#1254) * remove HasNoEther, HasNoTokens, HasNoContracts, and NoOwner * remove unused ERC223TokenMock * remove Contactable * remove TokenDestructible * remove DeprecatedERC721 * inline Destructible#destroy in Bounty * remove Destructible * Functions in interfaces changed to "external" (#1263) * Add a leading underscore to internal and private functions. (#1257) * Add a leading underscore to internal and private functions. Fixes #1176 * Remove super * update the ERC721 changes * add missing underscore after merge * Fix mock * Improve encapsulation on SignatureBouncer, Whitelist and RBAC example (#1265) * Improve encapsulation on Whitelist * remove only * update whitelisted crowdsale test * Improve encapsulation on SignatureBouncer * fix missing test * Improve encapsulation on RBAC example * Improve encapsulation on RBAC example * Remove extra visibility * Improve encapsulation on ERC20 Mintable * Improve encapsulation on Superuser * fix lint * add missing constant * Addressed review comments. * Fixed build error.
1 parent 0530e1e commit d8e7c25

File tree

173 files changed

+2960
-2621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+2960
-2621
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ jobs:
3838
- stage: tests
3939
name: "static tests"
4040
script: npm run lint
41+
- stage: update docs
42+
if: tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$
43+
addons:
44+
apt:
45+
packages:
46+
- curl
47+
script:
48+
- ./scripts/ci/trigger_docs_update "${TRAVIS_TAG}"
4149

4250
notifications:
4351
slack:

CODE_STYLE.md

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,59 @@ Any exception or additions specific to our project are documented below.
1818

1919
* Parameters must be prefixed with an underscore.
2020

21-
```
22-
function test(uint256 _testParameter1, uint256 _testParameter2) {
21+
```
22+
function test(uint256 _testParameter1, uint256 _testParameter2) {
2323
...
24-
}
25-
```
24+
}
25+
```
26+
27+
The exception are the parameters of events. There is no chance of ambiguity
28+
with these, so they should not have underscores. Not even if they are
29+
specified on an ERC with underscores; removing them doesn't change the ABI,
30+
so we should be consistent with the rest of the events in this repository
31+
and remove them.
32+
33+
* Internal and private state variables should have an underscore suffix.
34+
35+
```
36+
contract TestContract {
37+
uint256 internal internalVar_;
38+
uint256 private privateVar_;
39+
}
40+
```
41+
42+
Variables declared in a function should not follow this rule.
43+
44+
```
45+
function test() {
46+
uint256 functionVar;
47+
...
48+
}
49+
```
50+
51+
* Internal and private functions should have an underscore prefix.
52+
53+
```
54+
function _testInternal() internal {
55+
...
56+
}
57+
```
58+
59+
```
60+
function _testPrivate() private {
61+
...
62+
}
63+
```
64+
65+
* Events should be emitted immediately after the state change that they
66+
represent, and consequently they should be named in past tense.
67+
68+
```
69+
function _burn(address _who, uint256 _value) internal {
70+
super._burn(_who, _value);
71+
emit TokensBurned(_who, _value);
72+
}
73+
```
74+
75+
Some standards (e.g. ERC20) use present tense, and in those cases the
76+
standard specification prevails.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The following provides visibility into how OpenZeppelin's contracts are organize
8989
- **ERC20** - A standard interface for fungible tokens:
9090
- *Interfaces* - Includes the ERC-20 token standard basic interface. I.e., what the contract’s ABI can represent.
9191
- *Implementations* - Includes ERC-20 token implementations that include all required and some optional ERC-20 functionality.
92-
- **ERC721** - A standard interface for non-fungible tokens
92+
- **ERC721** - A standard interface for non-fungible tokens
9393
- *Interfaces* - Includes the ERC-721 token standard basic interface. I.e., what the contract’s ABI can represent.
9494
- *Implementations* - Includes ERC-721 token implementations that include all required and some optional ERC-721 functionality.
9595

@@ -125,6 +125,7 @@ Interested in contributing to OpenZeppelin?
125125
- Framework proposal and roadmap: https://medium.com/zeppelin-blog/zeppelin-framework-proposal-and-development-roadmap-fdfa9a3a32ab#.iain47pak
126126
- Issue tracker: https://github.com/OpenZeppelin/openzeppelin-solidity/issues
127127
- Contribution guidelines: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CONTRIBUTING.md
128+
- Code-style guide: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CODE_STYLE.md
128129
- Wiki: https://github.com/OpenZeppelin/openzeppelin-solidity/wiki
129130

130131
## License

RELEASING.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ We release a new version of OpenZeppelin monthly. Release cycles are tracked in
77
Each release has at least one release candidate published first, intended for community review and any critical fixes that may come out of it. At the moment we leave 1 week between the first release candidate and the final release.
88

99
Before starting make sure to verify the following items.
10-
* Your local `master` branch is in sync with your upstream remote.
10+
* Your local `master` branch is in sync with your `upstream` remote (it may have another name depending on your setup).
1111
* Your repo is clean, particularly with no untracked files in the contracts and tests directories. Verify with `git clean -n`.
1212

1313

@@ -44,8 +44,11 @@ Publish the release notes on GitHub and ask our community manager to announce th
4444

4545
## Creating the final release
4646

47+
Make sure to have the latest changes from `upstream` in your local release branch.
48+
4749
```
4850
git checkout release-vX.Y.Z
51+
git pull upstream
4952
```
5053

5154
Change the version string in `package.json`, `package-lock.json` and `ethpm.json` removing the "-rc.R" suffix. Commit these changes and tag the commit as `vX.Y.Z`.
@@ -75,7 +78,14 @@ npm dist-tag rm --otp $2FA_CODE openzeppelin-solidity next
7578

7679
## Merging the release branch
7780

78-
After the final release, the release branch should be merged back into `master`. This merge must not be squashed, because it would lose the tagged release commit, so it should be merged locally and pushed.
81+
After the final release, the release branch should be merged back into `master`. This merge must not be squashed because it would lose the tagged release commit. Since the GitHub repo is set up to only allow squashed merges, the merge should be done locally and pushed.
82+
83+
Make sure to have the latest changes from `upstream` in your local release branch.
84+
85+
```
86+
git checkout release-vX.Y.Z
87+
git pull upstream
88+
```
7989

8090
```
8191
git checkout master

contracts/LimitBalance.sol

Lines changed: 0 additions & 31 deletions
This file was deleted.

contracts/access/SignatureBouncer.sol

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pragma solidity ^0.4.24;
22

33
import "../ownership/Ownable.sol";
44
import "../access/rbac/RBAC.sol";
5-
import "../ECRecovery.sol";
5+
import "../cryptography/ECDSA.sol";
66

77

88
/**
@@ -17,7 +17,7 @@ import "../ECRecovery.sol";
1717
* valid addresses on-chain, simply sign a grant of the form
1818
* keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address.
1919
* Then restrict access to your crowdsale/whitelist/airdrop using the
20-
* `onlyValidSignature` modifier (or implement your own using isValidSignature).
20+
* `onlyValidSignature` modifier (or implement your own using _isValidSignature).
2121
* In addition to `onlyValidSignature`, `onlyValidSignatureAndMethod` and
2222
* `onlyValidSignatureAndData` can be used to restrict access to only a given method
2323
* or a given method with given parameters respectively.
@@ -30,19 +30,22 @@ import "../ECRecovery.sol";
3030
* much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
3131
*/
3232
contract SignatureBouncer is Ownable, RBAC {
33-
using ECRecovery for bytes32;
33+
using ECDSA for bytes32;
3434

35-
string public constant ROLE_BOUNCER = "bouncer";
36-
uint constant METHOD_ID_SIZE = 4;
37-
// signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
38-
uint constant SIGNATURE_SIZE = 96;
35+
// Name of the bouncer role.
36+
string private constant ROLE_BOUNCER = "bouncer";
37+
// Function selectors are 4 bytes long, as documented in
38+
// https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector
39+
uint256 private constant METHOD_ID_SIZE = 4;
40+
// Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
41+
uint256 private constant SIGNATURE_SIZE = 96;
3942

4043
/**
4144
* @dev requires that a valid signature of a bouncer was provided
4245
*/
4346
modifier onlyValidSignature(bytes _signature)
4447
{
45-
require(isValidSignature(msg.sender, _signature));
48+
require(_isValidSignature(msg.sender, _signature));
4649
_;
4750
}
4851

@@ -51,7 +54,7 @@ contract SignatureBouncer is Ownable, RBAC {
5154
*/
5255
modifier onlyValidSignatureAndMethod(bytes _signature)
5356
{
54-
require(isValidSignatureAndMethod(msg.sender, _signature));
57+
require(_isValidSignatureAndMethod(msg.sender, _signature));
5558
_;
5659
}
5760

@@ -60,10 +63,18 @@ contract SignatureBouncer is Ownable, RBAC {
6063
*/
6164
modifier onlyValidSignatureAndData(bytes _signature)
6265
{
63-
require(isValidSignatureAndData(msg.sender, _signature));
66+
require(_isValidSignatureAndData(msg.sender, _signature));
6467
_;
6568
}
6669

70+
/**
71+
* @dev Determine if an account has the bouncer role.
72+
* @return true if the account is a bouncer, false otherwise.
73+
*/
74+
function isBouncer(address _account) public view returns(bool) {
75+
return hasRole(_account, ROLE_BOUNCER);
76+
}
77+
6778
/**
6879
* @dev allows the owner to add additional bouncer addresses
6980
*/
@@ -72,7 +83,7 @@ contract SignatureBouncer is Ownable, RBAC {
7283
onlyOwner
7384
{
7485
require(_bouncer != address(0));
75-
addRole(_bouncer, ROLE_BOUNCER);
86+
_addRole(_bouncer, ROLE_BOUNCER);
7687
}
7788

7889
/**
@@ -82,19 +93,19 @@ contract SignatureBouncer is Ownable, RBAC {
8293
public
8394
onlyOwner
8495
{
85-
removeRole(_bouncer, ROLE_BOUNCER);
96+
_removeRole(_bouncer, ROLE_BOUNCER);
8697
}
8798

8899
/**
89100
* @dev is the signature of `this + sender` from a bouncer?
90101
* @return bool
91102
*/
92-
function isValidSignature(address _address, bytes _signature)
103+
function _isValidSignature(address _address, bytes _signature)
93104
internal
94105
view
95106
returns (bool)
96107
{
97-
return isValidDataHash(
108+
return _isValidDataHash(
98109
keccak256(abi.encodePacked(address(this), _address)),
99110
_signature
100111
);
@@ -104,7 +115,7 @@ contract SignatureBouncer is Ownable, RBAC {
104115
* @dev is the signature of `this + sender + methodId` from a bouncer?
105116
* @return bool
106117
*/
107-
function isValidSignatureAndMethod(address _address, bytes _signature)
118+
function _isValidSignatureAndMethod(address _address, bytes _signature)
108119
internal
109120
view
110121
returns (bool)
@@ -113,7 +124,7 @@ contract SignatureBouncer is Ownable, RBAC {
113124
for (uint i = 0; i < data.length; i++) {
114125
data[i] = msg.data[i];
115126
}
116-
return isValidDataHash(
127+
return _isValidDataHash(
117128
keccak256(abi.encodePacked(address(this), _address, data)),
118129
_signature
119130
);
@@ -124,7 +135,7 @@ contract SignatureBouncer is Ownable, RBAC {
124135
* @notice the _signature parameter of the method being validated must be the "last" parameter
125136
* @return bool
126137
*/
127-
function isValidSignatureAndData(address _address, bytes _signature)
138+
function _isValidSignatureAndData(address _address, bytes _signature)
128139
internal
129140
view
130141
returns (bool)
@@ -134,7 +145,7 @@ contract SignatureBouncer is Ownable, RBAC {
134145
for (uint i = 0; i < data.length; i++) {
135146
data[i] = msg.data[i];
136147
}
137-
return isValidDataHash(
148+
return _isValidDataHash(
138149
keccak256(abi.encodePacked(address(this), _address, data)),
139150
_signature
140151
);
@@ -145,14 +156,14 @@ contract SignatureBouncer is Ownable, RBAC {
145156
* and then recover the signature and check it against the bouncer role
146157
* @return bool
147158
*/
148-
function isValidDataHash(bytes32 _hash, bytes _signature)
159+
function _isValidDataHash(bytes32 _hash, bytes _signature)
149160
internal
150161
view
151162
returns (bool)
152163
{
153164
address signer = _hash
154165
.toEthSignedMessageHash()
155166
.recover(_signature);
156-
return hasRole(signer, ROLE_BOUNCER);
167+
return isBouncer(signer);
157168
}
158169
}

contracts/access/Whitelist.sol

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import "../access/rbac/RBAC.sol";
1111
* This simplifies the implementation of "user permissions".
1212
*/
1313
contract Whitelist is Ownable, RBAC {
14-
string public constant ROLE_WHITELISTED = "whitelist";
14+
15+
// Name of the whitelisted role.
16+
string private constant ROLE_WHITELISTED = "whitelist";
1517

1618
/**
1719
* @dev Throws if operator is not whitelisted.
@@ -31,13 +33,14 @@ contract Whitelist is Ownable, RBAC {
3133
public
3234
onlyOwner
3335
{
34-
addRole(_operator, ROLE_WHITELISTED);
36+
_addRole(_operator, ROLE_WHITELISTED);
3537
}
3638

3739
/**
38-
* @dev getter to determine if address is in whitelist
40+
* @dev Determine if an account is whitelisted.
41+
* @return true if the account is whitelisted, false otherwise.
3942
*/
40-
function whitelist(address _operator)
43+
function isWhitelisted(address _operator)
4144
public
4245
view
4346
returns (bool)
@@ -70,7 +73,7 @@ contract Whitelist is Ownable, RBAC {
7073
public
7174
onlyOwner
7275
{
73-
removeRole(_operator, ROLE_WHITELISTED);
76+
_removeRole(_operator, ROLE_WHITELISTED);
7477
}
7578

7679
/**

0 commit comments

Comments
 (0)