Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# x-release-please-start-version
version=9.2.1
# x-release-please-end
iexecCommonsPocoVersion=5.4.0
iexecCommonsPocoVersion=5.4.1
iexecCommonVersion=9.2.0
iexecBlockchainAdapterVersion=9.0.4
iexecResultVersion=9.1.0
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/iexec/core/chain/IexecHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
@Service
public class IexecHubService extends IexecHubAbstractService implements Purgeable {

private final SignerService signerService;
private final Web3jService web3jService;

public IexecHubService(final SignerService signerService,
Expand All @@ -49,7 +48,6 @@ public IexecHubService(final SignerService signerService,
signerService.getCredentials(),
web3jService,
chainConfig.getHubAddress());
this.signerService = signerService;
this.web3jService = web3jService;
if (!hasEnoughGas()) {
System.exit(0);
Expand Down Expand Up @@ -118,12 +116,6 @@ public Date getChainDealFinalDeadline(ChainDeal chainDeal) {
return new Date(startTime + maxTime * 10);
}

public boolean hasEnoughGas() {
final boolean hasEnoughGas = hasEnoughGas(signerService.getAddress());
log.debug("Gas status [hasEnoughGas:{}]", hasEnoughGas);
return hasEnoughGas;
}

// region check contribution status
public boolean repeatIsContributedTrue(String chainTaskId, String walletAddress) {
return web3jService.repeatCheck(NB_BLOCKS_TO_WAIT_PER_RETRY, MAX_RETRIES,
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2026 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -195,7 +195,6 @@ TaskNotificationType getNextActionWhenStatusAndCause(ReplicateStatus whenStatus,
log.error("TaskDescription is null with a COMPUTED status, this case shouldn't happen");
return PLEASE_ABORT;
}
// We must check CallBack is empty because there is an issue in poco (transaction is revert)
if (taskDescription.isEligibleToContributeAndFinalize()) {
return PLEASE_CONTRIBUTE_AND_FINALIZE;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/iexec/core/chain/IexecHubServiceTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2026 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,7 +69,7 @@ void init() throws Exception {
final Credentials credentials = Credentials.create(Keys.createEcKeyPair());

when(signerService.getCredentials()).thenReturn(credentials);
when(web3jService.hasEnoughGas(any())).thenReturn(true);
when(web3jService.isSidechain()).thenReturn(true);
when(chainConfig.getHubAddress()).thenReturn("0x748e091bf16048cb5103E0E10F9D5a8b7fBDd860");

iexecHubService = spy(new IexecHubService(signerService, web3jService, chainConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ private Replicate getReplicateWithStatus(final ReplicateStatus replicateStatus)
}

// Helper method to avoid redundancy
private void mockTaskAndTaskDecription(final String callback) {
private void mockTaskAndTaskDescription(final String callback) {
final Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
when(iexecHubService.getTaskDescription(anyString())).thenReturn(
TaskDescription.builder()
.trust(BigInteger.ONE)
.isTeeTask(true)
.teeFramework(TeeFramework.SCONE)
.teeFramework(TeeFramework.TDX)
.callback(callback)
.build()
);
Expand All @@ -115,7 +114,7 @@ private void mockTaskAndTaskDecription(final String callback) {
@ParameterizedTest
@ValueSource(strings = {"", CALLBACK})
void shouldDetectBothChangesOnChain(final String callback) {
mockTaskAndTaskDecription(callback);
mockTaskAndTaskDescription(callback);

final Replicate replicate = getReplicateWithStatus(CONTRIBUTE_AND_FINALIZE_ONGOING);
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
Expand All @@ -140,7 +139,7 @@ void shouldDetectBothChangesOnChain(final String callback) {
@ParameterizedTest
@ValueSource(strings = {"", CALLBACK})
void shouldDetectMissedUpdateSinceOffChainOngoing(final String callback) {
mockTaskAndTaskDecription(callback);
mockTaskAndTaskDescription(callback);

final Replicate replicate = getReplicateWithStatus(CONTRIBUTE_AND_FINALIZE_ONGOING);
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
Expand Down Expand Up @@ -168,7 +167,7 @@ void shouldNotDetectMissedUpdateSinceNotOffChainOngoing(final String callback) {
@ParameterizedTest
@ValueSource(strings = {"", CALLBACK})
void shouldNotDetectMissedUpdateSinceNotOnChainDone(final String callback) {
mockTaskAndTaskDecription(callback);
mockTaskAndTaskDescription(callback);

final Replicate replicate = getReplicateWithStatus(CONTRIBUTE_AND_FINALIZE_ONGOING);
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
Expand All @@ -195,7 +194,7 @@ static Stream<Arguments> provideReplicateStatusAndCallback() {
@ParameterizedTest
@MethodSource("provideReplicateStatusAndCallback")
void shouldDetectMissedUpdateSinceOnChainDoneNotOffChainDone(final ReplicateStatus replicateStatus, final String callback) {
mockTaskAndTaskDecription(callback);
mockTaskAndTaskDescription(callback);

final Replicate replicate = getReplicateWithStatus(replicateStatus);
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
Expand Down Expand Up @@ -226,22 +225,6 @@ void shouldNotDetectMissedUpdateSinceOnChainDoneAndOffChainDone() {
.updateReplicateStatus(any(), any(), any(ReplicateStatusUpdate.class));
}

@Test
void shouldNotDetectMissedUpdateSinceOnChainDoneAndNotEligibleToContributeAndFinalize() {
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)).thenReturn(
TaskDescription.builder().trust(BigInteger.ONE).isTeeTask(true).callback("0x2").build());
final Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
when(taskService.findByCurrentStatus(TaskStatus.getWaitingContributionStatuses())).thenReturn(Collections.singletonList(task));

final Replicate replicate = getReplicateWithStatus(CONTRIBUTING);
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));

detector.detectOnchainDone();

Mockito.verify(replicatesService, never())
.updateReplicateStatus(any(), any(), any(ReplicateStatusUpdate.class));
}

// endregion

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.iexec.common.replicate.ReplicateStatusUpdate;
import com.iexec.commons.poco.chain.ChainReceipt;
import com.iexec.commons.poco.task.TaskDescription;
import com.iexec.commons.poco.tee.TeeFramework;
import com.iexec.commons.poco.utils.BytesUtils;
import com.iexec.core.chain.IexecHubService;
import com.iexec.core.configuration.CronConfiguration;
Expand Down Expand Up @@ -88,7 +89,6 @@ private void mockTaskAndTaskDescription() {
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
when(iexecHubService.getTaskDescription(anyString())).thenReturn(TaskDescription.builder()
.trust(BigInteger.ONE)
.isTeeTask(false)
.build());
when(taskService.findByCurrentStatus(TaskStatus.getWaitingContributionStatuses())).thenReturn(Collections.singletonList(task));
}
Expand Down Expand Up @@ -208,10 +208,11 @@ void shouldNotDetectMissedUpdateSinceOnChainDoneAndOffChainDone() {
.updateReplicateStatus(any(), any(), any(ReplicateStatusUpdate.class));
}

@Test
void shouldNotDetectMissedUpdateSinceOnChainDoneAndEligibleToContributeAndFinalize() {
@ParameterizedTest
@EnumSource(value = TeeFramework.class)
void shouldNotDetectMissedUpdateSinceOnChainDoneAndEligibleToContributeAndFinalize(final TeeFramework teeFramework) {
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)).thenReturn(
TaskDescription.builder().trust(BigInteger.ONE).isTeeTask(true).callback(BytesUtils.EMPTY_ADDRESS).build());
TaskDescription.builder().trust(BigInteger.ONE).teeFramework(teeFramework).callback(BytesUtils.EMPTY_ADDRESS).build());
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
when(taskService.findByCurrentStatus(TaskStatus.getWaitingContributionStatuses())).thenReturn(Collections.singletonList(task));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2025 IEXEC BLOCKCHAIN TECH
* Copyright 2023-2026 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -296,7 +296,6 @@ private Task.TaskBuilder mockOnchainTask(final String chainTaskId, final ChainTa
private void mockTaskDescriptionFromTask(final Task task) {
final TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(task.getChainTaskId())
.isTeeTask(task.isTeeTask())
.teeFramework(TeeUtils.getTeeFramework(task.getTag()))
.trust(BigInteger.valueOf(task.getTrust()))
.callback("")
Expand Down
57 changes: 32 additions & 25 deletions src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2026 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import com.iexec.commons.poco.chain.ChainTask;
import com.iexec.commons.poco.chain.DealParams;
import com.iexec.commons.poco.task.TaskDescription;
import com.iexec.commons.poco.tee.TeeFramework;
import com.iexec.commons.poco.utils.BytesUtils;
import com.iexec.core.chain.IexecHubService;
import com.iexec.core.chain.Web3jService;
Expand All @@ -33,7 +34,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.NullSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
Expand Down Expand Up @@ -382,8 +384,7 @@ void shouldUpdateReplicateStatusWithoutStdout() {
.build();
replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate);

Mockito.verify(applicationEventPublisher, Mockito.times(1))
.publishEvent(argumentCaptor.capture());
verify(applicationEventPublisher).publishEvent(argumentCaptor.capture());

ReplicateUpdatedEvent capturedEvent = argumentCaptor.getAllValues().get(0);
assertThat(capturedEvent.getChainTaskId()).isEqualTo(replicate.getChainTaskId());
Expand All @@ -397,8 +398,10 @@ void shouldUpdateReplicateStatusWithoutStdout() {
assertThat(capturedEvent.getReplicateStatusUpdate().getDetails().getComputeLogs()).isNull();
}

@Test
void shouldUpdateReplicateStatusWithStdoutIfComputed() {
@ParameterizedTest
@NullSource
@EnumSource(value = TeeFramework.class)
void shouldUpdateReplicateStatusWithStdoutIfComputed(final TeeFramework teeFramework) {
String stdout = "This is an stdout message !";
Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID);
replicate.updateStatus(COMPUTING, ReplicateStatusModifier.WORKER);
Expand All @@ -413,11 +416,10 @@ void shouldUpdateReplicateStatusWithStdoutIfComputed() {
.build();
ArgumentCaptor<ReplicateUpdatedEvent> argumentCaptor = ArgumentCaptor.forClass(ReplicateUpdatedEvent.class);
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
.thenReturn(TaskDescription.builder().isTeeTask(true).build());
.thenReturn(TaskDescription.builder().teeFramework(teeFramework).build());

replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate);
Mockito.verify(applicationEventPublisher, Mockito.times(1))
.publishEvent(argumentCaptor.capture());
verify(applicationEventPublisher).publishEvent(argumentCaptor.capture());
ReplicateUpdatedEvent capturedEvent = argumentCaptor.getAllValues().get(0);
assertThat(capturedEvent.getChainTaskId()).isEqualTo(replicate.getChainTaskId());
assertThat(capturedEvent.getWalletAddress()).isEqualTo(WALLET_WORKER_1);
Expand Down Expand Up @@ -750,15 +752,16 @@ void shouldGetReplicateWithResultUploadedStatus() {
// region isResultUploaded

@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldCheckResultServiceAndReturnTrue(final boolean isTeeTask) {
@NullSource
@EnumSource(value = TeeFramework.class)
void shouldCheckResultServiceAndReturnTrue(final TeeFramework teeFramework) {
final DealParams dealParams = DealParams.builder()
.iexecResultStorageProvider(IPFS_RESULT_STORAGE_PROVIDER)
.build();
TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback(BytesUtils.EMPTY_ADDRESS)
.isTeeTask(isTeeTask)
.teeFramework(teeFramework)
.dealParams(dealParams)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
Expand All @@ -771,15 +774,16 @@ void shouldCheckResultServiceAndReturnTrue(final boolean isTeeTask) {
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldCheckResultServiceAndReturnFalse(final boolean isTeeTask) {
@NullSource
@EnumSource(value = TeeFramework.class)
void shouldCheckResultServiceAndReturnFalse(final TeeFramework teeFramework) {
final DealParams dealParams = DealParams.builder()
.iexecResultStorageProvider(IPFS_RESULT_STORAGE_PROVIDER)
.build();
final TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback(BytesUtils.EMPTY_ADDRESS)
.isTeeTask(isTeeTask)
.teeFramework(teeFramework)
.dealParams(dealParams)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
Expand All @@ -802,12 +806,13 @@ void shouldReturnFalseSinceTaskNotFound() {
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldReturnTrueForCallbackTask(boolean isTeeTask) {
@NullSource
@EnumSource(value = TeeFramework.class)
void shouldReturnTrueForCallbackTask(final TeeFramework teeFramework) {
TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback("callback")
.isTeeTask(isTeeTask)
.teeFramework(teeFramework)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
.thenReturn(taskDescription);
Expand All @@ -817,15 +822,17 @@ void shouldReturnTrueForCallbackTask(boolean isTeeTask) {
verifyNoInteractions(resultService);
}

@Test
void shouldReturnTrueIfPrivateStorageForTeeTask() {
@ParameterizedTest
@NullSource
@EnumSource(value = TeeFramework.class)
void shouldReturnTrueIfPrivateStorage(final TeeFramework teeFramework) {
final DealParams dealParams = DealParams.builder()
.iexecResultStorageProvider(DROPBOX_RESULT_STORAGE_PROVIDER)
.build();
final TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback(BytesUtils.EMPTY_ADDRESS)
.isTeeTask(true)
.teeFramework(teeFramework)
.dealParams(dealParams)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
Expand Down Expand Up @@ -1120,7 +1127,6 @@ void shouldNotAuthorizeUpdateOnResultUploadedSinceNoResultLink() {
.taskDescription(TaskDescription.builder().chainTaskId(CHAIN_TASK_ID).build())
.build();


assertThat(replicatesService.canUpdateReplicateStatus(replicate, statusUpdate, updateArgs))
.isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE);
}
Expand Down Expand Up @@ -1166,8 +1172,9 @@ void shouldAuthorizeUpdateOnContributeAndFinalizeOnGoing() {
.isEqualTo(ReplicateStatusUpdateError.NO_ERROR);
}

@Test
void shouldAuthorizeUpdateOnContributeAndFinalizeDone() {
@ParameterizedTest
@EnumSource(value = TeeFramework.class)
void shouldAuthorizeUpdateOnContributeAndFinalizeDone(final TeeFramework teeFramework) {
final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID);
replicate.updateStatus(CONTRIBUTE_AND_FINALIZE_ONGOING, ReplicateStatusModifier.WORKER);

Expand All @@ -1178,7 +1185,7 @@ void shouldAuthorizeUpdateOnContributeAndFinalizeDone() {
final TaskDescription task = TaskDescription
.builder()
.chainTaskId(CHAIN_TASK_ID)
.isTeeTask(true)
.teeFramework(teeFramework)
.build();

when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1))
Expand Down
Loading
Loading