diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index 03ab507e..eabde721 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -19,22 +19,22 @@ import com.iexec.common.lifecycle.purge.Purgeable; import com.iexec.commons.poco.chain.*; import com.iexec.commons.poco.contract.generated.IexecHubContract; -import com.iexec.commons.poco.utils.BytesUtils; +import com.iexec.commons.poco.encoding.LogTopic; import io.reactivex.Flowable; import jakarta.annotation.PreDestroy; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import org.web3j.abi.EventEncoder; -import org.web3j.abi.datatypes.Event; import org.web3j.protocol.core.DefaultBlockParameter; import org.web3j.protocol.core.methods.request.EthFilter; +import org.web3j.protocol.core.methods.response.EthLog; +import org.web3j.protocol.core.methods.response.Log; import java.math.BigInteger; +import java.util.Arrays; import java.util.Date; import static com.iexec.commons.poco.chain.ChainContributionStatus.CONTRIBUTED; import static com.iexec.commons.poco.chain.ChainContributionStatus.REVEALED; -import static com.iexec.commons.poco.contract.generated.IexecHubContract.*; @Slf4j @Service @@ -43,9 +43,9 @@ public class IexecHubService extends IexecHubAbstractService implements Purgeabl private final SignerService signerService; private final Web3jService web3jService; - public IexecHubService(SignerService signerService, - Web3jService web3jService, - ChainConfig chainConfig) { + public IexecHubService(final SignerService signerService, + final Web3jService web3jService, + final ChainConfig chainConfig) { super( signerService.getCredentials(), web3jService, @@ -156,124 +156,95 @@ public boolean isRevealed(String... args) { // endregion // region get event blocks - public ChainReceipt getContributionBlock(String chainTaskId, - String workerWallet, - long fromBlock) { - long latestBlock = web3jService.getLatestBlockNumber(); + public ChainReceipt getInitializeBlock(final String chainTaskId, + final long fromBlock) { + log.debug("getInitializeBlock [chainTaskId:{}]", chainTaskId); + final long latestBlock = web3jService.getLatestBlockNumber(); if (fromBlock > latestBlock) { return ChainReceipt.builder().build(); } - - EthFilter ethFilter = createContributeEthFilter(fromBlock, latestBlock); - - // filter only taskContribute events for the chainTaskId and the worker's wallet - // and retrieve the block number of the event - return iexecHubContract.taskContributeEventFlowable(ethFilter) - .filter(eventResponse -> - chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) && - workerWallet.equals(eventResponse.worker) - ) - .map(eventResponse -> ChainReceipt.builder() - .blockNumber(eventResponse.log.getBlockNumber().longValue()) - .txHash(eventResponse.log.getTransactionHash()) - .build()) + final EthFilter ethFilter = createEthFilter( + fromBlock, latestBlock, LogTopic.TASK_INITIALIZE_EVENT, chainTaskId); + return web3jService.getWeb3j().ethGetLogs(ethFilter).flowable() + .map(this::createChainReceipt) .blockingFirst(); } - public ChainReceipt getConsensusBlock(String chainTaskId, long fromBlock) { + public ChainReceipt getContributionBlock(final String chainTaskId, + final String workerWallet, + final long fromBlock) { + log.debug("getContributionBlock [chainTaskId:{}]", chainTaskId); long latestBlock = web3jService.getLatestBlockNumber(); if (fromBlock > latestBlock) { return ChainReceipt.builder().build(); } - - EthFilter ethFilter = createConsensusEthFilter(fromBlock, latestBlock); - - // filter only taskConsensus events for the chainTaskId (there should be only one) - // and retrieve the block number of the event - return iexecHubContract.taskConsensusEventFlowable(ethFilter) - .filter(eventResponse -> chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid))) - .map(eventResponse -> ChainReceipt.builder() - .blockNumber(eventResponse.log.getBlockNumber().longValue()) - .txHash(eventResponse.log.getTransactionHash()) - .build()) + final EthFilter ethFilter = createEthFilter( + fromBlock, latestBlock, LogTopic.TASK_CONTRIBUTE_EVENT, chainTaskId, workerWallet); + return web3jService.getWeb3j().ethGetLogs(ethFilter).flowable() + .map(this::createChainReceipt) .blockingFirst(); } - public ChainReceipt getRevealBlock(String chainTaskId, - String workerWallet, - long fromBlock) { + public ChainReceipt getConsensusBlock(final String chainTaskId, final long fromBlock) { + log.debug("getConsensusBlock [chainTaskId:{}]", chainTaskId); long latestBlock = web3jService.getLatestBlockNumber(); if (fromBlock > latestBlock) { return ChainReceipt.builder().build(); } - - EthFilter ethFilter = createRevealEthFilter(fromBlock, latestBlock); - - // filter only taskReveal events for the chainTaskId and the worker's wallet - // and retrieve the block number of the event - return iexecHubContract.taskRevealEventFlowable(ethFilter) - .filter(eventResponse -> - chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) && - workerWallet.equals(eventResponse.worker) - ) - .map(eventResponse -> ChainReceipt.builder() - .blockNumber(eventResponse.log.getBlockNumber().longValue()) - .txHash(eventResponse.log.getTransactionHash()) - .build()) + final EthFilter ethFilter = createEthFilter( + fromBlock, latestBlock, LogTopic.TASK_CONSENSUS_EVENT, chainTaskId); + return web3jService.getWeb3j().ethGetLogs(ethFilter).flowable() + .map(this::createChainReceipt) .blockingFirst(); } - public ChainReceipt getFinalizeBlock(String chainTaskId, long fromBlock) { + public ChainReceipt getRevealBlock(final String chainTaskId, + final String workerWallet, + final long fromBlock) { + log.debug("getRevealBlock [chainTaskId:{}]", chainTaskId); long latestBlock = web3jService.getLatestBlockNumber(); if (fromBlock > latestBlock) { return ChainReceipt.builder().build(); } - - EthFilter ethFilter = createFinalizeEthFilter(fromBlock, latestBlock); - - // filter only taskFinalize events for the chainTaskId (there should be only one) - // and retrieve the block number of the event - return iexecHubContract.taskFinalizeEventFlowable(ethFilter) - .filter(eventResponse -> - chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) - ) - .map(eventResponse -> ChainReceipt.builder() - .blockNumber(eventResponse.log.getBlockNumber().longValue()) - .txHash(eventResponse.log.getTransactionHash()) - .build()) + final EthFilter ethFilter = createEthFilter( + fromBlock, latestBlock, LogTopic.TASK_REVEAL_EVENT, chainTaskId, workerWallet); + return web3jService.getWeb3j().ethGetLogs(ethFilter).flowable() + .map(this::createChainReceipt) .blockingFirst(); } - private EthFilter createContributeEthFilter(long fromBlock, long toBlock) { - return createEthFilter(fromBlock, toBlock, TASKCONTRIBUTE_EVENT); - } - - private EthFilter createConsensusEthFilter(long fromBlock, long toBlock) { - return createEthFilter(fromBlock, toBlock, TASKCONSENSUS_EVENT); - } - - private EthFilter createRevealEthFilter(long fromBlock, long toBlock) { - return createEthFilter(fromBlock, toBlock, TASKREVEAL_EVENT); + public ChainReceipt getFinalizeBlock(final String chainTaskId, + final long fromBlock) { + log.debug("getFinalizeBlock [chainTaskId:{}]", chainTaskId); + long latestBlock = web3jService.getLatestBlockNumber(); + if (fromBlock > latestBlock) { + return ChainReceipt.builder().build(); + } + final EthFilter ethFilter = createEthFilter( + fromBlock, latestBlock, LogTopic.TASK_FINALIZE_EVENT, chainTaskId); + return web3jService.getWeb3j().ethGetLogs(ethFilter).flowable() + .map(this::createChainReceipt) + .blockingFirst(); } - private EthFilter createFinalizeEthFilter(long fromBlock, long toBlock) { - return createEthFilter(fromBlock, toBlock, TASKFINALIZE_EVENT); + private ChainReceipt createChainReceipt(final EthLog ethLog) { + final Log logEvent = (Log) ethLog.getLogs().get(0); + return ChainReceipt.builder() + .blockNumber(logEvent.getBlockNumber().longValue()) + .txHash(logEvent.getTransactionHash()) + .build(); } - private EthFilter createEthFilter(long fromBlock, long toBlock, Event event) { - IexecHubContract iexecHub = getHubContract(); - DefaultBlockParameter startBlock = - DefaultBlockParameter.valueOf(BigInteger.valueOf(fromBlock)); - DefaultBlockParameter endBlock = - DefaultBlockParameter.valueOf(BigInteger.valueOf(toBlock)); - - // define the filter - EthFilter ethFilter = new EthFilter( - startBlock, - endBlock, - iexecHub.getContractAddress() + private EthFilter createEthFilter(final long fromBlock, + final long toBlock, + final String... topics) { + log.debug("createEthFilter [from:{}, to:{}]", fromBlock, toBlock); + final EthFilter ethFilter = new EthFilter( + DefaultBlockParameter.valueOf(BigInteger.valueOf(fromBlock)), + DefaultBlockParameter.valueOf(BigInteger.valueOf(toBlock)), + iexecHubAddress ); - ethFilter.addSingleTopic(EventEncoder.encode(event)); + Arrays.stream(topics).forEach(ethFilter::addSingleTopic); return ethFilter; } diff --git a/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java b/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java index 0ff9bee2..56f4dcf3 100644 --- a/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java +++ b/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2025 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. @@ -28,8 +28,6 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import java.util.Optional; - @Slf4j @Service public class InitializedTaskDetector implements Detector { @@ -38,9 +36,9 @@ public class InitializedTaskDetector implements Detector { private final TaskUpdateRequestManager taskUpdateRequestManager; private final IexecHubService iexecHubService; - public InitializedTaskDetector(TaskService taskService, - TaskUpdateRequestManager taskUpdateRequestManager, - IexecHubService iexecHubService) { + public InitializedTaskDetector(final TaskService taskService, + final TaskUpdateRequestManager taskUpdateRequestManager, + final IexecHubService iexecHubService) { this.taskService = taskService; this.taskUpdateRequestManager = taskUpdateRequestManager; this.iexecHubService = iexecHubService; @@ -54,8 +52,8 @@ public InitializedTaskDetector(TaskService taskService, public void detect() { log.debug("Trying to detect initializable tasks"); for (Task task : taskService.getInitializableTasks()) { - Optional chainTask = iexecHubService.getChainTask(task.getChainTaskId()); - if (chainTask.isEmpty() || chainTask.get().getStatus().equals(ChainTaskStatus.UNSET)) { + final ChainTask chainTask = iexecHubService.getChainTask(task.getChainTaskId()).orElse(null); + if (chainTask == null || chainTask.getStatus() == ChainTaskStatus.UNSET) { continue; } log.info("Detected confirmed missing update (task) [is:{}, should:{}, taskId:{}]", diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index 7e1b2ab5..b1b0ec32 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -242,8 +242,9 @@ void initializing2Initialized(final Task task) { log.info("Initialized on blockchain (tx mined) [chainTaskId:{}]", task.getChainTaskId()); final Update update = new Update(); // Without receipt, using deal block for initialization block - task.setInitializationBlockNumber(task.getDealBlockNumber()); - update.set("initializationBlockNumber", task.getDealBlockNumber()); + final ChainReceipt chainReceipt = iexecHubService.getInitializeBlock(task.getChainTaskId(), task.getDealBlockNumber()); + task.setInitializationBlockNumber(chainReceipt.getBlockNumber()); + update.set("initializationBlockNumber", chainReceipt.getBlockNumber()); // Create enclave challenge after task has been initialized on-chain final Optional enclaveChallenge = smsService.getEnclaveChallenge( diff --git a/src/test/java/com/iexec/core/TestUtils.java b/src/test/java/com/iexec/core/TestUtils.java index 4b139dd5..3732e4a4 100644 --- a/src/test/java/com/iexec/core/TestUtils.java +++ b/src/test/java/com/iexec/core/TestUtils.java @@ -30,6 +30,7 @@ public class TestUtils { public static final String CHAIN_DEAL_ID = "0xd82223e5feff6720792ffed1665e980da95e5d32b177332013eaba8edc07f31c"; public static final String CHAIN_TASK_ID = "0x65bc5e94ed1486b940bd6cc0013c418efad58a0a52a3d08cee89faaa21970426"; public static final int TASK_INDEX = 0; + public static final long DEAL_BLOCK = 1_000L; public static final String WORKER_ADDRESS = "0x87ae2b87b5db23830572988fb1f51242fbc471ce"; public static final String WALLET_WORKER_1 = "0x1a69b2eb604db8eba185df03ea4f5288dcbbd248"; @@ -45,6 +46,7 @@ public class TestUtils { public static Task getStubTask() { final Task task = new Task(CHAIN_DEAL_ID, 0, DAPP_NAME, COMMAND_LINE, 1, 60000, NO_TEE_TAG); + task.setDealBlockNumber(DEAL_BLOCK); task.setContributionDeadline(Date.from(Instant.now().plus(1, ChronoUnit.MINUTES))); task.setFinalDeadline(Date.from(Instant.now().plus(1, ChronoUnit.MINUTES))); return task; diff --git a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java index ff95d5be..6a0155f5 100644 --- a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java +++ b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java @@ -17,8 +17,6 @@ package com.iexec.core.chain; import com.iexec.commons.poco.chain.*; -import com.iexec.commons.poco.contract.generated.IexecHubContract; -import com.iexec.commons.poco.utils.BytesUtils; import io.reactivex.Flowable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -28,11 +26,13 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.test.util.ReflectionTestUtils; import org.web3j.crypto.Credentials; import org.web3j.crypto.Keys; -import org.web3j.protocol.core.methods.response.Log; +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.Request; +import org.web3j.protocol.core.methods.response.EthLog; +import java.util.List; import java.util.Optional; import java.util.function.BiFunction; import java.util.stream.Stream; @@ -57,6 +57,11 @@ class IexecHubServiceTests { @Mock private ChainConfig chainConfig; + @Mock + private Web3j web3j; + @Mock + private Request logRequest; + private IexecHubService iexecHubService; @BeforeEach @@ -125,20 +130,27 @@ void shouldNotBeRevealed(ChainContributionStatus status) { // endregion // region get event blocks + private EthLog mockWeb3jCall(final long latestBlock) { + when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); + when(web3jService.getWeb3j()).thenReturn(web3j); + doReturn(logRequest).when(web3j).ethGetLogs(any()); + final EthLog ethLog = new EthLog(); + final EthLog.LogObject logObject = new EthLog.LogObject(); + logObject.setBlockNumber(String.valueOf(latestBlock)); + logObject.setTransactionHash(TRANSACTION_HASH); + ethLog.setResult(List.of(logObject)); + return ethLog; + } + @Test - void shouldGetContributionBlock() { + void shouldGetInitializationBlock() { final int fromBlock = 0; final long latestBlock = 1; - when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); - final IexecHubContract hubContract = mock(IexecHubContract.class); - ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); + final EthLog ethLog = mockWeb3jCall(latestBlock); + when(logRequest.flowable()).thenReturn(Flowable.fromArray(ethLog)); - final IexecHubContract.TaskContributeEventResponse taskContributeEventResponse = getTaskContributeEventResponse(latestBlock); - when(hubContract.taskContributeEventFlowable(any())) - .thenReturn(Flowable.fromArray(taskContributeEventResponse)); - - final ChainReceipt chainReceipt = iexecHubService.getContributionBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock); + final ChainReceipt chainReceipt = iexecHubService.getInitializeBlock(CHAIN_TASK_ID, fromBlock); assertThat(chainReceipt) .isEqualTo(ChainReceipt.builder() @@ -147,29 +159,28 @@ void shouldGetContributionBlock() { .build()); } - private static IexecHubContract.TaskContributeEventResponse getTaskContributeEventResponse(long latestBlock) { - final IexecHubContract.TaskContributeEventResponse taskContributeEventResponse = - new IexecHubContract.TaskContributeEventResponse(); - taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); - taskContributeEventResponse.worker = WORKER_ADDRESS; - taskContributeEventResponse.log = new Log(); - taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); - taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); - return taskContributeEventResponse; + @Test + void shouldGetContributionBlock() { + final int fromBlock = 1; + final long latestBlock = 2; + final EthLog ethLog = mockWeb3jCall(latestBlock); + when(logRequest.flowable()).thenReturn(Flowable.fromArray(ethLog)); + + final ChainReceipt chainReceipt = iexecHubService.getContributionBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock); + + assertThat(chainReceipt) + .isEqualTo(ChainReceipt.builder() + .blockNumber(latestBlock) + .txHash(TRANSACTION_HASH) + .build()); } @Test void shouldGetConsensusBlock() { - final int fromBlock = 0; - final long latestBlock = 1; - when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); - - final IexecHubContract hubContract = mock(IexecHubContract.class); - ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); - - final IexecHubContract.TaskConsensusEventResponse taskConsensusEventResponse = getTaskConsensusEventResponse(latestBlock); - when(hubContract.taskConsensusEventFlowable(any())) - .thenReturn(Flowable.fromArray(taskConsensusEventResponse)); + final int fromBlock = 2; + final long latestBlock = 3; + final EthLog ethLog = mockWeb3jCall(latestBlock); + when(logRequest.flowable()).thenReturn(Flowable.fromArray(ethLog)); final ChainReceipt chainReceipt = iexecHubService.getConsensusBlock(CHAIN_TASK_ID, fromBlock); @@ -180,28 +191,12 @@ void shouldGetConsensusBlock() { .build()); } - private static IexecHubContract.TaskConsensusEventResponse getTaskConsensusEventResponse(long latestBlock) { - final IexecHubContract.TaskConsensusEventResponse taskContributeEventResponse = - new IexecHubContract.TaskConsensusEventResponse(); - taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); - taskContributeEventResponse.log = new Log(); - taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); - taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); - return taskContributeEventResponse; - } - @Test void shouldGetRevealBlock() { - final int fromBlock = 0; - final long latestBlock = 1; - when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); - - final IexecHubContract hubContract = mock(IexecHubContract.class); - ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); - - final IexecHubContract.TaskRevealEventResponse taskRevealEventResponse = getTaskRevealEventResponse(latestBlock); - when(hubContract.taskRevealEventFlowable(any())) - .thenReturn(Flowable.fromArray(taskRevealEventResponse)); + final int fromBlock = 3; + final long latestBlock = 4; + final EthLog ethLog = mockWeb3jCall(latestBlock); + when(logRequest.flowable()).thenReturn(Flowable.fromArray(ethLog)); final ChainReceipt chainReceipt = iexecHubService.getRevealBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock); @@ -212,29 +207,12 @@ void shouldGetRevealBlock() { .build()); } - private static IexecHubContract.TaskRevealEventResponse getTaskRevealEventResponse(long latestBlock) { - final IexecHubContract.TaskRevealEventResponse taskContributeEventResponse = - new IexecHubContract.TaskRevealEventResponse(); - taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); - taskContributeEventResponse.worker = WORKER_ADDRESS; - taskContributeEventResponse.log = new Log(); - taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); - taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); - return taskContributeEventResponse; - } - @Test void shouldGetFinalizeBlock() { - final int fromBlock = 0; - final long latestBlock = 1; - when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); - - final IexecHubContract hubContract = mock(IexecHubContract.class); - ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); - - final IexecHubContract.TaskFinalizeEventResponse taskFinalizeEventResponse = getTaskFinalizeEventResponse(latestBlock); - when(hubContract.taskFinalizeEventFlowable(any())) - .thenReturn(Flowable.fromArray(taskFinalizeEventResponse)); + final int fromBlock = 4; + final long latestBlock = 5; + final EthLog ethLog = mockWeb3jCall(latestBlock); + when(logRequest.flowable()).thenReturn(Flowable.fromArray(ethLog)); final ChainReceipt chainReceipt = iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, fromBlock); @@ -245,18 +223,9 @@ void shouldGetFinalizeBlock() { .build()); } - private static IexecHubContract.TaskFinalizeEventResponse getTaskFinalizeEventResponse(long latestBlock) { - final IexecHubContract.TaskFinalizeEventResponse taskContributeEventResponse = - new IexecHubContract.TaskFinalizeEventResponse(); - taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); - taskContributeEventResponse.log = new Log(); - taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); - taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); - return taskContributeEventResponse; - } - static Stream> eventBlockGetters() { return Stream.of( + (iexecHubService, fromBlock) -> iexecHubService.getInitializeBlock(CHAIN_TASK_ID, fromBlock), (iexecHubService, fromBlock) -> iexecHubService.getContributionBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock), (iexecHubService, fromBlock) -> iexecHubService.getConsensusBlock(CHAIN_TASK_ID, fromBlock), (iexecHubService, fromBlock) -> iexecHubService.getRevealBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock), @@ -266,7 +235,7 @@ static Stream> eventBlockGetters @ParameterizedTest @MethodSource("eventBlockGetters") - void shouldNotGetEventBlockWhenFromBlockInFuture(BiFunction eventBlockGetter) { + void shouldNotGetEventBlockWhenFromBlockInFuture(final BiFunction eventBlockGetter) { final long fromBlock = 2; final long latestBlock = 1; when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); diff --git a/src/test/java/com/iexec/core/task/TaskServiceTests.java b/src/test/java/com/iexec/core/task/TaskServiceTests.java index cdc225f9..ac34178b 100644 --- a/src/test/java/com/iexec/core/task/TaskServiceTests.java +++ b/src/test/java/com/iexec/core/task/TaskServiceTests.java @@ -136,7 +136,7 @@ void shouldAddTask() { task.setContributionDeadline(contributionDeadline); task.setFinalDeadline(finalDeadline); - Optional saved = taskService.addTask(CHAIN_DEAL_ID, 0, 0, DAPP_NAME, COMMAND_LINE, + Optional saved = taskService.addTask(CHAIN_DEAL_ID, 0, DEAL_BLOCK, DAPP_NAME, COMMAND_LINE, 2, maxExecutionTime, NO_TEE_TAG, contributionDeadline, finalDeadline); assertThat(saved) .usingRecursiveComparison() diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTests.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTests.java index 8d619916..28bb6f87 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTests.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTests.java @@ -258,6 +258,7 @@ void shouldUpdateInitializing2InitializeFailedSinceEnclaveChallengeIsEmpty() { when(blockchainAdapterService.requestInitialize(CHAIN_DEAL_ID, 0)).thenReturn(Optional.of(CHAIN_TASK_ID)); when(blockchainAdapterService.isInitialized(CHAIN_TASK_ID)).thenReturn(Optional.of(true)); + when(iexecHubService.getInitializeBlock(CHAIN_TASK_ID, DEAL_BLOCK)).thenReturn(ChainReceipt.builder().blockNumber(DEAL_BLOCK).build()); when(smsService.getVerifiedSmsUrl(CHAIN_TASK_ID, TEE_TAG)).thenReturn(Optional.of(SMS_URL)); when(smsService.getEnclaveChallenge(CHAIN_TASK_ID, CHAIN_DEAL_ID, 0, SMS_URL)).thenReturn(Optional.empty()); @@ -275,6 +276,7 @@ void shouldUpdateReceived2Initializing2InitializedOnStandard() { when(blockchainAdapterService.requestInitialize(CHAIN_DEAL_ID, 0)).thenReturn(Optional.of(CHAIN_TASK_ID)); when(blockchainAdapterService.isInitialized(CHAIN_TASK_ID)).thenReturn(Optional.of(true)); + when(iexecHubService.getInitializeBlock(CHAIN_TASK_ID, DEAL_BLOCK)).thenReturn(ChainReceipt.builder().blockNumber(DEAL_BLOCK).build()); when(smsService.getEnclaveChallenge(CHAIN_TASK_ID, CHAIN_DEAL_ID, 0, null)).thenReturn(Optional.of(BytesUtils.EMPTY_ADDRESS)); taskUpdateManager.updateTask(CHAIN_TASK_ID); @@ -295,6 +297,7 @@ void shouldUpdateReceived2Initializing2InitializedOnTee() { when(blockchainAdapterService.requestInitialize(CHAIN_DEAL_ID, 0)).thenReturn(Optional.of(CHAIN_TASK_ID)); when(blockchainAdapterService.isInitialized(CHAIN_TASK_ID)).thenReturn(Optional.of(true)); + when(iexecHubService.getInitializeBlock(CHAIN_TASK_ID, DEAL_BLOCK)).thenReturn(ChainReceipt.builder().blockNumber(DEAL_BLOCK).build()); when(smsService.getVerifiedSmsUrl(CHAIN_TASK_ID, tag)).thenReturn(Optional.of(SMS_URL)); when(smsService.getEnclaveChallenge(CHAIN_TASK_ID, CHAIN_DEAL_ID, 0, SMS_URL)).thenReturn(Optional.of(BytesUtils.EMPTY_ADDRESS)); @@ -336,6 +339,7 @@ void shouldUpdateInitializing2Initialized() { taskRepository.save(task); when(blockchainAdapterService.isInitialized(CHAIN_TASK_ID)).thenReturn(Optional.of(true)); + when(iexecHubService.getInitializeBlock(CHAIN_TASK_ID, DEAL_BLOCK)).thenReturn(ChainReceipt.builder().blockNumber(DEAL_BLOCK).build()); when(smsService.getEnclaveChallenge(CHAIN_TASK_ID, CHAIN_DEAL_ID, 0, null)).thenReturn(Optional.of(BytesUtils.EMPTY_ADDRESS)); taskUpdateManager.updateTask(CHAIN_TASK_ID);