Skip to content

Commit

Permalink
Increasing the code coverage, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed May 23, 2024
1 parent b80ca5d commit 7535266
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 47 deletions.
7 changes: 6 additions & 1 deletion src/OptimisticTokenVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ contract OptimisticTokenVotingPlugin is
/// @param account The address of the _account.
error ProposalVetoingForbidden(uint256 proposalId, address account);

/// @notice Thrown if the Bridge attempts to cast a veto directly. A dedicated function for relayed votes must be used instead.
error BridgeDirectVetoForbidden();

/// @notice Thrown if the proposal execution is forbidden.
/// @param proposalId The ID of the proposal.
error ProposalExecutionForbidden(uint256 proposalId);
Expand Down Expand Up @@ -329,7 +332,7 @@ contract OptimisticTokenVotingPlugin is
}

// Checks
bool _enableL2 = isL2Available();
bool _enableL2 = votingToken.getPastVotes(taikoBridge, snapshotTimestamp) > 0 && isL2Available();
if (effectiveVotingPower(snapshotTimestamp, _enableL2) == 0) {
revert NoVotingPower();
}
Expand Down Expand Up @@ -385,6 +388,8 @@ contract OptimisticTokenVotingPlugin is

if (!canVeto(_proposalId, _voter)) {
revert ProposalVetoingForbidden({proposalId: _proposalId, account: _voter});
} else if (_voter == taikoBridge) {
revert BridgeDirectVetoForbidden();
}

