Jelajahi Sumber

Add `GUIDELINES.md` for marking `abstract` contracts (#4010)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco Giordano <fg@frang.io>
Ernesto García 2 tahun lalu
induk
melakukan
5cc1ea0a39

+ 7 - 0
GUIDELINES.md

@@ -114,6 +114,13 @@ In addition to the official Solidity Style Guide we have a number of other conve
   interface IERC777 {
   ```
 
+* Contracts not intended to be used standalone should be marked abstract
+  so they are required to be inherited to other contracts.
+
+  ```solidity
+  abstract contract AccessControl is ..., {
+  ```
+
 * Unchecked arithmetic blocks should contain comments explaining why overflow is guaranteed not to happen. If the reason is immediately apparent from the line above the unchecked block, the comment may be omitted.
 
 * Custom errors should be declared following the [EIP-6093](https://eips.ethereum.org/EIPS/eip-6093) rationale whenever reasonable. Also, consider the following:

+ 1 - 1
contracts/token/ERC1155/ERC1155.sol

@@ -17,7 +17,7 @@ import "../../interfaces/draft-IERC6093.sol";
  *
  * _Available since v3.1._
  */
-contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors {
+abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors {
     // Mapping from token ID to account balances
     mapping(uint256 => mapping(address => uint256)) private _balances;
 

+ 1 - 1
contracts/token/ERC1155/utils/ERC1155Holder.sol

@@ -13,7 +13,7 @@ import "./ERC1155Receiver.sol";
  *
  * @dev _Available since v3.1._
  */
-contract ERC1155Holder is ERC1155Receiver {
+abstract contract ERC1155Holder is ERC1155Receiver {
     function onERC1155Received(
         address,
         address,

+ 1 - 1
contracts/token/ERC20/ERC20.sol

@@ -35,7 +35,7 @@ import "../../interfaces/draft-IERC6093.sol";
  * functions have been added to mitigate the well-known issues around setting
  * allowances. See {IERC20-approve}.
  */
-contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
+abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
     mapping(address => uint256) private _balances;
 
     mapping(address => mapping(address => uint256)) private _allowances;

+ 1 - 1
contracts/token/ERC721/ERC721.sol

@@ -16,7 +16,7 @@ import "../../interfaces/draft-IERC6093.sol";
  * the Metadata extension, but not including the Enumerable extension, which is available separately as
  * {ERC721Enumerable}.
  */
-contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
+abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
     using Strings for uint256;
 
     // Token name

+ 1 - 1
contracts/token/ERC721/utils/ERC721Holder.sol

@@ -11,7 +11,7 @@ import "../IERC721Receiver.sol";
  * Accepts all token transfers.
  * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
  */
-contract ERC721Holder is IERC721Receiver {
+abstract contract ERC721Holder is IERC721Receiver {
     /**
      * @dev See {IERC721Receiver-onERC721Received}.
      *

+ 1 - 1
test/token/ERC1155/utils/ERC1155Holder.test.js

@@ -1,6 +1,6 @@
 const { BN } = require('@openzeppelin/test-helpers');
 
-const ERC1155Holder = artifacts.require('ERC1155Holder');
+const ERC1155Holder = artifacts.require('$ERC1155Holder');
 const ERC1155 = artifacts.require('$ERC1155');
 
 const { expect } = require('chai');

+ 1 - 1
test/token/ERC721/utils/ERC721Holder.test.js

@@ -1,6 +1,6 @@
 const { expect } = require('chai');
 
-const ERC721Holder = artifacts.require('ERC721Holder');
+const ERC721Holder = artifacts.require('$ERC721Holder');
 const ERC721 = artifacts.require('$ERC721');
 
 contract('ERC721Holder', function (accounts) {