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

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
0xrajath committed Dec 8, 2023
1 parent 295d652 commit ae0b6a9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 37 deletions.
44 changes: 22 additions & 22 deletions test/token-voting/LlamaTokenVotingFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,6 @@ contract LlamaTokenVotingFactoryTest is LlamaTokenVotingTestSetup {
function setUp() public override {
LlamaTokenVotingTestSetup.setUp();
}

function _setPermissionCreateApproveAndQueueAction(bytes memory data) internal returns (ActionInfo memory actionInfo) {
// Assign `deployTokenVotingModule` permission to the `CORE_TEAM_ROLE` role.
ILlamaPolicy.PermissionData memory deployTokenVotingPermission = ILlamaPolicy.PermissionData(
address(tokenVotingFactory), LlamaTokenVotingFactory.deployTokenVotingModule.selector, address(STRATEGY)
);

vm.prank(address(EXECUTOR));
POLICY.setRolePermission(CORE_TEAM_ROLE, deployTokenVotingPermission, true);

// Create an action and queue it to deploy the token voting module.
vm.prank(coreTeam4);
uint256 actionId = CORE.createAction(CORE_TEAM_ROLE, STRATEGY, address(tokenVotingFactory), 0, data, "");
actionInfo = ActionInfo(actionId, coreTeam4, CORE_TEAM_ROLE, STRATEGY, address(tokenVotingFactory), 0, data);

vm.prank(coreTeam1);
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, "");
vm.prank(coreTeam2);
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, "");
vm.prank(coreTeam3);
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, "");
}
}

contract Constructor is LlamaTokenVotingFactoryTest {
Expand All @@ -77,6 +55,28 @@ contract Constructor is LlamaTokenVotingFactoryTest {
}

contract DeployTokenVotingModule is LlamaTokenVotingFactoryTest {
function _setPermissionCreateApproveAndQueueAction(bytes memory data) internal returns (ActionInfo memory actionInfo) {
// Assign `deployTokenVotingModule` permission to the `CORE_TEAM_ROLE` role.
ILlamaPolicy.PermissionData memory deployTokenVotingPermission = ILlamaPolicy.PermissionData(
address(tokenVotingFactory), LlamaTokenVotingFactory.deployTokenVotingModule.selector, address(STRATEGY)
);

vm.prank(address(EXECUTOR));
POLICY.setRolePermission(CORE_TEAM_ROLE, deployTokenVotingPermission, true);

// Create an action and queue it to deploy the token voting module.
vm.prank(coreTeam4);
uint256 actionId = CORE.createAction(CORE_TEAM_ROLE, STRATEGY, address(tokenVotingFactory), 0, data, "");
actionInfo = ActionInfo(actionId, coreTeam4, CORE_TEAM_ROLE, STRATEGY, address(tokenVotingFactory), 0, data);

vm.prank(coreTeam1);
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, "");
vm.prank(coreTeam2);
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, "");
vm.prank(coreTeam3);
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, "");
}

