@@ -174,4 +174,138 @@ contract EntropyAuthorized is Test, EntropyTestUtils {
174174 vm.expectRevert (EntropyErrors.Unauthorized.selector );
175175 random.acceptAdmin ();
176176 }
177+
178+ function testWithdrawFeeByAdmin () public {
179+ // Register provider1 first
180+ bytes32 [] memory hashChain = generateHashChain (provider1, 0 , 100 );
181+ vm.prank (provider1);
182+ random.register (0 , hashChain[0 ], hex "0100 " , 100 , "" );
183+
184+ // First accrue some fees through requests
185+ vm.prank (admin);
186+ random.setPythFee (10 );
187+
188+ // Make a few requests to accrue fees
189+ bytes32 userCommitment = random.constructUserCommitment (
190+ bytes32 (uint256 (42 ))
191+ );
192+ vm.deal (address (this ), 50 );
193+ for (uint i = 0 ; i < 5 ; i++ ) {
194+ random.request {value: 10 }(provider1, userCommitment, false );
195+ }
196+ assertEq (random.getAccruedPythFees (), 50 );
197+
198+ address targetAddress = address (123 );
199+ uint128 withdrawAmount = 30 ;
200+
201+ vm.prank (admin);
202+ random.withdrawFee (targetAddress, withdrawAmount);
203+
204+ assertEq (random.getAccruedPythFees (), 20 );
205+ assertEq (targetAddress.balance, withdrawAmount);
206+ }
207+
208+ function testWithdrawFeeByOwner () public {
209+ // Register provider1 first
210+ bytes32 [] memory hashChain = generateHashChain (provider1, 0 , 100 );
211+ vm.prank (provider1);
212+ random.register (0 , hashChain[0 ], hex "0100 " , 100 , "" );
213+
214+ // First accrue some fees through requests
215+ vm.prank (admin);
216+ random.setPythFee (10 );
217+
218+ // Make a few requests to accrue fees
219+ bytes32 userCommitment = random.constructUserCommitment (
220+ bytes32 (uint256 (42 ))
221+ );
222+ vm.deal (address (this ), 50 );
223+ for (uint i = 0 ; i < 5 ; i++ ) {
224+ random.request {value: 10 }(provider1, userCommitment, false );
225+ }
226+ assertEq (random.getAccruedPythFees (), 50 );
227+
228+ address targetAddress = address (123 );
229+ uint128 withdrawAmount = 30 ;
230+
231+ vm.prank (owner);
232+ random.withdrawFee (targetAddress, withdrawAmount);
233+
234+ assertEq (random.getAccruedPythFees (), 20 );
235+ assertEq (targetAddress.balance, withdrawAmount);
236+ }
237+
238+ function testWithdrawFeeByUnauthorized () public {
239+ // Register provider1 first
240+ bytes32 [] memory hashChain = generateHashChain (provider1, 0 , 100 );
241+ vm.prank (provider1);
242+ random.register (0 , hashChain[0 ], hex "0100 " , 100 , "" );
243+
244+ // First accrue some fees through requests
245+ vm.prank (admin);
246+ random.setPythFee (10 );
247+
248+ // Make a few requests to accrue fees
249+ bytes32 userCommitment = random.constructUserCommitment (
250+ bytes32 (uint256 (42 ))
251+ );
252+ vm.deal (address (this ), 50 );
253+ for (uint i = 0 ; i < 5 ; i++ ) {
254+ random.request {value: 10 }(provider1, userCommitment, false );
255+ }
256+
257+ vm.prank (admin2);
258+ vm.expectRevert (EntropyErrors.Unauthorized.selector );
259+ random.withdrawFee (address (123 ), 30 );
260+ }
261+
262+ function testWithdrawFeeInsufficientBalance () public {
263+ // Register provider1 first
264+ bytes32 [] memory hashChain = generateHashChain (provider1, 0 , 100 );
265+ vm.prank (provider1);
266+ random.register (0 , hashChain[0 ], hex "0100 " , 100 , "" );
267+
268+ // First accrue some fees through requests
269+ vm.prank (admin);
270+ random.setPythFee (10 );
271+
272+ // Make a few requests to accrue fees
273+ bytes32 userCommitment = random.constructUserCommitment (
274+ bytes32 (uint256 (42 ))
275+ );
276+ vm.deal (address (this ), 50 );
277+ for (uint i = 0 ; i < 5 ; i++ ) {
278+ random.request {value: 10 }(provider1, userCommitment, false );
279+ }
280+ assertEq (random.getAccruedPythFees (), 50 );
281+
282+ vm.prank (admin);
283+ vm.expectRevert (EntropyErrors.InsufficientFee.selector );
284+ random.withdrawFee (address (123 ), 60 );
285+ }
286+
287+ function testWithdrawFeeToZeroAddress () public {
288+ // Register provider1 first
289+ bytes32 [] memory hashChain = generateHashChain (provider1, 0 , 100 );
290+ vm.prank (provider1);
291+ random.register (0 , hashChain[0 ], hex "0100 " , 100 , "" );
292+
293+ // First accrue some fees through requests
294+ vm.prank (admin);
295+ random.setPythFee (10 );
296+
297+ // Make a few requests to accrue fees
298+ bytes32 userCommitment = random.constructUserCommitment (
299+ bytes32 (uint256 (42 ))
300+ );
301+ vm.deal (address (this ), 50 );
302+ for (uint i = 0 ; i < 5 ; i++ ) {
303+ random.request {value: 10 }(provider1, userCommitment, false );
304+ }
305+ assertEq (random.getAccruedPythFees (), 50 );
306+
307+ vm.prank (admin);
308+ vm.expectRevert ("targetAddress is zero address " );
309+ random.withdrawFee (address (0 ), 30 );
310+ }
177311}
0 commit comments