Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into theo/post-audit-test-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dd0sxx committed Dec 29, 2023
2 parents 3a8a811 + 02dc7fd commit 812c8be
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 51 deletions.
36 changes: 24 additions & 12 deletions test/token-voting/LlamaTokenVotingFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,16 @@ contract DeployTokenVotingModule is LlamaTokenVotingFactoryTest {
CORE.executeAction(actionInfo);

assertEq(address(llamaERC20TokenAdapter.token()), address(erc20VotesToken));
assertEq(LlamaTokenAdapterVotesTimestamp(address(llamaERC20TokenAdapter)).CLOCK_MODE(), "mode=timestamp");
assertEq(address(llamaERC20TokenGovernor.llamaCore()), address(CORE));
(uint16 voteQuorumPct, uint16 vetoQuorumPct) = llamaERC20TokenGovernor.getQuorum();
assertEq(ERC20_VOTE_QUORUM_PCT, voteQuorumPct);
assertEq(ERC20_VETO_QUORUM_PCT, vetoQuorumPct);
assertEq(address(llamaERC20TokenGovernor.tokenAdapter()), address(llamaERC20TokenAdapter));
assertEq(llamaERC20TokenGovernor.creationThreshold(), ERC20_CREATION_THRESHOLD);
assertEq(address(llamaERC20TokenAdapter.token()), address(erc20VotesToken));
(uint16 voteQuorumPct, uint16 vetoQuorumPct) = llamaERC20TokenGovernor.getQuorum();
assertEq(voteQuorumPct, ERC20_VOTE_QUORUM_PCT);
assertEq(vetoQuorumPct, ERC20_VETO_QUORUM_PCT);
(uint16 delayPeriodPct, uint16 castingPeriodPct) = llamaERC20TokenGovernor.getPeriodPcts();
assertEq(delayPeriodPct, uint16(ONE_QUARTER_IN_BPS));
assertEq(castingPeriodPct, uint16(TWO_QUARTERS_IN_BPS));
}

