Skip to content

Commit

Permalink
Remove unnecessary virtual (OpenZeppelin#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronhuafeng committed Sep 9, 2022
1 parent d150716 commit 457ecc6
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 52 deletions.
2 changes: 1 addition & 1 deletion contracts/mocks/AccessControlCrossChainMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract AccessControlCrossChainMock is AccessControlCrossChain, CrossChainEnabl

function senderProtected(bytes32 roleId) public onlyRole(roleId) {}

function crossChainRoleAlias(bytes32 role) public pure virtual returns (bytes32) {
function crossChainRoleAlias(bytes32 role) public pure returns (bytes32) {
return _crossChainRoleAlias(role);
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/ERC1155PausableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract ERC1155PausableMock is ERC1155Mock, ERC1155Pausable {
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Pausable) {
) internal override(ERC1155, ERC1155Pausable) {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/ERC1155SupplyMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract ERC1155SupplyMock is ERC1155Mock, ERC1155Supply {
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Supply) {
) internal override(ERC1155, ERC1155Supply) {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/ERC1155URIStorageMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "../token/ERC1155/extensions/ERC1155URIStorage.sol";
contract ERC1155URIStorageMock is ERC1155Mock, ERC1155URIStorage {
constructor(string memory _uri) ERC1155Mock(_uri) {}

function uri(uint256 tokenId) public view virtual override(ERC1155, ERC1155URIStorage) returns (string memory) {
function uri(uint256 tokenId) public view override(ERC1155, ERC1155URIStorage) returns (string memory) {
return ERC1155URIStorage.uri(tokenId);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC165/ERC165ReturnBomb.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";

contract ERC165ReturnBombMock is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
if (interfaceId == type(IERC165).interfaceId) {
assembly {
mstore(0, 1)
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC20DecimalsMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract ERC20DecimalsMock is ERC20 {
_decimals = decimals_;
}

function decimals() public view virtual override returns (uint8) {
function decimals() public view override returns (uint8) {
return _decimals;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/ERC2771ContextMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ contract ERC2771ContextMock is ContextMock, ERC2771Context {
emit Sender(_msgSender()); // _msgSender() should be accessible during construction
}

function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address) {
function _msgSender() internal view override(Context, ERC2771Context) returns (address) {
return ERC2771Context._msgSender();
}

function _msgData() internal view virtual override(Context, ERC2771Context) returns (bytes calldata) {
function _msgData() internal view override(Context, ERC2771Context) returns (bytes calldata) {
return ERC2771Context._msgData();
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/ERC721EnumerableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract ERC721EnumerableMock is ERC721Enumerable {

constructor(string memory name, string memory symbol) ERC721(name, symbol) {}

function _baseURI() internal view virtual override returns (string memory) {
function _baseURI() internal view override returns (string memory) {
return _baseTokenURI;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC721URIStorageMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract ERC721URIStorageMock is ERC721URIStorage {

constructor(string memory name, string memory symbol) ERC721(name, symbol) {}

function _baseURI() internal view virtual override returns (string memory) {
function _baseURI() internal view override returns (string memory) {
return _baseTokenURI;
}

Expand Down
15 changes: 6 additions & 9 deletions contracts/mocks/GovernorCompatibilityBravoMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ contract GovernorCompatibilityBravoMock is
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, Governor, GovernorTimelockCompound)
returns (bool)
{
Expand All @@ -44,7 +43,6 @@ contract GovernorCompatibilityBravoMock is
function state(uint256 proposalId)
public
view
virtual
override(IGovernor, Governor, GovernorTimelockCompound)
returns (ProposalState)
{
Expand All @@ -54,7 +52,6 @@ contract GovernorCompatibilityBravoMock is
function proposalEta(uint256 proposalId)
public
view
virtual
override(IGovernorTimelock, GovernorTimelockCompound)
returns (uint256)
{
Expand All @@ -70,7 +67,7 @@ contract GovernorCompatibilityBravoMock is
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual override(IGovernor, Governor, GovernorCompatibilityBravo) returns (uint256) {
) public override(IGovernor, Governor, GovernorCompatibilityBravo) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}

Expand All @@ -79,7 +76,7 @@ contract GovernorCompatibilityBravoMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 salt
) public virtual override(IGovernorTimelock, GovernorTimelockCompound) returns (uint256) {
) public override(IGovernorTimelock, GovernorTimelockCompound) returns (uint256) {
return super.queue(targets, values, calldatas, salt);
}

Expand All @@ -88,7 +85,7 @@ contract GovernorCompatibilityBravoMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 salt
) public payable virtual override(IGovernor, Governor) returns (uint256) {
) public payable override(IGovernor, Governor) returns (uint256) {
return super.execute(targets, values, calldatas, salt);
}

Expand All @@ -98,7 +95,7 @@ contract GovernorCompatibilityBravoMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override(Governor, GovernorTimelockCompound) {
) internal override(Governor, GovernorTimelockCompound) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}

Expand All @@ -120,11 +117,11 @@ contract GovernorCompatibilityBravoMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 salt
) internal virtual override(Governor, GovernorTimelockCompound) returns (uint256 proposalId) {
) internal override(Governor, GovernorTimelockCompound) returns (uint256 proposalId) {
return super._cancel(targets, values, calldatas, salt);
}

function _executor() internal view virtual override(Governor, GovernorTimelockCompound) returns (address) {
function _executor() internal view override(Governor, GovernorTimelockCompound) returns (address) {
return super._executor();
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/GovernorMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract GovernorMock is
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual override(Governor, GovernorProposalThreshold) returns (uint256) {
) public override(Governor, GovernorProposalThreshold) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}
}
7 changes: 3 additions & 4 deletions contracts/mocks/GovernorPreventLateQuorumMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ contract GovernorPreventLateQuorumMock is
_quorum = quorum_;
}

function quorum(uint256) public view virtual override returns (uint256) {
function quorum(uint256) public view override returns (uint256) {
return _quorum;
}

function proposalDeadline(uint256 proposalId)
public
view
virtual
override(Governor, GovernorPreventLateQuorum)
returns (uint256)
{
return super.proposalDeadline(proposalId);
}

function proposalThreshold() public view virtual override(Governor, GovernorSettings) returns (uint256) {
function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
return super.proposalThreshold();
}

Expand All @@ -55,7 +54,7 @@ contract GovernorPreventLateQuorumMock is
uint8 support,
string memory reason,
bytes memory params
) internal virtual override(Governor, GovernorPreventLateQuorum) returns (uint256) {
) internal override(Governor, GovernorPreventLateQuorum) returns (uint256) {
return super._castVote(proposalId, account, support, reason, params);
}
}
8 changes: 3 additions & 5 deletions contracts/mocks/GovernorTimelockCompoundMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ contract GovernorTimelockCompoundMock is
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(Governor, GovernorTimelockCompound)
returns (bool)
{
Expand Down Expand Up @@ -62,7 +61,6 @@ contract GovernorTimelockCompoundMock is
function state(uint256 proposalId)
public
view
virtual
override(Governor, GovernorTimelockCompound)
returns (ProposalState)
{
Expand All @@ -79,7 +77,7 @@ contract GovernorTimelockCompoundMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override(Governor, GovernorTimelockCompound) {
) internal override(Governor, GovernorTimelockCompound) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}

Expand All @@ -88,11 +86,11 @@ contract GovernorTimelockCompoundMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 salt
) internal virtual override(Governor, GovernorTimelockCompound) returns (uint256 proposalId) {
) internal override(Governor, GovernorTimelockCompound) returns (uint256 proposalId) {
return super._cancel(targets, values, calldatas, salt);
}

function _executor() internal view virtual override(Governor, GovernorTimelockCompound) returns (address) {
function _executor() internal view override(Governor, GovernorTimelockCompound) returns (address) {
return super._executor();
}
}
15 changes: 4 additions & 11 deletions contracts/mocks/GovernorTimelockControlMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ contract GovernorTimelockControlMock is
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(Governor, GovernorTimelockControl)
returns (bool)
{
Expand Down Expand Up @@ -59,13 +58,7 @@ contract GovernorTimelockControlMock is
/**
* Overriding nightmare
*/
function state(uint256 proposalId)
public
view
virtual
override(Governor, GovernorTimelockControl)
returns (ProposalState)
{
function state(uint256 proposalId) public view override(Governor, GovernorTimelockControl) returns (ProposalState) {
return super.state(proposalId);
}

Expand All @@ -79,7 +72,7 @@ contract GovernorTimelockControlMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override(Governor, GovernorTimelockControl) {
) internal override(Governor, GovernorTimelockControl) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}

Expand All @@ -88,11 +81,11 @@ contract GovernorTimelockControlMock is
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override(Governor, GovernorTimelockControl) returns (uint256 proposalId) {
) internal override(Governor, GovernorTimelockControl) returns (uint256 proposalId) {
return super._cancel(targets, values, calldatas, descriptionHash);
}

function _executor() internal view virtual override(Governor, GovernorTimelockControl) returns (address) {
function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
return super._executor();
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/GovernorWithParamsMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract GovernorWithParamsMock is GovernorVotes, GovernorCountingSimple {
address account,
uint256 blockNumber,
bytes memory params
) internal view virtual override(Governor, GovernorVotes) returns (uint256) {
) internal view override(Governor, GovernorVotes) returns (uint256) {
uint256 reduction = 0;
// If the user provides parameters, we reduce the voting weight by the amount of the integer param
if (params.length > 0) {
Expand All @@ -42,7 +42,7 @@ contract GovernorWithParamsMock is GovernorVotes, GovernorCountingSimple {
uint8 support,
uint256 weight,
bytes memory params
) internal virtual override(Governor, GovernorCountingSimple) {
) internal override(Governor, GovernorCountingSimple) {
if (params.length > 0) {
(uint256 _uintParam, string memory _strParam) = abi.decode(params, (uint256, string));
emit CountParams(_uintParam, _strParam);
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/MultipleInheritanceInitializableMocks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract SampleHuman is Initializable {
contract SampleMother is Initializable, SampleHuman {
uint256 public mother;

function initialize(uint256 value) public virtual initializer {
function initialize(uint256 value) public initializer {
__SampleMother_init(value);
}

Expand All @@ -64,7 +64,7 @@ contract SampleMother is Initializable, SampleHuman {
contract SampleGramps is Initializable, SampleHuman {
string public gramps;

function initialize(string memory value) public virtual initializer {
function initialize(string memory value) public initializer {
__SampleGramps_init(value);
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/SafeERC20Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ contract ERC20PermitNoRevertMock is
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
) public {
super.permit(owner, spender, value, deadline, v, r, s);
}

Expand All @@ -134,7 +134,7 @@ contract ERC20PermitNoRevertMock is
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
) public override {
try this.permitThatMayRevert(owner, spender, value, deadline, v, r, s) {
// do nothing
} catch {
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/UUPS/UUPSLegacy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ contract UUPSUpgradeableLegacyMock is UUPSUpgradeableMock {
}

// hooking into the old mechanism
function upgradeTo(address newImplementation) external virtual override {
function upgradeTo(address newImplementation) external override {
_upgradeToAndCallSecureLegacyV1(newImplementation, bytes(""), false);
}

function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual override {
function upgradeToAndCall(address newImplementation, bytes memory data) external payable override {
_upgradeToAndCallSecureLegacyV1(newImplementation, data, false);
}
}
6 changes: 3 additions & 3 deletions contracts/mocks/UUPS/UUPSUpgradeableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import "../../proxy/utils/UUPSUpgradeable.sol";

contract UUPSUpgradeableMock is CountersImpl, UUPSUpgradeable {
// Not having any checks in this function is dangerous! Do not do this outside tests!
function _authorizeUpgrade(address) internal virtual override {}
function _authorizeUpgrade(address) internal override {}
}

contract UUPSUpgradeableUnsafeMock is UUPSUpgradeableMock {
function upgradeTo(address newImplementation) external virtual override {
function upgradeTo(address newImplementation) external override {
ERC1967Upgrade._upgradeToAndCall(newImplementation, bytes(""), false);
}

function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual override {
function upgradeToAndCall(address newImplementation, bytes memory data) external payable override {
ERC1967Upgrade._upgradeToAndCall(newImplementation, data, false);
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/VotesMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract VotesMock is Votes {
return _delegate(account, newDelegation);
}

function _getVotingUnits(address account) internal view virtual override returns (uint256) {
function _getVotingUnits(address account) internal view override returns (uint256) {
return _balances[account];
}

Expand Down

0 comments on commit 457ecc6

Please sign in to comment.