Skip to content

Commit

Permalink
Adapting the tests to the new spec
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed May 28, 2024
1 parent 89be576 commit b1e4ef4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 402 deletions.
27 changes: 3 additions & 24 deletions packages/contracts/src/governance/MainVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
proposal_.parameters.snapshotBlock = snapshotBlock;
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
proposal_.parameters.minVotingPower = _applyRatioCeiled(
totalVotingPower(snapshotBlock),
minParticipation()
);
proposalCreators[proposalId] = msg.sender;

// Reduce costs
Expand Down Expand Up @@ -261,10 +257,6 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
proposal_.parameters.snapshotBlock = snapshotBlock;
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
proposal_.parameters.minVotingPower = _applyRatioCeiled(
totalVotingPower(snapshotBlock),
minParticipation()
);
proposal_.actions.push(
IDAO.Action({
to: _spacePlugin,
Expand Down Expand Up @@ -309,10 +301,6 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
proposal_.parameters.snapshotBlock = snapshotBlock;
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
proposal_.parameters.minVotingPower = _applyRatioCeiled(
totalVotingPower(snapshotBlock),
minParticipation()
);
IDAO.Action memory _action = IDAO.Action({
to: _spacePlugin,
value: 0,
Expand Down Expand Up @@ -361,10 +349,6 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
proposal_.parameters.snapshotBlock = snapshotBlock;
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
proposal_.parameters.minVotingPower = _applyRatioCeiled(
totalVotingPower(snapshotBlock),
minParticipation()
);
IDAO.Action memory _action = IDAO.Action({
to: _spacePlugin,
value: 0,
Expand Down Expand Up @@ -392,7 +376,7 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
bytes calldata _metadata,
address _proposedMember
) public onlyMembers {
if (!isEditor(msg.sender)) {
if (!isMember(msg.sender)) {
revert ProposalCreationForbidden(msg.sender);
} else if (!isMember(_proposedMember)) {
revert AlreadyNotMember(_proposedMember);
Expand All @@ -413,10 +397,6 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
proposal_.parameters.snapshotBlock = snapshotBlock;
proposal_.parameters.votingMode = votingMode();
proposal_.parameters.supportThreshold = supportThreshold();
proposal_.parameters.minVotingPower = _applyRatioCeiled(
totalVotingPower(snapshotBlock),
minParticipation()
);
IDAO.Action memory _action = IDAO.Action({
to: address(this),
value: 0,
Expand Down Expand Up @@ -445,9 +425,8 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
if (proposal_.tally.yes == 0 && proposal_.tally.no == 0 && proposal_.tally.abstain == 0) {
return false;
}

// Just one voter
if (addresslistLengthAtBlock(proposal_.parameters.snapshotBlock) == 1) {
// Just one voter?
else if (addresslistLengthAtBlock(proposal_.parameters.snapshotBlock) == 1) {
return true;
}

Expand Down
37 changes: 3 additions & 34 deletions packages/contracts/src/governance/base/MajorityVotingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,10 @@ abstract contract MajorityVotingBase is
/// @notice A container for the majority voting settings that will be applied as parameters on proposal creation.
/// @param votingMode A parameter to select the vote mode. In standard mode (0), early execution and vote replacement are disabled. In early execution mode (1), a proposal can be executed early before the end date if the vote outcome cannot mathematically change by more voters voting. In vote replacement mode (2), voters can change their vote multiple times and only the latest vote option is tallied.
/// @param supportThreshold The support threshold value. Its value has to be in the interval [0, 10^6] defined by `RATIO_BASE = 10**6`.
/// @param minParticipation The minimum participation value. Its value has to be in the interval [0, 10^6] defined by `RATIO_BASE = 10**6`.
/// @param duration The duration of proposals in seconds.
struct VotingSettings {
VotingMode votingMode;
uint32 supportThreshold;
uint32 minParticipation;
uint64 duration;
}

Expand Down Expand Up @@ -149,14 +147,12 @@ abstract contract MajorityVotingBase is
/// @param startDate The start date of the proposal vote.
/// @param endDate The end date of the proposal vote.
/// @param snapshotBlock The number of the block prior to the proposal creation.
/// @param minVotingPower The minimum voting power needed.
struct ProposalParameters {
VotingMode votingMode;
uint32 supportThreshold;
uint64 startDate;
uint64 endDate;
uint64 snapshotBlock;
uint256 minVotingPower;
}

/// @notice A container for the proposal vote tally.
Expand Down Expand Up @@ -219,14 +215,8 @@ abstract contract MajorityVotingBase is
/// @notice Emitted when the voting settings are updated.
/// @param votingMode A parameter to select the vote mode.
/// @param supportThreshold The support threshold value.
/// @param minParticipation The minimum participation value.
/// @param duration The minimum duration of the proposal vote in seconds.
event VotingSettingsUpdated(
VotingMode votingMode,
uint32 supportThreshold,
uint32 minParticipation,
uint64 duration
);
event VotingSettingsUpdated(VotingMode votingMode, uint32 supportThreshold, uint64 duration);

/// @notice Initializes the component to be used by inheriting contracts.
/// @dev This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).
Expand Down Expand Up @@ -333,26 +323,13 @@ abstract contract MajorityVotingBase is
}

/// @inheritdoc IMajorityVoting
function isMinParticipationReached(uint256 _proposalId) public view virtual returns (bool) {
Proposal storage proposal_ = proposals[_proposalId];

// The code below implements the formula of the participation criterion explained in the top of this file.
// `N_yes + N_no + N_abstain >= minVotingPower = minParticipation * N_total`
return
proposal_.tally.yes + proposal_.tally.no + proposal_.tally.abstain >=
proposal_.parameters.minVotingPower;
}
function isMinParticipationReached(uint256 _proposalId) public view virtual returns (bool);

/// @inheritdoc IMajorityVoting
function supportThreshold() public view virtual returns (uint32) {
return votingSettings.supportThreshold;
}

/// @inheritdoc IMajorityVoting
function minParticipation() public view virtual returns (uint32) {
return votingSettings.minParticipation;
}

/// @notice Returns the minimum duration parameter stored in the voting settings.
/// @return The minimum duration parameter.
function duration() public view virtual returns (uint64) {
Expand Down Expand Up @@ -517,16 +494,9 @@ abstract contract MajorityVotingBase is
});
}

// Require the minimum participation value to be in the interval [0, 10^6], because `>=` comparision is used in the participation criterion.
if (_votingSettings.minParticipation > RATIO_BASE) {
revert RatioOutOfBounds({limit: RATIO_BASE, actual: _votingSettings.minParticipation});
}

if (_votingSettings.duration < 60 minutes) {
revert DurationOutOfBounds({limit: 60 minutes, actual: _votingSettings.duration});
}

if (_votingSettings.duration > 365 days) {
} else if (_votingSettings.duration > 365 days) {
revert DurationOutOfBounds({limit: 365 days, actual: _votingSettings.duration});
}

Expand All @@ -535,7 +505,6 @@ abstract contract MajorityVotingBase is
emit VotingSettingsUpdated({
votingMode: _votingSettings.votingMode,
supportThreshold: _votingSettings.supportThreshold,
minParticipation: _votingSettings.minParticipation,
duration: _votingSettings.duration
});
}
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts/test/unit-testing/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ export enum VotingMode {
export type VotingSettings = {
votingMode: number;
supportThreshold: BigNumber;
minParticipation: BigNumber;
duration: number;
};

export const defaultMainVotingSettings: VotingSettings = {
duration: 60 * 60, // 1 second
minParticipation: pctToRatio(30), // 30%
supportThreshold: pctToRatio(50), // 50% + 1
votingMode: VotingMode.EarlyExecution,
};
Loading

0 comments on commit b1e4ef4

Please sign in to comment.