2020import com .iexec .common .replicate .ReplicateStatusModifier ;
2121import com .iexec .commons .poco .chain .ChainTask ;
2222import com .iexec .commons .poco .chain .ChainTaskStatus ;
23+ import com .iexec .commons .poco .task .TaskDescription ;
2324import com .iexec .core .chain .IexecHubService ;
2425import com .iexec .core .replicate .Replicate ;
2526import com .iexec .core .replicate .ReplicatesService ;
3233import org .junit .jupiter .api .Test ;
3334import org .mockito .*;
3435
36+ import java .math .BigInteger ;
3537import java .util .List ;
3638import java .util .Optional ;
3739
@@ -69,6 +71,14 @@ void shouldDetectTasks() {
6971 final Task contributeAndFinalizeTask = getContributeAndFinalizeDoneTask (contributedAndFinalizedChainTaskId ).build ();
7072 when (taskService .findByCurrentStatus (TaskStatus .RUNNING )).thenReturn (List .of (contributeAndFinalizeTask ));
7173
74+ final TaskDescription taskDescription = TaskDescription .builder ()
75+ .chainTaskId (contributedAndFinalizedChainTaskId )
76+ .isTeeTask (true )
77+ .trust (BigInteger .ONE )
78+ .callback ("" )
79+ .build ();
80+ when (iexecHubService .getTaskDescription (contributedAndFinalizedChainTaskId )).thenReturn (taskDescription );
81+
7282 detector .detect ();
7383
7484 verify (taskUpdateRequestManager ).publishRequest (completedChainTaskId );
@@ -104,8 +114,15 @@ void shouldDetectNoFinalizedTaskAsTaskIsRevealing() {
104114 @ Test
105115 void shouldDetectContributeAndFinalizeDoneTask () {
106116 final Task task = getContributeAndFinalizeDoneTask (CHAIN_TASK_ID ).build ();
117+ final TaskDescription taskDescription = TaskDescription .builder ()
118+ .chainTaskId (CHAIN_TASK_ID )
119+ .isTeeTask (true )
120+ .trust (BigInteger .ONE )
121+ .callback ("" )
122+ .build ();
107123
108124 when (taskService .findByCurrentStatus (TaskStatus .RUNNING )).thenReturn (List .of (task ));
125+ when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
109126
110127 detector .detectContributeAndFinalizeDoneTasks ();
111128
@@ -115,8 +132,15 @@ void shouldDetectContributeAndFinalizeDoneTask() {
115132 @ Test
116133 void shouldDetectNoContributeAndFinalizeDoneTaskAsTaskIsRevealing () {
117134 final Task task = getOnchainRevealingTask (CHAIN_DEAL_ID ).build ();
135+ final TaskDescription taskDescription = TaskDescription .builder ()
136+ .chainTaskId (task .getChainTaskId ())
137+ .isTeeTask (true )
138+ .trust (BigInteger .ONE )
139+ .callback ("" )
140+ .build ();
118141
119142 when (taskService .findByCurrentStatus (TaskStatus .RUNNING )).thenReturn (List .of (task ));
143+ when (iexecHubService .getTaskDescription (task .getChainTaskId ())).thenReturn (taskDescription );
120144
121145 detector .detectContributeAndFinalizeDoneTasks ();
122146
@@ -162,6 +186,13 @@ void shouldChainTaskNotBeCompletedAsChainTaskNotCompleted() {
162186 @ Test
163187 void shouldTaskBeContributeAndFinalizeDone () {
164188 final Task task = getContributeAndFinalizeDoneTask (CHAIN_TASK_ID ).build ();
189+ final TaskDescription taskDescription = TaskDescription .builder ()
190+ .chainTaskId (CHAIN_TASK_ID )
191+ .isTeeTask (true )
192+ .trust (BigInteger .ONE )
193+ .callback ("" )
194+ .build ();
195+ when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
165196
166197 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
167198
@@ -175,6 +206,13 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsNotTee() {
175206 .currentStatus (TaskStatus .FINALIZING )
176207 .tag (NO_TEE_TAG )
177208 .build ();
209+ final TaskDescription taskDescription = TaskDescription .builder ()
210+ .chainTaskId (CHAIN_TASK_ID )
211+ .isTeeTask (false )
212+ .trust (BigInteger .ONE )
213+ .callback ("" )
214+ .build ();
215+ when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
178216
179217 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
180218
@@ -194,9 +232,16 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsMultipleReplicates() {
194232 .chainTaskId (CHAIN_TASK_ID )
195233 .status (ChainTaskStatus .COMPLETED )
196234 .build ();
235+ final TaskDescription taskDescription = TaskDescription .builder ()
236+ .chainTaskId (CHAIN_TASK_ID )
237+ .isTeeTask (true )
238+ .trust (BigInteger .ONE )
239+ .callback ("" )
240+ .build ();
197241
198242 when (replicatesService .getReplicates (CHAIN_TASK_ID )).thenReturn (List .of (replicate1 , replicate2 ));
199243 when (iexecHubService .getChainTask (CHAIN_TASK_ID )).thenReturn (Optional .of (chainTask ));
244+ when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
200245
201246 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
202247
@@ -212,8 +257,15 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsReplicateNotDone() {
212257 .build ();
213258 final Replicate replicate = new Replicate (WALLET_WORKER_1 , CHAIN_TASK_ID );
214259 replicate .updateStatus (ReplicateStatus .COMPUTING , ReplicateStatusModifier .WORKER );
260+ final TaskDescription taskDescription = TaskDescription .builder ()
261+ .chainTaskId (CHAIN_TASK_ID )
262+ .isTeeTask (true )
263+ .trust (BigInteger .ONE )
264+ .callback ("" )
265+ .build ();
215266
216267 when (replicatesService .getReplicates (CHAIN_TASK_ID )).thenReturn (List .of (replicate ));
268+ when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
217269
218270 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
219271
@@ -233,9 +285,16 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsChainTaskNotCompleted() {
233285 .chainTaskId (CHAIN_TASK_ID )
234286 .status (ChainTaskStatus .REVEALING )
235287 .build ();
288+ final TaskDescription taskDescription = TaskDescription .builder ()
289+ .chainTaskId (CHAIN_TASK_ID )
290+ .isTeeTask (true )
291+ .trust (BigInteger .ONE )
292+ .callback ("" )
293+ .build ();
236294
237295 when (replicatesService .getReplicates (CHAIN_TASK_ID )).thenReturn (List .of (replicate ));
238296 when (iexecHubService .getChainTask (CHAIN_TASK_ID )).thenReturn (Optional .of (chainTask ));
297+ when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
239298
240299 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
241300
0 commit comments