Skip to content

Commit

Permalink
Effective and bridged tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed May 24, 2024
1 parent e7af295 commit 6c656fb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/OptimisticTokenVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ contract OptimisticTokenVotingPlugin is
}
// Check if L2 bridged vetoes are still possible
// For emergency multisig proposals with _duration == 0, this will return false because the L2 aggregation is skipped
else if (_proposalL2VetoingOpen(proposal_)) {
else if (_proposalL2VetoAggregationOpen(proposal_)) {
return false;
}
// Check that not enough voters have vetoed the proposal
Expand All @@ -285,7 +285,7 @@ contract OptimisticTokenVotingPlugin is
function isMinVetoRatioReached(uint256 _proposalId) public view virtual returns (bool) {
Proposal storage proposal_ = proposals[_proposalId];

bool _usingL2VotingPower = _proposalCanUseL2VotingPower(proposal_);
bool _usingL2VotingPower = _proposalUsesL2Vetoes(proposal_);
uint256 _totalVotingPower = effectiveVotingPower(proposal_.parameters.snapshotTimestamp, _usingL2VotingPower);
uint256 _minVetoPower = _applyRatioCeiled(_totalVotingPower, proposal_.parameters.minVetoRatio);
return proposal_.vetoTally >= _minVetoPower;
Expand Down Expand Up @@ -525,8 +525,8 @@ contract OptimisticTokenVotingPlugin is

/// @notice Determines whether the proposal has L2 voting enabled or not.
/// @param proposal_ The proposal
function _proposalCanUseL2VotingPower(Proposal storage proposal_) internal view returns (bool) {
if (_proposalL2VetoingOpen(proposal_)) {
function _proposalUsesL2Vetoes(Proposal storage proposal_) internal view returns (bool) {
if (_proposalL2VetoAggregationOpen(proposal_)) {
return true;
}

Expand All @@ -538,7 +538,7 @@ contract OptimisticTokenVotingPlugin is
/// @notice Internal function to check if a proposal may still receive L2 vetoes.
/// @param proposal_ The proposal struct.
/// @return True if the proposal may still receive L2 bridged votes, false otherwise.
function _proposalL2VetoingOpen(Proposal storage proposal_) internal view virtual returns (bool) {
function _proposalL2VetoAggregationOpen(Proposal storage proposal_) internal view virtual returns (bool) {
if (proposal_.parameters.skipL2) {
return false;
}
Expand Down
73 changes: 72 additions & 1 deletion test/OptimisticTokenVotingPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,77 @@ contract OptimisticTokenVotingPluginTest is AragonTest {
assertEq(votingToken.getPastTotalSupply(block.timestamp - 1), 180.1234 ether, "Incorrect past supply");
}

function test_BridgedVotingPowerReturnsTheRightValue() public {
// No bridged tokens
assertEq(optimisticPlugin.bridgedVotingPower(block.timestamp - 1), 0, "Incorrect bridged voting power");
assertEq(votingToken.getPastVotes(taikoBridge, block.timestamp - 1), 0, "Incorrect past votes");
assertEq(votingToken.getPastTotalSupply(block.timestamp - 1), 10 ether, "Incorrect past supply");

// 1 bridged tokens
builder = new DaoBuilder();
(, optimisticPlugin,,, votingToken,) =
builder.withTokenHolder(alice, 10 ether).withTokenHolder(taikoBridge, 10 ether).build();

assertEq(optimisticPlugin.bridgedVotingPower(block.timestamp - 1), 10 ether, "Incorrect bridged voting power");
assertEq(votingToken.getPastVotes(taikoBridge, block.timestamp - 1), 10 ether, "Incorrect past votes");
assertEq(votingToken.getPastTotalSupply(block.timestamp - 1), 20 ether, "Incorrect past supply");

// 2 bridged tokens
builder = new DaoBuilder();
(, optimisticPlugin,,, votingToken,) = builder.withTokenHolder(alice, 10 ether).withTokenHolder(bob, 1 ether)
.withTokenHolder(taikoBridge, 1).build();

assertEq(optimisticPlugin.bridgedVotingPower(block.timestamp - 1), 1, "Incorrect bridged voting power");
assertEq(votingToken.getPastVotes(taikoBridge, block.timestamp - 1), 1, "Incorrect past votes");
assertEq(votingToken.getPastTotalSupply(block.timestamp - 1), 11 ether + 1, "Incorrect past supply");
}

function test_EffectiveVotingPowerReturnsTheRightValue() public {
// No bridged tokens
assertEq(
optimisticPlugin.effectiveVotingPower(block.timestamp - 1, false),
10 ether,
"Incorrect effective voting power"
);
assertEq(
optimisticPlugin.effectiveVotingPower(block.timestamp - 1, true),
10 ether,
"Incorrect effective voting power"
);

// 1 bridged tokens
builder = new DaoBuilder();
(, optimisticPlugin,,, votingToken,) =
builder.withTokenHolder(alice, 10 ether).withTokenHolder(taikoBridge, 10 ether).build();

assertEq(
optimisticPlugin.effectiveVotingPower(block.timestamp - 1, false),
10 ether,
"Incorrect effective voting power"
);
assertEq(
optimisticPlugin.effectiveVotingPower(block.timestamp - 1, true),
20 ether,
"Incorrect effective voting power"
);

// 2 bridged tokens
builder = new DaoBuilder();
(, optimisticPlugin,,, votingToken,) = builder.withTokenHolder(alice, 10 ether).withTokenHolder(bob, 1 ether)
.withTokenHolder(taikoBridge, 1234).build();

assertEq(
optimisticPlugin.effectiveVotingPower(block.timestamp - 1, false),
11 ether,
"Incorrect effective voting power"
);
assertEq(
optimisticPlugin.effectiveVotingPower(block.timestamp - 1, true),
11 ether + 1234,
"Incorrect effective voting power"
);
}

function test_MinVetoRatioReturnsTheRightValue() public {
assertEq(optimisticPlugin.minVetoRatio(), uint32(RATIO_BASE / 10), "Incorrect minVetoRatio");

Expand Down Expand Up @@ -1596,7 +1667,7 @@ contract OptimisticTokenVotingPluginTest is AragonTest {
(open, executed, parameters,,,,) = optimisticPlugin.getProposal(proposalId);

assertEq(open, false, "Open should be false");
assertEq(executed, true, "Executed should be true");
assertEq(executed, false, "Executed should be false");
assertEq(parameters.skipL2, false, "SkipL2 should be false");

// Grace period over
Expand Down

0 comments on commit 6c656fb

Please sign in to comment.