From 55e7f7684a9318e1bd95e11b2118f07465da8b75 Mon Sep 17 00:00:00 2001 From: sherlock-admin4 <162441180+sherlock-admin4@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:25:28 +0100 Subject: [PATCH] message --- DelegationSurrogate.t.sol | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 DelegationSurrogate.t.sol diff --git a/DelegationSurrogate.t.sol b/DelegationSurrogate.t.sol new file mode 100644 index 0000000..936f8ad --- /dev/null +++ b/DelegationSurrogate.t.sol @@ -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); + } +}