Skip to content

Commit 093b0bb

Browse files
committed
Added more tests
1 parent 7de5cf2 commit 093b0bb

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

packages/foundry/contracts/KiddoPerks.sol

+5-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ contract KiddoPerks is Ownable {
104104
return s_tasks[id];
105105
}
106106

107-
function completeTask(uint256 taskId, address by) public onlyOwner {
107+
function completeTask(
108+
uint256 taskId,
109+
address by
110+
) public onlyOwner onlyValidChild(by) {
108111
if (taskId >= s_taskNextId) {
109112
revert KiddoPerks__TaskNotFound(taskId);
110113
}
@@ -138,7 +141,7 @@ contract KiddoPerks is Ownable {
138141
function isTaskCompletedBy(
139142
uint256 taskId,
140143
address by
141-
) public view onlyValidChild(by) returns (bool) {
144+
) public view returns (bool) {
142145
return s_completedTasksByUser[by][taskId];
143146
}
144147

packages/foundry/test/KiddoPerks.t.sol

+44-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ contract KiddoPerksTest is Test {
102102
assertTrue(isCompleted);
103103
}
104104

105-
function testRevertsIfCompletedTaskIdNotExists() public withTaskCreated {
105+
function testRevertsIfCompletedTaskIdNotExists()
106+
public
107+
withTaskCreated
108+
withChildCreated
109+
{
106110
uint256 taskId = 4;
107111
vm.prank(PARENT);
108112
vm.expectRevert(
@@ -113,7 +117,11 @@ contract KiddoPerksTest is Test {
113117
kiddoPerks.completeTask(taskId, CHILD_ONE);
114118
}
115119

116-
function testRevertsIfCompleteARemovedTask() public withTaskCreated {
120+
function testRevertsIfCompleteARemovedTask()
121+
public
122+
withTaskCreated
123+
withChildCreated
124+
{
117125
uint256 taskId = 0;
118126

119127
vm.prank(PARENT);
@@ -178,6 +186,40 @@ contract KiddoPerksTest is Test {
178186
assertTrue(kiddoPerks.taskBy(id).removed);
179187
}
180188

189+
function testRevertsIfNoValidChildTriesToCompleteTask()
190+
public
191+
withTaskCreated
192+
{
193+
uint256 taskId = 0;
194+
vm.prank(PARENT);
195+
vm.expectRevert(
196+
abi.encodeWithSelector(
197+
KiddoPerks.KiddoPerks__NoValidChild.selector, CHILD_ONE
198+
)
199+
);
200+
kiddoPerks.completeTask(taskId, CHILD_ONE);
201+
}
202+
203+
function testRevertsIfRemovedChildTriesToCompleteTask()
204+
public
205+
withTaskCreated
206+
withChildCreated
207+
{
208+
uint256 taskId = 0;
209+
uint256 childId = 0;
210+
211+
vm.prank(PARENT);
212+
kiddoPerks.removeChild(childId);
213+
214+
vm.prank(PARENT);
215+
vm.expectRevert(
216+
abi.encodeWithSelector(
217+
KiddoPerks.KiddoPerks__NoValidChild.selector, CHILD_ONE
218+
)
219+
);
220+
kiddoPerks.completeTask(taskId, CHILD_ONE);
221+
}
222+
181223
/////////////////////
182224
//// Perk test
183225
/////////////////////

0 commit comments

Comments
 (0)