-
Notifications
You must be signed in to change notification settings - Fork 163
test: improve horizon and subgraph-service test coverage #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.27; | ||
|
|
||
| import { Test } from "forge-std/Test.sol"; | ||
| import { Controller } from "@graphprotocol/contracts/contracts/governance/Controller.sol"; | ||
| import { PaymentsEscrow } from "contracts/payments/PaymentsEscrow.sol"; | ||
| import { IPaymentsEscrow } from "@graphprotocol/interfaces/contracts/horizon/IPaymentsEscrow.sol"; | ||
|
|
||
| contract GraphEscrowConstructorTest is Test { | ||
| Controller public controller; | ||
|
|
||
| function setUp() public { | ||
| controller = new Controller(); | ||
|
|
||
| // GraphDirectory requires all proxy contracts to be registered | ||
| controller.setContractProxy(keccak256("GraphToken"), makeAddr("GraphToken")); | ||
| controller.setContractProxy(keccak256("Staking"), makeAddr("Staking")); | ||
| controller.setContractProxy(keccak256("GraphPayments"), makeAddr("GraphPayments")); | ||
| controller.setContractProxy(keccak256("PaymentsEscrow"), makeAddr("PaymentsEscrow")); | ||
| controller.setContractProxy(keccak256("EpochManager"), makeAddr("EpochManager")); | ||
| controller.setContractProxy(keccak256("RewardsManager"), makeAddr("RewardsManager")); | ||
| controller.setContractProxy(keccak256("GraphTokenGateway"), makeAddr("GraphTokenGateway")); | ||
| controller.setContractProxy(keccak256("GraphProxyAdmin"), makeAddr("GraphProxyAdmin")); | ||
| controller.setContractProxy(keccak256("Curation"), makeAddr("Curation")); | ||
| } | ||
|
|
||
| function testConstructor_MaxWaitPeriodBoundary() public { | ||
| uint256 maxWaitPeriod = 90 days; | ||
|
|
||
| // Exactly at MAX_WAIT_PERIOD should succeed | ||
| PaymentsEscrow escrowAtMax = new PaymentsEscrow(address(controller), maxWaitPeriod); | ||
| assertEq(escrowAtMax.WITHDRAW_ESCROW_THAWING_PERIOD(), maxWaitPeriod); | ||
| } | ||
|
|
||
| function testConstructor_RevertWhen_ThawingPeriodTooLong() public { | ||
| uint256 maxWaitPeriod = 90 days; | ||
| uint256 tooLong = maxWaitPeriod + 1; | ||
|
|
||
| vm.expectRevert( | ||
| abi.encodeWithSelector(IPaymentsEscrow.PaymentsEscrowThawingPeriodTooLong.selector, tooLong, maxWaitPeriod) | ||
| ); | ||
| new PaymentsEscrow(address(controller), tooLong); | ||
| } | ||
|
|
||
| function testConstructor_ZeroThawingPeriod() public { | ||
| PaymentsEscrow escrowZero = new PaymentsEscrow(address(controller), 0); | ||
| assertEq(escrowZero.WITHDRAW_ESCROW_THAWING_PERIOD(), 0); | ||
| } | ||
| } |
This file contains hidden or 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,76 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.27; | ||
|
|
||
| import { GraphEscrowTest } from "./GraphEscrow.t.sol"; | ||
|
|
||
| contract GraphEscrowIsolationTest is GraphEscrowTest { | ||
| /* | ||
| * TESTS | ||
| */ | ||
|
|
||
| function testIsolation_DifferentCollectorsSamePayerReceiver(uint256 amount) public useGateway { | ||
| amount = bound(amount, 1, MAX_STAKING_TOKENS / 2); | ||
|
|
||
| address collector1 = users.verifier; | ||
| address collector2 = users.operator; | ||
|
|
||
| _depositTokens(collector1, users.indexer, amount); | ||
| _depositTokens(collector2, users.indexer, amount * 2); | ||
|
|
||
| (uint256 balance1, , ) = escrow.escrowAccounts(users.gateway, collector1, users.indexer); | ||
| (uint256 balance2, , ) = escrow.escrowAccounts(users.gateway, collector2, users.indexer); | ||
|
|
||
| assertEq(balance1, amount); | ||
| assertEq(balance2, amount * 2); | ||
| } | ||
|
|
||
| function testIsolation_DifferentReceiversSamePayerCollector(uint256 amount) public useGateway { | ||
| amount = bound(amount, 1, MAX_STAKING_TOKENS / 2); | ||
|
|
||
| address receiver1 = users.indexer; | ||
| address receiver2 = users.delegator; | ||
|
|
||
| _depositTokens(users.verifier, receiver1, amount); | ||
| _depositTokens(users.verifier, receiver2, amount * 2); | ||
|
|
||
| (uint256 balance1, , ) = escrow.escrowAccounts(users.gateway, users.verifier, receiver1); | ||
| (uint256 balance2, , ) = escrow.escrowAccounts(users.gateway, users.verifier, receiver2); | ||
|
|
||
| assertEq(balance1, amount); | ||
| assertEq(balance2, amount * 2); | ||
| } | ||
|
|
||
| function testIsolation_ThawOneTupleDoesNotAffectAnother(uint256 amount) public useGateway { | ||
| amount = bound(amount, 2, MAX_STAKING_TOKENS / 2); | ||
|
|
||
| _depositTokens(users.verifier, users.indexer, amount); | ||
| _depositTokens(users.verifier, users.delegator, amount); | ||
|
|
||
| // Thaw only the first tuple | ||
| escrow.thaw(users.verifier, users.indexer, amount / 2); | ||
|
|
||
| // Second tuple should be unaffected | ||
| (, uint256 tokensThawing2, uint256 thawEndTimestamp2) = escrow.escrowAccounts( | ||
| users.gateway, | ||
| users.verifier, | ||
| users.delegator | ||
| ); | ||
| assertEq(tokensThawing2, 0); | ||
| assertEq(thawEndTimestamp2, 0); | ||
|
|
||
| // First tuple should have thawing | ||
| (, uint256 tokensThawing1, ) = escrow.escrowAccounts(users.gateway, users.verifier, users.indexer); | ||
| assertEq(tokensThawing1, amount / 2); | ||
| } | ||
|
|
||
| function testIsolation_EscrowAccounts_NeverUsedAccount() public view { | ||
| (uint256 balance, uint256 tokensThawing, uint256 thawEndTimestamp) = escrow.escrowAccounts( | ||
| address(0xdead), | ||
| address(0xbeef), | ||
| address(0xface) | ||
| ); | ||
| assertEq(balance, 0); | ||
| assertEq(tokensThawing, 0); | ||
| assertEq(thawEndTimestamp, 0); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.