Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikki-kiga committed May 30, 2024
1 parent 2c1b902 commit 0edd467
Show file tree
Hide file tree
Showing 3 changed files with 336 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten

// Checks
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert IGachaLazyClaim.InvalidStorageProtocol();
if (claimParameters.startDate >= claimParameters.endDate) revert IGachaLazyClaim.InvalidStartDate();
if (claimParameters.endDate != 0 && claimParameters.startDate >= claimParameters.endDate) revert IGachaLazyClaim.InvalidDate();

address[] memory receivers = new address[](1);
receivers[0] = msg.sender;
Expand Down Expand Up @@ -93,11 +93,11 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
) external override adminRequired {
Claim memory claim = _getClaim(creatorContractAddress, instanceId);
if (claimParameters.endDate != 0 && claimParameters.startDate >= claimParameters.endDate)
revert IGachaLazyClaim.InvalidStartDate();
revert IGachaLazyClaim.InvalidDate();
if (claimParameters.totalMax != claim.totalMax) revert IGachaLazyClaim.CannotChangeTotalMax();
if (claimParameters.startingTokenId != claim.startingTokenId) revert IGachaLazyClaim.CannotChangeStartingTokenId();
if (claimParameters.itemVariations != claim.itemVariations) revert IGachaLazyClaim.CannotChangeItemVariations();
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert IGachaLazyClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol != claim.storageProtocol) revert IGachaLazyClaim.CannotChangeStorageProtocol();
if (keccak256(abi.encodePacked(claimParameters.location)) != keccak256(abi.encodePacked(claim.location))) {
revert IGachaLazyClaim.CannotChangeLocation();
}
Expand Down Expand Up @@ -156,8 +156,8 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
// Checks for reserving
if (claim.startDate > block.timestamp) revert IGachaLazyClaim.ClaimInactive();
if (claim.endDate > 0 && claim.endDate < block.timestamp) revert IGachaLazyClaim.ClaimInactive();
require(msg.value == (claim.cost + MINT_FEE) * mintCount, "Incorrect payment amount");
if (claim.endDate > 0 && claim.endDate <= block.timestamp) revert IGachaLazyClaim.ClaimInactive();
if (msg.value < (claim.cost + MINT_FEE) * mintCount) revert IGachaLazyClaim.InvalidPayment();
uint32 amountAvailable = claim.totalMax - claim.total;
if (amountAvailable == 0 ) revert IGachaLazyClaim.ClaimSoldOut();

Expand All @@ -167,8 +167,8 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
_reservedMintsPerWallet[creatorContractAddress][instanceId][msg.sender] += amountToReserve;

// Refund any overpayment
if (amountToReserve < mintCount) {
uint256 refundAmount = (mintCount - amountToReserve) * (claim.cost + MINT_FEE);
if (msg.value > (claim.cost + MINT_FEE) * amountToReserve){
uint256 refundAmount = msg.value - (claim.cost + MINT_FEE) * amountToReserve;
_sendFunds(payable(msg.sender), refundAmount);
}
emit GachaClaimMintReserved(creatorContractAddress, instanceId, msg.sender, amountToReserve);
Expand Down
3 changes: 2 additions & 1 deletion packages/manifold/contracts/gachaclaims/IGachaLazyClaim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ interface IGachaLazyClaim {
}

error InvalidStorageProtocol();
error InvalidStartDate();
error InvalidDate();
error InvalidInstance();
error InvalidInput();
error InvalidPayment();
error InvalidSignature();
error InvalidVariationIndex();
error ClaimAlreadyInitialized();
Expand Down
Loading

0 comments on commit 0edd467

Please sign in to comment.