@@ -5,89 +5,10 @@ import "forge-std/Test.sol";
55
66import { IHorizonStakingMain } from "../../contracts/interfaces/internal/IHorizonStakingMain.sol " ;
77import { IGraphPayments } from "../../contracts/interfaces/IGraphPayments.sol " ;
8- import { IPaymentsEscrow } from "../../contracts/interfaces/IPaymentsEscrow.sol " ;
98
109import { GraphEscrowTest } from "./GraphEscrow.t.sol " ;
1110
1211contract GraphEscrowCollectTest is GraphEscrowTest {
13-
14- struct CollectPaymentData {
15- uint256 escrowBalance;
16- uint256 paymentsBalance;
17- uint256 receiverBalance;
18- uint256 delegationPoolBalance;
19- uint256 dataServiceBalance;
20- }
21-
22- function _collect (
23- IGraphPayments.PaymentTypes _paymentType ,
24- address _payer ,
25- address _receiver ,
26- uint256 _tokens ,
27- address _dataService ,
28- uint256 _tokensDataService
29- ) private {
30- (, address _collector , ) = vm.readCallers ();
31-
32- // Previous balances
33- (uint256 previousPayerEscrowBalance ,,) = escrow.escrowAccounts (_payer, _collector, _receiver);
34- CollectPaymentData memory previousBalances = CollectPaymentData ({
35- escrowBalance: token.balanceOf (address (escrow)),
36- paymentsBalance: token.balanceOf (address (payments)),
37- receiverBalance: token.balanceOf (_receiver),
38- delegationPoolBalance: staking.getDelegatedTokensAvailable (
39- _receiver,
40- _dataService
41- ),
42- dataServiceBalance: token.balanceOf (_dataService)
43- });
44-
45- vm.expectEmit (address (escrow));
46- emit IPaymentsEscrow.EscrowCollected (_payer, _collector, _receiver, _tokens);
47- escrow.collect (_paymentType, _payer, _receiver, _tokens, _dataService, _tokensDataService);
48-
49- // Calculate cuts
50- uint256 protocolPaymentCut = payments.PROTOCOL_PAYMENT_CUT ();
51- uint256 delegatorCut = staking.getDelegationFeeCut (
52- _receiver,
53- _dataService,
54- _paymentType
55- );
56-
57- // After balances
58- (uint256 afterPayerEscrowBalance ,,) = escrow.escrowAccounts (_payer, _collector, _receiver);
59- CollectPaymentData memory afterBalances = CollectPaymentData ({
60- escrowBalance: token.balanceOf (address (escrow)),
61- paymentsBalance: token.balanceOf (address (payments)),
62- receiverBalance: token.balanceOf (_receiver),
63- delegationPoolBalance: staking.getDelegatedTokensAvailable (
64- _receiver,
65- _dataService
66- ),
67- dataServiceBalance: token.balanceOf (_dataService)
68- });
69-
70- // Check receiver balance after payment
71- uint256 receiverExpectedPayment = _tokens - _tokensDataService - _tokens * protocolPaymentCut / MAX_PPM - _tokens * delegatorCut / MAX_PPM;
72- assertEq (afterBalances.receiverBalance - previousBalances.receiverBalance, receiverExpectedPayment);
73- assertEq (token.balanceOf (address (payments)), 0 );
74-
75- // Check delegation pool balance after payment
76- assertEq (afterBalances.delegationPoolBalance - previousBalances.delegationPoolBalance, _tokens * delegatorCut / MAX_PPM);
77-
78- // Check that the escrow account has been updated
79- assertEq (previousBalances.escrowBalance, afterBalances.escrowBalance + _tokens);
80-
81- // Check that payments balance didn't change
82- assertEq (previousBalances.paymentsBalance, afterBalances.paymentsBalance);
83-
84- // Check data service balance after payment
85- assertEq (afterBalances.dataServiceBalance - previousBalances.dataServiceBalance, _tokensDataService);
86-
87- // Check payers escrow balance after payment
88- assertEq (previousPayerEscrowBalance - _tokens, afterPayerEscrowBalance);
89- }
90-
9112 /*
9213 * TESTS
9314 */
@@ -96,9 +17,14 @@ contract GraphEscrowCollectTest is GraphEscrowTest {
9617 uint256 tokens ,
9718 uint256 delegationTokens ,
9819 uint256 tokensDataService
99- ) public useIndexer useProvision (tokens, 0 , 0 ) useDelegationFeeCut (IGraphPayments.PaymentTypes.QueryFee, delegationFeeCut) {
100- uint256 tokensProtocol = tokens * protocolPaymentCut / MAX_PPM;
101- uint256 tokensDelegatoion = tokens * delegationFeeCut / MAX_PPM;
20+ )
21+ public
22+ useIndexer
23+ useProvision (tokens, 0 , 0 )
24+ useDelegationFeeCut (IGraphPayments.PaymentTypes.QueryFee, delegationFeeCut)
25+ {
26+ uint256 tokensProtocol = (tokens * protocolPaymentCut) / MAX_PPM;
27+ uint256 tokensDelegatoion = (tokens * delegationFeeCut) / MAX_PPM;
10228 vm.assume (tokensDataService < tokens - tokensProtocol - tokensDelegatoion);
10329
10430 delegationTokens = bound (delegationTokens, 1 , MAX_STAKING_TOKENS);
@@ -109,55 +35,96 @@ contract GraphEscrowCollectTest is GraphEscrowTest {
10935 _depositTokens (users.verifier, users.indexer, tokens);
11036
11137 resetPrank (users.verifier);
112- _collect (IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, tokens, subgraphDataServiceAddress, tokensDataService);
38+ _collectEscrow (
39+ IGraphPayments.PaymentTypes.QueryFee,
40+ users.gateway,
41+ users.indexer,
42+ tokens,
43+ subgraphDataServiceAddress,
44+ tokensDataService
45+ );
11346 }
11447
11548 function testCollect_RevertWhen_SenderHasInsufficientAmountInEscrow (
116- uint256 amount ,
49+ uint256 amount ,
11750 uint256 insufficientAmount
118- ) public useGateway useDeposit (insufficientAmount) {
51+ ) public useGateway useDeposit (insufficientAmount) {
11952 vm.assume (amount > 0 );
12053 vm.assume (insufficientAmount < amount);
12154
12255 vm.startPrank (users.verifier);
123- bytes memory expectedError = abi.encodeWithSignature ("PaymentsEscrowInsufficientBalance(uint256,uint256) " , insufficientAmount, amount);
56+ bytes memory expectedError = abi.encodeWithSignature (
57+ "PaymentsEscrowInsufficientBalance(uint256,uint256) " ,
58+ insufficientAmount,
59+ amount
60+ );
12461 vm.expectRevert (expectedError);
125- escrow.collect (IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, amount, subgraphDataServiceAddress, 0 );
62+ escrow.collect (
63+ IGraphPayments.PaymentTypes.QueryFee,
64+ users.gateway,
65+ users.indexer,
66+ amount,
67+ subgraphDataServiceAddress,
68+ 0
69+ );
12670 vm.stopPrank ();
12771 }
12872
12973 function testCollect_RevertWhen_InvalidPool (
13074 uint256 amount
131- ) public useIndexer useProvision (amount, 0 , 0 ) useDelegationFeeCut (IGraphPayments.PaymentTypes.QueryFee, delegationFeeCut) {
75+ )
76+ public
77+ useIndexer
78+ useProvision (amount, 0 , 0 )
79+ useDelegationFeeCut (IGraphPayments.PaymentTypes.QueryFee, delegationFeeCut)
80+ {
13281 vm.assume (amount > 1 ether);
13382
13483 resetPrank (users.gateway);
13584 _depositTokens (users.verifier, users.indexer, amount);
13685
13786 resetPrank (users.verifier);
138- vm.expectRevert (abi.encodeWithSelector (
139- IHorizonStakingMain.HorizonStakingInvalidDelegationPool.selector ,
87+ vm.expectRevert (
88+ abi.encodeWithSelector (
89+ IHorizonStakingMain.HorizonStakingInvalidDelegationPool.selector ,
90+ users.indexer,
91+ subgraphDataServiceAddress
92+ )
93+ );
94+ escrow.collect (
95+ IGraphPayments.PaymentTypes.QueryFee,
96+ users.gateway,
14097 users.indexer,
141- subgraphDataServiceAddress
142- ));
143- escrow.collect (IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, amount, subgraphDataServiceAddress, 1 );
98+ amount,
99+ subgraphDataServiceAddress,
100+ 1
101+ );
144102 }
145103
146104 function testCollect_RevertWhen_InvalidProvision (
147105 uint256 amount
148106 ) public useIndexer useDelegationFeeCut (IGraphPayments.PaymentTypes.QueryFee, delegationFeeCut) {
149107 vm.assume (amount > 1 ether);
150108 vm.assume (amount <= MAX_STAKING_TOKENS);
151-
109+
152110 resetPrank (users.gateway);
153111 _depositTokens (users.verifier, users.indexer, amount);
154112
155113 resetPrank (users.verifier);
156- vm.expectRevert (abi.encodeWithSelector (
157- IHorizonStakingMain.HorizonStakingInvalidProvision.selector ,
114+ vm.expectRevert (
115+ abi.encodeWithSelector (
116+ IHorizonStakingMain.HorizonStakingInvalidProvision.selector ,
117+ users.indexer,
118+ subgraphDataServiceAddress
119+ )
120+ );
121+ escrow.collect (
122+ IGraphPayments.PaymentTypes.QueryFee,
123+ users.gateway,
158124 users.indexer,
159- subgraphDataServiceAddress
160- ));
161- escrow.collect (IGraphPayments.PaymentTypes.QueryFee, users.gateway, users.indexer, amount, subgraphDataServiceAddress, 1 );
125+ amount,
126+ subgraphDataServiceAddress,
127+ 1
128+ );
162129 }
163- }
130+ }
0 commit comments