@@ -65,9 +65,7 @@ public class ReplicateSupplyServiceTests {
6565 private final static String TEE_TAG = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
6666 private final static String ENCLAVE_CHALLENGE = "dummyEnclave" ;
6767 private final static long maxExecutionTime = 60000 ;
68- long initBlock = 10 ;
69- long coreLastBlock = initBlock + 2 ;
70- long workerLastBlock = coreLastBlock ;
68+ long workerLastBlock = 12 ;
7169
7270 @ Mock private ReplicatesService replicatesService ;
7371 @ Mock private SignatureService signatureService ;
@@ -109,13 +107,11 @@ public void shouldNotGetReplicateSinceWorkerLastBlockNotAvailable() {
109107 .build ();
110108
111109 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
112- runningTask .setInitializationBlockNumber (initBlock );
113110 runningTask .setMaxExecutionTime (maxExecutionTime );
114111 runningTask .changeStatus (RUNNING );
115112 runningTask .setTag (NO_TEE_TAG );
116113
117114 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
118- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
119115 when (workerService .getWorker (WALLET_WORKER_1 )).thenReturn (Optional .of (existingWorker ));
120116 when (taskService .getInitializedOrRunningTasks ())
121117 .thenReturn (Collections .singletonList (runningTask ));
@@ -203,49 +199,6 @@ public void shouldNotGetAnyReplicateSinceWorkerDoesNotHaveEnoughGas() {
203199 assertTaskAccessForNewReplicateLockNeverUsed ();
204200 }
205201
206- @ Test
207- public void shouldNotGetReplicateSinceIsNotFewBlocksAfterInitialization () {
208- Worker existingWorker = Worker .builder ()
209- .id ("1" )
210- .walletAddress (WALLET_WORKER_1 )
211- .cpuNb (2 )
212- .teeEnabled (false )
213- .lastAliveDate (new Date ())
214- .build ();
215-
216- Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
217- runningTask .setInitializationBlockNumber (initBlock );
218- runningTask .setMaxExecutionTime (maxExecutionTime );
219- runningTask .changeStatus (RUNNING );
220- runningTask .setTag (NO_TEE_TAG );
221- runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
222-
223- when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
224- when (web3jService .getLatestBlockNumber ()).thenReturn (initBlock + 1 );//should be 2
225- when (workerService .getWorker (WALLET_WORKER_1 )).thenReturn (Optional .of (existingWorker ));
226- when (taskService .getInitializedOrRunningTasks ())
227- .thenReturn (Collections .singletonList (runningTask ));
228- when (workerService .canAcceptMoreWorks (WALLET_WORKER_1 )).thenReturn (true );
229- when (web3jService .hasEnoughGas (WALLET_WORKER_1 )).thenReturn (true );
230- when (replicatesService .hasWorkerAlreadyParticipated (CHAIN_TASK_ID , WALLET_WORKER_1 ))
231- .thenReturn (false );
232- when (consensusService .doesTaskNeedMoreContributionsForConsensus (CHAIN_TASK_ID , runningTask .getTrust (),
233- runningTask .getMaxExecutionTime ())).thenReturn (true );
234- when (smsService .getEnclaveChallenge (CHAIN_TASK_ID , false )).thenReturn (BytesUtils .EMPTY_ADDRESS );
235- when (signatureService .createAuthorization (WALLET_WORKER_1 , CHAIN_TASK_ID , BytesUtils .EMPTY_ADDRESS ))
236- .thenReturn (new WorkerpoolAuthorization ());
237-
238- Optional <WorkerpoolAuthorization > oAuthorization = replicateSupplyService .getAuthOfAvailableReplicate (workerLastBlock , WALLET_WORKER_1 );
239-
240- assertThat (oAuthorization ).isEmpty ();
241-
242- Mockito .verify (replicatesService , Mockito .times (0 ))
243- .addNewReplicate (CHAIN_TASK_ID , WALLET_WORKER_1 );
244- Mockito .verify (workerService , Mockito .times (0 ))
245- .addChainTaskIdToWorker (CHAIN_TASK_ID , WALLET_WORKER_1 );
246- assertTaskAccessForNewReplicateNotDeadLocking ();
247- }
248-
249202 @ Test
250203 public void shouldNotGetAnyReplicateSinceWorkerAlreadyParticipated () {
251204 Worker existingWorker = Worker .builder ()
@@ -256,14 +209,12 @@ public void shouldNotGetAnyReplicateSinceWorkerAlreadyParticipated() {
256209 .build ();
257210
258211 Task runningTask1 = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
259- runningTask1 .setInitializationBlockNumber (initBlock );
260212 runningTask1 .setMaxExecutionTime (maxExecutionTime );
261213 runningTask1 .changeStatus (RUNNING );
262214 runningTask1 .setTag (NO_TEE_TAG );
263215 runningTask1 .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
264216
265217 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
266- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
267218 when (workerService .canAcceptMoreWorks (WALLET_WORKER_1 )).thenReturn (true );
268219 when (web3jService .hasEnoughGas (WALLET_WORKER_1 )).thenReturn (true );
269220 when (taskService .getInitializedOrRunningTasks ())
@@ -291,13 +242,11 @@ public void shouldNotGetReplicateSinceNeedsMoreContributionsForConsensus() {
291242
292243 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
293244 runningTask .changeStatus (RUNNING );
294- runningTask .setInitializationBlockNumber (initBlock );
295245 runningTask .setMaxExecutionTime (maxExecutionTime );
296246 runningTask .setTag (NO_TEE_TAG );
297247 runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
298248
299249 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
300- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
301250 when (workerService .canAcceptMoreWorks (WALLET_WORKER_1 )).thenReturn (true );
302251 when (web3jService .hasEnoughGas (WALLET_WORKER_1 )).thenReturn (true );
303252 when (taskService .getInitializedOrRunningTasks ())
@@ -324,14 +273,12 @@ public void shouldNotGetReplicateSinceEnclaveChallengeNeededButNotGenerated() {
324273 .build ();
325274
326275 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
327- runningTask .setInitializationBlockNumber (initBlock );
328276 runningTask .setMaxExecutionTime (maxExecutionTime );
329277 runningTask .changeStatus (RUNNING );
330278 runningTask .setTag (TEE_TAG );
331279 runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
332280
333281 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
334- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
335282 when (workerService .getWorker (WALLET_WORKER_1 )).thenReturn (Optional .of (existingWorker ));
336283 when (taskService .getInitializedOrRunningTasks ())
337284 .thenReturn (Collections .singletonList (runningTask ));
@@ -367,14 +314,12 @@ public void shouldGetOnlyOneReplicateSinceOtherOneReachedConsensusDeadline() {
367314 .build ();
368315
369316 Task task1 = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
370- task1 .setInitializationBlockNumber (initBlock );
371317 task1 .setMaxExecutionTime (maxExecutionTime );
372318 task1 .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
373319 task1 .changeStatus (RUNNING );
374320 task1 .setTag (NO_TEE_TAG );
375321
376322 Task taskDeadlineReached = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
377- taskDeadlineReached .setInitializationBlockNumber (initBlock );
378323 taskDeadlineReached .setMaxExecutionTime (maxExecutionTime );
379324 taskDeadlineReached .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), -60 ));
380325 taskDeadlineReached .changeStatus (RUNNING );
@@ -387,7 +332,6 @@ public void shouldGetOnlyOneReplicateSinceOtherOneReachedConsensusDeadline() {
387332 tasks .add (task1 );
388333 tasks .add (taskDeadlineReached );
389334 when (taskService .getInitializedOrRunningTasks ()).thenReturn (tasks );
390- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
391335 doNothing ().when (contributionTimeoutTaskDetector ).detect ();
392336
393337 replicateSupplyService .getAuthOfAvailableReplicate (workerLastBlock , WALLET_WORKER_1 );
@@ -408,14 +352,12 @@ public void shouldNotGetReplicateWhenTaskAlreadyAccessed() {
408352 .build ();
409353
410354 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
411- runningTask .setInitializationBlockNumber (initBlock );
412355 runningTask .setMaxExecutionTime (maxExecutionTime );
413356 runningTask .changeStatus (RUNNING );
414357 runningTask .setTag (NO_TEE_TAG );
415358 runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
416359
417360 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (true );
418- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
419361 when (workerService .getWorker (WALLET_WORKER_1 )).thenReturn (Optional .of (existingWorker ));
420362 when (taskService .getInitializedOrRunningTasks ())
421363 .thenReturn (Collections .singletonList (runningTask ));
@@ -450,14 +392,12 @@ public void shouldGetReplicateWithNoTee() {
450392 .build ();
451393
452394 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
453- runningTask .setInitializationBlockNumber (initBlock );
454395 runningTask .setMaxExecutionTime (maxExecutionTime );
455396 runningTask .changeStatus (RUNNING );
456397 runningTask .setTag (NO_TEE_TAG );
457398 runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
458399
459400 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
460- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
461401 when (workerService .getWorker (WALLET_WORKER_1 )).thenReturn (Optional .of (existingWorker ));
462402 when (taskService .getInitializedOrRunningTasks ())
463403 .thenReturn (Collections .singletonList (runningTask ));
@@ -493,14 +433,12 @@ public void shouldGetReplicateWithTee() {
493433 .build ();
494434
495435 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
496- runningTask .setInitializationBlockNumber (initBlock );
497436 runningTask .setMaxExecutionTime (maxExecutionTime );
498437 runningTask .changeStatus (RUNNING );
499438 runningTask .setTag (TEE_TAG );
500439 runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
501440
502441 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
503- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
504442 when (workerService .getWorker (WALLET_WORKER_1 )).thenReturn (Optional .of (existingWorker ));
505443 when (taskService .getInitializedOrRunningTasks ())
506444 .thenReturn (Collections .singletonList (runningTask ));
@@ -536,14 +474,12 @@ public void shouldTeeNeededTaskNotBeGivenToTeeDisabledWorker() {
536474 .build ();
537475
538476 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
539- runningTask .setInitializationBlockNumber (initBlock );
540477 runningTask .setMaxExecutionTime (maxExecutionTime );
541478 runningTask .changeStatus (RUNNING );
542479 runningTask .setTag (TEE_TAG );
543480 runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
544481
545482 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
546- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
547483 when (workerService .canAcceptMoreWorks (WALLET_WORKER_1 )).thenReturn (true );
548484 when (taskService .getInitializedOrRunningTasks ())
549485 .thenReturn (Collections .singletonList (runningTask ));
@@ -571,14 +507,12 @@ public void shouldTeeNeededTaskBeGivenToTeeEnabledWorker() {
571507 .build ();
572508
573509 Task runningTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
574- runningTask .setInitializationBlockNumber (initBlock );
575510 runningTask .setMaxExecutionTime (maxExecutionTime );
576511 runningTask .changeStatus (RUNNING );
577512 runningTask .setTag (TEE_TAG );
578513 runningTask .setContributionDeadline (DateTimeUtils .addMinutesToDate (new Date (), 60 ));
579514
580515 when (taskService .isTaskBeingAccessedForNewReplicate (CHAIN_TASK_ID )).thenReturn (false );
581- when (web3jService .getLatestBlockNumber ()).thenReturn (coreLastBlock );
582516 when (workerService .canAcceptMoreWorks (WALLET_WORKER_1 )).thenReturn (true );
583517 when (web3jService .hasEnoughGas (WALLET_WORKER_1 )).thenReturn (true );
584518 when (taskService .getInitializedOrRunningTasks ())
@@ -632,7 +566,6 @@ public void shouldNotGetInterruptedReplicateSinceEnclaveChallengeNeededButNotGen
632566
633567 List <String > ids = Arrays .asList (CHAIN_TASK_ID );
634568 Task teeTask = new Task (DAPP_NAME , COMMAND_LINE , 5 , CHAIN_TASK_ID );
635- teeTask .setInitializationBlockNumber (initBlock );
636569 Optional <Replicate > noTeeReplicate = getStubReplicate (ReplicateStatus .COMPUTING );
637570 teeTask .setTag (TEE_TAG );
638571
0 commit comments