4141import static org .junit .jupiter .api .Assertions .assertEquals ;
4242import static org .junit .jupiter .api .Assertions .assertNotNull ;
4343import static org .mockito .ArgumentMatchers .anyString ;
44- import static org .mockito .Mockito .verify ;
45- import static org .mockito .Mockito .when ;
44+ import static org .mockito .Mockito .*;
4645
4746@ ExtendWith (MockitoExtension .class )
4847class ContributionServiceTests {
@@ -116,6 +115,7 @@ void getCannotContributeStatusShouldReturnChainUnreachable() {
116115
117116 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId ))
118117 .thenReturn (getTeeWorkerpoolAuth ());
118+ when (iexecHubService .getTaskDescription (chainTaskId )).thenReturn (taskDescription );
119119 when (iexecHubService .getChainTask (chainTaskId )).thenReturn (Optional .empty ());
120120
121121 assertThat (contributionService .getCannotContributeStatusCause (chainTaskId ).orElse (null ))
@@ -130,6 +130,7 @@ void getCannotContributeStatusShouldReturnStakeTooLow() {
130130
131131 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId ))
132132 .thenReturn (getTeeWorkerpoolAuth ());
133+ when (iexecHubService .getTaskDescription (chainTaskId )).thenReturn (taskDescription );
133134 when (iexecHubService .getChainTask (chainTaskId )).thenReturn (Optional .of (chainTask ));
134135 when (iexecHubService .getChainAccount ()).thenReturn (Optional .of (ChainAccount .builder ().deposit (0 ).build ()));
135136 when (iexecHubService .getChainDeal (CHAIN_DEAL_ID )).thenReturn (Optional .of (ChainDeal .builder ().workerStake (BigInteger .valueOf (5 )).build ()));
@@ -153,6 +154,7 @@ void getCannotContributeStatusShouldReturnTaskNotActive() {
153154
154155 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId ))
155156 .thenReturn (getTeeWorkerpoolAuth ());
157+ when (iexecHubService .getTaskDescription (chainTaskId )).thenReturn (taskDescription );
156158 when (iexecHubService .getChainTask (chainTaskId )).thenReturn (Optional .of (inactiveTask ));
157159 when (iexecHubService .getChainAccount ()).thenReturn (Optional .of (ChainAccount .builder ().deposit (1000 ).build ()));
158160 when (iexecHubService .getChainDeal (CHAIN_DEAL_ID )).thenReturn (Optional .of (ChainDeal .builder ().workerStake (BigInteger .valueOf (5 )).build ()));
@@ -177,6 +179,7 @@ void getCannotContributeStatusShouldReturnAfterDeadline() {
177179
178180 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId ))
179181 .thenReturn (getTeeWorkerpoolAuth ());
182+ when (iexecHubService .getTaskDescription (chainTaskId )).thenReturn (taskDescription );
180183 when (iexecHubService .getChainTask (chainTaskId )).thenReturn (Optional .of (timedOutChainTask ));
181184 when (iexecHubService .getChainAccount ())
182185 .thenReturn (Optional .of (ChainAccount .builder ().deposit (1000 ).build ()));
@@ -204,6 +207,7 @@ void getCannotContributeStatusShouldReturnContributionAlreadySet() {
204207
205208 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId ))
206209 .thenReturn (getTeeWorkerpoolAuth ());
210+ when (iexecHubService .getTaskDescription (chainTaskId )).thenReturn (taskDescription );
207211 when (iexecHubService .getChainTask (chainTaskId )).thenReturn (Optional .of (alreadyContributedChainTask ));
208212 when (iexecHubService .getChainAccount ())
209213 .thenReturn (Optional .of (ChainAccount .builder ().deposit (1000 ).build ()));
@@ -224,6 +228,7 @@ void getCannotContributeStatusCauseShouldReturnEmpty() {
224228
225229 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId ))
226230 .thenReturn (getTeeWorkerpoolAuth ());
231+ when (iexecHubService .getTaskDescription (chainTaskId )).thenReturn (taskDescription );
227232 when (iexecHubService .getChainTask (chainTaskId ))
228233 .thenReturn (Optional .of (chainTask ));
229234 when (iexecHubService .getChainAccount ())
@@ -238,6 +243,26 @@ void getCannotContributeStatusCauseShouldReturnEmpty() {
238243 verify (iexecHubService ).getChainDeal (CHAIN_DEAL_ID );
239244 verify (workerpoolAuthorizationService ).getWorkerpoolAuthorization (chainTaskId );
240245 }
246+
247+ @ Test
248+ void getCannotContributeStatusShouldReturnEmptyForContributeAndFinalizeFlow () {
249+ final String chainTaskId = chainTask .getChainTaskId ();
250+ final TaskDescription contributeAndFinalizeTaskDescription = TaskDescription .builder ()
251+ .trust (BigInteger .ONE )
252+ .isTeeTask (true )
253+ .build ();
254+
255+ when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId ))
256+ .thenReturn (getTeeWorkerpoolAuth ());
257+ when (iexecHubService .getTaskDescription (chainTaskId )).thenReturn (contributeAndFinalizeTaskDescription );
258+ when (iexecHubService .getChainTask (chainTaskId )).thenReturn (Optional .of (chainTask ));
259+
260+ assertThat (contributionService .getCannotContributeStatusCause (chainTaskId )).isEmpty ();
261+
262+ verify (iexecHubService ).getChainTask (chainTaskId );
263+ verify (iexecHubService , never ()).getChainAccount ();
264+ verify (iexecHubService , never ()).getChainDeal (CHAIN_DEAL_ID );
265+ }
241266 //endregion
242267
243268 // region getCannotContributeAndFinalizeStatusCause
0 commit comments