@@ -85,7 +85,11 @@ contract KiddoPerksTest is Test {
85
85
event TaskCompleted (address indexed by , string title , uint256 taskId );
86
86
event TokenMinted (address by , uint256 tokenReward );
87
87
88
- function testParentCanMarkTaskAsCompleted () public withTaskCreated {
88
+ function testParentCanMarkTaskAsCompleted ()
89
+ public
90
+ withTaskCreated
91
+ withChildCreated
92
+ {
89
93
vm.prank (PARENT);
90
94
vm.expectEmit (true , true , false , true );
91
95
emit TaskCompleted (CHILD_ONE, "Clean up room " , 0 );
@@ -255,7 +259,7 @@ contract KiddoPerksTest is Test {
255
259
256
260
event PerkRedeemed (uint256 perkId , address by );
257
261
258
- function testChildCanRedeemPerk () public withPerkCreated {
262
+ function testChildCanRedeemPerk () public withPerkCreated withChildCreated {
259
263
uint256 perkId = 0 ;
260
264
uint256 initialChildBalance = 5 * 10 ** 18 ;
261
265
uint256 perkTokensRequired = 2 * 10 ** 18 ;
@@ -274,7 +278,11 @@ contract KiddoPerksTest is Test {
274
278
assertEq (initialChildBalance, perkTokensRequired + userFinalBalance);
275
279
}
276
280
277
- function testChildCannotReddemMoreThanOnceAPerk () public withPerkCreated {
281
+ function testChildCannotReddemMoreThanOnceAPerk ()
282
+ public
283
+ withPerkCreated
284
+ withChildCreated
285
+ {
278
286
uint256 perkId = 0 ;
279
287
uint256 initialChildBalance = 5 * 10 ** 18 ;
280
288
uint256 perkTokensRequired = 2 * 10 ** 18 ;
@@ -301,26 +309,69 @@ contract KiddoPerksTest is Test {
301
309
function testRevertsOnRedeemWhenChildHasNotEnoughTokenBalance ()
302
310
public
303
311
withPerkCreated
312
+ withChildCreated
304
313
{
305
314
uint256 perkId = 0 ;
315
+ uint256 tokensToMint = 1 * 10 ** 18 ;
316
+ uint256 perkTokensRequired = 2 * 10 ** 18 ;
306
317
vm.prank (address (kiddoPerks));
307
- kdoToken.mint (CHILD_ONE, 1 * 10 ** 18 );
318
+ kdoToken.mint (CHILD_ONE, tokensToMint );
308
319
309
320
vm.prank (CHILD_ONE);
310
321
vm.expectRevert (
311
322
abi.encodeWithSelector (
312
323
KiddoPerks.KiddoPerks__NotEnoughTokenBalance.selector ,
313
324
perkId,
314
325
CHILD_ONE,
315
- 2 * 10 ** 18
326
+ perkTokensRequired
327
+ )
328
+ );
329
+ kiddoPerks.redeemPerk (perkId);
330
+ }
331
+
332
+ function testRevertIfNoValidChildTriesToRedeemPerk () public withPerkCreated {
333
+ uint256 perkId = 0 ;
334
+ uint256 tokensToMint = 1 * 10 ** 18 ;
335
+
336
+ vm.prank (address (kiddoPerks));
337
+ kdoToken.mint (CHILD_TWO, tokensToMint);
338
+
339
+ vm.prank (CHILD_TWO);
340
+ vm.expectRevert (
341
+ abi.encodeWithSelector (
342
+ KiddoPerks.KiddoPerks__NoValidChild.selector , CHILD_TWO
316
343
)
317
344
);
318
345
kiddoPerks.redeemPerk (perkId);
319
346
}
320
347
348
+ function testRevertIfRemovedChildTriesToRedeemPerk ()
349
+ public
350
+ withPerkCreated
351
+ withChildCreated
352
+ {
353
+ uint256 perkId = 0 ;
354
+ uint256 childId = 0 ;
355
+ uint256 tokensToMint = 1 * 10 ** 18 ;
356
+
357
+ vm.prank (address (kiddoPerks));
358
+ kdoToken.mint (CHILD_ONE, tokensToMint);
359
+
360
+ vm.prank (PARENT);
361
+ kiddoPerks.removeChild (childId);
362
+
363
+ vm.prank (CHILD_ONE);
364
+ vm.expectRevert (
365
+ abi.encodeWithSelector (
366
+ KiddoPerks.KiddoPerks__NoValidChild.selector , CHILD_ONE
367
+ )
368
+ );
369
+ kiddoPerks.redeemPerk (perkId);
370
+ }
321
371
/////////////////////
322
372
//// Child test
323
373
/////////////////////
374
+
324
375
function testRevertsIfNoParentTriesToAddChild () public withTaskCreated {
325
376
string memory childName = "Willy " ;
326
377
vm.prank (CHILD_ONE);
0 commit comments