diff --git a/src/EmergencyMultisig.sol b/src/EmergencyMultisig.sol index c8fb149..d6249ae 100644 --- a/src/EmergencyMultisig.sol +++ b/src/EmergencyMultisig.sol @@ -60,11 +60,6 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade Addresslist memberListSource; } - /// @notice The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract. - bytes4 internal constant EMERGENCY_MULTISIG_INTERFACE_ID = this.initialize.selector - ^ this.updateMultisigSettings.selector ^ this.createProposal.selector ^ this.getProposal.selector - ^ this.hashActions.selector; - /// @notice The ID of the permission required to call the `addAddresses` and `removeAddresses` functions. bytes32 public constant UPDATE_MULTISIG_SETTINGS_PERMISSION_ID = keccak256("UPDATE_MULTISIG_SETTINGS_PERMISSION"); @@ -154,8 +149,8 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade override(PluginUUPSUpgradeable, ProposalUpgradeable) returns (bool) { - return _interfaceId == EMERGENCY_MULTISIG_INTERFACE_ID || _interfaceId == type(IEmergencyMultisig).interfaceId - || _interfaceId == type(IMembership).interfaceId || super.supportsInterface(_interfaceId); + return _interfaceId == type(IEmergencyMultisig).interfaceId || _interfaceId == type(IMembership).interfaceId + || super.supportsInterface(_interfaceId); } /// @notice Updates the plugin settings. @@ -179,8 +174,8 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade OptimisticTokenVotingPlugin _destinationPlugin, bool _approveProposal ) external returns (uint256 proposalId) { - if (multisigSettings.onlyListed && !multisigSettings.memberListSource.isListed(_msgSender())) { - revert ProposalCreationForbidden(_msgSender()); + if (multisigSettings.onlyListed && !multisigSettings.memberListSource.isListed(msg.sender)) { + revert ProposalCreationForbidden(msg.sender); } uint64 snapshotBlock; @@ -191,18 +186,11 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade // Revert if the settings have been changed in the same block as this proposal should be created in. // This prevents a malicious party from voting with previous addresses and the new settings. if (lastMultisigSettingsChange > snapshotBlock) { - revert ProposalCreationForbidden(_msgSender()); + revert ProposalCreationForbidden(msg.sender); } proposalId = _createProposalId(); - emit ProposalCreated({ - proposalId: proposalId, - creator: _msgSender(), - encryptedPayloadURI: _encryptedPayloadURI, - destinationActionsHash: _destinationActionsHash - }); - // Create the proposal Proposal storage proposal_ = proposals[proposalId]; proposal_.encryptedPayloadURI = _encryptedPayloadURI; @@ -214,6 +202,13 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade proposal_.destinationActionsHash = _destinationActionsHash; + emit ProposalCreated({ + proposalId: proposalId, + creator: msg.sender, + encryptedPayloadURI: _encryptedPayloadURI, + destinationActionsHash: _destinationActionsHash + }); + if (_approveProposal) { approve(proposalId); } @@ -221,7 +216,7 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade /// @inheritdoc IEmergencyMultisig function approve(uint256 _proposalId) public { - address approver = _msgSender(); + address approver = msg.sender; if (!_canApprove(_proposalId, approver)) { revert ApprovalCastForbidden(_proposalId, approver); } @@ -237,6 +232,9 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade proposal_.approvers[approver] = true; emit Approved({proposalId: _proposalId, approver: approver}); + + // Automatic execution is intentionally omitted in order to prevent + // private actions from accidentally leaving the local computer before being executed } /// @inheritdoc IEmergencyMultisig @@ -292,7 +290,7 @@ contract EmergencyMultisig is IEmergencyMultisig, IMembership, PluginUUPSUpgrade if (proposals[_proposalId].destinationActionsHash != hashActions(_actions)) { // This check is intentionally not part of canExecute() in order to prevent - // the private actions from ever leaving the local computer until being executed + // the private actions from ever leaving the local computer before being executed revert InvalidActions(_proposalId); } diff --git a/src/Multisig.sol b/src/Multisig.sol index 5b0022a..7cd9ab6 100644 --- a/src/Multisig.sol +++ b/src/Multisig.sol @@ -18,13 +18,7 @@ uint64 constant MULTISIG_PROPOSAL_EXPIRATION_PERIOD = 10 days; /// @title Multisig - Release 1, Build 1 /// @author Aragon Association - 2022-2024 /// @notice The on-chain multisig governance plugin in which a proposal passes if X out of Y approvals are met. -contract Multisig is - IMultisig, - IMembership, - PluginUUPSUpgradeable, - ProposalUpgradeable, - Addresslist -{ +contract Multisig is IMultisig, IMembership, PluginUUPSUpgradeable, ProposalUpgradeable, Addresslist { using SafeCastUpgradeable for uint256; /// @notice A container for proposal-related information. @@ -69,16 +63,8 @@ contract Multisig is uint64 destinationMinDuration; } - /// @notice The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract. - bytes4 internal constant MULTISIG_INTERFACE_ID = - this.initialize.selector ^ - this.updateMultisigSettings.selector ^ - this.createProposal.selector ^ - this.getProposal.selector; - /// @notice The ID of the permission required to call the `addAddresses` and `removeAddresses` functions. - bytes32 public constant UPDATE_MULTISIG_SETTINGS_PERMISSION_ID = - keccak256("UPDATE_MULTISIG_SETTINGS_PERMISSION"); + bytes32 public constant UPDATE_MULTISIG_SETTINGS_PERMISSION_ID = keccak256("UPDATE_MULTISIG_SETTINGS_PERMISSION"); /// @notice A mapping between proposal IDs and proposal information. mapping(uint256 => Proposal) internal proposals; @@ -134,29 +120,21 @@ contract Multisig is /// @param onlyListed Whether only listed addresses can create a proposal. /// @param minApprovals The minimum amount of approvals needed to pass a proposal. /// @param destinationMinDuration The minimum duration (in seconds) that will be required on the destination plugin - event MultisigSettingsUpdated( - bool onlyListed, - uint16 indexed minApprovals, - uint64 destinationMinDuration - ); + event MultisigSettingsUpdated(bool onlyListed, uint16 indexed minApprovals, uint64 destinationMinDuration); /// @notice Initializes Release 1, Build 2. /// @dev This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822). /// @param _dao The IDAO interface of the associated DAO. /// @param _members The addresses of the initial members to be added. /// @param _multisigSettings The multisig settings. - function initialize( - IDAO _dao, - address[] calldata _members, - MultisigSettings calldata _multisigSettings - ) external initializer { + function initialize(IDAO _dao, address[] calldata _members, MultisigSettings calldata _multisigSettings) + external + initializer + { __PluginUUPSUpgradeable_init(_dao); if (_members.length > type(uint16).max) { - revert AddresslistLengthOutOfBounds({ - limit: type(uint16).max, - actual: _members.length - }); + revert AddresslistLengthOutOfBounds({limit: type(uint16).max, actual: _members.length}); } _addAddresses(_members); @@ -168,35 +146,24 @@ contract Multisig is /// @notice Checks if this or the parent contract supports an interface by its ID. /// @param _interfaceId The ID of the interface. /// @return Returns `true` if the interface is supported. - function supportsInterface( - bytes4 _interfaceId - ) + function supportsInterface(bytes4 _interfaceId) public view virtual override(PluginUUPSUpgradeable, ProposalUpgradeable) returns (bool) { - return - _interfaceId == MULTISIG_INTERFACE_ID || - _interfaceId == type(IMultisig).interfaceId || - _interfaceId == type(Addresslist).interfaceId || - _interfaceId == type(IMembership).interfaceId || - super.supportsInterface(_interfaceId); + return _interfaceId == type(IMultisig).interfaceId || _interfaceId == type(Addresslist).interfaceId + || _interfaceId == type(IMembership).interfaceId || super.supportsInterface(_interfaceId); } /// @inheritdoc IMultisig - function addAddresses( - address[] calldata _members - ) external auth(UPDATE_MULTISIG_SETTINGS_PERMISSION_ID) { + function addAddresses(address[] calldata _members) external auth(UPDATE_MULTISIG_SETTINGS_PERMISSION_ID) { uint256 newAddresslistLength = addresslistLength() + _members.length; // Check if the new address list length would be greater than `type(uint16).max`, the maximal number of approvals. if (newAddresslistLength > type(uint16).max) { - revert AddresslistLengthOutOfBounds({ - limit: type(uint16).max, - actual: newAddresslistLength - }); + revert AddresslistLengthOutOfBounds({limit: type(uint16).max, actual: newAddresslistLength}); } _addAddresses(_members); @@ -205,19 +172,12 @@ contract Multisig is } /// @inheritdoc IMultisig - function removeAddresses( - address[] calldata _members - ) external auth(UPDATE_MULTISIG_SETTINGS_PERMISSION_ID) { - uint16 newAddresslistLength = uint16( - addresslistLength() - _members.length - ); + function removeAddresses(address[] calldata _members) external auth(UPDATE_MULTISIG_SETTINGS_PERMISSION_ID) { + uint16 newAddresslistLength = uint16(addresslistLength() - _members.length); // Check if the new address list length would become less than the current minimum number of approvals required. if (newAddresslistLength < multisigSettings.minApprovals) { - revert MinApprovalsOutOfBounds({ - limit: multisigSettings.minApprovals, - actual: newAddresslistLength - }); + revert MinApprovalsOutOfBounds({limit: multisigSettings.minApprovals, actual: newAddresslistLength}); } _removeAddresses(_members); @@ -227,9 +187,10 @@ contract Multisig is /// @notice Updates the plugin settings. /// @param _multisigSettings The new settings. - function updateMultisigSettings( - MultisigSettings calldata _multisigSettings - ) external auth(UPDATE_MULTISIG_SETTINGS_PERMISSION_ID) { + function updateMultisigSettings(MultisigSettings calldata _multisigSettings) + external + auth(UPDATE_MULTISIG_SETTINGS_PERMISSION_ID) + { _updateMultisigSettings(_multisigSettings); } @@ -282,14 +243,12 @@ contract Multisig is proposal_.destinationPlugin = _destinationPlugin; proposal_.parameters.snapshotBlock = snapshotBlock; - proposal_.parameters.expirationDate = - uint64(block.timestamp) + - MULTISIG_PROPOSAL_EXPIRATION_PERIOD; + proposal_.parameters.expirationDate = uint64(block.timestamp) + MULTISIG_PROPOSAL_EXPIRATION_PERIOD; proposal_.parameters.destinationStartDate = _destinationStartDate; proposal_.parameters.destinationEndDate = _destinationEndDate; proposal_.parameters.minApprovals = multisigSettings.minApprovals; - for (uint256 i; i < _destinationActions.length; ) { + for (uint256 i; i < _destinationActions.length;) { proposal_.destinationActions.push(_destinationActions[i]); unchecked { ++i; @@ -326,10 +285,7 @@ contract Multisig is } /// @inheritdoc IMultisig - function canApprove( - uint256 _proposalId, - address _account - ) external view returns (bool) { + function canApprove(uint256 _proposalId, address _account) external view returns (bool) { return _canApprove(_proposalId, _account); } @@ -346,9 +302,7 @@ contract Multisig is /// @return metadataURI The URI at which the corresponding human readable data can be found. /// @return destinationActions The actions to be executed by the destination plugin after the proposal passes. /// @return destinationPlugin The address of the plugin where the proposal will be forwarded to when executed. - function getProposal( - uint256 _proposalId - ) + function getProposal(uint256 _proposalId) public view returns ( @@ -371,10 +325,7 @@ contract Multisig is } /// @inheritdoc IMultisig - function hasApproved( - uint256 _proposalId, - address _account - ) public view returns (bool) { + function hasApproved(uint256 _proposalId, address _account) public view returns (bool) { return proposals[_proposalId].approvers[_account]; } @@ -413,10 +364,7 @@ contract Multisig is /// @param _proposalId The ID of the proposal. /// @param _account The account to check. /// @return Returns `true` if the given account can approve on a certain proposal and `false` otherwise. - function _canApprove( - uint256 _proposalId, - address _account - ) internal view returns (bool) { + function _canApprove(uint256 _proposalId, address _account) internal view returns (bool) { Proposal storage proposal_ = proposals[_proposalId]; if (!_isProposalOpen(proposal_)) { @@ -454,34 +402,22 @@ contract Multisig is /// @notice Internal function to check if a proposal is still open. /// @param proposal_ The proposal struct. /// @return True if the proposal vote is open, false otherwise. - function _isProposalOpen( - Proposal storage proposal_ - ) internal view returns (bool) { + function _isProposalOpen(Proposal storage proposal_) internal view returns (bool) { uint64 currentTimestamp64 = block.timestamp.toUint64(); - return - !proposal_.executed && - proposal_.parameters.expirationDate >= currentTimestamp64; + return !proposal_.executed && proposal_.parameters.expirationDate >= currentTimestamp64; } /// @notice Internal function to update the plugin settings. /// @param _multisigSettings The new settings. - function _updateMultisigSettings( - MultisigSettings calldata _multisigSettings - ) internal { + function _updateMultisigSettings(MultisigSettings calldata _multisigSettings) internal { uint16 addresslistLength_ = uint16(addresslistLength()); if (_multisigSettings.minApprovals > addresslistLength_) { - revert MinApprovalsOutOfBounds({ - limit: addresslistLength_, - actual: _multisigSettings.minApprovals - }); + revert MinApprovalsOutOfBounds({limit: addresslistLength_, actual: _multisigSettings.minApprovals}); } if (_multisigSettings.minApprovals < 1) { - revert MinApprovalsOutOfBounds({ - limit: 1, - actual: _multisigSettings.minApprovals - }); + revert MinApprovalsOutOfBounds({limit: 1, actual: _multisigSettings.minApprovals}); } multisigSettings = _multisigSettings; @@ -497,10 +433,7 @@ contract Multisig is /// @notice Attempts to detect eventual issues on the destination plugin ahead of time. /// @param _start The start date of the proposal vote. If 0, the current timestamp is used and the vote starts immediately. /// @param _end The end date of the proposal vote. If 0, `_start + minDuration` is used. - function _validateProposalDates( - uint64 _start, - uint64 _end - ) internal view virtual { + function _validateProposalDates(uint64 _start, uint64 _end) internal view virtual { uint64 currentTimestamp = block.timestamp.toUint64(); uint64 startDate; @@ -510,22 +443,13 @@ contract Multisig is startDate = _start; if (startDate < currentTimestamp) { - revert DateOutOfBounds({ - limit: currentTimestamp, - actual: startDate - }); + revert DateOutOfBounds({limit: currentTimestamp, actual: startDate}); } } // Compare against the earliest end date - if ( - _end != 0 && - _end < startDate + multisigSettings.destinationMinDuration - ) { - revert DateOutOfBounds({ - limit: startDate + multisigSettings.destinationMinDuration, - actual: _end - }); + if (_end != 0 && _end < startDate + multisigSettings.destinationMinDuration) { + revert DateOutOfBounds({limit: startDate + multisigSettings.destinationMinDuration, actual: _end}); } } diff --git a/src/OptimisticTokenVotingPlugin.sol b/src/OptimisticTokenVotingPlugin.sol index a96cf40..de4d89a 100644 --- a/src/OptimisticTokenVotingPlugin.sol +++ b/src/OptimisticTokenVotingPlugin.sol @@ -69,19 +69,15 @@ contract OptimisticTokenVotingPlugin is } /// @notice The ID of the permission required to create a proposal. - bytes32 public constant PROPOSER_PERMISSION_ID = - keccak256("PROPOSER_PERMISSION"); + bytes32 public constant PROPOSER_PERMISSION_ID = keccak256("PROPOSER_PERMISSION"); /// @notice The ID of the permission required to call the `updateOptimisticGovernanceSettings` function. - bytes32 - public constant UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID = + bytes32 public constant UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID = keccak256("UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION"); /// @notice The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract. bytes4 public constant OPTIMISTIC_GOVERNANCE_INTERFACE_ID = - this.initialize.selector ^ - this.getProposal.selector ^ - this.updateOptimisticGovernanceSettings.selector; + this.initialize.selector ^ this.getProposal.selector ^ this.updateOptimisticGovernanceSettings.selector; /// @notice An [OpenZeppelin `Votes`](https://docs.openzeppelin.com/contracts/4.x/api/governance#Votes) compatible contract referencing the token being used for voting. IVotesUpgradeable public votingToken; @@ -96,21 +92,13 @@ contract OptimisticTokenVotingPlugin is /// @param minVetoRatio The support threshold value. /// @param minDuration The minimum duration of the proposal vote in seconds. /// @param minProposerVotingPower The minimum vetoing power required to create a proposal. - event OptimisticGovernanceSettingsUpdated( - uint32 minVetoRatio, - uint64 minDuration, - uint256 minProposerVotingPower - ); + event OptimisticGovernanceSettingsUpdated(uint32 minVetoRatio, uint64 minDuration, uint256 minProposerVotingPower); /// @notice Emitted when a veto is cast by a voter. /// @param proposalId The ID of the proposal. /// @param voter The voter casting the veto. /// @param votingPower The voting power behind this veto. - event VetoCast( - uint256 indexed proposalId, - address indexed voter, - uint256 votingPower - ); + event VetoCast(uint256 indexed proposalId, address indexed voter, uint256 votingPower); /// @notice Thrown if a date is out of bounds. /// @param limit The limit value. @@ -152,11 +140,10 @@ contract OptimisticTokenVotingPlugin is /// @param _dao The IDAO interface of the associated DAO. /// @param _governanceSettings The vetoing settings. /// @param _token The [ERC-20](https://eips.ethereum.org/EIPS/eip-20) token used for voting. - function initialize( - IDAO _dao, - OptimisticGovernanceSettings calldata _governanceSettings, - IVotesUpgradeable _token - ) external initializer { + function initialize(IDAO _dao, OptimisticGovernanceSettings calldata _governanceSettings, IVotesUpgradeable _token) + external + initializer + { __PluginUUPSUpgradeable_init(_dao); votingToken = _token; @@ -168,20 +155,14 @@ contract OptimisticTokenVotingPlugin is /// @notice Checks if this or the parent contract supports an interface by its ID. /// @param _interfaceId The ID of the interface. /// @return Returns `true` if the interface is supported. - function supportsInterface( - bytes4 _interfaceId - ) + function supportsInterface(bytes4 _interfaceId) public view virtual override(ERC165Upgradeable, PluginUUPSUpgradeable, ProposalUpgradeable) returns (bool) { - return - _interfaceId == OPTIMISTIC_GOVERNANCE_INTERFACE_ID || - _interfaceId == type(IOptimisticTokenVoting).interfaceId || - _interfaceId == type(IMembership).interfaceId || - super.supportsInterface(_interfaceId); + return super.supportsInterface(_interfaceId); } /// @inheritdoc IOptimisticTokenVoting @@ -190,33 +171,23 @@ contract OptimisticTokenVotingPlugin is } /// @inheritdoc IOptimisticTokenVoting - function totalVotingPower( - uint256 _blockNumber - ) public view returns (uint256) { + function totalVotingPower(uint256 _blockNumber) public view returns (uint256) { return votingToken.getPastTotalSupply(_blockNumber); } /// @inheritdoc IMembership function isMember(address _account) external view returns (bool) { // A member must own at least one token or have at least one token delegated to her/him. - return - votingToken.getVotes(_account) > 0 || - IERC20Upgradeable(address(votingToken)).balanceOf(_account) > 0; + return votingToken.getVotes(_account) > 0 || IERC20Upgradeable(address(votingToken)).balanceOf(_account) > 0; } /// @inheritdoc IOptimisticTokenVoting - function hasVetoed( - uint256 _proposalId, - address _voter - ) public view returns (bool) { + function hasVetoed(uint256 _proposalId, address _voter) public view returns (bool) { return proposals[_proposalId].vetoVoters[_voter]; } /// @inheritdoc IOptimisticTokenVoting - function canVeto( - uint256 _proposalId, - address _voter - ) public view virtual returns (bool) { + function canVeto(uint256 _proposalId, address _voter) public view virtual returns (bool) { Proposal storage proposal_ = proposals[_proposalId]; // The proposal vote hasn't started or has already ended. @@ -230,12 +201,7 @@ contract OptimisticTokenVotingPlugin is } // The voter has no voting power. - if ( - votingToken.getPastVotes( - _voter, - proposal_.parameters.snapshotBlock - ) == 0 - ) { + if (votingToken.getPastVotes(_voter, proposal_.parameters.snapshotBlock) == 0) { return false; } @@ -243,9 +209,7 @@ contract OptimisticTokenVotingPlugin is } /// @inheritdoc IOptimisticTokenVoting - function canExecute( - uint256 _proposalId - ) public view virtual returns (bool) { + function canExecute(uint256 _proposalId) public view virtual returns (bool) { Proposal storage proposal_ = proposals[_proposalId]; // Verify that the vote has not been executed already. @@ -265,9 +229,7 @@ contract OptimisticTokenVotingPlugin is } /// @inheritdoc IOptimisticTokenVoting - function isMinVetoRatioReached( - uint256 _proposalId - ) public view virtual returns (bool) { + function isMinVetoRatioReached(uint256 _proposalId) public view virtual returns (bool) { Proposal storage proposal_ = proposals[_proposalId]; return proposal_.vetoTally >= proposal_.parameters.minVetoVotingPower; @@ -296,9 +258,7 @@ contract OptimisticTokenVotingPlugin is /// @return vetoTally The current voting power used to veto the proposal. /// @return actions The actions to be executed in the associated DAO after the proposal has passed. /// @return allowFailureMap The bit map representations of which actions are allowed to revert so tx still succeeds. - function getProposal( - uint256 _proposalId - ) + function getProposal(uint256 _proposalId) public view virtual @@ -336,12 +296,8 @@ contract OptimisticTokenVotingPlugin is if (minProposerVotingPower_ != 0) { // Because of the checks in `OptimisticTokenVotingSetup`, we can assume that `votingToken` is an [ERC-20](https://eips.ethereum.org/EIPS/eip-20) token. if ( - votingToken.getVotes(_msgSender()) < - minProposerVotingPower_ && - IERC20Upgradeable(address(votingToken)).balanceOf( - _msgSender() - ) < - minProposerVotingPower_ + votingToken.getVotes(_msgSender()) < minProposerVotingPower_ + && IERC20Upgradeable(address(votingToken)).balanceOf(_msgSender()) < minProposerVotingPower_ ) { revert ProposalCreationForbidden(_msgSender()); } @@ -376,17 +332,14 @@ contract OptimisticTokenVotingPlugin is proposal_.parameters.startDate = _startDate; proposal_.parameters.endDate = _endDate; proposal_.parameters.snapshotBlock = snapshotBlock.toUint64(); - proposal_.parameters.minVetoVotingPower = _applyRatioCeiled( - totalVotingPower_, - minVetoRatio() - ); + proposal_.parameters.minVetoVotingPower = _applyRatioCeiled(totalVotingPower_, minVetoRatio()); // Save gas if (_allowFailureMap != 0) { proposal_.allowFailureMap = _allowFailureMap; } - for (uint256 i; i < _actions.length; ) { + for (uint256 i; i < _actions.length;) { proposal_.actions.push(_actions[i]); unchecked { ++i; @@ -399,19 +352,13 @@ contract OptimisticTokenVotingPlugin is address _voter = _msgSender(); if (!canVeto(_proposalId, _voter)) { - revert ProposalVetoingForbidden({ - proposalId: _proposalId, - account: _voter - }); + revert ProposalVetoingForbidden({proposalId: _proposalId, account: _voter}); } Proposal storage proposal_ = proposals[_proposalId]; // This could re-enter, though we can assume the governance token is not malicious - uint256 votingPower = votingToken.getPastVotes( - _voter, - proposal_.parameters.snapshotBlock - ); + uint256 votingPower = votingToken.getPastVotes(_voter, proposal_.parameters.snapshotBlock); // Not checking if the voter already voted, since canVeto() did it above @@ -419,11 +366,7 @@ contract OptimisticTokenVotingPlugin is proposal_.vetoTally += votingPower; proposal_.vetoVoters[_voter] = true; - emit VetoCast({ - proposalId: _proposalId, - voter: _voter, - votingPower: votingPower - }); + emit VetoCast({proposalId: _proposalId, voter: _voter, votingPower: votingPower}); } /// @inheritdoc IOptimisticTokenVoting @@ -434,49 +377,32 @@ contract OptimisticTokenVotingPlugin is proposals[_proposalId].executed = true; - _executeProposal( - dao(), - _proposalId, - proposals[_proposalId].actions, - proposals[_proposalId].allowFailureMap - ); + _executeProposal(dao(), _proposalId, proposals[_proposalId].actions, proposals[_proposalId].allowFailureMap); } /// @notice Updates the governance settings. /// @param _governanceSettings The new governance settings. - function updateOptimisticGovernanceSettings( - OptimisticGovernanceSettings calldata _governanceSettings - ) public virtual auth(UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID) { + function updateOptimisticGovernanceSettings(OptimisticGovernanceSettings calldata _governanceSettings) + public + virtual + auth(UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID) + { _updateOptimisticGovernanceSettings(_governanceSettings); } /// @notice Internal implementation - function _updateOptimisticGovernanceSettings( - OptimisticGovernanceSettings calldata _governanceSettings - ) internal { + function _updateOptimisticGovernanceSettings(OptimisticGovernanceSettings calldata _governanceSettings) internal { // Require the minimum veto ratio value to be in the interval [0, 10^6], because `>=` comparision is used. if (_governanceSettings.minVetoRatio == 0) { - revert RatioOutOfBounds({ - limit: 1, - actual: _governanceSettings.minVetoRatio - }); + revert RatioOutOfBounds({limit: 1, actual: _governanceSettings.minVetoRatio}); } else if (_governanceSettings.minVetoRatio > RATIO_BASE) { - revert RatioOutOfBounds({ - limit: RATIO_BASE, - actual: _governanceSettings.minVetoRatio - }); + revert RatioOutOfBounds({limit: RATIO_BASE, actual: _governanceSettings.minVetoRatio}); } if (_governanceSettings.minDuration < 4 days) { - revert MinDurationOutOfBounds({ - limit: 4 days, - actual: _governanceSettings.minDuration - }); + revert MinDurationOutOfBounds({limit: 4 days, actual: _governanceSettings.minDuration}); } else if (_governanceSettings.minDuration > 365 days) { - revert MinDurationOutOfBounds({ - limit: 365 days, - actual: _governanceSettings.minDuration - }); + revert MinDurationOutOfBounds({limit: 365 days, actual: _governanceSettings.minDuration}); } governanceSettings = _governanceSettings; @@ -491,23 +417,17 @@ contract OptimisticTokenVotingPlugin is /// @notice Internal function to check if a proposal vote is open. /// @param proposal_ The proposal struct. /// @return True if the proposal vote is open, false otherwise. - function _isProposalOpen( - Proposal storage proposal_ - ) internal view virtual returns (bool) { + function _isProposalOpen(Proposal storage proposal_) internal view virtual returns (bool) { uint64 currentTime = block.timestamp.toUint64(); - return - proposal_.parameters.startDate <= currentTime && - currentTime < proposal_.parameters.endDate && - !proposal_.executed; + return proposal_.parameters.startDate <= currentTime && currentTime < proposal_.parameters.endDate + && !proposal_.executed; } /// @notice Internal function to check if a proposal already ended. /// @param proposal_ The proposal struct. /// @return True if the end date of the proposal is already in the past, false otherwise. - function _isProposalEnded( - Proposal storage proposal_ - ) internal view virtual returns (bool) { + function _isProposalEnded(Proposal storage proposal_) internal view virtual returns (bool) { uint64 currentTime = block.timestamp.toUint64(); return currentTime >= proposal_.parameters.endDate; @@ -518,10 +438,12 @@ contract OptimisticTokenVotingPlugin is /// @param _end The end date of the proposal vote. If 0, `_start + minDuration` is used. /// @return startDate The validated start date of the proposal vote. /// @return endDate The validated end date of the proposal vote. - function _validateProposalDates( - uint64 _start, - uint64 _end - ) internal view virtual returns (uint64 startDate, uint64 endDate) { + function _validateProposalDates(uint64 _start, uint64 _end) + internal + view + virtual + returns (uint64 startDate, uint64 endDate) + { uint64 currentTimestamp = block.timestamp.toUint64(); if (_start == 0) { @@ -530,10 +452,7 @@ contract OptimisticTokenVotingPlugin is startDate = _start; if (startDate < currentTimestamp) { - revert DateOutOfBounds({ - limit: currentTimestamp, - actual: startDate - }); + revert DateOutOfBounds({limit: currentTimestamp, actual: startDate}); } } @@ -545,10 +464,7 @@ contract OptimisticTokenVotingPlugin is endDate = _end; if (endDate < earliestEndDate) { - revert DateOutOfBounds({ - limit: earliestEndDate, - actual: endDate - }); + revert DateOutOfBounds({limit: earliestEndDate, actual: endDate}); } } } diff --git a/src/conditions/StandardProposalCondition.sol b/src/conditions/StandardProposalCondition.sol index d6b8361..a450e40 100644 --- a/src/conditions/StandardProposalCondition.sol +++ b/src/conditions/StandardProposalCondition.sol @@ -33,44 +33,32 @@ contract StandardProposalCondition is ERC165, IPermissionCondition { /// @notice Checks if an interface is supported by this or its parent contract. /// @param _interfaceId The ID of the interface. /// @return Returns `true` if the interface is supported. - function supportsInterface( - bytes4 _interfaceId - ) public view virtual override returns (bool) { - return - _interfaceId == type(IPermissionCondition).interfaceId || - super.supportsInterface(_interfaceId); + function supportsInterface(bytes4 _interfaceId) public view virtual override returns (bool) { + return _interfaceId == type(IPermissionCondition).interfaceId || super.supportsInterface(_interfaceId); } - function isGranted( - address _where, - address _who, - bytes32 _permissionId, - bytes calldata _data - ) external view returns (bool isPermitted) { + function isGranted(address _where, address _who, bytes32 _permissionId, bytes calldata _data) + external + view + returns (bool isPermitted) + { (_where, _who, _permissionId); // Is it createProposal()? - if ( - _getSelector(_data) != - OptimisticTokenVotingPlugin.createProposal.selector - ) { + if (_getSelector(_data) != OptimisticTokenVotingPlugin.createProposal.selector) { return false; } // Decode proposal params - (, , , uint64 _startDate, uint64 _endDate) = abi.decode( - _data[4:], - (bytes, IDAO.Action[], uint256, uint64, uint64) - ); + (,,, uint64 _startDate, uint64 _endDate) = + abi.decode(_data[4:], (bytes, IDAO.Action[], uint256, uint64, uint64)); if (_endDate <= _startDate) return false; else if (_endDate - _startDate < minDelay) return false; return true; } - function _getSelector( - bytes memory _data - ) internal pure returns (bytes4 selector) { + function _getSelector(bytes memory _data) internal pure returns (bytes4 selector) { // Slices are only supported for bytes calldata, not bytes memory // Bytes memory requires an assembly block assembly { diff --git a/test/OptimisticTokenVotingPlugin.t.sol b/test/OptimisticTokenVotingPlugin.t.sol index c31d295..0cc5b96 100644 --- a/test/OptimisticTokenVotingPlugin.t.sol +++ b/test/OptimisticTokenVotingPlugin.t.sol @@ -13,7 +13,8 @@ import {RATIO_BASE, RatioOutOfBounds} from "@aragon/osx/plugins/utils/Ratio.sol" import {DaoUnauthorized} from "@aragon/osx/core/utils/auth.sol"; import {ERC20VotesMock} from "./mocks/ERC20VotesMock.sol"; import {IERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol"; -import {IERC1822ProxiableUpgradeable} from "@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol"; +import {IERC1822ProxiableUpgradeable} from + "@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol"; import {createProxyAndCall} from "./helpers.sol"; contract OptimisticTokenVotingPluginTest is AragonTest { @@ -32,25 +33,15 @@ contract OptimisticTokenVotingPluginTest is AragonTest { IDAO.Action[] actions, uint256 allowFailureMap ); - event VetoCast( - uint256 indexed proposalId, - address indexed voter, - uint256 votingPower - ); + event VetoCast(uint256 indexed proposalId, address indexed voter, uint256 votingPower); event ProposalExecuted(uint256 indexed proposalId); - event OptimisticGovernanceSettingsUpdated( - uint32 minVetoRatio, - uint64 minDuration, - uint256 minProposerVotingPower - ); + event OptimisticGovernanceSettingsUpdated(uint32 minVetoRatio, uint64 minDuration, uint256 minProposerVotingPower); event Upgraded(address indexed implementation); function setUp() public { vm.startPrank(alice); - (dao, plugin, votingToken) = makeDaoWithOptimisticTokenVoting( - alice - ); + (dao, plugin, votingToken) = makeDaoWithOptimisticTokenVoting(alice); // The plugin can execute on the DAO dao.grant(address(dao), address(plugin), dao.EXECUTE_PERMISSION_ID()); @@ -61,91 +52,59 @@ contract OptimisticTokenVotingPluginTest is AragonTest { // Initialize function test_InitializeRevertsIfInitialized() public { - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 0 + }); - vm.expectRevert( - bytes("Initializable: contract is already initialized") - ); + vm.expectRevert(bytes("Initializable: contract is already initialized")); plugin.initialize(dao, settings, votingToken); } function test_InitializeSetsTheProperValues() public { // Initial settings - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); - assertEq( - plugin.totalVotingPower(block.number - 1), - 10 ether, - "Incorrect token supply" - ); - assertEq( - plugin.minVetoRatio(), - uint32(RATIO_BASE / 10), - "Incorrect minVetoRatio" - ); + assertEq(plugin.totalVotingPower(block.number - 1), 10 ether, "Incorrect token supply"); + assertEq(plugin.minVetoRatio(), uint32(RATIO_BASE / 10), "Incorrect minVetoRatio"); assertEq(plugin.minDuration(), 10 days, "Incorrect minDuration"); - assertEq( - plugin.minProposerVotingPower(), - 0, - "Incorrect minProposerVotingPower" - ); + assertEq(plugin.minProposerVotingPower(), 0, "Incorrect minProposerVotingPower"); // Different minVetoRatio settings.minVetoRatio = uint32(RATIO_BASE / 5); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); - assertEq( - plugin.minVetoRatio(), - uint32(RATIO_BASE / 5), - "Incorrect minVetoRatio" - ); + assertEq(plugin.minVetoRatio(), uint32(RATIO_BASE / 5), "Incorrect minVetoRatio"); // Different minDuration settings.minDuration = 25 days; plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); assertEq(plugin.minDuration(), 25 days, "Incorrect minDuration"); // A token with 10 eth supply votingToken = ERC20VotesMock( - createProxyAndCall( - address(VOTING_TOKEN_BASE), - abi.encodeCall(ERC20VotesMock.initialize, ()) - ) + createProxyAndCall(address(VOTING_TOKEN_BASE), abi.encodeCall(ERC20VotesMock.initialize, ())) ); votingToken.mint(alice, 10 ether); vm.roll(block.number + 5); @@ -153,44 +112,29 @@ contract OptimisticTokenVotingPluginTest is AragonTest { plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); - assertEq( - plugin.totalVotingPower(block.number - 1), - 10 ether, - "Incorrect token supply" - ); + assertEq(plugin.totalVotingPower(block.number - 1), 10 ether, "Incorrect token supply"); // Different minProposerVotingPower settings.minProposerVotingPower = 1 ether; plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); - assertEq( - plugin.minProposerVotingPower(), - 1 ether, - "Incorrect minProposerVotingPower" - ); + assertEq(plugin.minProposerVotingPower(), 1 ether, "Incorrect minProposerVotingPower"); } function test_InitializeEmitsEvent() public { - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 0 + }); vm.expectEmit(); emit Initialized(uint8(1)); @@ -198,55 +142,23 @@ contract OptimisticTokenVotingPluginTest is AragonTest { plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); } // Getters - function test_SupportsOptimisticGovernanceInterface() public view { - bool supported = plugin.supportsInterface( - plugin.OPTIMISTIC_GOVERNANCE_INTERFACE_ID() - ); - assertEq( - supported, - true, - "Should support OPTIMISTIC_GOVERNANCE_INTERFACE_ID" - ); - } - - function test_SupportsIOptimisticTokenVotingInterface() public view { - bool supported = plugin.supportsInterface( - type(IOptimisticTokenVoting).interfaceId - ); - assertEq(supported, true, "Should support IOptimisticTokenVoting"); - } - - function test_SupportsIMembershipInterface() public view { - bool supported = plugin.supportsInterface( - type(IMembership).interfaceId - ); - assertEq(supported, true, "Should support IMembership"); - } - function test_SupportsIProposalInterface() public view { bool supported = plugin.supportsInterface(type(IProposal).interfaceId); assertEq(supported, true, "Should support IProposal"); } function test_SupportsIERC165UpgradeableInterface() public view { - bool supported = plugin.supportsInterface( - type(IERC165Upgradeable).interfaceId - ); + bool supported = plugin.supportsInterface(type(IERC165Upgradeable).interfaceId); assertEq(supported, true, "Should support IERC165Upgradeable"); } - function testFuzz_SupportsInterfaceReturnsFalseOtherwise( - bytes4 _randomInterfaceId - ) public view { + function testFuzz_SupportsInterfaceReturnsFalseOtherwise(bytes4 _randomInterfaceId) public view { bool supported = plugin.supportsInterface(bytes4(0x000000)); assertEq(supported, false, "Should not support any other interface"); @@ -255,14 +167,12 @@ contract OptimisticTokenVotingPluginTest is AragonTest { // Certain fuzzing values are expected to be true if ( - _randomInterfaceId == plugin.OPTIMISTIC_GOVERNANCE_INTERFACE_ID() || - _randomInterfaceId == type(IERC165Upgradeable).interfaceId || - _randomInterfaceId == type(IPlugin).interfaceId || - _randomInterfaceId == type(IProposal).interfaceId || - _randomInterfaceId == - type(IERC1822ProxiableUpgradeable).interfaceId || - _randomInterfaceId == type(IOptimisticTokenVoting).interfaceId || - _randomInterfaceId == type(IMembership).interfaceId + _randomInterfaceId == plugin.OPTIMISTIC_GOVERNANCE_INTERFACE_ID() + || _randomInterfaceId == type(IERC165Upgradeable).interfaceId + || _randomInterfaceId == type(IPlugin).interfaceId || _randomInterfaceId == type(IProposal).interfaceId + || _randomInterfaceId == type(IERC1822ProxiableUpgradeable).interfaceId + || _randomInterfaceId == type(IOptimisticTokenVoting).interfaceId + || _randomInterfaceId == type(IMembership).interfaceId ) { supported = plugin.supportsInterface(_randomInterfaceId); assertEq(supported, true, "Interface should be supported"); @@ -274,51 +184,32 @@ contract OptimisticTokenVotingPluginTest is AragonTest { } function test_GetVotingTokenReturnsTheRightAddress() public { - assertEq( - address(plugin.getVotingToken()), - address(votingToken), - "Incorrect voting token" - ); + assertEq(address(plugin.getVotingToken()), address(votingToken), "Incorrect voting token"); address oldToken = address(plugin.getVotingToken()); // New token votingToken = ERC20VotesMock( - createProxyAndCall( - address(VOTING_TOKEN_BASE), - abi.encodeCall(ERC20VotesMock.initialize, ()) - ) + createProxyAndCall(address(VOTING_TOKEN_BASE), abi.encodeCall(ERC20VotesMock.initialize, ())) ); // Deploy a new plugin instance - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); - assertEq( - address(plugin.getVotingToken()), - address(votingToken), - "Incorrect voting token" - ); - assertEq( - address(votingToken) != oldToken, - true, - "The token address sould have changed" - ); + assertEq(address(plugin.getVotingToken()), address(votingToken), "Incorrect voting token"); + assertEq(address(votingToken) != oldToken, true, "The token address sould have changed"); } function test_TotalVotingPowerReturnsTheRightSupply() public { @@ -327,38 +218,27 @@ contract OptimisticTokenVotingPluginTest is AragonTest { votingToken.getPastTotalSupply(block.number - 1), "Incorrect total voting power" ); - assertEq( - plugin.totalVotingPower(block.number - 1), - 10 ether, - "Incorrect total voting power" - ); + assertEq(plugin.totalVotingPower(block.number - 1), 10 ether, "Incorrect total voting power"); // New token votingToken = ERC20VotesMock( - createProxyAndCall( - address(VOTING_TOKEN_BASE), - abi.encodeCall(ERC20VotesMock.initialize, ()) - ) + createProxyAndCall(address(VOTING_TOKEN_BASE), abi.encodeCall(ERC20VotesMock.initialize, ())) ); votingToken.mint(alice, 15 ether); vm.roll(block.number + 1); // Deploy a new plugin instance - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); @@ -367,65 +247,45 @@ contract OptimisticTokenVotingPluginTest is AragonTest { votingToken.getPastTotalSupply(block.number - 1), "Incorrect total voting power" ); - assertEq( - plugin.totalVotingPower(block.number - 1), - 15 ether, - "Incorrect total voting power" - ); + assertEq(plugin.totalVotingPower(block.number - 1), 15 ether, "Incorrect total voting power"); } function test_MinVetoRatioReturnsTheRightValue() public { - assertEq( - plugin.minVetoRatio(), - uint32(RATIO_BASE / 10), - "Incorrect minVetoRatio" - ); + assertEq(plugin.minVetoRatio(), uint32(RATIO_BASE / 10), "Incorrect minVetoRatio"); // New plugin instance - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 5), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 5), + minDuration: 10 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); - assertEq( - plugin.minVetoRatio(), - uint32(RATIO_BASE / 5), - "Incorrect minVetoRatio" - ); + assertEq(plugin.minVetoRatio(), uint32(RATIO_BASE / 5), "Incorrect minVetoRatio"); } function test_MinDurationReturnsTheRightValue() public { assertEq(plugin.minDuration(), 10 days, "Incorrect minDuration"); // New plugin instance - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 5), - minDuration: 25 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 5), + minDuration: 25 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); @@ -433,94 +293,64 @@ contract OptimisticTokenVotingPluginTest is AragonTest { } function test_MinProposerVotingPowerReturnsTheRightValue() public { - assertEq( - plugin.minProposerVotingPower(), - 0, - "Incorrect minProposerVotingPower" - ); + assertEq(plugin.minProposerVotingPower(), 0, "Incorrect minProposerVotingPower"); // New token votingToken = ERC20VotesMock( - createProxyAndCall( - address(VOTING_TOKEN_BASE), - abi.encodeCall(ERC20VotesMock.initialize, ()) - ) + createProxyAndCall(address(VOTING_TOKEN_BASE), abi.encodeCall(ERC20VotesMock.initialize, ())) ); votingToken.mint(alice, 10 ether); vm.roll(block.number + 1); // Deploy a new plugin instance - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 1 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 1 ether + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); - assertEq( - plugin.minProposerVotingPower(), - 1 ether, - "Incorrect minProposerVotingPower" - ); + assertEq(plugin.minProposerVotingPower(), 1 ether, "Incorrect minProposerVotingPower"); } function test_TokenHoldersAreMembers() public { assertEq(plugin.isMember(alice), true, "Alice should not be a member"); assertEq(plugin.isMember(bob), false, "Bob should not be a member"); - assertEq( - plugin.isMember(randomWallet), - false, - "Random wallet should not be a member" - ); + assertEq(plugin.isMember(randomWallet), false, "Random wallet should not be a member"); // New token votingToken = ERC20VotesMock( - createProxyAndCall( - address(VOTING_TOKEN_BASE), - abi.encodeCall(ERC20VotesMock.initialize, ()) - ) + createProxyAndCall(address(VOTING_TOKEN_BASE), abi.encodeCall(ERC20VotesMock.initialize, ())) ); votingToken.mint(alice, 10 ether); votingToken.mint(bob, 5 ether); vm.roll(block.number + 1); // Deploy a new plugin instance - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 1 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 1 ether + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); assertEq(plugin.isMember(alice), true, "Alice should be a member"); assertEq(plugin.isMember(bob), true, "Bob should be a member"); - assertEq( - plugin.isMember(randomWallet), - false, - "Random wallet should not be a member" - ); + assertEq(plugin.isMember(randomWallet), false, "Random wallet should not be a member"); } // Create proposal @@ -530,11 +360,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { IDAO.Action[] memory actions = new IDAO.Action[](0); vm.expectRevert( abi.encodeWithSelector( - DaoUnauthorized.selector, - address(dao), - address(plugin), - bob, - plugin.PROPOSER_PERMISSION_ID() + DaoUnauthorized.selector, address(dao), address(plugin), bob, plugin.PROPOSER_PERMISSION_ID() ) ); plugin.createProposal("", actions, 0, 0, 0); @@ -559,38 +385,26 @@ contract OptimisticTokenVotingPluginTest is AragonTest { assertEq(proposalId, 1); } - function test_CreateProposalRevertsWhenTheCallerOwnsLessThanTheMinimumVotingPower() - public - { + function test_CreateProposalRevertsWhenTheCallerOwnsLessThanTheMinimumVotingPower() public { vm.stopPrank(); vm.startPrank(alice); IDAO.Action[] memory actions = new IDAO.Action[](0); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory newSettings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 5 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory newSettings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 5 ether + }); dao.grant(address(plugin), bob, plugin.PROPOSER_PERMISSION_ID()); - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); plugin.updateOptimisticGovernanceSettings(newSettings); vm.stopPrank(); vm.startPrank(bob); // Bob holds no tokens - vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalCreationForbidden.selector, - bob - ) - ); + vm.expectRevert(abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalCreationForbidden.selector, bob)); plugin.createProposal("", actions, 0, 0, 0); } @@ -600,53 +414,36 @@ contract OptimisticTokenVotingPluginTest is AragonTest { // Deploy ERC20 token (0 supply) votingToken = ERC20VotesMock( - createProxyAndCall( - address(VOTING_TOKEN_BASE), - abi.encodeCall(ERC20VotesMock.initialize, ()) - ) + createProxyAndCall(address(VOTING_TOKEN_BASE), abi.encodeCall(ERC20VotesMock.initialize, ())) ); // Deploy a new plugin instance IDAO.Action[] memory actions = new IDAO.Action[](0); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 10 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); dao.grant(address(plugin), alice, plugin.PROPOSER_PERMISSION_ID()); // Try to create - vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.NoVotingPower.selector - ) - ); + vm.expectRevert(abi.encodeWithSelector(OptimisticTokenVotingPlugin.NoVotingPower.selector)); plugin.createProposal("", actions, 0, 0, 0); } - function test_CreateProposalRevertsIfTheStartDateIsAfterTheEndDate() - public - { + function test_CreateProposalRevertsIfTheStartDateIsAfterTheEndDate() public { IDAO.Action[] memory actions = new IDAO.Action[](0); uint32 startDate = 200000; uint32 endDate = 10; vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.DateOutOfBounds.selector, - startDate + 10 days, - endDate - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.DateOutOfBounds.selector, startDate + 10 days, endDate) ); plugin.createProposal("", actions, 0, startDate, endDate); } @@ -656,37 +453,23 @@ contract OptimisticTokenVotingPluginTest is AragonTest { IDAO.Action[] memory actions = new IDAO.Action[](0); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.DateOutOfBounds.selector, - block.timestamp, - 1 - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.DateOutOfBounds.selector, block.timestamp, 1) ); uint32 startDate = 1; plugin.createProposal("", actions, 0, startDate, startDate + 10 days); } - function test_CreateProposalRevertsIfEndDateIsEarlierThanMinDuration() - public - { + function test_CreateProposalRevertsIfEndDateIsEarlierThanMinDuration() public { vm.warp(500); // timestamp = 500 IDAO.Action[] memory actions = new IDAO.Action[](0); uint32 startDate = 1000; vm.expectRevert( abi.encodeWithSelector( - OptimisticTokenVotingPlugin.DateOutOfBounds.selector, - startDate + 10 days, - startDate + 10 minutes + OptimisticTokenVotingPlugin.DateOutOfBounds.selector, startDate + 10 days, startDate + 10 minutes ) ); - plugin.createProposal( - "", - actions, - 0, - startDate, - startDate + 10 minutes - ); + plugin.createProposal("", actions, 0, startDate, startDate + 10 minutes); } function test_CreateProposalStartsNowWhenStartDateIsZero() public { @@ -694,22 +477,9 @@ contract OptimisticTokenVotingPluginTest is AragonTest { IDAO.Action[] memory actions = new IDAO.Action[](0); uint32 startDate = 0; - uint256 proposalId = plugin.createProposal( - "", - actions, - 0, - startDate, - 0 - ); - - ( - , - , - OptimisticTokenVotingPlugin.ProposalParameters memory parameters, - , - , + uint256 proposalId = plugin.createProposal("", actions, 0, startDate, 0); - ) = plugin.getProposal(proposalId); + (,, OptimisticTokenVotingPlugin.ProposalParameters memory parameters,,,) = plugin.getProposal(proposalId); assertEq(500, parameters.startDate, "Incorrect startDate"); } @@ -719,22 +489,9 @@ contract OptimisticTokenVotingPluginTest is AragonTest { IDAO.Action[] memory actions = new IDAO.Action[](0); uint32 startDate = 0; uint32 endDate = 0; - uint256 proposalId = plugin.createProposal( - "", - actions, - 0, - startDate, - endDate - ); - - ( - , - , - OptimisticTokenVotingPlugin.ProposalParameters memory parameters, - , - , + uint256 proposalId = plugin.createProposal("", actions, 0, startDate, endDate); - ) = plugin.getProposal(proposalId); + (,, OptimisticTokenVotingPlugin.ProposalParameters memory parameters,,,) = plugin.getProposal(proposalId); assertEq(500 + 10 days, parameters.endDate, "Incorrect endDate"); } @@ -742,46 +499,27 @@ contract OptimisticTokenVotingPluginTest is AragonTest { IDAO.Action[] memory actions = new IDAO.Action[](0); uint256 proposalId = plugin.createProposal("", actions, 0, 0, 0); - ( - , - , - OptimisticTokenVotingPlugin.ProposalParameters memory parameters, - , - , - - ) = plugin.getProposal(proposalId); - assertEq( - parameters.minVetoVotingPower, - 1 ether, - "Incorrect minVetoVotingPower" - ); + (,, OptimisticTokenVotingPlugin.ProposalParameters memory parameters,,,) = plugin.getProposal(proposalId); + assertEq(parameters.minVetoVotingPower, 1 ether, "Incorrect minVetoVotingPower"); // Now with a different value - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 5), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 5), + minDuration: 10 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); dao.grant(address(plugin), alice, plugin.PROPOSER_PERMISSION_ID()); proposalId = plugin.createProposal("", actions, 0, 0, 0); - (, , parameters, , , ) = plugin.getProposal(proposalId); - assertEq( - parameters.minVetoVotingPower, - 2 ether, - "Incorrect minVetoVotingPower" - ); + (,, parameters,,,) = plugin.getProposal(proposalId); + assertEq(parameters.minVetoVotingPower, 2 ether, "Incorrect minVetoVotingPower"); } function test_CreateProposalReturnsTheProposalId() public { @@ -796,15 +534,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { function test_CreateProposalEmitsAnEvent() public { IDAO.Action[] memory actions = new IDAO.Action[](0); vm.expectEmit(); - emit ProposalCreated( - 0, - alice, - uint64(block.timestamp), - uint64(block.timestamp + 10 days), - "", - actions, - 0 - ); + emit ProposalCreated(0, alice, uint64(block.timestamp), uint64(block.timestamp + 10 days), "", actions, 0); plugin.createProposal("", actions, 0, 0, 0); } @@ -816,21 +546,12 @@ contract OptimisticTokenVotingPluginTest is AragonTest { IDAO.Action[] memory actions = new IDAO.Action[](1); actions[0].to = address(plugin); actions[0].value = 1 wei; - actions[0].data = abi.encodeCall( - OptimisticTokenVotingPlugin.totalVotingPower, - (0) - ); + actions[0].data = abi.encodeCall(OptimisticTokenVotingPlugin.totalVotingPower, (0)); uint256 failSafeBitmap = 1; - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - failSafeBitmap, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, failSafeBitmap, startDate, endDate); - (bool open0, , , , , ) = plugin.getProposal(proposalId); + (bool open0,,,,,) = plugin.getProposal(proposalId); assertEq(open0, false, "The proposal should not be open"); // Move on @@ -857,16 +578,12 @@ contract OptimisticTokenVotingPluginTest is AragonTest { ); assertEq(vetoTally, 0, "The tally should be zero"); assertEq(actualActions.length, 1, "Actions should have one item"); - assertEq( - actualFailSafeBitmap, - failSafeBitmap, - "Incorrect failsafe bitmap" - ); + assertEq(actualFailSafeBitmap, failSafeBitmap, "Incorrect failsafe bitmap"); // Move on vm.warp(endDate); - (bool open1, , , , , ) = plugin.getProposal(proposalId); + (bool open1,,,,,) = plugin.getProposal(proposalId); assertEq(open1, false, "The proposal should not be open anymore"); } @@ -878,17 +595,11 @@ contract OptimisticTokenVotingPluginTest is AragonTest { uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, 0, 0); vm.roll(20); - assertEq( - plugin.canVeto(proposalId, alice), - true, - "Alice should be able to veto" - ); + assertEq(plugin.canVeto(proposalId, alice), true, "Alice should be able to veto"); // non existing assertEq( - plugin.canVeto(proposalId + 200, alice), - false, - "Alice should not be able to veto on non existing proposals" + plugin.canVeto(proposalId + 200, alice), false, "Alice should not be able to veto on non existing proposals" ); } @@ -897,28 +608,14 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); // Unstarted - assertEq( - plugin.canVeto(proposalId, alice), - false, - "Alice should not be able to veto" - ); + assertEq(plugin.canVeto(proposalId, alice), false, "Alice should not be able to veto"); // Started vm.warp(startDate + 1); - assertEq( - plugin.canVeto(proposalId, alice), - true, - "Alice should be able to veto" - ); + assertEq(plugin.canVeto(proposalId, alice), true, "Alice should be able to veto"); } function test_CanVetoReturnsFalseWhenAVoterAlreadyVetoed() public { @@ -926,22 +623,12 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); plugin.veto(proposalId); - assertEq( - plugin.canVeto(proposalId, alice), - false, - "Alice should not be able to veto" - ); + assertEq(plugin.canVeto(proposalId, alice), false, "Alice should not be able to veto"); } function test_CanVetoReturnsFalseWhenAVoterAlreadyEnded() public { @@ -950,20 +637,10 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(endDate + 1); - assertEq( - plugin.canVeto(proposalId, alice), - false, - "Alice should not be able to veto" - ); + assertEq(plugin.canVeto(proposalId, alice), false, "Alice should not be able to veto"); } function test_CanVetoReturnsFalseWhenNoVotingPower() public { @@ -971,29 +648,15 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); // Alice owns tokens - assertEq( - plugin.canVeto(proposalId, alice), - true, - "Alice should be able to veto" - ); + assertEq(plugin.canVeto(proposalId, alice), true, "Alice should be able to veto"); // Bob owns no tokens - assertEq( - plugin.canVeto(proposalId, bob), - false, - "Bob should not be able to veto" - ); + assertEq(plugin.canVeto(proposalId, bob), false, "Bob should not be able to veto"); } function test_CanVetoReturnsTrueOtherwise() public { @@ -1001,20 +664,10 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); - assertEq( - plugin.canVeto(proposalId, alice), - true, - "Alice should be able to veto" - ); + assertEq(plugin.canVeto(proposalId, alice), true, "Alice should be able to veto"); } // Veto @@ -1024,21 +677,13 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.roll(20); // non existing vm.expectRevert( abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, - proposalId + 200, - alice + OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, proposalId + 200, alice ) ); plugin.veto(proposalId + 200); @@ -1049,37 +694,19 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); // Unstarted vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, - proposalId, - alice - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, proposalId, alice) ); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - false, - "Alice should not have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), false, "Alice should not have vetoed"); // Started vm.warp(startDate + 1); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - true, - "Alice should have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), true, "Alice should have vetoed"); } function test_VetoRevertsWhenAVoterAlreadyVetoed() public { @@ -1087,40 +714,18 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); - assertEq( - plugin.hasVetoed(proposalId, alice), - false, - "Alice should not have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), false, "Alice should not have vetoed"); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - true, - "Alice should have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), true, "Alice should have vetoed"); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, - proposalId, - alice - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, proposalId, alice) ); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - true, - "Alice should have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), true, "Alice should have vetoed"); } function test_VetoRevertsWhenAVoterAlreadyEnded() public { @@ -1129,28 +734,14 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(endDate + 1); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, - proposalId, - alice - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, proposalId, alice) ); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - false, - "Alice should not have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), false, "Alice should not have vetoed"); } function test_VetoRevertsWhenNoVotingPower() public { @@ -1158,13 +749,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); @@ -1173,58 +758,34 @@ contract OptimisticTokenVotingPluginTest is AragonTest { // Bob owns no tokens vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, - proposalId, - bob - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalVetoingForbidden.selector, proposalId, bob) ); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, bob), - false, - "Bob should not have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, bob), false, "Bob should not have vetoed"); vm.stopPrank(); vm.startPrank(alice); // Alice owns tokens plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - true, - "Alice should have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), true, "Alice should have vetoed"); } - function test_VetoRegistersAVetoForTheTokenHolderAndIncreasesTheTally() - public - { + function test_VetoRegistersAVetoForTheTokenHolderAndIncreasesTheTally() public { uint64 startDate = 50; vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); - (, , , uint256 tally1, , ) = plugin.getProposal(proposalId); + (,,, uint256 tally1,,) = plugin.getProposal(proposalId); assertEq(tally1, 0, "Tally should be zero"); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - true, - "Alice should have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), true, "Alice should have vetoed"); - (, , , uint256 tally2, , ) = plugin.getProposal(proposalId); + (,,, uint256 tally2,,) = plugin.getProposal(proposalId); assertEq(tally2, 10 ether, "Tally should be 10 eth"); } @@ -1233,13 +794,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); vm.expectEmit(); @@ -1253,26 +808,12 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - 0 - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, 0); vm.warp(startDate + 1); - assertEq( - plugin.hasVetoed(proposalId, alice), - false, - "Alice should not have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), false, "Alice should not have vetoed"); plugin.veto(proposalId); - assertEq( - plugin.hasVetoed(proposalId, alice), - true, - "Alice should have vetoed" - ); + assertEq(plugin.hasVetoed(proposalId, alice), true, "Alice should have vetoed"); } // Can execute @@ -1282,34 +823,16 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable"); vm.warp(startDate + 1); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable"); plugin.veto(proposalId); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable yet" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable yet"); } function test_CanExecuteReturnsFalseWhenDefeated() public { @@ -1318,36 +841,18 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable"); vm.warp(startDate + 1); plugin.veto(proposalId); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable yet" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable yet"); vm.warp(endDate + 1); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable"); } function test_CanExecuteReturnsFalseWhenAlreadyExecuted() public { @@ -1356,28 +861,14 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(endDate + 1); - assertEq( - plugin.canExecute(proposalId), - true, - "The proposal should be executable" - ); + assertEq(plugin.canExecute(proposalId), true, "The proposal should be executable"); plugin.execute(proposalId); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable"); } function test_CanExecuteReturnsTrueOtherwise() public { @@ -1386,45 +877,24 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable"); vm.warp(startDate + 1); - assertEq( - plugin.canExecute(proposalId), - false, - "The proposal shouldn't be executable yet" - ); + assertEq(plugin.canExecute(proposalId), false, "The proposal shouldn't be executable yet"); vm.warp(endDate + 1); - assertEq( - plugin.canExecute(proposalId), - true, - "The proposal should be executable" - ); + assertEq(plugin.canExecute(proposalId), true, "The proposal should be executable"); } // Veto threshold reached function test_IsMinVetoRatioReachedReturnsTheAppropriateValues() public { // Deploy ERC20 token votingToken = ERC20VotesMock( - createProxyAndCall( - address(VOTING_TOKEN_BASE), - abi.encodeCall(ERC20VotesMock.initialize, ()) - ) + createProxyAndCall(address(VOTING_TOKEN_BASE), abi.encodeCall(ERC20VotesMock.initialize, ())) ); votingToken.mint(alice, 24 ether); votingToken.mint(bob, 1 ether); @@ -1443,21 +913,17 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.roll(block.number + 1); // Deploy a new plugin instance - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32((RATIO_BASE * 25) / 100), - minDuration: 10 days, - minProposerVotingPower: 0 - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32((RATIO_BASE * 25) / 100), + minDuration: 10 days, + minProposerVotingPower: 0 + }); plugin = OptimisticTokenVotingPlugin( createProxyAndCall( address(OPTIMISTIC_BASE), - abi.encodeCall( - OptimisticTokenVotingPlugin.initialize, - (dao, settings, votingToken) - ) + abi.encodeCall(OptimisticTokenVotingPlugin.initialize, (dao, settings, votingToken)) ) ); @@ -1473,29 +939,15 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(startDate + 1); - assertEq( - plugin.isMinVetoRatioReached(proposalId), - false, - "The veto threshold shouldn't be met" - ); + assertEq(plugin.isMinVetoRatioReached(proposalId), false, "The veto threshold shouldn't be met"); // Alice vetoes 24% plugin.veto(proposalId); - assertEq( - plugin.isMinVetoRatioReached(proposalId), - false, - "The veto threshold shouldn't be met" - ); + assertEq(plugin.isMinVetoRatioReached(proposalId), false, "The veto threshold shouldn't be met"); vm.stopPrank(); vm.startPrank(bob); @@ -1503,11 +955,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { // Bob vetoes +1% => met plugin.veto(proposalId); - assertEq( - plugin.isMinVetoRatioReached(proposalId), - true, - "The veto threshold should be met" - ); + assertEq(plugin.isMinVetoRatioReached(proposalId), true, "The veto threshold should be met"); vm.stopPrank(); vm.startPrank(randomWallet); @@ -1515,11 +963,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { // Random wallet vetoes +75% => still met plugin.veto(proposalId); - assertEq( - plugin.isMinVetoRatioReached(proposalId), - true, - "The veto threshold should still be met" - ); + assertEq(plugin.isMinVetoRatioReached(proposalId), true, "The veto threshold should still be met"); } // Execute @@ -1529,36 +973,24 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, - proposalId - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, proposalId) ); plugin.execute(proposalId); vm.warp(startDate + 1); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, - proposalId - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, proposalId) ); plugin.execute(proposalId); vm.warp(endDate); plugin.execute(proposalId); - (, bool executed, , , , ) = plugin.getProposal(proposalId); + (, bool executed,,,,) = plugin.getProposal(proposalId); assertEq(executed, true, "The proposal should be executed"); } @@ -1568,37 +1000,25 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(startDate + 1); plugin.veto(proposalId); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, - proposalId - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, proposalId) ); plugin.execute(proposalId); vm.warp(endDate + 1); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, - proposalId - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, proposalId) ); plugin.execute(proposalId); - (, bool executed, , , , ) = plugin.getProposal(proposalId); + (, bool executed,,,,) = plugin.getProposal(proposalId); assertEq(executed, false, "The proposal should not be executed"); } @@ -1608,30 +1028,21 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(endDate + 1); plugin.execute(proposalId); - (, bool executed1, , , , ) = plugin.getProposal(proposalId); + (, bool executed1,,,,) = plugin.getProposal(proposalId); assertEq(executed1, true, "The proposal should be executed"); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, - proposalId - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.ProposalExecutionForbidden.selector, proposalId) ); plugin.execute(proposalId); - (, bool executed2, , , , ) = plugin.getProposal(proposalId); + (, bool executed2,,,,) = plugin.getProposal(proposalId); assertEq(executed2, true, "The proposal should be executed"); } @@ -1641,13 +1052,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(endDate + 1); @@ -1660,19 +1065,13 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(endDate + 1); plugin.execute(proposalId); - (, bool executed2, , , , ) = plugin.getProposal(proposalId); + (, bool executed2,,,,) = plugin.getProposal(proposalId); assertEq(executed2, true, "The proposal should be executed"); } @@ -1682,13 +1081,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.warp(startDate - 1); IDAO.Action[] memory actions = new IDAO.Action[](0); - uint256 proposalId = plugin.createProposal( - "ipfs://", - actions, - 0, - startDate, - endDate - ); + uint256 proposalId = plugin.createProposal("ipfs://", actions, 0, startDate, endDate); vm.warp(endDate + 1); @@ -1698,16 +1091,13 @@ contract OptimisticTokenVotingPluginTest is AragonTest { } // Update settings - function test_UpdateOptimisticGovernanceSettingsRevertsWhenNoPermission() - public - { - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory newSettings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 5), - minDuration: 15 days, - minProposerVotingPower: 1 ether - }); + function test_UpdateOptimisticGovernanceSettingsRevertsWhenNoPermission() public { + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory newSettings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 5), + minDuration: 15 days, + minProposerVotingPower: 1 ether + }); vm.expectRevert( abi.encodeWithSelector( DaoUnauthorized.selector, @@ -1719,85 +1109,44 @@ contract OptimisticTokenVotingPluginTest is AragonTest { ); plugin.updateOptimisticGovernanceSettings(newSettings); - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); plugin.updateOptimisticGovernanceSettings(newSettings); } - function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinVetoRatioIsZero() - public - { - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinVetoRatioIsZero() public { + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory newSettings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: 0, - minDuration: 10 days, - minProposerVotingPower: 0 ether - }); - vm.expectRevert( - abi.encodeWithSelector(RatioOutOfBounds.selector, 1, 0) - ); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory newSettings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({minVetoRatio: 0, minDuration: 10 days, minProposerVotingPower: 0 ether}); + vm.expectRevert(abi.encodeWithSelector(RatioOutOfBounds.selector, 1, 0)); plugin.updateOptimisticGovernanceSettings(newSettings); } - function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinVetoRatioIsAboveTheMaximum() - public - { - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinVetoRatioIsAboveTheMaximum() public { + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory newSettings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE + 1), - minDuration: 10 days, - minProposerVotingPower: 0 ether - }); - vm.expectRevert( - abi.encodeWithSelector( - RatioOutOfBounds.selector, - RATIO_BASE, - uint32(RATIO_BASE + 1) - ) - ); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory newSettings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE + 1), + minDuration: 10 days, + minProposerVotingPower: 0 ether + }); + vm.expectRevert(abi.encodeWithSelector(RatioOutOfBounds.selector, RATIO_BASE, uint32(RATIO_BASE + 1))); plugin.updateOptimisticGovernanceSettings(newSettings); } - function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinDurationIsLessThanFourDays() - public - { - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinDurationIsLessThanFourDays() public { + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory newSettings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 4 days - 1, - minProposerVotingPower: 0 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory newSettings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 4 days - 1, + minProposerVotingPower: 0 ether + }); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, - 4 days, - 4 days - 1 - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, 4 days, 4 days - 1) ); plugin.updateOptimisticGovernanceSettings(newSettings); @@ -1808,11 +1157,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { minProposerVotingPower: 0 ether }); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, - 4 days, - 10 hours - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, 4 days, 10 hours) ); plugin.updateOptimisticGovernanceSettings(newSettings); @@ -1822,38 +1167,21 @@ contract OptimisticTokenVotingPluginTest is AragonTest { minDuration: 0, minProposerVotingPower: 0 ether }); - vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, - 4 days, - 0 - ) - ); + vm.expectRevert(abi.encodeWithSelector(OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, 4 days, 0)); plugin.updateOptimisticGovernanceSettings(newSettings); } - function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinDurationIsMoreThanOneYear() - public - { - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + function test_UpdateOptimisticGovernanceSettingsRevertsWhenTheMinDurationIsMoreThanOneYear() public { + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory newSettings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 10), - minDuration: 365 days + 1, - minProposerVotingPower: 0 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory newSettings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 10), + minDuration: 365 days + 1, + minProposerVotingPower: 0 ether + }); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, - 365 days, - 365 days + 1 - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, 365 days, 365 days + 1) ); plugin.updateOptimisticGovernanceSettings(newSettings); @@ -1864,11 +1192,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { minProposerVotingPower: 0 ether }); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, - 365 days, - 500 days - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, 365 days, 500 days) ); plugin.updateOptimisticGovernanceSettings(newSettings); @@ -1879,31 +1203,20 @@ contract OptimisticTokenVotingPluginTest is AragonTest { minProposerVotingPower: 0 ether }); vm.expectRevert( - abi.encodeWithSelector( - OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, - 365 days, - 1000 days - ) + abi.encodeWithSelector(OptimisticTokenVotingPlugin.MinDurationOutOfBounds.selector, 365 days, 1000 days) ); plugin.updateOptimisticGovernanceSettings(newSettings); } - function test_UpdateOptimisticGovernanceSettingsEmitsAnEventWhenSuccessful() - public - { - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + function test_UpdateOptimisticGovernanceSettingsEmitsAnEventWhenSuccessful() public { + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory newSettings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 5), - minDuration: 15 days, - minProposerVotingPower: 1 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory newSettings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 5), + minDuration: 15 days, + minProposerVotingPower: 1 ether + }); vm.expectEmit(); emit OptimisticGovernanceSettingsUpdated({ @@ -1921,11 +1234,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest { vm.expectRevert( abi.encodeWithSelector( - DaoUnauthorized.selector, - address(dao), - address(plugin), - alice, - plugin.UPGRADE_PLUGIN_PERMISSION_ID() + DaoUnauthorized.selector, address(dao), address(plugin), alice, plugin.UPGRADE_PLUGIN_PERMISSION_ID() ) ); @@ -1933,47 +1242,30 @@ contract OptimisticTokenVotingPluginTest is AragonTest { } function test_UpgradeToAndCallRevertsWhenCalledFromNonUpgrader() public { - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); address _pluginBase = address(new OptimisticTokenVotingPlugin()); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 5), - minDuration: 15 days, - minProposerVotingPower: 1 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 5), + minDuration: 15 days, + minProposerVotingPower: 1 ether + }); vm.expectRevert( abi.encodeWithSelector( - DaoUnauthorized.selector, - address(dao), - address(plugin), - alice, - plugin.UPGRADE_PLUGIN_PERMISSION_ID() + DaoUnauthorized.selector, address(dao), address(plugin), alice, plugin.UPGRADE_PLUGIN_PERMISSION_ID() ) ); plugin.upgradeToAndCall( - _pluginBase, - abi.encodeCall( - OptimisticTokenVotingPlugin.updateOptimisticGovernanceSettings, - (settings) - ) + _pluginBase, abi.encodeCall(OptimisticTokenVotingPlugin.updateOptimisticGovernanceSettings, (settings)) ); } function test_UpgradeToSucceedsWhenCalledFromUpgrader() public { - dao.grant( - address(plugin), - alice, - plugin.UPGRADE_PLUGIN_PERMISSION_ID() - ); + dao.grant(address(plugin), alice, plugin.UPGRADE_PLUGIN_PERMISSION_ID()); address _pluginBase = address(new OptimisticTokenVotingPlugin()); @@ -1984,35 +1276,22 @@ contract OptimisticTokenVotingPluginTest is AragonTest { } function test_UpgradeToAndCallSucceedsWhenCalledFromUpgrader() public { - dao.grant( - address(plugin), - alice, - plugin.UPGRADE_PLUGIN_PERMISSION_ID() - ); - dao.grant( - address(plugin), - alice, - plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID() - ); + dao.grant(address(plugin), alice, plugin.UPGRADE_PLUGIN_PERMISSION_ID()); + dao.grant(address(plugin), alice, plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()); address _pluginBase = address(new OptimisticTokenVotingPlugin()); vm.expectEmit(); emit Upgraded(_pluginBase); - OptimisticTokenVotingPlugin.OptimisticGovernanceSettings - memory settings = OptimisticTokenVotingPlugin - .OptimisticGovernanceSettings({ - minVetoRatio: uint32(RATIO_BASE / 5), - minDuration: 15 days, - minProposerVotingPower: 1 ether - }); + OptimisticTokenVotingPlugin.OptimisticGovernanceSettings memory settings = OptimisticTokenVotingPlugin + .OptimisticGovernanceSettings({ + minVetoRatio: uint32(RATIO_BASE / 5), + minDuration: 15 days, + minProposerVotingPower: 1 ether + }); plugin.upgradeToAndCall( - _pluginBase, - abi.encodeCall( - OptimisticTokenVotingPlugin.updateOptimisticGovernanceSettings, - (settings) - ) + _pluginBase, abi.encodeCall(OptimisticTokenVotingPlugin.updateOptimisticGovernanceSettings, (settings)) ); } }