@@ -56,270 +56,4 @@ contract SuccinctVAppRewardsTest is SuccinctVAppTest {
5656 // Use vm.store to directly set the rewardsRoot in storage.
5757 vm.store (VAPP, bytes32 (REWARDS_ROOT_SLOT), _root);
5858 }
59-
60- // Initial state should have no root and all indexes should be unclaimed.
61- function test_Rewards_WhenInitialState () public view {
62- // Rewards root should be empty initially.
63- assertEq (SuccinctVApp (VAPP).rewardsRoot (), bytes32 (0 ));
64-
65- // All indexes should be unclaimed.
66- for (uint256 i = 0 ; i < rewardAccounts.length ; i++ ) {
67- assertEq (SuccinctVApp (VAPP).isClaimed (i), false );
68- }
69- }
70-
71- // A valid proof should be able to claim a reward.
72- function test_RewardClaim_WhenValid () public {
73- // Set the rewards root.
74- _setRewardsRoot (rewardsMerkleRoot);
75-
76- // Verify the root was set correctly.
77- assertEq (
78- SuccinctVApp (VAPP).rewardsRoot (), rewardsMerkleRoot, "Rewards root not set correctly "
79- );
80-
81- uint256 vappBalBefore = MockERC20 (PROVE).balanceOf (VAPP);
82-
83- for (uint256 i = 0 ; i < rewardAccounts.length ; i++ ) {
84- // Setup.
85- address claimer = rewardAccounts[i];
86- uint256 amount = rewardAmounts[i];
87- bytes32 [] memory proof = merkle.getProof (rewardLeaves, i);
88- uint256 preClaimerBalance = MockERC20 (PROVE).balanceOf (claimer);
89- bool preIsClaimedState = SuccinctVApp (VAPP).isClaimed (i);
90-
91- // Check pre-claim state.
92- assertEq (preClaimerBalance, 0 );
93- assertEq (preIsClaimedState, false );
94-
95- // Claim.
96- vm.expectEmit (true , true , true , true , VAPP);
97- emit ISuccinctVApp.RewardClaimed (i, claimer, amount);
98- SuccinctVApp (VAPP).rewardClaim (i, claimer, amount, proof);
99-
100- // Check post-claim state.
101- if (claimer == testProver) {
102- // For provers, PROVE is converted to iPROVE and sent to prover vault.
103- assertEq (MockERC20 (I_PROVE).balanceOf (claimer), amount);
104- assertEq (MockERC20 (PROVE).balanceOf (claimer), 0 );
105- } else {
106- // For regular accounts, PROVE is sent directly.
107- assertEq (MockERC20 (PROVE).balanceOf (claimer), amount);
108- }
109- vappBalBefore -= amount;
110- assertEq (MockERC20 (PROVE).balanceOf (VAPP), vappBalBefore);
111- assertEq (SuccinctVApp (VAPP).isClaimed (i), true );
112- }
113- }
114-
115- // Not allowed to re-claim a reward.
116- function test_RevertRewardClaim_WhenAlreadyClaimed () public {
117- // Set the rewards root.
118- _setRewardsRoot (rewardsMerkleRoot);
119-
120- // Claim all rewards.
121- for (uint256 i = 0 ; i < rewardAccounts.length ; i++ ) {
122- bytes32 [] memory proof = merkle.getProof (rewardLeaves, i);
123- SuccinctVApp (VAPP).rewardClaim (i, rewardAccounts[i], rewardAmounts[i], proof);
124- }
125-
126- // Attempt to claim again.
127- for (uint256 i = 0 ; i < rewardAccounts.length ; i++ ) {
128- bytes32 [] memory proof = merkle.getProof (rewardLeaves, i);
129- vm.expectRevert (ISuccinctVApp.RewardAlreadyClaimed.selector );
130- SuccinctVApp (VAPP).rewardClaim (i, rewardAccounts[i], rewardAmounts[i], proof);
131- }
132- }
133-
134- // Not allowed to claim with an invalid proof.
135- function test_RevertRewardClaim_WhenInvalidProof () public {
136- // Set the rewards root.
137- _setRewardsRoot (rewardsMerkleRoot);
138-
139- // Setup.
140- uint256 index = 0 ;
141- uint256 invalidIndex = 1 ;
142- address claimer = rewardAccounts[index];
143- uint256 amount = rewardAmounts[index];
144- bytes32 [] memory invalidProof = merkle.getProof (rewardLeaves, invalidIndex);
145-
146- // Attempt to claim with an invalid proof.
147- vm.expectRevert (ISuccinctVApp.InvalidProof.selector );
148- SuccinctVApp (VAPP).rewardClaim (index, claimer, amount, invalidProof);
149- }
150-
151- // Not allowed to claim when paused.
152- function test_RevertRewardClaim_WhenPaused () public {
153- // Pause the contract.
154- vm.prank (OWNER);
155- SuccinctVApp (VAPP).pause ();
156-
157- // Setup test data.
158- uint256 index = 0 ;
159- address claimer = rewardAccounts[index];
160- uint256 amount = rewardAmounts[index];
161- bytes32 [] memory proof = merkle.getProof (rewardLeaves, index);
162-
163- // Attempt to claim when paused.
164- vm.expectRevert (abi.encodeWithSelector (PausableUpgradeable.EnforcedPause.selector ));
165- SuccinctVApp (VAPP).rewardClaim (index, claimer, amount, proof);
166- }
167-
168- // isClaimed should correctly track claimed rewards.
169- function test_IsClaimed_BitMapLogic () public {
170- // Set the rewards root.
171- _setRewardsRoot (rewardsMerkleRoot);
172-
173- // Test the bitmap logic for various indexes.
174- assertEq (SuccinctVApp (VAPP).isClaimed (0 ), false );
175- assertEq (SuccinctVApp (VAPP).isClaimed (255 ), false );
176- assertEq (SuccinctVApp (VAPP).isClaimed (256 ), false );
177- assertEq (SuccinctVApp (VAPP).isClaimed (512 ), false );
178-
179- // Claim index 0.
180- bytes32 [] memory proof = merkle.getProof (rewardLeaves, 0 );
181- SuccinctVApp (VAPP).rewardClaim (0 , rewardAccounts[0 ], rewardAmounts[0 ], proof);
182- assertEq (SuccinctVApp (VAPP).isClaimed (0 ), true );
183- assertEq (SuccinctVApp (VAPP).isClaimed (1 ), false );
184- }
185-
186- // Anyone is allowed to claim a reward for an account as long it's valid.
187- function test_RewardClaim_WhenDifferentCaller () public {
188- // Set the rewards root.
189- _setRewardsRoot (rewardsMerkleRoot);
190-
191- // Anyone should be able to call rewardClaim for any account.
192- address randomCaller = makeAddr ("RANDOM_CALLER " );
193-
194- // Claim as a different caller.
195- bytes32 [] memory proof = merkle.getProof (rewardLeaves, 0 );
196- vm.prank (randomCaller);
197- SuccinctVApp (VAPP).rewardClaim (0 , rewardAccounts[0 ], rewardAmounts[0 ], proof);
198-
199- // Verify the reward went to the correct account.
200- assertEq (MockERC20 (PROVE).balanceOf (rewardAccounts[0 ]), rewardAmounts[0 ]);
201- assertEq (MockERC20 (PROVE).balanceOf (randomCaller), 0 );
202- }
203-
204- // Not allowed to claim with a wrong amount.
205- function test_RevertRewardClaim_WhenWrongAmount () public {
206- // Set the rewards root.
207- _setRewardsRoot (rewardsMerkleRoot);
208-
209- // Try to claim with wrong amount.
210- bytes32 [] memory proof = merkle.getProof (rewardLeaves, 0 );
211- uint256 wrongAmount = rewardAmounts[0 ] + 1 ;
212-
213- vm.expectRevert (ISuccinctVApp.InvalidProof.selector );
214- SuccinctVApp (VAPP).rewardClaim (0 , rewardAccounts[0 ], wrongAmount, proof);
215- }
216-
217- // Not allowed to claim with a wrong account.
218- function test_RevertRewardClaim_WhenWrongAccount () public {
219- // Set the rewards root.
220- _setRewardsRoot (rewardsMerkleRoot);
221-
222- // Try to claim with wrong account.
223- bytes32 [] memory proof = merkle.getProof (rewardLeaves, 0 );
224- address wrongAccount = makeAddr ("WRONG_ACCOUNT " );
225-
226- vm.expectRevert (ISuccinctVApp.InvalidProof.selector );
227- SuccinctVApp (VAPP).rewardClaim (0 , wrongAccount, rewardAmounts[0 ], proof);
228- }
229-
230- // Not allowed to claim with an empty proof.
231- function test_RevertRewardClaim_WhenEmptyProof () public {
232- // Set the rewards root.
233- _setRewardsRoot (rewardsMerkleRoot);
234-
235- // Try to claim with empty proof.
236- bytes32 [] memory emptyProof = new bytes32 [](0 );
237-
238- vm.expectRevert (ISuccinctVApp.InvalidProof.selector );
239- SuccinctVApp (VAPP).rewardClaim (0 , rewardAccounts[0 ], rewardAmounts[0 ], emptyProof);
240- }
241-
242- // It's valid if only a subset of accounts claim within an epoch.
243- function test_RewardClaim_WhenPartial () public {
244- // Set the rewards root.
245- _setRewardsRoot (rewardsMerkleRoot);
246-
247- // Claim only some rewards (not all).
248- uint256 totalClaimed = 0 ;
249- for (uint256 i = 0 ; i < 3 ; i++ ) {
250- bytes32 [] memory proof = merkle.getProof (rewardLeaves, i);
251- SuccinctVApp (VAPP).rewardClaim (i, rewardAccounts[i], rewardAmounts[i], proof);
252- totalClaimed += rewardAmounts[i];
253- }
254-
255- // Check claimed status.
256- assertEq (SuccinctVApp (VAPP).isClaimed (0 ), true );
257- assertEq (SuccinctVApp (VAPP).isClaimed (1 ), true );
258- assertEq (SuccinctVApp (VAPP).isClaimed (2 ), true );
259- assertEq (SuccinctVApp (VAPP).isClaimed (3 ), false );
260- assertEq (SuccinctVApp (VAPP).isClaimed (4 ), false );
261-
262- // Verify correct balances.
263- uint256 expectedRemainingBalance = 100 ether - totalClaimed;
264- assertEq (MockERC20 (PROVE).balanceOf (VAPP), expectedRemainingBalance);
265- }
266-
267- // Rewards should be transferred to the prover vault correctly: PROVE is sent to iPROVE,
268- // and the iPROVE is sent to the prover.
269- function test_RewardClaim_WhenToProverVault () public {
270- // Set the rewards root.
271- _setRewardsRoot (rewardsMerkleRoot);
272-
273- // Get the prover index (last one in our array).
274- uint256 proverIndex = rewardAccounts.length - 1 ;
275- address proverVault = rewardAccounts[proverIndex];
276- uint256 amount = rewardAmounts[proverIndex];
277-
278- // Verify it's recognized as a prover.
279- assertEq (proverVault, testProver);
280-
281- // Check initial balances.
282- uint256 initialVAppBalance = MockERC20 (PROVE).balanceOf (VAPP);
283- uint256 initialProverPROVEBalance = MockERC20 (PROVE).balanceOf (proverVault);
284- uint256 initialProveriPROVEBalance = MockERC20 (I_PROVE).balanceOf (proverVault);
285- assertEq (initialProverPROVEBalance, 0 );
286- assertEq (initialProveriPROVEBalance, 0 );
287-
288- // Claim reward for prover.
289- bytes32 [] memory proof = merkle.getProof (rewardLeaves, proverIndex);
290- vm.expectEmit (true , true , true , true , VAPP);
291- emit ISuccinctVApp.RewardClaimed (proverIndex, proverVault, amount);
292- SuccinctVApp (VAPP).rewardClaim (proverIndex, proverVault, amount, proof);
293-
294- // Verify the prover received iPROVE instead of PROVE.
295- assertEq (MockERC20 (PROVE).balanceOf (proverVault), 0 );
296- assertEq (MockERC20 (I_PROVE).balanceOf (proverVault), amount);
297- assertEq (MockERC20 (PROVE).balanceOf (VAPP), initialVAppBalance - amount);
298- assertEq (SuccinctVApp (VAPP).isClaimed (proverIndex), true );
299- }
300-
301- // Rewards should be transferred to mixed prover vaults and EOAs correctly.
302- function test_RewardClaim_WhenMixedAccountTypes () public {
303- // Set the rewards root.
304- _setRewardsRoot (rewardsMerkleRoot);
305-
306- // Claim for regular account (index 0).
307- bytes32 [] memory proof0 = merkle.getProof (rewardLeaves, 0 );
308- SuccinctVApp (VAPP).rewardClaim (0 , rewardAccounts[0 ], rewardAmounts[0 ], proof0);
309-
310- // Verify regular account received PROVE.
311- assertEq (MockERC20 (PROVE).balanceOf (rewardAccounts[0 ]), rewardAmounts[0 ]);
312- assertEq (MockERC20 (I_PROVE).balanceOf (rewardAccounts[0 ]), 0 );
313-
314- // Claim for prover (last index).
315- uint256 proverIndex = rewardAccounts.length - 1 ;
316- bytes32 [] memory proofProver = merkle.getProof (rewardLeaves, proverIndex);
317- SuccinctVApp (VAPP).rewardClaim (
318- proverIndex, testProver, rewardAmounts[proverIndex], proofProver
319- );
320-
321- // Verify prover received iPROVE.
322- assertEq (MockERC20 (PROVE).balanceOf (testProver), 0 );
323- assertEq (MockERC20 (I_PROVE).balanceOf (testProver), rewardAmounts[proverIndex]);
324- }
32559}
0 commit comments