@@ -394,4 +394,123 @@ contract EthscriptionsTokenTest is TestSetup {
394394 assertEq (token.name (), "erc-20 TEST " ); // Token name format is "protocol tick"
395395 assertEq (token.cap (), 1000000 ether); // Original cap, not the duplicate's
396396 }
397+
398+ function testMintWithInvalidIdZero () public {
399+ // Deploy the token first
400+ testTokenDeploy ();
401+
402+ // Try to mint with ID 0 (invalid - must be >= 1)
403+ vm.prank (bob);
404+ string memory mintContent = 'data:,{"p":"erc-20","op":"mint","tick":"TEST","id":"0","amt":"1000"} ' ;
405+
406+ TokenManager.MintOperation memory mintOp = TokenManager.MintOperation ({
407+ tick: "TEST " ,
408+ id: 0 , // Invalid ID - should be >= 1
409+ amount: 1000
410+ });
411+
412+ bytes32 invalidMintHash = bytes32 (uint256 (0xDEAD ));
413+ Ethscriptions.CreateEthscriptionParams memory mintParams = createTokenParams (
414+ invalidMintHash,
415+ bob,
416+ mintContent,
417+ "erc-20 " ,
418+ "mint " ,
419+ abi.encode (mintOp)
420+ );
421+
422+ // Create the ethscription - mint should fail due to invalid ID
423+ uint256 tokenId = ethscriptions.createEthscription (mintParams);
424+
425+ // Ethscription should still be created (but mint failed)
426+ assertEq (ethscriptions.ownerOf (tokenId), bob);
427+
428+ // Verify no tokens were minted due to invalid ID
429+ address tokenAddr = tokenManager.getTokenAddressByTick ("TEST " );
430+ EthscriptionsERC20 token = EthscriptionsERC20 (tokenAddr);
431+ assertEq (token.balanceOf (bob), 0 ); // Bob should have no tokens
432+
433+ // Verify total minted didn't increase
434+ TokenManager.TokenInfo memory info = tokenManager.getTokenInfo (DEPLOY_TX_HASH);
435+ assertEq (info.totalMinted, 0 );
436+ }
437+
438+ function testMintWithIdTooHigh () public {
439+ // Deploy the token first
440+ testTokenDeploy ();
441+
442+ // Try to mint with ID beyond maxId (maxSupply/mintAmount = 1000000/1000 = 1000)
443+ vm.prank (bob);
444+ string memory mintContent = 'data:,{"p":"erc-20","op":"mint","tick":"TEST","id":"1001","amt":"1000"} ' ;
445+
446+ TokenManager.MintOperation memory mintOp = TokenManager.MintOperation ({
447+ tick: "TEST " ,
448+ id: 1001 , // Invalid ID - maxId is 1000
449+ amount: 1000
450+ });
451+
452+ bytes32 invalidMintHash = bytes32 (uint256 (0xBEEF ));
453+ Ethscriptions.CreateEthscriptionParams memory mintParams = createTokenParams (
454+ invalidMintHash,
455+ bob,
456+ mintContent,
457+ "erc-20 " ,
458+ "mint " ,
459+ abi.encode (mintOp)
460+ );
461+
462+ // Create the ethscription - mint should fail due to ID too high
463+ uint256 tokenId = ethscriptions.createEthscription (mintParams);
464+
465+ // Ethscription should still be created (but mint failed)
466+ assertEq (ethscriptions.ownerOf (tokenId), bob);
467+
468+ // Verify no tokens were minted due to invalid ID
469+ address tokenAddr = tokenManager.getTokenAddressByTick ("TEST " );
470+ EthscriptionsERC20 token = EthscriptionsERC20 (tokenAddr);
471+ assertEq (token.balanceOf (bob), 0 ); // Bob should have no tokens
472+
473+ // Verify total minted didn't increase
474+ TokenManager.TokenInfo memory info = tokenManager.getTokenInfo (DEPLOY_TX_HASH);
475+ assertEq (info.totalMinted, 0 );
476+ }
477+
478+ function testMintWithMaxValidId () public {
479+ // Deploy the token first
480+ testTokenDeploy ();
481+
482+ // Mint with the maximum valid ID (maxSupply/mintAmount = 1000000/1000 = 1000)
483+ vm.prank (bob);
484+ string memory mintContent = 'data:,{"p":"erc-20","op":"mint","tick":"TEST","id":"1000","amt":"1000"} ' ;
485+
486+ TokenManager.MintOperation memory mintOp = TokenManager.MintOperation ({
487+ tick: "TEST " ,
488+ id: 1000 , // Maximum valid ID
489+ amount: 1000
490+ });
491+
492+ bytes32 validMintHash = bytes32 (uint256 (0xCAFE ));
493+ Ethscriptions.CreateEthscriptionParams memory mintParams = createTokenParams (
494+ validMintHash,
495+ bob,
496+ mintContent,
497+ "erc-20 " ,
498+ "mint " ,
499+ abi.encode (mintOp)
500+ );
501+
502+ uint256 tokenId = ethscriptions.createEthscription (mintParams);
503+
504+ // Verify Bob owns the mint ethscription NFT
505+ assertEq (ethscriptions.ownerOf (tokenId), bob);
506+
507+ // Verify Bob has the tokens (1000 * 10^18 with 18 decimals)
508+ address tokenAddr = tokenManager.getTokenAddressByTick ("TEST " );
509+ EthscriptionsERC20 token = EthscriptionsERC20 (tokenAddr);
510+ assertEq (token.balanceOf (bob), 1000 ether); // Should have tokens
511+
512+ // Verify total minted increased
513+ TokenManager.TokenInfo memory info = tokenManager.getTokenInfo (DEPLOY_TX_HASH);
514+ assertEq (info.totalMinted, 1000 );
515+ }
397516}
0 commit comments