|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity >=0.8.27; |
| 3 | + |
| 4 | +import {SysstiaBase} from "./Base.t.sol"; |
| 5 | + |
| 6 | +import {IERC20Errors} from "@oz/interfaces/draft-IERC6093.sol"; |
| 7 | + |
| 8 | +import {Errors} from "@aztec/governance/libraries/Errors.sol"; |
| 9 | + |
| 10 | +contract ClaimTest is SysstiaBase { |
| 11 | + address internal caller; |
| 12 | + |
| 13 | + function test_WhenCallerIsNotCanonical(address _caller) external { |
| 14 | + // it reverts |
| 15 | + vm.assume(_caller != address(0xdead)); |
| 16 | + |
| 17 | + vm.expectRevert( |
| 18 | + abi.encodeWithSelector(Errors.Sysstia__InvalidCaller.selector, _caller, address(0xdead)) |
| 19 | + ); |
| 20 | + vm.prank(_caller); |
| 21 | + sysstia.claim(_caller); |
| 22 | + } |
| 23 | + |
| 24 | + modifier whenCallerIsCanonical() { |
| 25 | + caller = address(0xdead); |
| 26 | + _; |
| 27 | + } |
| 28 | + |
| 29 | + function test_GivenBalanceSmallerThanReward() external whenCallerIsCanonical { |
| 30 | + // it reverts |
| 31 | + uint256 needed = sysstia.BLOCK_REWARD(); |
| 32 | + vm.prank(caller); |
| 33 | + vm.expectRevert( |
| 34 | + abi.encodeWithSelector( |
| 35 | + IERC20Errors.ERC20InsufficientBalance.selector, address(sysstia), 0, needed |
| 36 | + ) |
| 37 | + ); |
| 38 | + sysstia.claim(caller); |
| 39 | + } |
| 40 | + |
| 41 | + function test_GivenBalanceLargerOrEqualReward(uint256 _balance) external whenCallerIsCanonical { |
| 42 | + // it transfers block reward of asset |
| 43 | + // it returns block reward value |
| 44 | + uint256 balance = bound(_balance, sysstia.BLOCK_REWARD(), type(uint256).max); |
| 45 | + token.mint(address(sysstia), balance); |
| 46 | + |
| 47 | + uint256 callerBalance = token.balanceOf(caller); |
| 48 | + vm.prank(caller); |
| 49 | + sysstia.claim(caller); |
| 50 | + |
| 51 | + assertEq(token.balanceOf(caller), callerBalance + sysstia.BLOCK_REWARD()); |
| 52 | + } |
| 53 | +} |
0 commit comments