1818
1919import com .iexec .common .result .ComputedFile ;
2020import com .iexec .commons .poco .chain .*;
21+ import com .iexec .commons .poco .security .Signature ;
2122import com .iexec .commons .poco .task .TaskDescription ;
2223import com .iexec .commons .poco .utils .BytesUtils ;
2324import com .iexec .commons .poco .utils .HashUtils ;
24- import com .iexec .commons .poco .utils .TestUtils ;
25+ import com .iexec .commons .poco .utils .SignatureUtils ;
2526import org .junit .jupiter .api .BeforeEach ;
2627import org .junit .jupiter .api .Test ;
2728import org .junit .jupiter .api .extension .ExtendWith ;
@@ -48,6 +49,10 @@ class ContributionServiceTests {
4849
4950 private static final String CHAIN_DEAL_ID = "0x1566a9348a284d12f7d81fa017fbc440fd501ddef5746821860ffda7113eb847" ;
5051 private static final String WORKER_WALLET_ADDRESS = "0x49713c374C0D5259A0c0c4fCCd1254CdFd631b80" ;
52+ private static final String ENCLAVE_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ;
53+ private static final String CHAIN_TASK_ID = "0x1111111111111111111111111111111111111111111111111111111111111111" ;
54+ private static final String POOL_PRIVATE = "0xe2a973b083fae8043543f15313955aecee9de809a318656c1cfb22d3a6d52de1" ;
55+ private static final String WORKER_PRIVATE = "0xd0db6df0ebcd1d41439d91d86c5fc5c1806ee9cd8e71e3d5544bb7294b435c26" ;
5156
5257 @ Mock
5358 private IexecHubService iexecHubService ;
@@ -294,21 +299,21 @@ void getCannotContributeAndFinalizeStatusCauseShouldReturnEmpty() {
294299
295300 @ Test
296301 void getContribution () {
297- String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
298- String resultDigest = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
302+ final String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
303+ final String resultDigest = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
299304
300- String resultHash = HashUtils .concatenateAndHash (chainTaskId , resultDigest );
301- String resultSeal = HashUtils .concatenateAndHash (Credentials .create (TestUtils . WORKER_PRIVATE ).getAddress (), chainTaskId , resultDigest );
305+ final String resultHash = HashUtils .concatenateAndHash (chainTaskId , resultDigest );
306+ final String resultSeal = HashUtils .concatenateAndHash (Credentials .create (WORKER_PRIVATE ).getAddress (), chainTaskId , resultDigest );
302307
303- WorkerpoolAuthorization teeWorkerpoolAuth = TestUtils . getTeeWorkerpoolAuth ();
308+ final WorkerpoolAuthorization teeWorkerpoolAuth = getTeeWorkerpoolAuth ();
304309 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId )).thenReturn (teeWorkerpoolAuth );
305310 when (iexecHubService .isTeeTask (chainTaskId )).thenReturn (false );
306311
307- ComputedFile computedFile = ComputedFile .builder ()
312+ final ComputedFile computedFile = ComputedFile .builder ()
308313 .taskId (chainTaskId )
309314 .resultDigest (resultDigest )
310315 .build ();
311- Contribution contribution = contributionService .getContribution (computedFile );
316+ final Contribution contribution = contributionService .getContribution (computedFile );
312317
313318 assertNotNull (contribution );
314319
@@ -327,46 +332,56 @@ void getContribution() {
327332
328333 @ Test
329334 void getContributionWithTee () {
330- String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
331- String resultDigest = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
335+ final String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
336+ final String resultDigest = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
332337
333- String resultHash = HashUtils .concatenateAndHash (chainTaskId , resultDigest );
334- String resultSeal = HashUtils .concatenateAndHash (Credentials .create (TestUtils . WORKER_PRIVATE ).getAddress (), chainTaskId , resultDigest );
338+ final String resultHash = HashUtils .concatenateAndHash (chainTaskId , resultDigest );
339+ final String resultSeal = HashUtils .concatenateAndHash (Credentials .create (WORKER_PRIVATE ).getAddress (), chainTaskId , resultDigest );
335340
336- WorkerpoolAuthorization teeWorkerpoolAuth = TestUtils .getTeeWorkerpoolAuth ();
337- teeWorkerpoolAuth .setEnclaveChallenge (TestUtils .ENCLAVE_ADDRESS );
341+ final WorkerpoolAuthorization teeWorkerpoolAuth = getTeeWorkerpoolAuth ();
338342 when (workerpoolAuthorizationService .getWorkerpoolAuthorization (chainTaskId )).thenReturn (teeWorkerpoolAuth );
339343 when (enclaveAuthorizationService .
340344 isVerifiedEnclaveSignature (anyString (), anyString (), anyString (), anyString (), anyString ()))
341345 .thenReturn (true );
342346 when (iexecHubService .isTeeTask (chainTaskId )).thenReturn (true );
343347
344- ComputedFile computedFile = ComputedFile .builder ()
348+ final ComputedFile computedFile = ComputedFile .builder ()
345349 .taskId (chainTaskId )
346350 .resultDigest (resultDigest )
347351 .enclaveSignature ("0xenclaveSignature" )
348352 .build ();
349- Contribution contribution = contributionService .getContribution (computedFile );
353+ final Contribution contribution = contributionService .getContribution (computedFile );
350354
351355 assertNotNull (contribution );
352356 assertEquals (chainTaskId , contribution .chainTaskId ());
353357 assertEquals (resultDigest , contribution .resultDigest ());
354358 assertEquals (resultSeal , contribution .resultSeal ());
355- assertEquals (TestUtils . ENCLAVE_ADDRESS , contribution .enclaveChallenge ());
359+ assertEquals (ENCLAVE_ADDRESS , contribution .enclaveChallenge ());
356360 assertEquals ("0xenclaveSignature" , contribution .enclaveSignature ());
357361 assertEquals (teeWorkerpoolAuth .getSignature ().getValue (), contribution .workerPoolSignature ());
358362
359- Contribution expectedContribution = Contribution .builder ()
363+ final Contribution expectedContribution = Contribution .builder ()
360364 .chainTaskId (chainTaskId )
361365 .resultDigest (resultDigest )
362366 .resultHash (resultHash )
363367 .resultSeal (resultSeal )
364- .enclaveChallenge (TestUtils . ENCLAVE_ADDRESS )
368+ .enclaveChallenge (ENCLAVE_ADDRESS )
365369 .enclaveSignature ("0xenclaveSignature" )
366370 .workerPoolSignature (teeWorkerpoolAuth .getSignature ().getValue ())
367371 .build ();
368372 assertEquals (contribution , expectedContribution );
369373
370374 }
371375
376+ private WorkerpoolAuthorization getTeeWorkerpoolAuth () {
377+ final String hash = HashUtils .concatenateAndHash (WORKER_WALLET_ADDRESS , CHAIN_TASK_ID , ENCLAVE_ADDRESS );
378+ final Signature signature = SignatureUtils .signMessageHashAndGetSignature (hash , POOL_PRIVATE );
379+ return WorkerpoolAuthorization .builder ()
380+ .chainTaskId (CHAIN_TASK_ID )
381+ .workerWallet (WORKER_WALLET_ADDRESS )
382+ .enclaveChallenge (ENCLAVE_ADDRESS )
383+ .signature (signature )
384+ .build ();
385+ }
386+
372387}
0 commit comments