Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: capped minter v2 nested testing #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
7e8117f
feat: copy capped minter for v2 template
marcomariscal Dec 3, 2024
d8da7d0
feat: copy capped minter factory tests for v2
marcomariscal Dec 3, 2024
12b292d
feat: inherit from AccessControl and update accordingly
marcomariscal Dec 3, 2024
b597f72
feat: update tests to handle new auth functionality
marcomariscal Dec 3, 2024
2030897
feat: add minter role
marcomariscal Dec 3, 2024
f9ed313
feat: test admin can't mint by default
marcomariscal Dec 3, 2024
7483d1f
fix: name
marcomariscal Dec 3, 2024
59bccb4
feat: basic pause functionality
marcomariscal Dec 3, 2024
f5bb1a8
feat: pause/unpause tests
marcomariscal Dec 3, 2024
b85f60f
fix: assume cap is not zero
marcomariscal Dec 3, 2024
7eb43d0
fix: check for pauser role
marcomariscal Dec 3, 2024
29362c9
fix: separate role errors
marcomariscal Dec 4, 2024
b3e1cb4
feat: _revertIfNotPauser
marcomariscal Dec 4, 2024
a5c8e37
feat: close with tests
marcomariscal Dec 4, 2024
29a35e0
fix: use _revertIfNotPauser
marcomariscal Dec 4, 2024
85bf41a
chore: better comment for `close`
marcomariscal Dec 4, 2024
ab7a46d
feat: update with new time control params
marcomariscal Dec 4, 2024
01ee4e6
feat: time controls and tests
marcomariscal Dec 4, 2024
b309fb7
fix: clearer expiration checks
marcomariscal Dec 4, 2024
112421e
chore: comment
marcomariscal Dec 4, 2024
fe1dbb4
fix: should be able to mint at start and at expiry
marcomariscal Dec 4, 2024
9f8ea6e
feat: inherit from AccessControl and update accordingly
marcomariscal Dec 4, 2024
2aecdce
feat: update tests to handle new auth functionality
marcomariscal Dec 4, 2024
e293e2d
feat: add minter role
marcomariscal Dec 4, 2024
b7f4222
feat: test admin can't mint by default
marcomariscal Dec 4, 2024
726d0bf
fix: name
marcomariscal Dec 4, 2024
31d626f
fix: structure
marcomariscal Dec 4, 2024
fb88648
feat: basic pause functionality
marcomariscal Dec 3, 2024
946dc79
feat: pause/unpause tests
marcomariscal Dec 3, 2024
d9b3dba
fix: assume cap is not zero
marcomariscal Dec 3, 2024
1cfbef7
fix: check for pauser role
marcomariscal Dec 3, 2024
3379852
fix: separate role errors
marcomariscal Dec 4, 2024
004c789
feat: _revertIfNotPauser
marcomariscal Dec 4, 2024
4f29f5c
feat: close with tests
marcomariscal Dec 4, 2024
edf05f6
fix: use _revertIfNotPauser
marcomariscal Dec 4, 2024
bceb0f7
chore: better comment for `close`
marcomariscal Dec 4, 2024
6251a0b
Merge branch 'feat/capped-minter-v2-close' into feat/capped-minter-v2…
marcomariscal Dec 4, 2024
e680c31
chore: comment
marcomariscal Dec 10, 2024
6ee3fb1
feat: _grantMinterRole helper
marcomariscal Dec 10, 2024
72ef93c
fix: use _checkRole and remove unused unauth error
marcomariscal Dec 10, 2024
dd15cac
fix: assume cap
marcomariscal Dec 10, 2024
61e7247
fix: toml
marcomariscal Dec 10, 2024
1295f88
chore: format
marcomariscal Dec 10, 2024
54315f5
fix: import
marcomariscal Dec 10, 2024
2558249
fix: compile
marcomariscal Dec 10, 2024
857ebc6
chore: name
marcomariscal Dec 10, 2024
479ef77
fix: import
marcomariscal Dec 10, 2024
007784b
fix: remove unnecessary
marcomariscal Dec 10, 2024
bfbac0e
feat: _revertIfClosed
marcomariscal Dec 10, 2024
1b290b7
Merge branch 'feat/capped-minter-v2-close' into feat/capped-minter-v2…
marcomariscal Dec 10, 2024
8a5f057
Merge branch 'feat/capped-minter-v2-minter-role' into feat/capped-min…
marcomariscal Dec 10, 2024
493c1a6
feat: _formatAccessControlError
marcomariscal Dec 10, 2024
7d84ebe
Merge branch 'feat/capped-minter-v2-pause' into feat/capped-minter-v2…
marcomariscal Dec 10, 2024
6bb7d1a
fix: formatted error
marcomariscal Dec 10, 2024
e6a8718
Merge branch 'feat/capped-minter-v2-close' into feat/capped-minter-v2…
marcomariscal Dec 10, 2024
fca3ffb
fix: remove assume cap greater than 0 in favor of bound
marcomariscal Dec 11, 2024
93e4af3
fix: remove unnecessary assumptions
marcomariscal Dec 11, 2024
225ba92
fix: use grant minter role
marcomariscal Dec 11, 2024
1942a64
fix: remove redundant balance check
marcomariscal Dec 11, 2024
77acf62
feat: refactor to set up capped minter in setup func
marcomariscal Dec 11, 2024
ecb275d
feat: testFuzz_CorrectlyPausesMintsWhenTogglingPause
marcomariscal Dec 11, 2024
43fa666
fix: move func
marcomariscal Dec 11, 2024
7da3772
Merge branch 'feat/capped-minter-v2-pause' into feat/capped-minter-v2…
marcomariscal Dec 12, 2024
57e1f4f
fix: only admin can close, fix mint to zero addr receiver, and format…
marcomariscal Dec 12, 2024
ef8ca96
fix: remove unnecessary revert if closed when unpausing
marcomariscal Dec 12, 2024
3fc7d3a
Update l2-contracts/src/ZkCappedMinterV2.sol
marcomariscal Dec 12, 2024
bb6854b
fix: test
marcomariscal Dec 12, 2024
0b17e88
fix: remove unnecessary pause from close
marcomariscal Dec 12, 2024
7631a29
fix: use global minter
marcomariscal Dec 12, 2024
b0da759
Merge branch 'feat/capped-minter-v2-close' into feat/capped-minter-v2…
marcomariscal Dec 12, 2024
ffc248a
fix: remove unnecessary cap bounds
marcomariscal Dec 12, 2024
d1a7306
fix: testFuzz_RevertIf_StartTimeAfterExpirationTime
marcomariscal Dec 12, 2024
70b49f0
fix: tests
marcomariscal Dec 12, 2024
4b8499f
fix: tests
marcomariscal Dec 12, 2024
246efdc
feat: test_CorrectlyChangesClosedVarWhenCalledByAdmin
marcomariscal Dec 16, 2024
37fe9e1
fix: make start time and expiration time uint48
marcomariscal Dec 16, 2024
083ef5f
fix: more readable default expiration distance
marcomariscal Dec 16, 2024
696bd69
Merge branch 'feat/capped-minter-v2-close' into feat/capped-minter-v2…
marcomariscal Dec 16, 2024
91c0ca8
fix: foundry toml revert
marcomariscal Dec 16, 2024
aa47d27
Merge branch 'feat/capped-minter-v2' into feat/capped-minter-v2-close
marcomariscal Dec 16, 2024
7a5e5a7
Merge branch 'feat/capped-minter-v2-close' into feat/capped-minter-v2…
marcomariscal Dec 16, 2024
eb0d858
feat: _grantMinterRoleToCappedMinter and nested minting tests
marcomariscal Dec 16, 2024
fcc7c6a
feat: testFuzz_NestedMintingContributesToParentCap
marcomariscal Dec 17, 2024
3441ce2
fix: _mintable and IMintable
marcomariscal Dec 17, 2024
15a6bf0
Merge branch 'feat/capped-minter-v2' into feat/capped-minter-v2-neste…
marcomariscal Dec 17, 2024
2d37a6e
chore: remove unused
marcomariscal Dec 17, 2024
ec8c0db
chore: comment clarity
marcomariscal Dec 17, 2024
164ec5d
fix: remove unnecessary token minter role
marcomariscal Dec 17, 2024
40c65fb
feat: function testFuzz_ParentMintDoesNotCountAgainstChildCap(
marcomariscal Dec 17, 2024
15f79ac
fix: bounds
marcomariscal Dec 17, 2024
56d5719
Merge branch 'feat/capped-minter-v2' into feat/capped-minter-v2-neste…
marcomariscal Dec 17, 2024
637ac39
fix: params
marcomariscal Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions l2-contracts/src/ZkCappedMinterV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ pragma solidity 0.8.24;

import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {IMintableAndDelegatable} from "src/interfaces/IMintableAndDelegatable.sol";
import {IMintable} from "src/interfaces/IMintable.sol";

/// @title ZkCappedMinterV2
/// @author [ScopeLift](https://scopelift.co)
/// @notice A contract to allow a permissioned entity to mint ZK tokens up to a given amount (the cap).
/// @custom:security-contact [email protected]
contract ZkCappedMinterV2 is AccessControl, Pausable {
/// @notice The contract where the tokens will be minted by an authorized minter.
IMintableAndDelegatable public immutable TOKEN;
IMintable public immutable MINTABLE;

/// @notice The maximum number of tokens that may be minted by the ZkCappedMinter.
uint256 public immutable CAP;
Expand Down Expand Up @@ -53,20 +53,20 @@ contract ZkCappedMinterV2 is AccessControl, Pausable {
error ZkCappedMinterV2__InvalidTime();

/// @notice Constructor for a new ZkCappedMinterV2 contract
/// @param _token The token contract where tokens will be minted.
/// @param _mintable The contract where tokens will be minted.
/// @param _admin The address that will be granted the admin role.
/// @param _cap The maximum number of tokens that may be minted by the ZkCappedMinter.
/// @param _startTime The timestamp when minting can begin.
/// @param _expirationTime The timestamp after which minting is no longer allowed (inclusive).
constructor(IMintableAndDelegatable _token, address _admin, uint256 _cap, uint48 _startTime, uint48 _expirationTime) {
constructor(IMintable _mintable, address _admin, uint256 _cap, uint48 _startTime, uint48 _expirationTime) {
if (_startTime > _expirationTime) {
revert ZkCappedMinterV2__InvalidTime();
}
if (_startTime < block.timestamp) {
revert ZkCappedMinterV2__InvalidTime();
}

TOKEN = _token;
MINTABLE = _mintable;
CAP = _cap;
START_TIME = _startTime;
EXPIRATION_TIME = _expirationTime;
Expand Down Expand Up @@ -102,8 +102,10 @@ contract ZkCappedMinterV2 is AccessControl, Pausable {
_requireNotPaused();
_checkRole(MINTER_ROLE, msg.sender);
_revertIfCapExceeded(_amount);

minted += _amount;
TOKEN.mint(_to, _amount);

MINTABLE.mint(_to, _amount);
}

/// @notice Reverts if the amount of new tokens will increase the minted tokens beyond the mint cap.
Expand Down
24 changes: 12 additions & 12 deletions l2-contracts/src/ZkCappedMinterV2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.24;

import {L2ContractHelper} from "src/lib/L2ContractHelper.sol";
import {ZkCappedMinterV2} from "src/ZkCappedMinterV2.sol";
import {IMintableAndDelegatable} from "src/interfaces/IMintableAndDelegatable.sol";
import {IMintable} from "src/interfaces/IMintable.sol";

/// @title ZkCappedMinterV2Factory
/// @author [ScopeLift](https://scopelift.co)
Expand All @@ -19,64 +19,64 @@ contract ZkCappedMinterV2Factory {

/// @notice Emitted when a new ZkCappedMinterV2 is created.
/// @param minterAddress The address of the newly deployed ZkCappedMinterV2.
/// @param token The token contract where tokens will be minted.
/// @param mintable The contract where tokens will be minted.
/// @param admin The address authorized to mint tokens.
/// @param cap The maximum number of tokens that may be minted.
/// @param startTime The timestamp when minting can begin.
/// @param expirationTime The timestamp after which minting is no longer allowed.
event CappedMinterV2Created(
address indexed minterAddress,
IMintableAndDelegatable token,
IMintable mintable,
address admin,
uint256 cap,
uint48 startTime,
uint48 expirationTime
);

/// @notice Deploys a new ZkCappedMinterV2 contract using CREATE2.
/// @param _token The token contract where tokens will be minted.
/// @param _mintable The contract where tokens will be minted.
/// @param _admin The address authorized to mint tokens.
/// @param _cap The maximum number of tokens that may be minted.
/// @param _startTime The timestamp when minting can begin.
/// @param _expirationTime The timestamp after which minting is no longer allowed.
/// @param _saltNonce A user-provided nonce for salt calculation.
/// @return minterAddress The address of the newly deployed ZkCappedMinterV2.
function createCappedMinter(
IMintableAndDelegatable _token,
IMintable _mintable,
address _admin,
uint256 _cap,
uint48 _startTime,
uint48 _expirationTime,
uint256 _saltNonce
) external returns (address minterAddress) {
bytes memory saltArgs = abi.encode(_token, _admin, _cap, _startTime, _expirationTime);
bytes memory saltArgs = abi.encode(_mintable, _admin, _cap, _startTime, _expirationTime);
bytes32 salt = _calculateSalt(saltArgs, _saltNonce);
ZkCappedMinterV2 instance = new ZkCappedMinterV2{salt: salt}(_token, _admin, _cap, _startTime, _expirationTime);
ZkCappedMinterV2 instance = new ZkCappedMinterV2{salt: salt}(_mintable, _admin, _cap, _startTime, _expirationTime);
minterAddress = address(instance);

emit CappedMinterV2Created(minterAddress, _token, _admin, _cap, _startTime, _expirationTime);
emit CappedMinterV2Created(minterAddress, _mintable, _admin, _cap, _startTime, _expirationTime);
}

/// @notice Computes the address of a ZkCappedMinterV2 deployed via this factory.
/// @param _token The token contract where tokens will be minted.
/// @param _mintable The contract where tokens will be minted.
/// @param _admin The address authorized to mint tokens.
/// @param _cap The maximum number of tokens that may be minted.
/// @param _startTime The timestamp when minting can begin.
/// @param _expirationTime The timestamp after which minting is no longer allowed.
/// @param _saltNonce The nonce used for salt calculation.
/// @return addr The address of the ZkCappedMinterV2.
function getMinter(
IMintableAndDelegatable _token,
IMintable _mintable,
address _admin,
uint256 _cap,
uint48 _startTime,
uint48 _expirationTime,
uint256 _saltNonce
) external view returns (address addr) {
bytes memory saltArgs = abi.encode(_token, _admin, _cap, _startTime, _expirationTime);
bytes memory saltArgs = abi.encode(_mintable, _admin, _cap, _startTime, _expirationTime);
bytes32 salt = _calculateSalt(saltArgs, _saltNonce);
addr = L2ContractHelper.computeCreate2Address(
address(this), salt, BYTECODE_HASH, keccak256(abi.encode(_token, _admin, _cap, _startTime, _expirationTime))
address(this), salt, BYTECODE_HASH, keccak256(abi.encode(_mintable, _admin, _cap, _startTime, _expirationTime))
);
}

Expand Down
180 changes: 167 additions & 13 deletions l2-contracts/test/ZkCappedMinterV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.24;

import {ZkTokenTest} from "test/utils/ZkTokenTest.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {IMintableAndDelegatable} from "src/interfaces/IMintableAndDelegatable.sol";
import {IMintable} from "src/interfaces/IMintable.sol";
import {ZkCappedMinterV2} from "src/ZkCappedMinterV2.sol";
import {console2} from "forge-std/Test.sol";

Expand All @@ -21,17 +21,25 @@ contract ZkCappedMinterV2Test is ZkTokenTest {
DEFAULT_START_TIME = uint48(vm.getBlockTimestamp());
DEFAULT_EXPIRATION_TIME = uint48(DEFAULT_START_TIME + 3 days);

cappedMinter = _createCappedMinter(cappedMinterAdmin, DEFAULT_CAP, DEFAULT_START_TIME, DEFAULT_EXPIRATION_TIME);
cappedMinter =
_createCappedMinter(address(token), cappedMinterAdmin, DEFAULT_CAP, DEFAULT_START_TIME, DEFAULT_EXPIRATION_TIME);

_grantMinterRoleToCappedMinter(address(cappedMinter));
}

function _grantMinterRoleToCappedMinter(address _cappedMinter) internal {
vm.prank(admin);
token.grantRole(MINTER_ROLE, address(cappedMinter));
token.grantRole(MINTER_ROLE, address(_cappedMinter));
}

function _createCappedMinter(address _admin, uint256 _cap, uint48 _startTime, uint48 _expirationTime)
internal
returns (ZkCappedMinterV2)
{
return new ZkCappedMinterV2(IMintableAndDelegatable(address(token)), _admin, _cap, _startTime, _expirationTime);
function _createCappedMinter(
address _mintable,
address _admin,
uint256 _cap,
uint48 _startTime,
uint48 _expirationTime
) internal returns (ZkCappedMinterV2) {
return new ZkCappedMinterV2(IMintable(_mintable), _admin, _cap, _startTime, _expirationTime);
}

function _boundToValidTimeControls(uint48 _startTime, uint48 _expirationTime) internal view returns (uint48, uint48) {
Expand Down Expand Up @@ -69,8 +77,8 @@ contract Constructor is ZkCappedMinterV2Test {
(_startTime, _expirationTime) = _boundToValidTimeControls(_startTime, _expirationTime);
vm.warp(_startTime);

ZkCappedMinterV2 cappedMinter = _createCappedMinter(_admin, _cap, _startTime, _expirationTime);
assertEq(address(cappedMinter.TOKEN()), address(token));
ZkCappedMinterV2 cappedMinter = _createCappedMinter(address(token), _admin, _cap, _startTime, _expirationTime);
assertEq(address(cappedMinter.MINTABLE()), address(token));
assertEq(cappedMinter.CAP(), _cap);
assertEq(cappedMinter.START_TIME(), _startTime);
assertEq(cappedMinter.EXPIRATION_TIME(), _expirationTime);
Expand All @@ -85,7 +93,7 @@ contract Constructor is ZkCappedMinterV2Test {
_startTime = uint48(bound(_startTime, 1, type(uint48).max));
_invalidExpirationTime = uint48(bound(_invalidExpirationTime, 0, _startTime - 1));
vm.expectRevert(ZkCappedMinterV2.ZkCappedMinterV2__InvalidTime.selector);
_createCappedMinter(_admin, _cap, _startTime, _invalidExpirationTime);
_createCappedMinter(address(token), _admin, _cap, _startTime, _invalidExpirationTime);
}

function testFuzz_RevertIf_StartTimeInPast(address _admin, uint256 _cap, uint48 _startTime, uint48 _expirationTime)
Expand All @@ -99,7 +107,7 @@ contract Constructor is ZkCappedMinterV2Test {
_expirationTime = uint48(bound(_expirationTime, _pastStartTime + 1, type(uint48).max));

vm.expectRevert(ZkCappedMinterV2.ZkCappedMinterV2__InvalidTime.selector);
_createCappedMinter(_admin, _cap, _pastStartTime, _expirationTime);
_createCappedMinter(address(token), _admin, _cap, _pastStartTime, _expirationTime);
}
}

Expand Down Expand Up @@ -165,6 +173,109 @@ contract Mint is ZkCappedMinterV2Test {
cappedMinter.mint(_receiver, _amount);
}

function testFuzz_NestedMintingContributesToParentCap(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add a test verifying the parent mint does not count against the child mint

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address _parentAdmin,
address _childAdmin,
address _minter,
address _receiver,
uint256 _parentCap,
uint256 _childCap,
uint256 _amount1,
uint256 _amount2,
uint48 _startTime,
uint48 _expirationTime
) public {
// Setup caps where child cap is less or equal to parent cap
_parentCap = bound(_parentCap, 2, DEFAULT_CAP);
_childCap = bound(_childCap, 2, _parentCap);

// Two amounts that together are within child cap
uint256 maxAmount = _childCap / 2;
_amount1 = bound(_amount1, 1, maxAmount);
_amount2 = bound(_amount2, 1, maxAmount);

vm.assume(_receiver != address(0));

(_startTime, _expirationTime) = _boundToValidTimeControls(_startTime, _expirationTime);
vm.warp(_startTime);

ZkCappedMinterV2 parentMinter =
_createCappedMinter(address(token), _parentAdmin, _parentCap, _startTime, _expirationTime);
// Create child minter with parent minter as token
ZkCappedMinterV2 childMinter =
_createCappedMinter(address(parentMinter), _childAdmin, _childCap, _startTime, _expirationTime);

_grantMinterRoleToCappedMinter(address(parentMinter));

// Parent minter grants MINTER_ROLE to child minter
_grantMinterRole(parentMinter, _parentAdmin, address(childMinter));
// Child minter grants MINTER_ROLE to minter
_grantMinterRole(childMinter, _childAdmin, _minter);

uint256 balanceBefore = token.balanceOf(_receiver);

// Minter mints through child contract
vm.prank(_minter);
childMinter.mint(_receiver, _amount1);

uint256 balanceAfter = token.balanceOf(_receiver);

// Verify amounts are tracked in both contracts
assertEq(childMinter.minted(), _amount1);
assertEq(parentMinter.minted(), _amount1);
assertEq(balanceAfter, balanceBefore + _amount1);

// Mint again
vm.prank(_minter);
childMinter.mint(_receiver, _amount2);

balanceAfter = token.balanceOf(_receiver);

// Verify total amounts are tracked in both contracts
assertEq(childMinter.minted(), _amount1 + _amount2);
assertEq(parentMinter.minted(), _amount1 + _amount2);
assertEq(balanceAfter, balanceBefore + _amount1 + _amount2);
}

function testFuzz_ParentMintDoesNotCountAgainstChildCap(
address _parentAdmin,
address _childAdmin,
address _minter,
address _receiver,
uint256 _parentCap,
uint256 _childCap,
uint256 _amount,
uint48 _startTime,
uint48 _expirationTime
) public {
vm.assume(_receiver != address(0));

_parentCap = bound(_parentCap, 1, DEFAULT_CAP);
_amount = bound(_amount, 1, _parentCap);

(_startTime, _expirationTime) = _boundToValidTimeControls(_startTime, _expirationTime);
vm.warp(_startTime);

ZkCappedMinterV2 parentMinter =
_createCappedMinter(address(token), _parentAdmin, _parentCap, _startTime, _expirationTime);
// Create child minter with parent minter as token
ZkCappedMinterV2 childMinter =
_createCappedMinter(address(parentMinter), _childAdmin, _childCap, _startTime, _expirationTime);

_grantMinterRoleToCappedMinter(address(parentMinter));

// Parent minter grants MINTER_ROLE to minter
_grantMinterRole(parentMinter, _parentAdmin, _minter);

// Minter mints through parent contract
vm.prank(_minter);
parentMinter.mint(_receiver, _amount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we really want to test is that a minter on the child can mint from the child and that this minting consumes contributes towards the limit of the parent minter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I would change some naming in the main contract to reference _mintable or something similar instead of token


// Verify child contract is not affected
assertEq(childMinter.minted(), 0);
assertEq(parentMinter.minted(), _amount);
}

function testFuzz_RevertIf_MintAttemptedByNonMinter(address _nonMinter, uint256 _amount) public {
_amount = bound(_amount, 1, DEFAULT_CAP);

Expand Down Expand Up @@ -230,6 +341,49 @@ contract Mint is ZkCappedMinterV2Test {
vm.prank(_minter);
cappedMinter.mint(_receiver, _amount);
}

function testFuzz_RevertIf_ChildExceedsParentMintEvenThoughChildCapIsHigher(
address _parentAdmin,
address _childAdmin,
address _minter,
address _receiver,
uint256 _parentCap,
uint256 _childCap,
uint256 _amount,
uint48 _startTime,
uint48 _expirationTime
) public {
// Parent has lower cap than child
_parentCap = bound(_parentCap, 2, MAX_MINT_SUPPLY - 1);
_childCap = bound(_childCap, _parentCap + 1, MAX_MINT_SUPPLY);
// Amount exceeds parent cap but is within child cap
_amount = bound(_amount, _parentCap + 1, _childCap);

vm.assume(_parentAdmin != address(0));
vm.assume(_childAdmin != address(0));
vm.assume(_minter != address(0));
vm.assume(_receiver != address(0));
vm.assume(_receiver != initMintReceiver);

(_startTime, _expirationTime) = _boundToValidTimeControls(_startTime, _expirationTime);
vm.warp(_startTime);

ZkCappedMinterV2 parentMinter =
_createCappedMinter(address(token), _parentAdmin, _parentCap, _startTime, _expirationTime);
ZkCappedMinterV2 childMinter =
_createCappedMinter(address(parentMinter), _childAdmin, _childCap, _startTime, _expirationTime);

// Parent minter grants MINTER_ROLE to child minter
_grantMinterRole(parentMinter, _parentAdmin, address(childMinter));

// Child tries to mint more than parent's cap
vm.startPrank(address(childMinter));
vm.expectRevert(
abi.encodeWithSelector(ZkCappedMinterV2.ZkCappedMinterV2__CapExceeded.selector, address(childMinter), _amount)
);
parentMinter.mint(_receiver, _amount);
vm.stopPrank();
}
}

contract Pause is ZkCappedMinterV2Test {
Expand Down Expand Up @@ -342,7 +496,7 @@ contract SetMetadataURI is ZkCappedMinterV2Test {
{
(_startTime, _expirationTime) = _boundToValidTimeControls(_startTime, _expirationTime);

ZkCappedMinterV2 cappedMinter = _createCappedMinter(_admin, _cap, _startTime, _expirationTime);
ZkCappedMinterV2 cappedMinter = _createCappedMinter(address(token), _admin, _cap, _startTime, _expirationTime);
assertEq(cappedMinter.metadataURI(), bytes32(0));
}

Expand Down
Loading
Loading