From 3e5f4f1c90d1f2c5520bf929c983323917581ca4 Mon Sep 17 00:00:00 2001 From: Michael De Luca <35537333+deluca-mike@users.noreply.github.com> Date: Fri, 10 Dec 2021 07:26:51 -0500 Subject: [PATCH] chore: cleanup (#10) --- config/ci.json | 50 ++++++++++++------------- config/dev.json | 48 ++++++++++++------------ config/prod.json | 58 ++++++++++++++--------------- package.yaml | 2 +- src/ERC20.sol | 56 ++++++++++++++-------------- src/interfaces/IERC20.sol | 64 ++++++++++++++++---------------- src/test/ERC20.t.sol | 2 +- src/test/accounts/ERC20User.sol | 26 +++++++------ src/test/mocks/MockERC20.sol | 12 +++--- src/test/utils/InvariantTest.sol | 14 +++---- test.sh | 4 +- 11 files changed, 170 insertions(+), 166 deletions(-) diff --git a/config/ci.json b/config/ci.json index ef5af17..57d90e6 100644 --- a/config/ci.json +++ b/config/ci.json @@ -1,29 +1,29 @@ { - "language": "Solidity", - "sources": { - "src/ERC20.sol": { - "urls": ["src/ERC20.sol"] + "language": "Solidity", + "sources": { + "src/ERC20.sol": { + "urls": ["src/ERC20.sol"] + }, + "src/test/ERC20.t.sol": { + "urls": ["src/test/ERC20.t.sol"] + } }, - "src/test/ERC20.t.sol": { - "urls": ["src/test/ERC20.t.sol"] + "settings": { + "optimizer": { + "enabled": true, + "runs": 200 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode" + ], + "": [ + "ast" + ] + } + } } - }, - "settings": { - "optimizer": { - "enabled": true, - "runs": 200 - }, - "outputSelection": { - "*": { - "*": [ - "abi", - "evm.bytecode", - "evm.deployedBytecode" - ], - "": [ - "ast" - ] - } - } - } } diff --git a/config/dev.json b/config/dev.json index 4739c7b..e9d585b 100644 --- a/config/dev.json +++ b/config/dev.json @@ -1,28 +1,28 @@ { - "language": "Solidity", - "sources": { - "src/ERC20.sol": { - "urls": ["src/ERC20.sol"] + "language": "Solidity", + "sources": { + "src/ERC20.sol": { + "urls": ["src/ERC20.sol"] + }, + "src/test/ERC20.t.sol": { + "urls": ["src/test/ERC20.t.sol"] + } }, - "src/test/ERC20.t.sol": { - "urls": ["src/test/ERC20.t.sol"] + "settings": { + "optimizer": { + "enabled": false + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "metadata", + "evm.bytecode", + "evm.deployedBytecode", + "evm.gasEstimates" + ], + "": ["ast"] + } + } } - }, - "settings": { - "optimizer": { - "enabled": false - }, - "outputSelection": { - "*": { - "*": [ - "abi", - "metadata", - "evm.bytecode", - "evm.deployedBytecode", - "evm.gasEstimates" - ], - "": ["ast"] - } - } - } } diff --git a/config/prod.json b/config/prod.json index 243c271..96ed6d2 100644 --- a/config/prod.json +++ b/config/prod.json @@ -1,33 +1,33 @@ { - "language": "Solidity", - "sources": { - "src/ERC20.sol": { - "urls": ["src/ERC20.sol"] - } - }, - "settings": { - "optimizer": { - "enabled": true, - "runs": 200 - }, - "outputSelection": { - "*": { - "*": [ - "abi", - "devdoc", - "userdoc", - "metadata", - "evm.bytecode", - "evm.deployedBytecode", - "evm.gasEstimates" - ], - "": [ - "ast" - ] - } + "language": "Solidity", + "sources": { + "src/ERC20.sol": { + "urls": ["src/ERC20.sol"] + } }, - "metadata": { - "bytecodeHash": "none" + "settings": { + "optimizer": { + "enabled": true, + "runs": 200 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "devdoc", + "userdoc", + "metadata", + "evm.bytecode", + "evm.deployedBytecode", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "bytecodeHash": "none" + } } - } } diff --git a/package.yaml b/package.yaml index da69329..41b9f63 100644 --- a/package.yaml +++ b/package.yaml @@ -4,5 +4,5 @@ source: src packages: - path: src/ERC20.sol contractName: ERC20 - customChecksum: 0x98d4afd18b750d8da28fe9c2baff010a76336cd20c085c15457a9f599de21aec + customChecksum: 0xc98bdfa894c6adc0616f92279032e0230473ab4077f221f8c3539c5a807cb147 customDescription: ERC-20 Artifacts and ABIs diff --git a/src/ERC20.sol b/src/ERC20.sol index c8caa9a..6e3e8c8 100644 --- a/src/ERC20.sol +++ b/src/ERC20.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.7; import { IERC20 } from "./interfaces/IERC20.sol"; /** - * @title Modern and gas efficient ERC-20 implementation. + * @title Modern and gas efficient ERC-20 implementation. * @dev Code taken from https://github.com/maple-labs/erc20 * @dev Acknowledgements to Solmate, OpenZeppelin, and DSS for inspiring this code. */ @@ -21,59 +21,59 @@ contract ERC20 is IERC20 { mapping(address => mapping(address => uint256)) public override allowance; - constructor(string memory _name, string memory _symbol, uint8 _decimals) { - name = _name; - symbol = _symbol; - decimals = _decimals; + constructor(string memory name_, string memory symbol_, uint8 decimals_) { + name = name_; + symbol = symbol_; + decimals = decimals_; } /**************************/ /*** External Functions ***/ /**************************/ - - function approve(address spender, uint256 amount) external override returns (bool) { - _approve(msg.sender, spender, amount); + + function approve(address spender_, uint256 amount_) external override returns (bool success_) { + _approve(msg.sender, spender_, amount_); return true; } - function transfer(address to, uint256 amount) external override returns (bool) { - _transfer(msg.sender, to, amount); + function transfer(address to_, uint256 amount_) external override returns (bool success_) { + _transfer(msg.sender, to_, amount_); return true; } - function transferFrom(address owner, address recipient, uint256 amount) external override returns (bool) { - _approve(owner, msg.sender, allowance[owner][msg.sender] - amount); - _transfer(owner, recipient, amount); + function transferFrom(address owner_, address recipient_, uint256 amount_) external override returns (bool success_) { + _approve(owner_, msg.sender, allowance[owner_][msg.sender] - amount_); + _transfer(owner_, recipient_, amount_); return true; } /**************************/ /*** Internal Functions ***/ /**************************/ - - function _approve(address owner, address spender, uint256 amount) internal { - emit Approval(owner, spender, allowance[owner][spender] = amount); + + function _approve(address owner_, address spender_, uint256 amount_) internal { + emit Approval(owner_, spender_, allowance[owner_][spender_] = amount_); } - function _transfer(address owner, address recipient, uint256 amount) internal { - balanceOf[owner] -= amount; - balanceOf[recipient] += amount; + function _transfer(address owner_, address recipient_, uint256 amount_) internal { + balanceOf[owner_] -= amount_; + balanceOf[recipient_] += amount_; - emit Transfer(owner, recipient, amount); + emit Transfer(owner_, recipient_, amount_); } - function _mint(address recipient, uint256 amount) internal { - totalSupply += amount; - balanceOf[recipient] += amount; + function _mint(address recipient_, uint256 amount_) internal { + totalSupply += amount_; + balanceOf[recipient_] += amount_; - emit Transfer(address(0), recipient, amount); + emit Transfer(address(0), recipient_, amount_); } - function _burn(address owner, uint256 amount) internal { - balanceOf[owner] -= amount; - totalSupply -= amount; + function _burn(address owner_, uint256 amount_) internal { + balanceOf[owner_] -= amount_; + totalSupply -= amount_; - emit Transfer(owner, address(0), amount); + emit Transfer(owner_, address(0), amount_); } } diff --git a/src/interfaces/IERC20.sol b/src/interfaces/IERC20.sol index ca76199..6aca03d 100644 --- a/src/interfaces/IERC20.sol +++ b/src/interfaces/IERC20.sol @@ -5,15 +5,15 @@ pragma solidity ^0.8.7; interface IERC20 { /** - * @dev Emits an event indicating that tokens have moved from one account to another. - * @param from Account that tokens have moved from. - * @param to Account that tokens have moved to. + * @dev Emits an event indicating that tokens have moved from one account to another. + * @param from Account that tokens have moved from. + * @param to Account that tokens have moved to. * @param amount Amount of tokens that have been transferred. */ event Transfer(address indexed from, address indexed to, uint256 amount); /** - * @dev Emits an event indicating that one account has set the allowance of another account over their tokens. + * @dev Emits an event indicating that one account has set the allowance of another account over their tokens. * @param owner Account that tokens are approved from. * @param spender Account that tokens are approved for. * @param amount Amount of tokens that have been approved. @@ -23,61 +23,63 @@ interface IERC20 { /** * @dev Returns the name of the token. */ - function name() external view returns (string memory); + function name() external view returns (string memory name_); /** * @dev Returns the symbol of the token. */ - function symbol() external view returns (string memory); + function symbol() external view returns (string memory symbol_); /** * @dev Returns the decimal precision used by the token. */ - function decimals() external view returns (uint8); + function decimals() external view returns (uint8 decimals_); /** * @dev Returns the total amount of tokens in existence. */ - function totalSupply() external view returns (uint256); + function totalSupply() external view returns (uint256 totalSupply_); /** * @dev Returns the amount of tokens owned by a given account. - * @param account Account that owns the tokens. + * @param account_ Account that owns the tokens. */ - function balanceOf(address account) external view returns (uint256); + function balanceOf(address account_) external view returns (uint256 balance_); /** * @dev Function that returns the allowance that one account has given another over their tokens. - * @param owner Account that tokens are approved from. - * @param spender Account that tokens are approved for. + * @param owner_ Account that tokens are approved from. + * @param spender_ Account that tokens are approved for. */ - function allowance(address owner, address spender) external view returns (uint256); + function allowance(address owner_, address spender_) external view returns (uint256 allowance_); /** - * @dev Function that allows one account to set the allowance of another account over their tokens. - * @dev Emits an {Approval} event. - * @param spender Account that tokens are approved for. - * @param amount Amount of tokens that have been approved. + * @dev Function that allows one account to set the allowance of another account over their tokens. + * @dev Emits an {Approval} event. + * @param spender_ Account that tokens are approved for. + * @param amount_ Amount of tokens that have been approved. + * @return success_ Boolean indicating whether the operation succeeded. */ - function approve(address spender, uint256 amount) external returns (bool); + function approve(address spender_, uint256 amount_) external returns (bool success_); /** - * @dev Moves an amount of tokens from `msg.sender` to a specified account. - * @dev Emits a {Transfer} event. - * @param recipient Account that recieves tokens. - * @param amount Amount of tokens that are transferred. - * @return Boolean amount indicating whether the operation succeeded. + * @dev Moves an amount of tokens from `msg.sender` to a specified account. + * @dev Emits a {Transfer} event. + * @param recipient_ Account that receives tokens. + * @param amount_ Amount of tokens that are transferred. + * @return success_ Boolean indicating whether the operation succeeded. */ - function transfer(address recipient, uint256 amount) external returns (bool); + function transfer(address recipient_, uint256 amount_) external returns (bool success_); /** - * @dev Moves a pre-approved amount of tokens from a sender to a specified account. - * @dev Emits a {Transfer} event. - * @dev Emits an {Approval} event. - * @param owner Account that tokens are moving from. - * @param recipient Account that recieves tokens. - * @param amount Amount of tokens that are transferred. + * @dev Moves a pre-approved amount of tokens from a sender to a specified account. + * @dev Emits a {Transfer} event. + * @dev Emits an {Approval} event. + * @param owner_ Account that tokens are moving from. + * @param recipient_ Account that receives tokens. + * @param amount_ Amount of tokens that are transferred. + * @return success_ Boolean indicating whether the operation succeeded. */ - function transferFrom(address owner, address recipient, uint256 amount) external returns (bool); + function transferFrom(address owner_, address recipient_, uint256 amount_) external returns (bool success_); } diff --git a/src/test/ERC20.t.sol b/src/test/ERC20.t.sol index 1066002..3b85343 100644 --- a/src/test/ERC20.t.sol +++ b/src/test/ERC20.t.sol @@ -8,7 +8,7 @@ import { MockERC20 } from "./mocks/MockERC20.sol"; import { InvariantTest } from "./utils/InvariantTest.sol"; contract ERC20Test is DSTest { - + MockERC20 token; address internal immutable self = address(this); diff --git a/src/test/accounts/ERC20User.sol b/src/test/accounts/ERC20User.sol index 4c4eecf..97a1b00 100644 --- a/src/test/accounts/ERC20User.sol +++ b/src/test/accounts/ERC20User.sol @@ -8,31 +8,33 @@ contract ERC20User { /************************/ /*** Direct Functions ***/ /************************/ - function erc20_approve(address token, address spender, uint256 amount) external { - IERC20(token).approve(spender, amount); + + function erc20_approve(address token_, address spender_, uint256 amount_) external { + IERC20(token_).approve(spender_, amount_); } - function erc20_transfer(address token, address recipient, uint256 amount) external { - IERC20(token).transfer(recipient, amount); + function erc20_transfer(address token_, address recipient_, uint256 amount_) external { + IERC20(token_).transfer(recipient_, amount_); } - function erc20_transferFrom(address token, address owner, address recipient, uint256 amount) external { - IERC20(token).transferFrom(owner, recipient, amount); + function erc20_transferFrom(address token_, address owner_, address recipient_, uint256 amount_) external { + IERC20(token_).transferFrom(owner_, recipient_, amount_); } /*********************/ /*** Try Functions ***/ /*********************/ - function try_erc20_approve(address token, address spender, uint256 amount) external returns (bool ok) { - (ok,) = token.call(abi.encodeWithSelector(IERC20.approve.selector, spender, amount)); + + function try_erc20_approve(address token_, address spender, uint256 amount_) external returns (bool ok_) { + ( ok_, ) = token_.call(abi.encodeWithSelector(IERC20.approve.selector, spender, amount_)); } - function try_erc20_transfer(address token, address recipient, uint256 amount) external returns (bool ok) { - (ok,) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, recipient, amount)); + function try_erc20_transfer(address token_, address recipient_, uint256 amount_) external returns (bool ok_) { + ( ok_, ) = token_.call(abi.encodeWithSelector(IERC20.transfer.selector, recipient_, amount_)); } - function try_erc20_transferFrom(address token, address owner, address recipient, uint256 amount) external returns (bool ok) { - (ok,) = token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, owner, recipient, amount)); + function try_erc20_transferFrom(address token_, address owner_, address recipient_, uint256 amount_) external returns (bool ok_) { + ( ok_, ) = token_.call(abi.encodeWithSelector(IERC20.transferFrom.selector, owner_, recipient_, amount_)); } } diff --git a/src/test/mocks/MockERC20.sol b/src/test/mocks/MockERC20.sol index 2f56f46..861006f 100644 --- a/src/test/mocks/MockERC20.sol +++ b/src/test/mocks/MockERC20.sol @@ -5,14 +5,14 @@ import { ERC20 } from "../../ERC20.sol"; contract MockERC20 is ERC20 { - constructor(string memory _name, string memory _symbol, uint8 _decimals) ERC20(_name, _symbol, _decimals) {} + constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_, decimals_) {} - function mint(address to, uint256 value) external { - _mint(to, value); + function mint(address to_, uint256 value_) external { + _mint(to_, value_); } - function burn(address from, uint256 value) external { - _burn(from, value); + function burn(address from_, uint256 value_) external { + _burn(from_, value_); } - + } diff --git a/src/test/utils/InvariantTest.sol b/src/test/utils/InvariantTest.sol index eeff890..2c45ecc 100644 --- a/src/test/utils/InvariantTest.sol +++ b/src/test/utils/InvariantTest.sol @@ -2,16 +2,16 @@ pragma solidity ^0.8.7; contract InvariantTest { - - address[] private targetContracts_; - function targetContracts() public view returns (address[] memory) { - require(targetContracts_.length > 0, "NO_TARGET_CONTRACTS"); - return targetContracts_; + address[] private _targetContracts; + + function targetContracts() public view returns (address[] memory targetContracts_) { + require(_targetContracts.length != uint256(0), "NO_TARGET_CONTRACTS"); + return _targetContracts; } - function addTargetContract(address newTargetContract) internal { - targetContracts_.push(newTargetContract); + function addTargetContract(address newTargetContract_) internal { + _targetContracts.push(newTargetContract_); } } diff --git a/test.sh b/test.sh index f8695c7..84a62c9 100755 --- a/test.sh +++ b/test.sh @@ -24,6 +24,6 @@ if [ "$skip_build" = "1" ]; then export DAPP_SKIP_BUILD=1; fi if [ -z "$test" ]; then match="[src/test/*.t.sol]"; dapp_test_verbosity=1; else match=$test; dapp_test_verbosity=2; fi -echo LANG=C.UTF-8 dapp test --match "$match" --rpc-url "$ETH_RPC_URL" --verbosity $dapp_test_verbosity --fuzz-runs $runs +echo LANG=C.UTF-8 dapp test --match "$match" --verbosity $dapp_test_verbosity --fuzz-runs $runs -LANG=C.UTF-8 dapp test --match "$match" --rpc-url "$ETH_RPC_URL" --verbosity $dapp_test_verbosity --fuzz-runs $runs; +LANG=C.UTF-8 dapp test --match "$match" --verbosity $dapp_test_verbosity --fuzz-runs $runs;