function test_CanDeployERC721TokenVotingModule() public {
Expand Down Expand Up @@ -233,12 +237,16 @@ contract DeployTokenVotingModule is LlamaTokenVotingFactoryTest {
CORE.executeAction(actionInfo);

assertEq(address(llamaERC721TokenAdapter.token()), address(erc721VotesToken));
assertEq(LlamaTokenAdapterVotesTimestamp(address(llamaERC721TokenAdapter)).CLOCK_MODE(), "mode=timestamp");
assertEq(address(llamaERC721TokenGovernor.llamaCore()), address(CORE));
(uint16 voteQuorumPct, uint16 vetoQuorumPct) = llamaERC721TokenGovernor.getQuorum();
assertEq(ERC721_VOTE_QUORUM_PCT, voteQuorumPct);
assertEq(ERC721_VETO_QUORUM_PCT, vetoQuorumPct);
assertEq(address(llamaERC721TokenGovernor.tokenAdapter()), address(llamaERC721TokenAdapter));
assertEq(llamaERC721TokenGovernor.creationThreshold(), ERC721_CREATION_THRESHOLD);
assertEq(address(llamaERC721TokenAdapter.token()), address(erc721VotesToken));
(uint16 voteQuorumPct, uint16 vetoQuorumPct) = llamaERC721TokenGovernor.getQuorum();
assertEq(voteQuorumPct, ERC721_VOTE_QUORUM_PCT);
assertEq(vetoQuorumPct, ERC721_VETO_QUORUM_PCT);
(uint16 delayPeriodPct, uint16 castingPeriodPct) = llamaERC721TokenGovernor.getPeriodPcts();
assertEq(delayPeriodPct, uint16(ONE_QUARTER_IN_BPS));
assertEq(castingPeriodPct, uint16(TWO_QUARTERS_IN_BPS));
}

function test_CanBeDeployedByAnyone(address randomCaller) public {
Expand Down Expand Up @@ -289,12 +297,16 @@ contract DeployTokenVotingModule is LlamaTokenVotingFactoryTest {
tokenVotingFactory.deploy(config);

assertEq(address(llamaERC20TokenAdapter.token()), address(erc20VotesToken));
assertEq(LlamaTokenAdapterVotesTimestamp(address(llamaERC20TokenAdapter)).CLOCK_MODE(), "mode=timestamp");
assertEq(address(llamaERC20TokenGovernor.llamaCore()), address(CORE));
(uint16 voteQuorumPct, uint16 vetoQuorumPct) = llamaERC20TokenGovernor.getQuorum();
assertEq(ERC20_VOTE_QUORUM_PCT, voteQuorumPct);
assertEq(ERC20_VETO_QUORUM_PCT, vetoQuorumPct);
assertEq(address(llamaERC20TokenGovernor.tokenAdapter()), address(llamaERC20TokenAdapter));
assertEq(llamaERC20TokenGovernor.creationThreshold(), ERC20_CREATION_THRESHOLD);
assertEq(address(llamaERC20TokenAdapter.token()), address(erc20VotesToken));
(uint16 voteQuorumPct, uint16 vetoQuorumPct) = llamaERC20TokenGovernor.getQuorum();
assertEq(voteQuorumPct, ERC20_VOTE_QUORUM_PCT);
assertEq(vetoQuorumPct, ERC20_VETO_QUORUM_PCT);
(uint16 delayPeriodPct, uint16 castingPeriodPct) = llamaERC20TokenGovernor.getPeriodPcts();
assertEq(delayPeriodPct, uint16(ONE_QUARTER_IN_BPS));
assertEq(castingPeriodPct, uint16(TWO_QUARTERS_IN_BPS));
}

function test_CanBeDeployedMoreThanOnceBySameDeployer() public {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ pragma solidity ^0.8.23;

import {Test, console2} from "forge-std/Test.sol";

import {Initializable} from "@openzeppelin/proxy/utils/Initializable.sol";

import {LlamaTokenVotingTestSetup} from "test/token-voting/LlamaTokenVotingTestSetup.sol";
import {LlamaCoreSigUtils} from "test/utils/LlamaCoreSigUtils.sol";

import {ILlamaCore} from "src/interfaces/ILlamaCore.sol";
import {ILlamaTokenAdapter} from "src/token-voting/interfaces/ILlamaTokenAdapter.sol";
import {ActionState} from "src/lib/Enums.sol";
import {Action, ActionInfo} from "src/lib/Structs.sol";
import {LlamaTokenGovernor} from "src/token-voting/LlamaTokenGovernor.sol";
Expand Down Expand Up @@ -43,6 +46,24 @@ contract LlamaTokenGovernorActionCreation is LlamaTokenVotingTestSetup, LlamaCor
}
}

contract Constructor is LlamaTokenGovernorActionCreation {
function test_RevertIf_InitializeImplementationContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaTokenGovernorLogic.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC20_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract Initialize is LlamaTokenGovernorActionCreation {
function test_RevertIf_InitializeAlreadyInitializedContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaERC20TokenGovernor.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC20_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract CreateAction is LlamaTokenGovernorActionCreation {
bytes data = abi.encodeCall(mockProtocol.pause, (true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.23;
import {Test, console2} from "forge-std/Test.sol";

import {Clones} from "@openzeppelin/proxy/Clones.sol";
import {Initializable} from "@openzeppelin/proxy/utils/Initializable.sol";

import {LlamaTokenVotingTestSetup} from "test/token-voting/LlamaTokenVotingTestSetup.sol";
import {LlamaCoreSigUtils} from "test/utils/LlamaCoreSigUtils.sol";
Expand Down Expand Up @@ -118,6 +119,24 @@ contract LlamaTokenGovernorCasting is LlamaTokenVotingTestSetup, LlamaCoreSigUti
}
}

contract Constructor is LlamaTokenGovernorCasting {
function test_RevertIf_InitializeImplementationContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaTokenGovernorLogic.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC20_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract Initialize is LlamaTokenGovernorCasting {
function test_RevertIf_InitializeAlreadyInitializedContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaERC20TokenGovernor.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC20_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract CastVote is LlamaTokenGovernorCasting {
function setUp() public virtual override {
LlamaTokenGovernorCasting.setUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ pragma solidity ^0.8.23;

import {Test, console2} from "forge-std/Test.sol";

import {Initializable} from "@openzeppelin/proxy/utils/Initializable.sol";

import {LlamaTokenVotingTestSetup} from "test/token-voting/LlamaTokenVotingTestSetup.sol";
import {LlamaCoreSigUtils} from "test/utils/LlamaCoreSigUtils.sol";

import {ILlamaCore} from "src/interfaces/ILlamaCore.sol";
import {ILlamaTokenAdapter} from "src/token-voting/interfaces/ILlamaTokenAdapter.sol";
import {ActionState} from "src/lib/Enums.sol";
import {Action, ActionInfo} from "src/lib/Structs.sol";
import {LlamaTokenGovernor} from "src/token-voting/LlamaTokenGovernor.sol";
Expand Down Expand Up @@ -43,45 +46,23 @@ contract LlamaERC721TokenGovernorActionCreationTest is LlamaTokenVotingTestSetup
}
}

// contract Constructor is LlamaERC721TokenGovernorActionCreationTest {
// function test_RevertIf_InvalidLlamaCore() public {
// // With invalid LlamaCore instance, LlamaTokenGovernor.InvalidLlamaCoreAddress is unreachable
// vm.expectRevert();
// new LlamaTokenGovernor(erc721VotesToken, ILlamaCore(makeAddr("invalid-llama-core")),
// uint256(0));
// }

// function test_RevertIf_InvalidTokenAddress() public {
// vm.expectRevert(); // will EvmError: Revert vecause totalSupply fn does not exist
// new LlamaTokenGovernor(ERC20Votes(makeAddr("invalid-erc721VotesToken")), CORE, uint256(0));
// }

// function test_RevertIf_CreationThresholdExceedsTotalSupply() public {
// erc721VotesToken.mint(tokenHolder1, 1_000_000e18); // we use erc721VotesToken because IVotesToken is an interface
// // without the `mint` function

// vm.warp(block.timestamp + 1);

// vm.expectRevert(LlamaTokenGovernor.InvalidCreationThreshold.selector);
// new LlamaTokenGovernor(erc721VotesToken, CORE, 17_000_000_000_000_000_000_000_000);
// }

// function test_ProperlySetsConstructorArguments() public {
// uint256 threshold = 500_000e18;
// erc721VotesToken.mint(tokenHolder1, 1_000_000e18); // we use erc721VotesToken because IVotesToken is an interface
// // without the `mint` function

// vm.warp(block.timestamp + 1);

// LlamaTokenGovernor llamaERC721TokenGovernor = new
// LlamaTokenGovernor(erc721VotesToken,
// CORE,
// threshold);
// assertEq(address(llamaERC721TokenGovernor.TOKEN()), address(erc721VotesToken));
// assertEq(address(llamaERC721TokenGovernor.LLAMA_CORE()), address(CORE));
// assertEq(llamaERC721TokenGovernor.creationThreshold(), threshold);
// }
// }
contract Constructor is LlamaERC721TokenGovernorActionCreationTest {
function test_RevertIf_InitializeImplementationContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaTokenGovernorLogic.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC721_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract Initialize is LlamaERC721TokenGovernorActionCreationTest {
function test_RevertIf_InitializeAlreadyInitializedContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaERC721TokenGovernor.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC721_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract CreateAction is LlamaERC721TokenGovernorActionCreationTest {
bytes data = abi.encodeCall(mockProtocol.pause, (true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.23;
import {Test, console2} from "forge-std/Test.sol";

import {Clones} from "@openzeppelin/proxy/Clones.sol";
import {Initializable} from "@openzeppelin/proxy/utils/Initializable.sol";

import {LlamaTokenVotingTestSetup} from "test/token-voting/LlamaTokenVotingTestSetup.sol";
import {LlamaCoreSigUtils} from "test/utils/LlamaCoreSigUtils.sol";
Expand Down Expand Up @@ -118,6 +119,24 @@ contract LlamaTokenGovernorCastingTest is LlamaTokenVotingTestSetup, LlamaCoreSi
}
}

contract Constructor is LlamaTokenGovernorCastingTest {
function test_RevertIf_InitializeImplementationContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaTokenGovernorLogic.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC721_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract Initialize is LlamaTokenGovernorCastingTest {
function test_RevertIf_InitializeAlreadyInitializedContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaERC721TokenGovernor.initialize(
CORE, ILlamaTokenAdapter(address(0)), ERC721_CREATION_THRESHOLD, defaultCasterConfig
);
}
}

contract CastVote is LlamaTokenGovernorCastingTest {
function setUp() public virtual override {
LlamaTokenGovernorCastingTest.setUp();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {Test, console2} from "forge-std/Test.sol";

import {Clones} from "@openzeppelin/proxy/Clones.sol";
import {Initializable} from "@openzeppelin/proxy/utils/Initializable.sol";

import {LlamaTokenVotingTestSetup} from "test/token-voting/LlamaTokenVotingTestSetup.sol";
import {LlamaCoreSigUtils} from "test/utils/LlamaCoreSigUtils.sol";

import {ILlamaTokenAdapter} from "src/token-voting/interfaces/ILlamaTokenAdapter.sol";
import {LlamaTokenAdapterVotesTimestamp} from "src/token-voting/token-adapters/LlamaTokenAdapterVotesTimestamp.sol";

contract LlamaTokenAdapterVotesTimestampTest is LlamaTokenVotingTestSetup, LlamaCoreSigUtils {
function setUp() public virtual override {
LlamaTokenVotingTestSetup.setUp();

// Mint tokens to tokenholders so that there is an existing supply.
erc20VotesToken.mint(tokenHolder0, ERC20_CREATION_THRESHOLD);

// Mine block so that the ERC20 and ERC721 supply will be available when doing a past timestamp check at initialize
// during deployment.
mineBlock();

// Deploy ERC20 Token Voting Module.
_deployERC20TokenVotingModuleAndSetRole();
}
}

contract Constructor is LlamaTokenAdapterVotesTimestampTest {
function test_RevertIf_InitializeImplementationContract() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
bytes memory adapterConfig = abi.encode(LlamaTokenAdapterVotesTimestamp.Config(address(erc20VotesToken)));
llamaTokenAdapterTimestampLogic.initialize(adapterConfig);
}
}

contract Initialize is LlamaTokenAdapterVotesTimestampTest {
function test_RevertIf_InitializeAlreadyInitializedContract() public {
bytes memory adapterConfig = abi.encode(LlamaTokenAdapterVotesTimestamp.Config(address(erc20VotesToken)));
bytes32 salt = keccak256(abi.encodePacked(address(EXECUTOR), address(CORE), adapterConfig, uint256(0)));

ILlamaTokenAdapter llamaERC20TokenAdapter = ILlamaTokenAdapter(
Clones.predictDeterministicAddress(
address(llamaTokenAdapterTimestampLogic),
salt,
address(tokenVotingFactory) // deployer
)
);

vm.expectRevert(Initializable.InvalidInitialization.selector);
llamaERC20TokenAdapter.initialize(adapterConfig);
}
}

0 comments on commit 812c8be

Please sign in to comment.