Proposal storage proposal_ = proposals[_proposalId];
Expand Down
17 changes: 10 additions & 7 deletions test/EmergencyMultisig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ contract EmergencyMultisigTest is AragonTest {

function setUp() public {
switchTo(alice);
setTime(1 days);
setBlock(100);

builder = new DaoBuilder();
(dao, optimisticPlugin, stdMultisig, eMultisig,,) = builder.withMultisigMember(alice).withMultisigMember(bob)
Expand Down Expand Up @@ -1391,7 +1393,7 @@ contract EmergencyMultisigTest is AragonTest {
eMultisig.approve(pid);
assertEq(eMultisig.canExecute(pid), true, "Should be true");

setTime(EMERGENCY_MULTISIG_PROPOSAL_EXPIRATION_PERIOD + 1);
timeForward(EMERGENCY_MULTISIG_PROPOSAL_EXPIRATION_PERIOD);

vm.expectRevert(abi.encodeWithSelector(EmergencyMultisig.ProposalExecutionForbidden.selector, pid));
eMultisig.execute(pid, actions);
Expand All @@ -1409,7 +1411,7 @@ contract EmergencyMultisigTest is AragonTest {
eMultisig.approve(pid);
assertEq(eMultisig.canExecute(pid), true, "Should be true");

setTime(100 days + EMERGENCY_MULTISIG_PROPOSAL_EXPIRATION_PERIOD + 1);
timeForward(EMERGENCY_MULTISIG_PROPOSAL_EXPIRATION_PERIOD);

vm.expectRevert(abi.encodeWithSelector(EmergencyMultisig.ProposalExecutionForbidden.selector, pid));
eMultisig.execute(pid, actions);
Expand Down Expand Up @@ -1443,7 +1445,7 @@ contract EmergencyMultisigTest is AragonTest {
function test_ExecuteEmitsEvents() public {
// emits the `ProposalExecuted` and `ProposalCreated` events

setTime(10);
setTime(5 days);
vm.deal(address(dao), 1 ether);

IDAO.Action[] memory actions = new IDAO.Action[](0);
Expand All @@ -1465,8 +1467,8 @@ contract EmergencyMultisigTest is AragonTest {
vm.expectEmit();
emit Executed(pid);
vm.expectEmit();
uint256 targetPid = 10 << 128 | 10 << 64;
emit ProposalCreated(targetPid, address(eMultisig), 10, 10, "", actions, 0);
uint256 targetPid = 5 days << 128 | 5 days << 64;
emit ProposalCreated(targetPid, address(eMultisig), 5 days, 5 days, "", actions, 0);
eMultisig.execute(pid, actions);

// 2
Expand Down Expand Up @@ -1799,7 +1801,7 @@ contract EmergencyMultisigTest is AragonTest {
IDAO.Action[] memory retrievedActions;
uint256 allowFailureMap;

setTime(10);
setTime(10 days);

vm.deal(address(dao), 100 ether);

Expand Down Expand Up @@ -1853,6 +1855,7 @@ contract EmergencyMultisigTest is AragonTest {
assertEq(allowFailureMap, 0, "Should be 0");

// New proposal
setTime(15 days);

submittedActions = new IDAO.Action[](2);
submittedActions[1].to = address(dao);
Expand Down Expand Up @@ -1883,7 +1886,7 @@ contract EmergencyMultisigTest is AragonTest {
assertEq(executed, true, "Should be executed");
assertEq(vetoTally, 0, "Should be 0");

assertEq(parameters.vetoEndDate, 10, "Incorrect vetoEndDate");
assertEq(parameters.vetoEndDate, 15 days, "Incorrect vetoEndDate");
assertEq(parameters.metadataUri, "ipfs://more-metadata", "Incorrect target metadataUri");

assertEq(retrievedActions.length, 2, "Should be 2");
Expand Down
26 changes: 14 additions & 12 deletions test/Multisig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ contract MultisigTest is AragonTest {

function setUp() public {
switchTo(alice);
setTime(1 days);
setBlock(100);

builder = new DaoBuilder();
(dao, optimisticPlugin, multisig,,,) = builder.withMultisigMember(alice).withMultisigMember(bob)
Expand Down Expand Up @@ -933,7 +935,7 @@ contract MultisigTest is AragonTest {
creator: alice,
metadata: "",
startDate: uint64(block.timestamp),
endDate: 10 days + 1,
endDate: uint64(block.timestamp) + 10 days,
actions: actions,
allowFailureMap: 0
});
Expand All @@ -954,7 +956,7 @@ contract MultisigTest is AragonTest {
creator: bob,
metadata: "ipfs://",
startDate: uint64(block.timestamp),
endDate: 10 days + 1,
endDate: uint64(block.timestamp) + 10 days,
actions: actions,
allowFailureMap: 0
});
Expand Down Expand Up @@ -1780,7 +1782,7 @@ contract MultisigTest is AragonTest {
// 2
(dao, optimisticPlugin, multisig,,,) = builder.withDuration(50 days).build();

setTime(5000);
setTime(20 days);
actions = new IDAO.Action[](1);
actions[0].value = 1 ether;
actions[0].to = address(bob);
Expand All @@ -1805,7 +1807,7 @@ contract MultisigTest is AragonTest {
targetPid = (uint256(block.timestamp) << 128 | uint256(block.timestamp + 50 days) << 64);
vm.expectEmit();
emit ProposalCreated(
targetPid, address(multisig), uint64(block.timestamp), 5000 + 50 days, "ipfs://", actions, 0
targetPid, address(multisig), uint64(block.timestamp), 20 days + 50 days, "ipfs://", actions, 0
);
multisig.execute(pid);
}
Expand Down Expand Up @@ -2060,7 +2062,7 @@ contract MultisigTest is AragonTest {
IDAO.Action[] memory actions;
OptimisticTokenVotingPlugin destPlugin;

setTime(10);
setTime(5 days);

IDAO.Action[] memory createActions = new IDAO.Action[](3);
createActions[0].to = alice;
Expand Down Expand Up @@ -2203,7 +2205,7 @@ contract MultisigTest is AragonTest {
createActions[0].value = 3 ether;
createActions[0].data = hex"223344556677";

setTime(50); // Timestamp = 50
setTime(15 days);

pid = multisig.createProposal("ipfs://different-metadata", createActions, optimisticPlugin, true);
assertEq(pid, 0, "PID should be 0");
Expand Down Expand Up @@ -2319,7 +2321,7 @@ contract MultisigTest is AragonTest {
IDAO.Action[] memory actions;
uint256 allowFailureMap;

setTime(1 days);
setTime(2 days);

IDAO.Action[] memory createActions = new IDAO.Action[](3);
createActions[0].to = alice;
Expand All @@ -2345,15 +2347,15 @@ contract MultisigTest is AragonTest {
multisig.execute(pid);

// Check round
uint256 targetPid = uint256(1 days) << 128 | uint256(1 days + 10 days) << 64; // start=1d, end=10d, counter=0
uint256 targetPid = uint256(2 days) << 128 | uint256(2 days + 10 days) << 64; // start=1d, end=10d, counter=0
(open, executed, parameters, vetoTally, actions, allowFailureMap) = optimisticPlugin.getProposal(targetPid);

assertEq(open, true, "Should be open");
assertEq(executed, false, "Should not be executed");
assertEq(vetoTally, 0, "Should be 0");

assertEq(parameters.metadataUri, "ipfs://metadata", "Incorrect target metadataUri");
assertEq(parameters.vetoEndDate, 1 days + 10 days, "Incorrect target vetoEndDate");
assertEq(parameters.vetoEndDate, 2 days + 10 days, "Incorrect target vetoEndDate");

assertEq(actions.length, 3, "Should be 3");

Expand All @@ -2370,7 +2372,7 @@ contract MultisigTest is AragonTest {
assertEq(allowFailureMap, 0, "Should be 0");

// New proposal
setTime(2 days);
setTime(3 days);

createActions = new IDAO.Action[](2);
createActions[1].to = alice;
Expand All @@ -2393,15 +2395,15 @@ contract MultisigTest is AragonTest {
multisig.execute(pid);

// Check round
targetPid = (uint256(2 days) << 128 | uint256(2 days + 10 days) << 64) + 1;
targetPid = (uint256(3 days) << 128 | uint256(3 days + 10 days) << 64) + 1;
(open, executed, parameters, vetoTally, actions, allowFailureMap) = optimisticPlugin.getProposal(targetPid);

assertEq(open, true, "Should be open");
assertEq(executed, false, "Should not be executed");
assertEq(vetoTally, 0, "Should be 0");

assertEq(parameters.metadataUri, "ipfs://more-metadata", "Incorrect target metadataUri");
assertEq(parameters.vetoEndDate, 2 days + 10 days, "Incorrect target vetoEndDate");
assertEq(parameters.vetoEndDate, 3 days + 10 days, "Incorrect target vetoEndDate");

assertEq(actions.length, 2, "Should be 2");

Expand Down
Loading

0 comments on commit 7535266

Please sign in to comment.