Skip to content

Commit

Permalink
fix overpayment
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Wolf <wolfynft@gmail.com>
  • Loading branch information
wolfy-nft committed Jan 20, 2025
1 parent 2638278 commit 7dbd380
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 5 additions & 5 deletions contracts/nft/erc1155m/clones/ERC1155MagicDropCloneable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ contract ERC1155MagicDropCloneable is ERC1155MagicDropMetadataCloneable {
error AllowlistStageNotActive();

/// @notice Thrown when the provided ETH value for a mint is insufficient.
error NotEnoughValue();
error RequiredValueNotMet();

/// @notice Thrown when the provided Merkle proof for an allowlist mint is invalid.
error InvalidProof();
Expand Down Expand Up @@ -161,8 +161,8 @@ contract ERC1155MagicDropCloneable is ERC1155MagicDropMetadataCloneable {
}

uint256 requiredPayment = stage.price * qty;
if (msg.value < requiredPayment) {
revert NotEnoughValue();
if (msg.value != requiredPayment) {
revert RequiredValueNotMet();
}

if (_walletLimit[tokenId] > 0 && _totalMintedByUserPerToken[to][tokenId] + qty > _walletLimit[tokenId]) {
Expand Down Expand Up @@ -201,8 +201,8 @@ contract ERC1155MagicDropCloneable is ERC1155MagicDropMetadataCloneable {
}

uint256 requiredPayment = stage.price * qty;
if (msg.value < requiredPayment) {
revert NotEnoughValue();
if (msg.value != requiredPayment) {
revert RequiredValueNotMet();
}

if (_walletLimit[tokenId] > 0 && _totalMintedByUserPerToken[to][tokenId] + qty > _walletLimit[tokenId]) {
Expand Down
28 changes: 24 additions & 4 deletions test/erc1155m/clones/ERC1155MagicDropCloneable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract ERC1155MagicDropCloneableTest is Test {
vm.deal(user, 0.005 ether);

vm.prank(user);
vm.expectRevert(ERC1155MagicDropCloneable.NotEnoughValue.selector);
vm.expectRevert(ERC1155MagicDropCloneable.RequiredValueNotMet.selector);
token.mintPublic{value: 0.005 ether}(user, tokenId, 1, "");
}

Expand Down Expand Up @@ -164,6 +164,16 @@ contract ERC1155MagicDropCloneableTest is Test {
token.mintPublic{value: 10.01 ether}(user, tokenId, 1001, "");
}

function testMintPublicOverpayReverts() public {
vm.warp(publicStart + 1);

vm.deal(user, 1 ether);

vm.prank(user);
vm.expectRevert(ERC1155MagicDropCloneable.RequiredValueNotMet.selector);
token.mintPublic{value: 0.02 ether}(user, tokenId, 1, "");
}

/*==============================================================
= TEST ALLOWLIST MINTING STAGE =
==============================================================*/
Expand Down Expand Up @@ -214,7 +224,7 @@ contract ERC1155MagicDropCloneableTest is Test {
vm.deal(allowedAddr, 0.001 ether);
vm.prank(allowedAddr);

vm.expectRevert(ERC1155MagicDropCloneable.NotEnoughValue.selector);
vm.expectRevert(ERC1155MagicDropCloneable.RequiredValueNotMet.selector);
token.mintAllowlist{value: 0.001 ether}(allowedAddr, tokenId, 1, proof, "");
}

Expand All @@ -241,13 +251,23 @@ contract ERC1155MagicDropCloneableTest is Test {
// unlimited wallet limit for the purpose of this test
token.setWalletLimit(tokenId, 0);

vm.deal(allowedAddr, 11 ether);
vm.deal(allowedAddr, 5.005 ether);
vm.prank(allowedAddr);

bytes32[] memory proof = merkleHelper.getProofFor(allowedAddr);

vm.expectRevert(IMagicDropMetadata.CannotExceedMaxSupply.selector);
token.mintAllowlist{value: 11 ether}(allowedAddr, tokenId, 1001, proof, "");
token.mintAllowlist{value: 5.005 ether}(allowedAddr, tokenId, 1001, proof, "");
}

function testMintAllowlistOverpayReverts() public {
vm.warp(allowlistStart + 1);

bytes32[] memory proof = merkleHelper.getProofFor(allowedAddr);
vm.deal(allowedAddr, 1 ether);

vm.expectRevert(ERC1155MagicDropCloneable.RequiredValueNotMet.selector);
token.mintAllowlist{value: 0.02 ether}(allowedAddr, tokenId, 1, proof, "");
}

/*==============================================================
Expand Down

0 comments on commit 7dbd380

Please sign in to comment.