Commit 537cdea 1 parent 8307b30 commit 537cdea Copy full SHA for 537cdea
File tree 2 files changed +26
-3
lines changed
2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ contract KiddoPerks is Ownable {
28
28
);
29
29
error KiddoPerks__PerkAlreadyRedeemmed (uint256 id , address by );
30
30
error KiddoPerks__NoValidChild (address childAddr );
31
- error KiddoPerks__CannotMintAnyNFTYet (address who );
31
+ error KiddoPerks__CannotMintAnyNFTYet (address who , uint256 numTasksCompleted );
32
32
33
33
uint256 constant MIN_TASK_COMPLETED_NFT = 5 ;
34
34
@@ -126,6 +126,8 @@ contract KiddoPerks is Ownable {
126
126
127
127
token.mint (by, taskCompleted.tokensReward);
128
128
emit TokenMinted (by, taskCompleted.tokensReward);
129
+
130
+ s_childNumTasksCompleted[by] += 1 ;
129
131
}
130
132
131
133
function removeTask (
@@ -278,7 +280,9 @@ contract KiddoPerks is Ownable {
278
280
function mintNFTByTaskCompletion () public {
279
281
uint256 numTaskCompletedByChild = s_childNumTasksCompleted[msg .sender ];
280
282
if (numTaskCompletedByChild < MIN_TASK_COMPLETED_NFT) {
281
- revert KiddoPerks__CannotMintAnyNFTYet (msg .sender );
283
+ revert KiddoPerks__CannotMintAnyNFTYet (
284
+ msg .sender , numTaskCompletedByChild
285
+ );
282
286
}
283
287
nft.mintNft (msg .sender , s_childNumTasksCompleted[msg .sender ]);
284
288
}
Original file line number Diff line number Diff line change @@ -543,12 +543,31 @@ contract KiddoPerksTest is Test {
543
543
vm.prank (CHILD_ONE);
544
544
vm.expectRevert (
545
545
abi.encodeWithSelector (
546
- KiddoPerks.KiddoPerks__CannotMintAnyNFTYet.selector , CHILD_ONE
546
+ KiddoPerks.KiddoPerks__CannotMintAnyNFTYet.selector , CHILD_ONE, 4
547
547
)
548
548
);
549
549
kiddoPerks.mintNFTByTaskCompletion ();
550
550
}
551
551
552
+ function testCanMintNFT () public withChildCreated withTaskCreated {
553
+ vm.startPrank (PARENT);
554
+ kiddoPerks.createTask ("Clean up room " , SMALL_REQUIRED_TOKENS_AMOUNT);
555
+ kiddoPerks.createTask ("Make bed " , SMALL_REQUIRED_TOKENS_AMOUNT);
556
+ kiddoPerks.createTask ("Brush teeth " , SMALL_REQUIRED_TOKENS_AMOUNT);
557
+ kiddoPerks.createTask ("Do homework " , SMALL_REQUIRED_TOKENS_AMOUNT);
558
+ kiddoPerks.createTask ("Throw out trash " , SMALL_REQUIRED_TOKENS_AMOUNT);
559
+
560
+ kiddoPerks.completeTask (0 , CHILD_ONE);
561
+ kiddoPerks.completeTask (1 , CHILD_ONE);
562
+ kiddoPerks.completeTask (2 , CHILD_ONE);
563
+ kiddoPerks.completeTask (3 , CHILD_ONE);
564
+ kiddoPerks.completeTask (4 , CHILD_ONE);
565
+ vm.stopPrank ();
566
+
567
+ vm.prank (CHILD_ONE);
568
+ kiddoPerks.mintNFTByTaskCompletion ();
569
+ }
570
+
552
571
/**
553
572
* Modifiers
554
573
*/
You can’t perform that action at this time.
0 commit comments