diff --git a/script/DeployTokenWithProxy.s.sol b/script/DeployTokenWithProxy.s.sol index 9545950..4725005 100644 --- a/script/DeployTokenWithProxy.s.sol +++ b/script/DeployTokenWithProxy.s.sol @@ -14,9 +14,6 @@ contract DeployTokenWithProxy is BaseScript { // Read desired max supply from env or use default uint256 defaultMaxSupply = vm.envOr({ name: "MAX_SUPPLY", defaultValue: uint256(1_000_000 * 10 ** 18) }); - // Validate value is sensible - require(defaultMaxSupply > 0, "MAX_SUPPLY must be > 0"); - // Deploy the initial implementation address implementation = address(new TestStableToken()); diff --git a/test/TestStableToken.sol b/test/TestStableToken.sol index fb75c27..8197434 100644 --- a/test/TestStableToken.sol +++ b/test/TestStableToken.sol @@ -15,6 +15,7 @@ error AccountAlreadyMinter(); error AccountNotInMinterList(); error InsufficientETH(); error ExceedsMaxSupply(); +error InvalidMaxSupply(uint256 supplied); contract TestStableToken is Initializable, @@ -45,6 +46,7 @@ contract TestStableToken is __ERC20Permit_init("TestStableToken"); __Ownable_init(); __UUPSUpgradeable_init(); + if (_maxSupply == 0) revert InvalidMaxSupply(_maxSupply); maxSupply = _maxSupply; } @@ -97,9 +99,6 @@ contract TestStableTokenFactory is BaseScript { // Read desired max supply from env or use default uint256 defaultMaxSupply = vm.envOr({ name: "MAX_SUPPLY", defaultValue: uint256(1_000_000 * 10 ** 18) }); - // Validate value is sensible - if (defaultMaxSupply == 0) revert("MAX_SUPPLY must be > 0"); - // Deploy the implementation address implementation = address(new TestStableToken()); diff --git a/test/TestStableToken.t.sol b/test/TestStableToken.t.sol index 8954232..82f20db 100644 --- a/test/TestStableToken.t.sol +++ b/test/TestStableToken.t.sol @@ -8,7 +8,8 @@ import { AccountAlreadyMinter, AccountNotInMinterList, InsufficientETH, - ExceedsMaxSupply + ExceedsMaxSupply, + InvalidMaxSupply } from "./TestStableToken.sol"; import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import { DeployTokenWithProxy } from "../script/DeployTokenWithProxy.s.sol"; @@ -336,4 +337,18 @@ contract TestStableTokenTest is Test { vm.expectRevert("Ownable: caller is not the owner"); token.setMaxSupply(newMaxSupply); } + + function test__InitializeZeroReverts() external { + // Deploy implementation directly + TestStableToken implementation = new TestStableToken(); + + // Build initializer calldata with zero + bytes memory initData = abi.encodeCall(TestStableToken.initialize, (uint256(0))); + + // Expect the InvalidMaxSupply reversion including the supplied value + vm.expectRevert(abi.encodeWithSelector(InvalidMaxSupply.selector, uint256(0))); + + // Attempt to deploy proxy with initData - should revert + new ERC1967Proxy(address(implementation), initData); + } }