function test_CanDeployERC20TokenVotingModule() public {
// Set up action to call `deployTokenVotingModule` with the ERC20 token.
bytes memory data = abi.encodeWithSelector(
Expand Down
66 changes: 51 additions & 15 deletions test/token-voting/LlamaTokenVotingTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import {LlamaPeripheryTestSetup} from "test/LlamaPeripheryTestSetup.sol";

import {DeployLlamaTokenVotingFactory} from "script/DeployLlamaTokenVotingFactory.s.sol";

import {ERC20TokenholderActionCreator} from "src/token-voting/ERC20TokenholderActionCreator.sol";
import {ERC20TokenholderCaster} from "src/token-voting/ERC20TokenholderCaster.sol";
import {ERC721TokenholderActionCreator} from "src/token-voting/ERC721TokenholderActionCreator.sol";
import {ERC721TokenholderCaster} from "src/token-voting/ERC721TokenholderCaster.sol";

contract LlamaTokenVotingTestSetup is LlamaPeripheryTestSetup, DeployLlamaTokenVotingFactory {
// ERC20 Token Voting Constants.
uint256 public constant ERC20_CREATION_THRESHOLD = 100;
uint256 public constant ERC20_CREATION_THRESHOLD = 500_000e18;
uint256 public constant ERC20_MIN_APPROVAL_PCT = 1000;
uint256 public constant ERC20_MIN_DISAPPROVAL_PCT = 1000;

Expand All @@ -26,8 +31,14 @@ contract LlamaTokenVotingTestSetup is LlamaPeripheryTestSetup, DeployLlamaTokenV
MockERC721Votes public erc721VotesToken;

// Token holders.
address tokenHolder;
uint256 tokenHolderPrivateKey;
address tokenHolder1;
uint256 tokenHolder1PrivateKey;
address tokenHolder2;
uint256 tokenHolder2PrivateKey;
address tokenHolder3;
uint256 tokenHolder3PrivateKey;
address notTokenHolder;
uint256 notTokenHolderPrivateKey;

function setUp() public virtual override {
LlamaPeripheryTestSetup.setUp();
Expand All @@ -39,20 +50,45 @@ contract LlamaTokenVotingTestSetup is LlamaPeripheryTestSetup, DeployLlamaTokenV
erc20VotesToken = new MockERC20Votes();
erc721VotesToken = new MockERC721Votes();

// Setting up tokenholder addresses and private keys.
(tokenHolder1, tokenHolder1PrivateKey) = makeAddrAndKey("tokenHolder1");
(tokenHolder2, tokenHolder2PrivateKey) = makeAddrAndKey("tokenHolder2");
(tokenHolder3, tokenHolder3PrivateKey) = makeAddrAndKey("tokenHolder3");
(notTokenHolder, notTokenHolderPrivateKey) = makeAddrAndKey("notTokenHolder");

// Mint tokens to core team members.
erc20VotesToken.mint(coreTeam1, 100);
erc20VotesToken.mint(coreTeam2, 100);
erc20VotesToken.mint(coreTeam3, 100);
erc20VotesToken.mint(coreTeam4, 100);
erc721VotesToken.mint(coreTeam1, 0);
erc721VotesToken.mint(coreTeam2, 1);
erc721VotesToken.mint(coreTeam3, 2);
erc721VotesToken.mint(coreTeam4, 3);

// Mine block so that the ERC20 and ERC721 supply will be available when doing a past timestamp check at initialize.
erc20VotesToken.mint(tokenHolder1, ERC20_CREATION_THRESHOLD);
erc20VotesToken.mint(tokenHolder2, ERC20_CREATION_THRESHOLD);
erc20VotesToken.mint(tokenHolder3, ERC20_CREATION_THRESHOLD);
erc721VotesToken.mint(tokenHolder1, 0);
erc721VotesToken.mint(tokenHolder2, 1);
erc721VotesToken.mint(tokenHolder3, 2);

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

// Setting up tokenholder addresses and private keys.
(tokenHolder, tokenHolderPrivateKey) = makeAddrAndKey("tokenHolder");
// =========================
// ======== Helpers ========
// =========================

function _deployERC20TokenVotingModule() internal returns (ERC20TokenholderActionCreator, ERC20TokenholderCaster) {
vm.prank(address(EXECUTOR));
(address erc20TokenholderActionCreator, address erc20TokenholderCaster) = tokenVotingFactory.deployTokenVotingModule(
address(erc20VotesToken), true, ERC20_CREATION_THRESHOLD, ERC20_MIN_APPROVAL_PCT, ERC20_MIN_DISAPPROVAL_PCT
);
return
(ERC20TokenholderActionCreator(erc20TokenholderActionCreator), ERC20TokenholderCaster(erc20TokenholderCaster));
}

function _deployERC721TokenVotingModule() internal returns (ERC721TokenholderActionCreator, ERC721TokenholderCaster) {
vm.prank(address(EXECUTOR));
(address erc721TokenholderActionCreator, address erc721TokenholderCaster) = tokenVotingFactory
.deployTokenVotingModule(
address(erc721VotesToken), false, ERC721_CREATION_THRESHOLD, ERC721_MIN_APPROVAL_PCT, ERC721_MIN_DISAPPROVAL_PCT
);
return
(ERC721TokenholderActionCreator(erc721TokenholderActionCreator), ERC721TokenholderCaster(erc721TokenholderCaster));
}
}

0 comments on commit ae0b6a9

Please sign in to comment.