Skip to content

Commit

Permalink
fix setClaimCondition for DropSinglePhase1155 (#353)
Browse files Browse the repository at this point in the history
* fix setClaimCondition for DropSinglePhase1155: generate unique conditionId for every tokenId

* remove unused imports
  • Loading branch information
kumaryash90 authored Mar 14, 2023
1 parent c2aa16c commit 3a0568e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions contracts/extension/DropSinglePhase1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ abstract contract DropSinglePhase1155 is IDropSinglePhase1155 {

uint256 supplyClaimedAlready = condition.supplyClaimed;

if (_resetClaimEligibility) {
if (targetConditionId == bytes32(0) || _resetClaimEligibility) {
supplyClaimedAlready = 0;
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number));
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number, _tokenId));
}

if (supplyClaimedAlready > _condition.maxClaimableSupply) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ abstract contract DropSinglePhase1155_V1 is IDropSinglePhase1155_V1 {

uint256 supplyClaimedAlready = condition.supplyClaimed;

if (_resetClaimEligibility) {
if (targetConditionId == bytes32(0) || _resetClaimEligibility) {
supplyClaimedAlready = 0;
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number));
targetConditionId = keccak256(abi.encodePacked(_dropMsgSender(), block.number, _tokenId));
}

if (supplyClaimedAlready > _condition.maxClaimableSupply) {
Expand Down
32 changes: 32 additions & 0 deletions src/test/sdk/extension/DropSinglePhase1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,43 @@ contract ExtensionDropSinglePhase1155 is DSTest, Test {
ext.claim(receiver, 0, 10, address(0), 0, alp, "");
assertEq(ext.getSupplyClaimedByWallet(0, receiver), 10);

vm.roll(100);
ext.setClaimConditions(0, conditions[0], true);
assertEq(ext.getSupplyClaimedByWallet(0, receiver), 0);

vm.prank(receiver, receiver);
ext.claim(receiver, 0, 10, address(0), 0, alp, "");
assertEq(ext.getSupplyClaimedByWallet(0, receiver), 10);
}

/**
* note: Testing state; unique condition Id for every token.
*/
function test_state_claimCondition_uniqueConditionId() public {
ext.setCondition(true);
vm.warp(1);

address receiver = address(0x123);
address claimer1 = address(0x345);
bytes32[] memory proofs = new bytes32[](0);
uint256 _tokenId = 0;

MyDropSinglePhase1155.AllowlistProof memory alp;
alp.proof = proofs;

MyDropSinglePhase1155.ClaimCondition[] memory conditions = new MyDropSinglePhase1155.ClaimCondition[](1);
conditions[0].maxClaimableSupply = 100;
conditions[0].quantityLimitPerWallet = 100;

ext.setClaimConditions(_tokenId, conditions[0], false);

vm.prank(claimer1, claimer1);
ext.claim(receiver, _tokenId, 100, address(0), 0, alp, "");

assertEq(ext.getSupplyClaimedByWallet(_tokenId, claimer1), 100);

// supply claimed for other tokenIds should be 0
assertEq(ext.getSupplyClaimedByWallet(1, claimer1), 0);
assertEq(ext.getSupplyClaimedByWallet(2, claimer1), 0);
}
}

0 comments on commit 3a0568e

Please sign in to comment.