Skip to content

Commit 3eff772

Browse files
committed
update test 3, 4, 5 to use teeDealTag and create helper function
1 parent a829e5f commit 3eff772

File tree

2 files changed

+72
-11
lines changed

2 files changed

+72
-11
lines changed

test/000_fullchain.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import { IexecWrapper } from './utils/IexecWrapper';
2424
// | [3] | ✔ | x | ✔ | ✔ | ✔ | Standard,TEE |
2525
// | [4] | x | x | ✔ | ✔ | ✔ | Standard,TEE |
2626
// | [5] | x | x | x | x | x | Standard,TEE |
27-
// | [6.x] | x | ✔ | x | x | x | Standard,TEE, X good workers |
28-
// | [7] | x | ✔ | x | x | x | Standard,TEE, 4 good workers 1 bad worker |
27+
// | [6.x] | x | ✔ | x | x | x | Standard, X good workers |
28+
// | [7] | x | ✔ | x | x | x | Standard, 4 good workers 1 bad worker |
2929
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------------------+
3030

3131
const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000';
@@ -320,7 +320,7 @@ describe('Integration tests', function () {
320320
assets: ordersAssets,
321321
prices: ordersPrices,
322322
requester: requester.address,
323-
tag: standardDealTag,
323+
tag: teeDealTag,
324324
beneficiary: beneficiary.address,
325325
callback: callbackAddress,
326326
volume,
@@ -341,7 +341,7 @@ describe('Integration tests', function () {
341341
// Finalize each task and check balance changes.
342342
for (let taskIndex = 0; taskIndex < volume; taskIndex++) {
343343
const taskId = await iexecWrapper.initializeTask(dealId, taskIndex);
344-
const { workerStakePerTask } = await iexecWrapper.contributeToTask(
344+
const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask(
345345
dealId,
346346
taskIndex,
347347
callbackResultDigest,
@@ -399,7 +399,7 @@ describe('Integration tests', function () {
399399
assets: ordersAssets,
400400
prices: ordersPrices,
401401
requester: requester.address,
402-
tag: standardDealTag,
402+
tag: teeDealTag,
403403
beneficiary: beneficiary.address,
404404
callback: callbackAddress,
405405
volume,
@@ -421,7 +421,7 @@ describe('Integration tests', function () {
421421
// Finalize each task and check balance changes.
422422
for (let taskIndex = 0; taskIndex < volume; taskIndex++) {
423423
const taskId = await iexecWrapper.initializeTask(dealId, taskIndex);
424-
const { workerStakePerTask } = await iexecWrapper.contributeToTask(
424+
const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask(
425425
dealId,
426426
taskIndex,
427427
callbackResultDigest,
@@ -478,7 +478,7 @@ describe('Integration tests', function () {
478478
assets: ordersAssets,
479479
prices: ordersPrices,
480480
requester: requester.address,
481-
tag: standardDealTag,
481+
tag: teeDealTag,
482482
volume,
483483
trust: 1,
484484
});
@@ -497,7 +497,7 @@ describe('Integration tests', function () {
497497
const accountsInitialFrozens = await getInitialFrozens(accounts);
498498
const taskIndex = 0;
499499
const taskId = await iexecWrapper.initializeTask(dealId, taskIndex);
500-
const { workerStakePerTask } = await iexecWrapper.contributeToTask(
500+
const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask(
501501
dealId,
502502
taskIndex,
503503
resultDigest,

test/utils/IexecWrapper.ts

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
IexecAccounts,
3636
PocoMode,
3737
buildAndSignContributionAuthorizationMessage,
38+
buildAndSignPocoClassicEnclaveMessage,
3839
buildResultHashAndResultSeal,
3940
getDealId,
4041
getTaskId,
@@ -345,7 +346,7 @@ export class IexecWrapper {
345346
/**
346347
* Helper function to contribute to a task. The contributor's stake is
347348
* automatically deposited before contributing.
348-
* Note: no enclave address is used.
349+
* Note: no enclave is used.
349350
* @param contributor Signer to sign the contribution
350351
* @param dealId id of the deal
351352
* @param taskIndex index of the task.
@@ -358,8 +359,60 @@ export class IexecWrapper {
358359
resultDigest: string,
359360
contributor: SignerWithAddress,
360361
) {
361-
const enclaveAddress = AddressZero;
362-
const enclaveSignature = '0x';
362+
const { taskId, workerStakePerTask } = await this._contributeToTask(
363+
dealId,
364+
taskIndex,
365+
resultDigest,
366+
contributor,
367+
false, // No enclave used
368+
);
369+
return { taskId, workerStakePerTask };
370+
}
371+
372+
/**
373+
* Helper function to contribute to a task using a secure enclave. The contributor's stake is
374+
* automatically deposited before contributing.
375+
* This function is used for enclave-based contributions (involving a secure enclave address).
376+
* @param contributor Signer to sign the contribution
377+
* @param dealId id of the deal
378+
* @param taskIndex index of the task.
379+
* @param resultDigest hash of the result
380+
* @returns id of the task
381+
*/
382+
async contributeTeeToTask(
383+
dealId: string,
384+
taskIndex: number,
385+
resultDigest: string,
386+
contributor: SignerWithAddress,
387+
) {
388+
const { taskId, workerStakePerTask } = await this._contributeToTask(
389+
dealId,
390+
taskIndex,
391+
resultDigest,
392+
contributor,
393+
true,
394+
);
395+
return { taskId, workerStakePerTask };
396+
}
397+
398+
/**
399+
* Internal helper function to handle task contributions with optional enclave support.
400+
* Automatically deposits the contributor's stake before contributing and handles
401+
* enclave-related signing and validation if required.
402+
* @param contributor Signer to sign the contribution
403+
* @param dealId id of the deal
404+
* @param taskIndex index of the task.
405+
* @param resultDigest hash of the result
406+
* @param useEnclave - Boolean flag indicating whether an enclave is used for this contribution.
407+
* @returns id of the task
408+
*/
409+
async _contributeToTask(
410+
dealId: string,
411+
taskIndex: number,
412+
resultDigest: string,
413+
contributor: SignerWithAddress,
414+
useEnclave: Boolean,
415+
) {
363416
const taskId = getTaskId(dealId, taskIndex);
364417
const workerStakePerTask = await IexecAccessors__factory.connect(
365418
this.proxyAddress,
@@ -372,6 +425,14 @@ export class IexecWrapper {
372425
resultDigest,
373426
contributor,
374427
);
428+
const enclaveAddress = useEnclave ? this.accounts.enclave.address : AddressZero;
429+
const enclaveSignature = useEnclave
430+
? await buildAndSignPocoClassicEnclaveMessage(
431+
resultHash,
432+
resultSeal,
433+
this.accounts.enclave,
434+
)
435+
: '0x';
375436
const schedulerSignature = await buildAndSignContributionAuthorizationMessage(
376437
contributor.address,
377438
taskId,

0 commit comments

Comments
 (0)