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

govstaking/test/DelegationSurrogate.t.sol #6

Open
wants to merge 1 commit into
base: base
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions DelegationSurrogate.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.23;

import {Test, console2} from "forge-std/Test.sol";
import {DelegationSurrogateVotes} from "src/DelegationSurrogateVotes.sol";
import {ERC20VotesMock} from "test/mocks/MockERC20Votes.sol";

contract DelegationSurrogateVotesTest is Test {
ERC20VotesMock govToken;

function setUp() public {
govToken = new ERC20VotesMock();
vm.label(address(govToken), "Governance Token");
}

function __deploy(address _deployer, address _delegatee)
public
returns (DelegationSurrogateVotes)
{
vm.assume(_deployer != address(0));

vm.prank(_deployer);
DelegationSurrogateVotes _surrogate = new DelegationSurrogateVotes(govToken, _delegatee);
return _surrogate;
}
}

contract Constructor is DelegationSurrogateVotesTest {
function testFuzz_DelegatesToDeployer(address _deployer, address _delegatee) public {
DelegationSurrogateVotes _surrogate = __deploy(_deployer, _delegatee);
assertEq(_delegatee, govToken.delegates(address(_surrogate)));
}

function testFuzz_MaxApprovesDeployerToEnableWithdrawals(
address _deployer,
address _delegatee,
uint256 _amount,
address _receiver
) public {
vm.assume(_receiver != address(0));

DelegationSurrogateVotes _surrogate = __deploy(_deployer, _delegatee);
govToken.mint(address(_surrogate), _amount);

uint256 _allowance = govToken.allowance(address(_surrogate), _deployer);
assertEq(_allowance, type(uint256).max);

vm.prank(_deployer);
govToken.transferFrom(address(_surrogate), _receiver, _amount);

assertEq(govToken.balanceOf(_receiver), _amount);
}
}