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 pause #11

Merged

Conversation

marcomariscal
Copy link

No description provided.

@marcomariscal marcomariscal linked an issue Dec 4, 2024 that may be closed by this pull request
5 tasks
@marcomariscal marcomariscal changed the base branch from master to feat/capped-minter-v2-minter-role December 4, 2024 16:35
@marcomariscal marcomariscal force-pushed the feat/capped-minter-v2-pause branch 3 times, most recently from f96ae77 to 29362c9 Compare December 4, 2024 17:44
@marcomariscal marcomariscal force-pushed the feat/capped-minter-v2-minter-role branch from 7483d1f to f417601 Compare December 4, 2024 17:46
@marcomariscal marcomariscal force-pushed the feat/capped-minter-v2-pause branch from b3e1cb4 to ca259f4 Compare December 4, 2024 23:04
@marcomariscal marcomariscal force-pushed the feat/capped-minter-v2-minter-role branch from bbaec92 to 31d626f Compare December 4, 2024 23:17
@marcomariscal marcomariscal force-pushed the feat/capped-minter-v2-pause branch from ca259f4 to 004c789 Compare December 4, 2024 23:17
@marcomariscal marcomariscal force-pushed the feat/capped-minter-v2-minter-role branch from af16880 to 007784b Compare December 10, 2024 19:18
Copy link
Collaborator

@alexkeating alexkeating left a comment

Choose a reason for hiding this comment

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

Some initial thoughts

@@ -46,6 +57,7 @@ contract Mint is ZkCappedMinterV2Test {
uint256 _amount
) public {
_cap = bound(_cap, 0, MAX_MINT_SUPPLY);
vm.assume(_cap > 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use bound for this assume as it is more efficient

Copy link
Author

Choose a reason for hiding this comment

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

fca3ffb

originally had because it's implied that the cap can indeed be 0.

given that this is a permissioned minter where admins are deploying it, and a zero cap would be caught quickly in testing/first use, we probably don't need to check this in the contract or the factory, but just want to call out. omitting a zero cap check here, but lemme know if you think otherwise.

Copy link
Collaborator

Choose a reason for hiding this comment

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

originally had because it's implied that the cap can indeed be 0.

I thought this assume will remove the possibility of the cap being 0 because it must be greater than 0

Copy link
Author

Choose a reason for hiding this comment

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

removes the possibility of the cap being 0 in the test, but you can init the capped minter with a cap of 0.

Copy link
Author

Choose a reason for hiding this comment

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

how we set the bounds now with the bound starting at 1, it's implied that the cap can't be zero, but it can (was how i was thinking bout it).

_cap = bound(_cap, 0, MAX_MINT_SUPPLY);
ZkCappedMinterV2 cappedMinter = createCappedMinter(_cappedMinterAdmin, _cap);
vm.assume(_admin != address(0));
vm.assume(_nonMinter != address(0) && _nonMinter != _admin);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't both of these addresses non minters?

Copy link
Author

Choose a reason for hiding this comment

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

truth; remove all unnecessary assumptions including the above:

93e4af3

)
)
);
vm.expectRevert(_formatAccessControlError(_admin, MINTER_ROLE));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the receiver assume can be removed as there should be no restriction on address

Copy link
Author

Choose a reason for hiding this comment

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

uint256 _amount
) public {
_cap = bound(_cap, 0, MAX_MINT_SUPPLY);
vm.assume(_cap > 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed if the bound above starts with 1

Copy link
Author

Choose a reason for hiding this comment

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

vm.assume(_cap > 0);
_amount = bound(_amount, 1, _cap);
vm.assume(_admin != address(0));
vm.assume(_minter != address(0) && _minter != _admin);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is nothing stopping the minter from being these values

Copy link
Author

Choose a reason for hiding this comment

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

_amount = bound(_amount, 1, _cap);
vm.assume(_admin != address(0));
vm.assume(_minter != address(0) && _minter != _admin);
vm.assume(_receiver != address(0) && _receiver != initMintReceiver);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Copy link
Author

Choose a reason for hiding this comment

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


vm.prank(_minter);
cappedMinter.mint(_receiver, _amount);
assertEq(token.balanceOf(_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.

I think this can be removed as it is tested in another test

Copy link
Author

Choose a reason for hiding this comment

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

_cap = bound(_cap, 0, MAX_MINT_SUPPLY);
vm.assume(_admin != address(0));

ZkCappedMinterV2 cappedMinter = createCappedMinter(_admin, _cap);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Creating the capped minter is a bit redundant. It may be good to move this setup to a helper or the setup and transfer admin role when necessary

Copy link
Author

Choose a reason for hiding this comment

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

}

contract Unpause is ZkCappedMinterV2Test {
function testFuzz_CorrectlyAllowsNewMintsWhenUnpaused(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would take a look at this test with some of the recommendations above

Copy link
Author

Choose a reason for hiding this comment

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

if addressing all of the comments above doesn't resolve this comment, lemme know (not sure what exactly you were talking bout here).

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems resolved, was asking to cleanup test assumes etc..

}
}

contract Pause is ZkCappedMinterV2Test {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be good to have a test case for pause, unpause and then pause again

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@alexkeating alexkeating left a comment

Choose a reason for hiding this comment

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

Looking close a couple small changes left I think

@@ -8,29 +8,46 @@ import {ZkCappedMinterV2} from "src/ZkCappedMinterV2.sol";
import {console2} from "forge-std/Test.sol";

contract ZkCappedMinterV2Test is ZkTokenTest {
ZkCappedMinterV2 public cappedMinter;
uint256 constant DEFAULT_CAP = 1000e18;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would increase this default cap to be more realistic

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe 100_000_000_000e18

Copy link
Author

Choose a reason for hiding this comment

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

_amount1 = bound(_amount1, 1, DEFAULT_CAP / 2);
_amount2 = bound(_amount2, 1, DEFAULT_CAP / 2);
vm.assume(_amount1 + _amount2 < DEFAULT_CAP);
vm.assume(_receiver1 != address(0) && _receiver2 != address(0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to assume this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am seeing this in a bunch of spots and I think it can be removed

Copy link
Author

Choose a reason for hiding this comment

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

receiver being address zero? erc20 throws an error on zero address receiver

}

contract Unpause is ZkCappedMinterV2Test {
function testFuzz_CorrectlyAllowsNewMintsWhenUnpaused(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems resolved, was asking to cleanup test assumes etc..

@marcomariscal marcomariscal merged commit 8289ce2 into feat/capped-minter-v2-minter-role Dec 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pausable Functionality
2 participants