Commit 093b0bb 1 parent 7de5cf2 commit 093b0bb Copy full SHA for 093b0bb
File tree 2 files changed +49
-4
lines changed
2 files changed +49
-4
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,10 @@ contract KiddoPerks is Ownable {
104
104
return s_tasks[id];
105
105
}
106
106
107
- function completeTask (uint256 taskId , address by ) public onlyOwner {
107
+ function completeTask (
108
+ uint256 taskId ,
109
+ address by
110
+ ) public onlyOwner onlyValidChild (by) {
108
111
if (taskId >= s_taskNextId) {
109
112
revert KiddoPerks__TaskNotFound (taskId);
110
113
}
@@ -138,7 +141,7 @@ contract KiddoPerks is Ownable {
138
141
function isTaskCompletedBy (
139
142
uint256 taskId ,
140
143
address by
141
- ) public view onlyValidChild (by) returns (bool ) {
144
+ ) public view returns (bool ) {
142
145
return s_completedTasksByUser[by][taskId];
143
146
}
144
147
Original file line number Diff line number Diff line change @@ -102,7 +102,11 @@ contract KiddoPerksTest is Test {
102
102
assertTrue (isCompleted);
103
103
}
104
104
105
- function testRevertsIfCompletedTaskIdNotExists () public withTaskCreated {
105
+ function testRevertsIfCompletedTaskIdNotExists ()
106
+ public
107
+ withTaskCreated
108
+ withChildCreated
109
+ {
106
110
uint256 taskId = 4 ;
107
111
vm.prank (PARENT);
108
112
vm.expectRevert (
@@ -113,7 +117,11 @@ contract KiddoPerksTest is Test {
113
117
kiddoPerks.completeTask (taskId, CHILD_ONE);
114
118
}
115
119
116
- function testRevertsIfCompleteARemovedTask () public withTaskCreated {
120
+ function testRevertsIfCompleteARemovedTask ()
121
+ public
122
+ withTaskCreated
123
+ withChildCreated
124
+ {
117
125
uint256 taskId = 0 ;
118
126
119
127
vm.prank (PARENT);
@@ -178,6 +186,40 @@ contract KiddoPerksTest is Test {
178
186
assertTrue (kiddoPerks.taskBy (id).removed);
179
187
}
180
188
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
+
181
223
/////////////////////
182
224
//// Perk test
183
225
/////////////////////
You can’t perform that action at this time.
0 commit comments