|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity >=0.8.27; |
| 3 | + |
| 4 | +import {Ownable} from "@oz/access/Ownable.sol"; |
| 5 | +import {IERC20} from "@oz/token/ERC20/IERC20.sol"; |
| 6 | +import {Errors} from "@aztec/governance/libraries/Errors.sol"; |
| 7 | +import {NomismatokopioBase} from "./Base.t.sol"; |
| 8 | + |
| 9 | +contract MintTest is NomismatokopioBase { |
| 10 | + uint256 internal constant RATE = 1e18; |
| 11 | + uint256 internal maxMint; |
| 12 | + |
| 13 | + function setUp() public { |
| 14 | + _deploy(RATE); |
| 15 | + vm.warp(block.timestamp + 1000); |
| 16 | + |
| 17 | + maxMint = nom.mintAvailable(); |
| 18 | + |
| 19 | + assertGt(maxMint, 0); |
| 20 | + } |
| 21 | + |
| 22 | + function test_GivenCallerIsNotOwner(address _caller) external { |
| 23 | + // it reverts |
| 24 | + vm.assume(_caller != address(this)); |
| 25 | + vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, _caller)); |
| 26 | + vm.prank(_caller); |
| 27 | + nom.mint(address(0xdead), 1); |
| 28 | + } |
| 29 | + |
| 30 | + modifier givenCallerIsOwner() { |
| 31 | + _; |
| 32 | + } |
| 33 | + |
| 34 | + function test_GivenAmountLargerThanMaxMint(uint256 _amount) external givenCallerIsOwner { |
| 35 | + // it reverts |
| 36 | + uint256 amount = bound(_amount, maxMint + 1, type(uint256).max); |
| 37 | + vm.expectRevert( |
| 38 | + abi.encodeWithSelector( |
| 39 | + Errors.Nomismatokopio__InssuficientMintAvailable.selector, maxMint, amount |
| 40 | + ) |
| 41 | + ); |
| 42 | + nom.mint(address(0xdead), amount); |
| 43 | + } |
| 44 | + |
| 45 | + function test_GivenAmountLessThanOrEqualMaxMint(uint256 _amount) external givenCallerIsOwner { |
| 46 | + // it updates timeOfLastMint |
| 47 | + // it mints amount |
| 48 | + // it emits a {Transfer} event |
| 49 | + // it will return 0 for mintAvailable in same block |
| 50 | + uint256 amount = bound(_amount, 1, maxMint); |
| 51 | + assertGt(amount, 0); |
| 52 | + uint256 balanceBefore = token.balanceOf(address(0xdead)); |
| 53 | + |
| 54 | + vm.expectEmit(true, true, true, false, address(token)); |
| 55 | + emit IERC20.Transfer(address(0), address(0xdead), amount); |
| 56 | + nom.mint(address(0xdead), amount); |
| 57 | + |
| 58 | + assertEq(token.balanceOf(address(0xdead)), balanceBefore + amount); |
| 59 | + assertEq(nom.mintAvailable(), 0); |
| 60 | + assertEq(nom.timeOfLastMint(), block.timestamp); |
| 61 | + } |
| 62 | +} |
0 commit comments