-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: addToDelegationPool access control and token transfer (OZ C-01)
- Loading branch information
Showing
7 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.26; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import { IHorizonStakingMain } from "../../../contracts/interfaces/internal/IHorizonStakingMain.sol"; | ||
import { HorizonStakingTest } from "../HorizonStaking.t.sol"; | ||
|
||
contract HorizonStakingDelegationAddToPoolTest is HorizonStakingTest { | ||
|
||
modifier useValidDelegationAmount(uint256 tokens) { | ||
vm.assume(tokens > 0); | ||
vm.assume(tokens <= MAX_STAKING_TOKENS); | ||
_; | ||
} | ||
|
||
/* | ||
* TESTS | ||
*/ | ||
|
||
function test_Delegation_AddToPool_Verifier( | ||
uint256 amount, | ||
uint256 delegationAmount | ||
) public useIndexer useProvision(amount, 0, 0) useValidDelegationAmount(delegationAmount) { | ||
uint256 stakingPreviousBalance = token.balanceOf(address(staking)); | ||
|
||
resetPrank(subgraphDataServiceAddress); | ||
mint(subgraphDataServiceAddress, delegationAmount); | ||
token.approve(address(staking), delegationAmount); | ||
vm.expectEmit(address(staking)); | ||
emit IHorizonStakingMain.TokensToDelegationPoolAdded(users.indexer, subgraphDataServiceAddress, delegationAmount); | ||
staking.addToDelegationPool(users.indexer, subgraphDataServiceAddress, delegationAmount); | ||
|
||
uint256 delegatedTokens = staking.getDelegatedTokensAvailable(users.indexer, subgraphDataServiceAddress); | ||
assertEq(delegatedTokens, delegationAmount); | ||
assertEq(token.balanceOf(subgraphDataServiceAddress), 0); | ||
assertEq(token.balanceOf(address(staking)), stakingPreviousBalance + delegationAmount); | ||
} | ||
|
||
function test_Delegation_AddToPool_Payments( | ||
uint256 amount, | ||
uint256 delegationAmount | ||
) public useIndexer useProvision(amount, 0, 0) useValidDelegationAmount(delegationAmount) { | ||
uint256 stakingPreviousBalance = token.balanceOf(address(staking)); | ||
|
||
resetPrank(address(payments)); | ||
mint(address(payments), delegationAmount); | ||
token.approve(address(staking), delegationAmount); | ||
staking.addToDelegationPool(users.indexer, subgraphDataServiceAddress, delegationAmount); | ||
|
||
uint256 delegatedTokens = staking.getDelegatedTokensAvailable(users.indexer, subgraphDataServiceAddress); | ||
assertEq(delegatedTokens, delegationAmount); | ||
assertEq(token.balanceOf(subgraphDataServiceAddress), 0); | ||
assertEq(token.balanceOf(address(staking)), stakingPreviousBalance + delegationAmount); | ||
} | ||
|
||
function test_Delegation_AddToPool_RevertWhen_InvalidSender( | ||
uint256 amount, | ||
uint256 delegationAmount | ||
) public useIndexer useProvision(amount, 0, 0) useValidDelegationAmount(delegationAmount) { | ||
vm.assume(delegationAmount > 0); | ||
vm.startPrank(users.delegator); | ||
bytes memory expectedError = abi.encodeWithSelector( | ||
IHorizonStakingMain.HorizonStakingInvalidDelegationPoolSender.selector, | ||
users.delegator | ||
); | ||
vm.expectRevert(expectedError); | ||
staking.addToDelegationPool(users.indexer, subgraphDataServiceAddress, delegationAmount); | ||
} | ||
|
||
function test_Delegation_AddToPool_RevertWhen_ZeroTokens( | ||
uint256 amount | ||
) public useIndexer useProvision(amount, 0, 0) { | ||
vm.startPrank(subgraphDataServiceAddress); | ||
bytes memory expectedError = abi.encodeWithSelector(IHorizonStakingMain.HorizonStakingInvalidZeroTokens.selector); | ||
vm.expectRevert(expectedError); | ||
staking.addToDelegationPool(users.indexer, subgraphDataServiceAddress, 0); | ||
} | ||
} |