Skip to content

Commit bb16b7a

Browse files
authored
fix: do not check worker deposit against required worker stake for contributeAndFinalize workflow (#652)
1 parent 47098bb commit bb16b7a

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/main/java/com/iexec/worker/chain/ContributionService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ public Optional<ReplicateStatusCause> getCannotContributeStatusCause(final Strin
5959
return Optional.of(WORKERPOOL_AUTHORIZATION_NOT_FOUND);
6060
}
6161

62+
final TaskDescription taskDescription = iexecHubService.getTaskDescription(chainTaskId);
63+
6264
final ChainTask chainTask = iexecHubService.getChainTask(chainTaskId).orElse(null);
6365
if (chainTask == null) {
6466
return Optional.of(CHAIN_UNREACHABLE);
6567
}
6668

67-
if (!hasEnoughStakeToContribute(chainTask)) {
69+
// No staking in contributeAndFinalize
70+
if (taskDescription != null && !taskDescription.isEligibleToContributeAndFinalize()
71+
&& !hasEnoughStakeToContribute(chainTask)) {
6872
return Optional.of(STAKE_TOO_LOW);
6973
}
7074

src/test/java/com/iexec/worker/chain/ContributionServiceTests.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
import static org.junit.jupiter.api.Assertions.assertEquals;
4242
import static org.junit.jupiter.api.Assertions.assertNotNull;
4343
import 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)
4847
class 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

Comments
 (0)