Skip to content

Commit

Permalink
Merge branch 'release-v3.2.0' into release-v3.2.0-solc-0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed Sep 8, 2020
2 parents 2acb1ab + f2fb8cf commit 22de765
Show file tree
Hide file tree
Showing 70 changed files with 2,327 additions and 522 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
trim_trailing_whitespace = false
max_line_length = 120

[*.sol]
indent_size = 4

[*.js]
indent_size = 2

[*.adoc]
max_line_length = 0
3 changes: 3 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
timeout: 4000,
};
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"mark-callable-contracts": "off",
"no-empty-blocks": "off",
"compiler-version": ["error", "^0.7.0"],
"private-vars-leading-underscore": "error"
"private-vars-leading-underscore": "error",
"reason-string": "off"
}
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 3.2.0 (unreleased)

### New features
* Proxies: added the proxy contracts from OpenZeppelin SDK. ([#2335](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2335))

### Improvements
* `Address.isContract`: switched from `extcodehash` to `extcodesize` for less gas usage. ([#2311](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2311))

### Breaking changes
* `ERC20Snapshot`: switched to using `_beforeTokenTransfer` hook instead of overriding ERC20 operations. ([#2312](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2312))

This small change in the way we implemented `ERC20Snapshot` may affect users who are combining this contract with
other ERC20 flavors, since it no longer overrides `_transfer`, `_mint`, and `_burn`. This can result in having to remove Solidity `override(...)` specifiers in derived contracts for these functions, and to instead have to add it for `_beforeTokenTransfer`. See [Using Hooks](https://docs.openzeppelin.com/contracts/3.x/extending-contracts#using-hooks) in the documentation.

## 3.1.0 (2020-06-23)

### New features
Expand Down
69 changes: 0 additions & 69 deletions CODE_STYLE.md

This file was deleted.

2 changes: 1 addition & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program that extracts the API Reference from source code.

The [`docs.openzeppelin.com`](https://github.com/OpenZeppelin/docs.openzeppelin.com)
repository hosts the configuration for the entire site, which includes
documetation for all of the OpenZeppelin projects.
documentation for all of the OpenZeppelin projects.

To run the docs locally you should run `npm run docs:watch` on this
repository.
75 changes: 58 additions & 17 deletions GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,78 @@ Consistency on the way classes are used is paramount to an easier understanding
#### D6 - Regular Audits
Following good programming practices is a way to reduce the risk of vulnerabilities, but professional code audits are still needed. We will perform regular code audits on major releases, and hire security professionals to provide independent review.

## Style Guidelines
# Style Guidelines

The design guidelines have quite a high abstraction level. These style guidelines are more concrete and easier to apply, and also more opinionated.
The design guidelines have quite a high abstraction level. These style guidelines are more concrete and easier to apply, and also more opinionated. We value clean code and consistency, and those are prerequisites for us to include new code in the repository. Before proposing a change, please read these guidelines and take some time to familiarize yourself with the style of the existing codebase.

### General
## Solidity code

#### G0 - Default to Solidity's official style guide.
In order to be consistent with all the other Solidity projects, we follow the
[official recommendations documented in the Solidity style guide](http://solidity.readthedocs.io/en/latest/style-guide.html).

Follow the official Solidity style guide: https://solidity.readthedocs.io/en/latest/style-guide.html
Any exception or additions specific to our project are documented below.

#### G1 - No Magic Constants
* Try to avoid acronyms and abbreviations.

Avoid constants in the code as much as possible. Magic strings are also magic constants.
* All state variables should be private.

#### G2 - Code that Fails Early
* Private state variables should have an underscore prefix.

We ask our code to fail as soon as possible when an unexpected input was provided or unexpected state was found.
```
contract TestContract {
uint256 private _privateVar;
uint256 internal _internalVar;
}
```
#### G3 - Internal Amounts Must be Signed Integers and Represent the Smallest Units.
* Parameters must not be prefixed with an underscore.
Avoid representation errors by always dealing with weis when handling ether. GUIs can convert to more human-friendly representations. Use Signed Integers (int) to prevent underflow problems.
```
function test(uint256 testParameter1, uint256 testParameter2) {
...
}
```
* Internal and private functions should have an underscore prefix.
### Testing
```
function _testInternal() internal {
...
}
```
#### T1 - Tests Must be Written Elegantly
```
function _testPrivate() private {
...
}
```
Style guidelines are not relaxed for tests. Tests are a good way to show how to use the library, and maintaining them is extremely necessary.
* Events should be emitted immediately after the state change that they
represent, and consequently they should be named in past tense.
Don't write long tests, write helper functions to make them be as short and concise as possible (they should take just a few lines each), and use good variable names.
```
function _burn(address who, uint256 value) internal {
super._burn(who, value);
emit TokensBurned(who, value);
}
```
#### T2 - Tests Must not be Random
Some standards (e.g. ERC20) use present tense, and in those cases the
standard specification prevails.
* Interface names should have a capital I prefix.
Inputs for tests should not be generated randomly. Accounts used to create test contracts are an exception, those can be random. Also, the type and structure of outputs should be checked.
```
interface IERC777 {
```
## Tests
* Tests Must be Written Elegantly
Tests are a good way to show how to use the library, and maintaining them is extremely necessary. Don't write long tests, write helper functions to make them be as short and concise as possible (they should take just a few lines each), and use good variable names.
* Tests Must not be Random
Inputs for tests should not be generated randomly. Accounts used to create test contracts are an exception, those can be random. Also, the type and structure of outputs should be checked.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <img src="logo.png" alt="OpenZeppelin" height="40px">
# <img src="logo.svg" alt="OpenZeppelin" height="40px">

[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/contracts)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/contracts.svg)](https://www.npmjs.org/package/@openzeppelin/contracts)
Expand Down Expand Up @@ -44,7 +44,7 @@ To keep your system secure, you should **always** use the installed code as-is,

## Learn More

The guides in the sidebar will teach about different concepts, and how to use the related contracts that OpenZeppelin Contracts provides:
The guides in the [docs site](https://docs.openzeppelin.com/contracts) will teach about different concepts, and how to use the related contracts that OpenZeppelin Contracts provides:

* [Access Control](https://docs.openzeppelin.com/contracts/access-control): decide who can perform each of the actions on your system.
* [Tokens](https://docs.openzeppelin.com/contracts/tokens): create tradeable assets or collectives, and distribute them via [Crowdsales](https://docs.openzeppelin.com/contracts/crowdsales).
Expand Down
4 changes: 2 additions & 2 deletions contracts/GSN/GSNRecipient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ abstract contract GSNRecipient is IRelayRecipient, Context {
/**
* @dev See `IRelayRecipient.preRelayedCall`.
*
* This function should not be overriden directly, use `_preRelayedCall` instead.
* This function should not be overridden directly, use `_preRelayedCall` instead.
*
* * Requirements:
*
Expand All @@ -138,7 +138,7 @@ abstract contract GSNRecipient is IRelayRecipient, Context {
/**
* @dev See `IRelayRecipient.postRelayedCall`.
*
* This function should not be overriden directly, use `_postRelayedCall` instead.
* This function should not be overridden directly, use `_postRelayedCall` instead.
*
* * Requirements:
*
Expand Down
4 changes: 2 additions & 2 deletions contracts/GSN/IRelayHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface IRelayHub {
function registerRelay(uint256 transactionFee, string calldata url) external;

/**
* @dev Emitted when a relay is registered or re-registerd. Looking at these events (and filtering out
* @dev Emitted when a relay is registered or re-registered. Looking at these events (and filtering out
* {RelayRemoved} events) lets a client discover the list of available relays.
*/
event RelayAdded(address indexed relay, address indexed owner, uint256 transactionFee, uint256 stake, uint256 unstakeDelay, string url);
Expand Down Expand Up @@ -105,7 +105,7 @@ interface IRelayHub {
event Deposited(address indexed recipient, address indexed from, uint256 amount);

/**
* @dev Returns an account's deposits. These can be either a contracts's funds, or a relay owner's revenue.
* @dev Returns an account's deposits. These can be either a contract's funds, or a relay owner's revenue.
*/
function balanceOf(address target) external view returns (uint256);

Expand Down
2 changes: 1 addition & 1 deletion contracts/GSN/IRelayRecipient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface IRelayRecipient {
*
* Returns a value to be passed to {postRelayedCall}.
*
* {preRelayedCall} is called with 100k gas: if it runs out during exection or otherwise reverts, the relayed call
* {preRelayedCall} is called with 100k gas: if it runs out during execution or otherwise reverts, the relayed call
* will not be executed, but the recipient will still be charged for the transaction's cost.
*/
function preRelayedCall(bytes calldata context) external returns (bytes32);
Expand Down
2 changes: 1 addition & 1 deletion contracts/math/SignedSafeMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pragma solidity ^0.7.0;
library SignedSafeMath {
int256 constant private _INT256_MIN = -2**255;

/**
/**
* @dev Returns the multiplication of two signed integers, reverting on
* overflow.
*
Expand Down
20 changes: 20 additions & 0 deletions contracts/mocks/ClashingImplementation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;


/**
* @dev Implementation contract with an admin() function made to clash with
* @dev TransparentUpgradeableProxy's to test correct functioning of the
* @dev Transparent Proxy feature.
*/
contract ClashingImplementation {

function admin() external pure returns (address) {
return 0x0000000000000000000000000000000011111142;
}

function delegatedFunction() external pure returns (bool) {
return true;
}
}
57 changes: 57 additions & 0 deletions contracts/mocks/DummyImplementation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

abstract contract Impl {
function version() public pure virtual returns (string memory);
}

contract DummyImplementation {
uint256 public value;
string public text;
uint256[] public values;

function initializeNonPayable() public {
value = 10;
}

function initializePayable() payable public {
value = 100;
}

function initializeNonPayable(uint256 _value) public {
value = _value;
}

function initializePayable(uint256 _value) payable public {
value = _value;
}

function initialize(uint256 _value, string memory _text, uint256[] memory _values) public {
value = _value;
text = _text;
values = _values;
}

function get() public pure returns (bool) {
return true;
}

function version() public pure virtual returns (string memory) {
return "V1";
}

function reverts() public pure {
require(false);
}
}

contract DummyImplementationV2 is DummyImplementation {
function migrate(uint256 newVal) payable public {
value = newVal;
}

function version() public pure override returns (string memory) {
return "V2";
}
}
Loading

0 comments on commit 22de765

Please sign in to comment.