-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #974 from graphprotocol/mde/horizon-staking-tests-…
…rebased [WIP] Graph Horizon: Staking unit tests
- Loading branch information
Showing
23 changed files
with
1,001 additions
and
36 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
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,86 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.26; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import { IHorizonStakingTypes } from "../../contracts/interfaces/internal/IHorizonStakingTypes.sol"; | ||
import { HorizonStakingSharedTest } from "../shared/horizon-staking/HorizonStakingShared.t.sol"; | ||
|
||
contract HorizonStakingTest is HorizonStakingSharedTest, IHorizonStakingTypes { | ||
|
||
modifier useOperator() { | ||
vm.startPrank(users.indexer); | ||
staking.setOperator(users.operator, subgraphDataServiceAddress, true); | ||
vm.startPrank(users.operator); | ||
_; | ||
vm.stopPrank(); | ||
} | ||
|
||
modifier useStake(uint256 amount) { | ||
vm.assume(amount > MIN_PROVISION_SIZE); | ||
approve(address(staking), amount); | ||
staking.stake(amount); | ||
_; | ||
} | ||
|
||
modifier useStakeTo(address to, uint256 amount) { | ||
vm.assume(amount > MIN_PROVISION_SIZE); | ||
_stakeTo(to, amount); | ||
_; | ||
} | ||
|
||
modifier useThawRequest(uint256 thawAmount) { | ||
vm.assume(thawAmount > 0); | ||
_createThawRequest(thawAmount); | ||
_; | ||
} | ||
|
||
modifier useThawAndDeprovision(uint256 amount, uint64 thawingPeriod) { | ||
vm.assume(amount > 0); | ||
_createThawRequest(amount); | ||
skip(thawingPeriod + 1); | ||
_deprovision(amount); | ||
_; | ||
} | ||
|
||
modifier useDelegation(uint256 delegationAmount) { | ||
address msgSender; | ||
(, msgSender,) = vm.readCallers(); | ||
vm.assume(delegationAmount > MIN_DELEGATION); | ||
vm.assume(delegationAmount <= 10_000_000_000 ether); | ||
vm.startPrank(users.delegator); | ||
_delegate(delegationAmount); | ||
vm.startPrank(msgSender); | ||
_; | ||
} | ||
|
||
function _stakeTo(address to, uint256 amount) internal { | ||
approve(address(staking), amount); | ||
staking.stakeTo(to, amount); | ||
} | ||
|
||
function _createThawRequest(uint256 thawAmount) internal returns (bytes32) { | ||
return staking.thaw(users.indexer, subgraphDataServiceAddress, thawAmount); | ||
} | ||
|
||
function _deprovision(uint256 amount) internal { | ||
staking.deprovision(users.indexer, subgraphDataServiceAddress, amount); | ||
} | ||
|
||
function _delegate(uint256 amount) internal { | ||
token.approve(address(staking), amount); | ||
staking.delegate(users.indexer, subgraphDataServiceAddress, amount, 0); | ||
} | ||
|
||
function _getDelegation() internal view returns (Delegation memory) { | ||
return staking.getDelegation(users.delegator, users.indexer, subgraphDataServiceAddress); | ||
} | ||
|
||
function _undelegate(uint256 shares) internal { | ||
staking.undelegate(users.indexer, subgraphDataServiceAddress, shares); | ||
} | ||
|
||
function _getDelegationPool() internal view returns (DelegationPool memory) { | ||
return staking.getDelegationPool(users.indexer, subgraphDataServiceAddress); | ||
} | ||
} |
Oops, something went wrong.