From 7453e5b52c245b8e37b9669d81ee57b5cec69563 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 11:50:50 +0100 Subject: [PATCH 01/18] implement todo save init frozen --- test/000_fullchain.test.ts | 85 +++++++++++++++----------------------- 1 file changed, 34 insertions(+), 51 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 73101d786..3b766fb5d 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -126,19 +126,9 @@ describe('Integration tests', function () { PocoMode.CLASSIC, ); const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; - // Check initial balances. - // TODO save initial balances and use them in for loop for comparison. - await checkBalancesAndFrozens({ - proxyBalance: dealPrice + schedulerStakePerDeal, - accounts: [ - { signer: sponsor, balance: 0, frozen: dealPrice }, - { signer: requester, balance: 0, frozen: 0 }, - { signer: scheduler, balance: 0, frozen: schedulerStakePerDeal }, - { signer: appProvider, balance: 0, frozen: 0 }, - { signer: datasetProvider, balance: 0, frozen: 0 }, - { signer: worker1, balance: 0, frozen: 0 }, - ], - }); + // Save frozens + const accounts = [sponsor, requester, scheduler, appProvider, datasetProvider, worker1]; + const accountsInitialFrozens = await getInitialFrozens(accounts); // Finalize each task and check balance changes. for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); @@ -152,10 +142,9 @@ describe('Integration tests', function () { .connect(worker1) .reveal(taskId, callbackResultDigest) .then((tx) => tx.wait()); - await iexecPoco + const finalizeTx = await iexecPoco .connect(scheduler) - .finalize(taskId, results, resultsCallback) - .then((tx) => tx.wait()); + .finalize(taskId, results, resultsCallback); expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); // Multiply amount by the number of finalized tasks to correctly compute // stake and reward amounts. @@ -174,27 +163,36 @@ describe('Integration tests', function () { // - Worker: // - balance: balance before + taskStake + taskReward // - frozen: frozen before - taskStake - await checkBalancesAndFrozens({ - proxyBalance: - dealPrice + - schedulerStakePerDeal - - (taskPrice + schedulerStakePerTask) * completedTasks, - accounts: [ - { signer: sponsor, balance: 0, frozen: dealPrice - taskPrice * completedTasks }, - { signer: requester, balance: 0, frozen: 0 }, - { - signer: scheduler, - balance: (schedulerStakePerTask + schedulerRewardPerTask) * completedTasks, - frozen: schedulerStakePerDeal - schedulerStakePerTask * completedTasks, - }, - { signer: appProvider, balance: appPrice * completedTasks, frozen: 0 }, - { signer: datasetProvider, balance: datasetPrice * completedTasks, frozen: 0 }, - { - signer: worker1, - balance: (workerStakePerTask + workerRewardPerTask) * completedTasks, - frozen: 0, - }, + // Verify token balance changes + const expectedProxyBalanceChange = -( + taskPrice * completedTasks + + schedulerStakePerTask * completedTasks + ); + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [proxyAddress, sponsor, scheduler, appProvider, datasetProvider, worker1], + [ + expectedProxyBalanceChange, // Proxy + -taskPrice * completedTasks, // Sponsor + schedulerStakePerTask + schedulerRewardPerTask, // Scheduler + appPrice, // AppProvider + datasetPrice, // DatasetProvider + workerStakePerTask + workerRewardPerTask, // Worker ], + ); + // Calculate expected frozen changes + const expectedFrozenChanges = [ + 0, // Proxy + -taskPrice * completedTasks, // Sponsor + 0, // Requester + -schedulerStakePerTask * completedTasks, // Scheduler + 0, // AppProvider + 0, // DatasetProvider + 0, // Worker + ]; + await changesInFrozen({ + accountsInitialFrozens, + frozenChanges: expectedFrozenChanges, }); } }); @@ -416,21 +414,6 @@ describe('Integration tests', function () { } }); -async function checkBalancesAndFrozens(args: { - proxyBalance: number; - accounts: { signer: SignerWithAddress; balance: number; frozen: number }[]; -}) { - expect(await iexecPoco.balanceOf(proxyAddress)).to.equal(args.proxyBalance); - for (const account of args.accounts) { - const message = `Failed with account at index ${args.accounts.indexOf(account)}`; - expect(await iexecPoco.balanceOf(account.signer.address)).to.equal( - account.balance, - message, - ); - expect(await iexecPoco.frozenOf(account.signer.address)).to.equal(account.frozen, message); - } -} - async function changesInFrozen(args: { accountsInitialFrozens: { address: string; frozen: number }[]; frozenChanges: number[]; From 6974ce21d7a830b818229dfb6508e6f126bb5b03 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 12:11:07 +0100 Subject: [PATCH 02/18] implement todo test 1 replication --- test/000_fullchain.test.ts | 48 ++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 3b766fb5d..c320b467a 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -107,6 +107,7 @@ describe('Integration tests', function () { it('[1] Sponsorship, beneficiary, callback, BoT, replication', async function () { const volume = 3; // Create deal. + const workers = [worker1, worker2]; const orders = buildOrders({ assets: ordersAssets, prices: ordersPrices, @@ -115,7 +116,7 @@ describe('Integration tests', function () { beneficiary: beneficiary.address, callback: callbackAddress, volume, - trust: 1, // TODO use 5 workers. + trust: workers.length ** 2 - 1, }); const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndSponsorMatchOrders(...orders.toArray()); @@ -127,21 +128,30 @@ describe('Integration tests', function () { ); const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; // Save frozens - const accounts = [sponsor, requester, scheduler, appProvider, datasetProvider, worker1]; + + const accounts = [sponsor, requester, scheduler, appProvider, datasetProvider, ...workers]; const accountsInitialFrozens = await getInitialFrozens(accounts); // Finalize each task and check balance changes. for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const { workerStakePerTask } = await iexecWrapper.contributeToTask( - dealId, - taskIndex, - callbackResultDigest, - worker1, - ); - await iexecPoco - .connect(worker1) - .reveal(taskId, callbackResultDigest) - .then((tx) => tx.wait()); + const workerStakePerTask = await iexecPoco + .viewDeal(dealId) + .then((deal) => deal.workerStake.toNumber()); + for (const worker of workers) { + await iexecWrapper.contributeToTask( + dealId, + taskIndex, + callbackResultDigest, + worker, + ); + } + // Reveal contributions for all workers + for (const worker of workers) { + await iexecPoco + .connect(worker) + .reveal(taskId, callbackResultDigest) + .then((tx) => tx.wait()); + } const finalizeTx = await iexecPoco .connect(scheduler) .finalize(taskId, results, resultsCallback); @@ -170,16 +180,22 @@ describe('Integration tests', function () { ); expect(finalizeTx).to.changeTokenBalances( iexecPoco, - [proxyAddress, sponsor, scheduler, appProvider, datasetProvider, worker1], + [proxyAddress, sponsor, scheduler, appProvider, datasetProvider], [ expectedProxyBalanceChange, // Proxy -taskPrice * completedTasks, // Sponsor schedulerStakePerTask + schedulerRewardPerTask, // Scheduler appPrice, // AppProvider datasetPrice, // DatasetProvider - workerStakePerTask + workerRewardPerTask, // Worker ], ); + for (const worker of workers) { + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [worker], + [workerStakePerTask + workerRewardPerTask / workers.length], + ); + } // Calculate expected frozen changes const expectedFrozenChanges = [ 0, // Proxy @@ -188,8 +204,10 @@ describe('Integration tests', function () { -schedulerStakePerTask * completedTasks, // Scheduler 0, // AppProvider 0, // DatasetProvider - 0, // Worker ]; + for (let i = 0; i < workers.length; i++) { + expectedFrozenChanges.push(0); + } await changesInFrozen({ accountsInitialFrozens, frozenChanges: expectedFrozenChanges, From 078b54f52b36b5c2b8a127544520171278421f31 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 14:01:39 +0100 Subject: [PATCH 03/18] implement test number 2 --- test/000_fullchain.test.ts | 102 +++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 3 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index c320b467a..f53b614d5 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -180,10 +180,11 @@ describe('Integration tests', function () { ); expect(finalizeTx).to.changeTokenBalances( iexecPoco, - [proxyAddress, sponsor, scheduler, appProvider, datasetProvider], + [proxyAddress, sponsor, requester, scheduler, appProvider, datasetProvider], [ expectedProxyBalanceChange, // Proxy -taskPrice * completedTasks, // Sponsor + 0, // Requester schedulerStakePerTask + schedulerRewardPerTask, // Scheduler appPrice, // AppProvider datasetPrice, // DatasetProvider @@ -215,9 +216,104 @@ describe('Integration tests', function () { } }); - // TODO implement the following tests. + it('[2] No sponsorship, beneficiary, callback, BoT, replication', async function () { + const volume = 3; + // Create deal. + const workers = [worker1, worker2]; + const orders = buildOrders({ + assets: ordersAssets, + prices: ordersPrices, + requester: requester.address, + tag: standardDealTag, + beneficiary: beneficiary.address, + callback: callbackAddress, + volume, + trust: workers.length ** 2 - 1, + }); + const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndMatchOrders( + ...orders.toArray(), + ); + const taskPrice = appPrice + datasetPrice + workerpoolPrice; + const schedulerStakePerTask = schedulerStakePerDeal / volume; + const workerRewardPerTask = await iexecWrapper.computeWorkerRewardPerTask( + dealId, + PocoMode.CLASSIC, + ); + const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; + // Save frozens - it('[2] No sponsorship, beneficiary, callback, BoT, replication', async function () {}); + const accounts = [requester, scheduler, appProvider, datasetProvider, ...workers]; + const accountsInitialFrozens = await getInitialFrozens(accounts); + // Finalize each task and check balance changes. + for (let taskIndex = 0; taskIndex < volume; taskIndex++) { + const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); + const workerStakePerTask = await iexecPoco + .viewDeal(dealId) + .then((deal) => deal.workerStake.toNumber()); + for (const worker of workers) { + await iexecWrapper.contributeToTask( + dealId, + taskIndex, + callbackResultDigest, + worker, + ); + } + // Reveal contributions for all workers + for (const worker of workers) { + await iexecPoco + .connect(worker) + .reveal(taskId, callbackResultDigest) + .then((tx) => tx.wait()); + } + const finalizeTx = await iexecPoco + .connect(scheduler) + .finalize(taskId, results, resultsCallback); + expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); + // Multiply amount by the number of finalized tasks to correctly compute + // stake and reward amounts. + const completedTasks = taskIndex + 1; + // Verify token balance changes + const expectedProxyBalanceChange = -( + taskPrice * completedTasks + + schedulerStakePerTask * completedTasks + ); + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [proxyAddress, requester, scheduler, appProvider, datasetProvider], + [ + expectedProxyBalanceChange, // Proxy + -taskPrice * completedTasks, // Requester + schedulerStakePerTask + schedulerRewardPerTask, // Scheduler + appPrice, // AppProvider + datasetPrice, // DatasetProvider + ], + ); + for (const worker of workers) { + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [worker], + [workerStakePerTask + workerRewardPerTask / workers.length], + ); + } + // Calculate expected frozen changes + const expectedFrozenChanges = [ + 0, // Proxy + -taskPrice * completedTasks, // Requester + -schedulerStakePerTask * completedTasks, // Scheduler + 0, // AppProvider + 0, // DatasetProvider + ]; + for (let i = 0; i < workers.length; i++) { + expectedFrozenChanges.push(0); + } + await changesInFrozen({ + accountsInitialFrozens, + frozenChanges: expectedFrozenChanges, + }); + } + }); + + // TODO implement the following tests. it('[3] Sponsorship, beneficiary, callback, BoT, no replication', async function () {}); From 46fa4c2240e07a7076e982b2eabb0012ddf9892e Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 14:11:35 +0100 Subject: [PATCH 04/18] implement test number 3 --- test/000_fullchain.test.ts | 82 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index f53b614d5..9202681ef 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -313,10 +313,86 @@ describe('Integration tests', function () { } }); - // TODO implement the following tests. - - it('[3] Sponsorship, beneficiary, callback, BoT, no replication', async function () {}); + it('[3] Sponsorship, beneficiary, callback, BoT, no replication', async function () { + const volume = 3; + // Create deal. + const orders = buildOrders({ + assets: ordersAssets, + prices: ordersPrices, + requester: requester.address, + tag: standardDealTag, + beneficiary: beneficiary.address, + callback: callbackAddress, + volume, + trust: 1, + }); + const { dealId, dealPrice, schedulerStakePerDeal } = + await iexecWrapper.signAndSponsorMatchOrders(...orders.toArray()); + const taskPrice = appPrice + datasetPrice + workerpoolPrice; + const schedulerStakePerTask = schedulerStakePerDeal / volume; + const workerRewardPerTask = await iexecWrapper.computeWorkerRewardPerTask( + dealId, + PocoMode.CLASSIC, + ); + const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; + // Save frozens + const accounts = [sponsor, requester, scheduler, appProvider, datasetProvider, worker1]; + const accountsInitialFrozens = await getInitialFrozens(accounts); + // Finalize each task and check balance changes. + for (let taskIndex = 0; taskIndex < volume; taskIndex++) { + const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); + const { workerStakePerTask } = await iexecWrapper.contributeToTask( + dealId, + taskIndex, + callbackResultDigest, + worker1, + ); + await iexecPoco + .connect(worker1) + .reveal(taskId, callbackResultDigest) + .then((tx) => tx.wait()); + const finalizeTx = await iexecPoco + .connect(scheduler) + .finalize(taskId, results, resultsCallback); + expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); + // Multiply amount by the number of finalized tasks to correctly compute + // stake and reward amounts. + const completedTasks = taskIndex + 1; + // Verify token balance changes + const expectedProxyBalanceChange = -( + taskPrice * completedTasks + + schedulerStakePerTask * completedTasks + ); + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [proxyAddress, sponsor, scheduler, appProvider, datasetProvider, worker1], + [ + expectedProxyBalanceChange, // Proxy + -taskPrice * completedTasks, // Sponsor + schedulerStakePerTask + schedulerRewardPerTask, // Scheduler + appPrice, // AppProvider + datasetPrice, // DatasetProvider + workerStakePerTask + workerRewardPerTask, // Worker + ], + ); + // Calculate expected frozen changes + const expectedFrozenChanges = [ + 0, // Proxy + -taskPrice * completedTasks, // Sponsor + 0, // Requester + -schedulerStakePerTask * completedTasks, // Scheduler + 0, // AppProvider + 0, // DatasetProvider + 0, // Worker + ]; + await changesInFrozen({ + accountsInitialFrozens, + frozenChanges: expectedFrozenChanges, + }); + } + }); + // TODO implement the following tests. it('[4] No sponsorship, beneficiary, callback, BoT, no replication', async function () {}); it('[5] No sponsorship, no beneficiary, no callback, no BoT, no replication', async function () {}); From 7ac5fa64cf8944fa47f58e5218ee397d74bec91d Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 14:15:21 +0100 Subject: [PATCH 05/18] implement test 4 --- test/000_fullchain.test.ts | 81 +++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 9202681ef..6511ed4a7 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -392,9 +392,86 @@ describe('Integration tests', function () { } }); - // TODO implement the following tests. - it('[4] No sponsorship, beneficiary, callback, BoT, no replication', async function () {}); + it('[4] No sponsorship, beneficiary, callback, BoT, no replication', async function () { + const volume = 3; + // Create deal. + const orders = buildOrders({ + assets: ordersAssets, + prices: ordersPrices, + requester: requester.address, + tag: standardDealTag, + beneficiary: beneficiary.address, + callback: callbackAddress, + volume, + trust: 1, + }); + const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndMatchOrders( + ...orders.toArray(), + ); + const taskPrice = appPrice + datasetPrice + workerpoolPrice; + const schedulerStakePerTask = schedulerStakePerDeal / volume; + const workerRewardPerTask = await iexecWrapper.computeWorkerRewardPerTask( + dealId, + PocoMode.CLASSIC, + ); + const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; + // Save frozens + const accounts = [requester, scheduler, appProvider, datasetProvider, worker1]; + const accountsInitialFrozens = await getInitialFrozens(accounts); + // Finalize each task and check balance changes. + for (let taskIndex = 0; taskIndex < volume; taskIndex++) { + const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); + const { workerStakePerTask } = await iexecWrapper.contributeToTask( + dealId, + taskIndex, + callbackResultDigest, + worker1, + ); + await iexecPoco + .connect(worker1) + .reveal(taskId, callbackResultDigest) + .then((tx) => tx.wait()); + const finalizeTx = await iexecPoco + .connect(scheduler) + .finalize(taskId, results, resultsCallback); + expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); + // Multiply amount by the number of finalized tasks to correctly compute + // stake and reward amounts. + const completedTasks = taskIndex + 1; + // Verify token balance changes + const expectedProxyBalanceChange = -( + taskPrice * completedTasks + + schedulerStakePerTask * completedTasks + ); + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [proxyAddress, requester, scheduler, appProvider, datasetProvider, worker1], + [ + expectedProxyBalanceChange, // Proxy + -taskPrice * completedTasks, // Requester + schedulerStakePerTask + schedulerRewardPerTask, // Scheduler + appPrice, // AppProvider + datasetPrice, // DatasetProvider + workerStakePerTask + workerRewardPerTask, // Worker + ], + ); + // Calculate expected frozen changes + const expectedFrozenChanges = [ + 0, // Proxy + -taskPrice * completedTasks, // Requester + -schedulerStakePerTask * completedTasks, // Scheduler + 0, // AppProvider + 0, // DatasetProvider + 0, // Worker + ]; + await changesInFrozen({ + accountsInitialFrozens, + frozenChanges: expectedFrozenChanges, + }); + } + }); + // TODO implement the following tests. it('[5] No sponsorship, no beneficiary, no callback, no BoT, no replication', async function () {}); describe('Integration tests array of worker', function () { From 5b3145b5040b8bd734edfb44a175ad4365d855dd Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 14:53:41 +0100 Subject: [PATCH 06/18] implement test 5 --- test/000_fullchain.test.ts | 74 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 6511ed4a7..a9216fcd5 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -471,8 +471,78 @@ describe('Integration tests', function () { } }); - // TODO implement the following tests. - it('[5] No sponsorship, no beneficiary, no callback, no BoT, no replication', async function () {}); + it('[5] No sponsorship, no beneficiary, no callback, no BoT, no replication', async function () { + const volume = 1; + // Create deal. + const orders = buildOrders({ + assets: ordersAssets, + prices: ordersPrices, + requester: requester.address, + tag: standardDealTag, + volume, + trust: 1, + }); + const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndMatchOrders( + ...orders.toArray(), + ); + const taskPrice = appPrice + datasetPrice + workerpoolPrice; + const schedulerStakePerTask = schedulerStakePerDeal / volume; + const workerRewardPerTask = await iexecWrapper.computeWorkerRewardPerTask( + dealId, + PocoMode.CLASSIC, + ); + const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; + // Save frozens + const accounts = [requester, scheduler, appProvider, datasetProvider, worker1]; + const accountsInitialFrozens = await getInitialFrozens(accounts); + const taskIndex = 0; + const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); + const { workerStakePerTask } = await iexecWrapper.contributeToTask( + dealId, + taskIndex, + resultDigest, + worker1, + ); + await iexecPoco + .connect(worker1) + .reveal(taskId, resultDigest) + .then((tx) => tx.wait()); + const finalizeTx = await iexecPoco.connect(scheduler).finalize(taskId, results, '0x'); + expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); + // Multiply amount by the number of finalized tasks to correctly compute + // stake and reward amounts. + const completedTasks = taskIndex + 1; + // Verify token balance changes + const expectedProxyBalanceChange = -( + taskPrice * completedTasks + + schedulerStakePerTask * completedTasks + ); + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [proxyAddress, requester, scheduler, appProvider, datasetProvider, worker1], + [ + expectedProxyBalanceChange, // Proxy + -taskPrice * completedTasks, // Requester + schedulerStakePerTask + schedulerRewardPerTask, // Scheduler + appPrice, // AppProvider + datasetPrice, // DatasetProvider + workerStakePerTask + workerRewardPerTask, // Worker + ], + ); + // Calculate expected frozen changes + const expectedFrozenChanges = [ + 0, // Proxy + -taskPrice * completedTasks, // Requester + -schedulerStakePerTask * completedTasks, // Scheduler + 0, // AppProvider + 0, // DatasetProvider + 0, // Worker + ]; + await changesInFrozen({ + accountsInitialFrozens, + frozenChanges: expectedFrozenChanges, + }); + }); describe('Integration tests array of worker', function () { for (let workerNumber = 1; workerNumber < 6; workerNumber++) { From a829e5f2f62c089933216e96ee01dc21f87669e1 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 14:55:30 +0100 Subject: [PATCH 07/18] remove beneficary from test 6 and 7 --- test/000_fullchain.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index a9216fcd5..37d7d23b9 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -557,7 +557,6 @@ describe('Integration tests', function () { prices: ordersPrices, requester: requester.address, tag: standardDealTag, - beneficiary: beneficiary.address, volume, trust: workerNumber ** 2 - 1, }); @@ -654,7 +653,6 @@ describe('Integration tests', function () { prices: ordersPrices, requester: requester.address, tag: standardDealTag, - beneficiary: beneficiary.address, volume, trust: winningWorkers.length, }); From 3eff772f7fdcfe604c73fff9dcd6e93deda3e9eb Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 15:35:45 +0100 Subject: [PATCH 08/18] update test 3, 4, 5 to use teeDealTag and create helper function --- test/000_fullchain.test.ts | 16 ++++----- test/utils/IexecWrapper.ts | 67 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 11 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 37d7d23b9..bdb645a30 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -24,8 +24,8 @@ import { IexecWrapper } from './utils/IexecWrapper'; // | [3] | ✔ | x | ✔ | ✔ | ✔ | Standard,TEE | // | [4] | x | x | ✔ | ✔ | ✔ | Standard,TEE | // | [5] | x | x | x | x | x | Standard,TEE | -// | [6.x] | x | ✔ | x | x | x | Standard,TEE, X good workers | -// | [7] | x | ✔ | x | x | x | Standard,TEE, 4 good workers 1 bad worker | +// | [6.x] | x | ✔ | x | x | x | Standard, X good workers | +// | [7] | x | ✔ | x | x | x | Standard, 4 good workers 1 bad worker | // +---------+-------------+-------------+-------------+----------+-----+---------------------------------------------+ const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000'; @@ -320,7 +320,7 @@ describe('Integration tests', function () { assets: ordersAssets, prices: ordersPrices, requester: requester.address, - tag: standardDealTag, + tag: teeDealTag, beneficiary: beneficiary.address, callback: callbackAddress, volume, @@ -341,7 +341,7 @@ describe('Integration tests', function () { // Finalize each task and check balance changes. for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const { workerStakePerTask } = await iexecWrapper.contributeToTask( + const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask( dealId, taskIndex, callbackResultDigest, @@ -399,7 +399,7 @@ describe('Integration tests', function () { assets: ordersAssets, prices: ordersPrices, requester: requester.address, - tag: standardDealTag, + tag: teeDealTag, beneficiary: beneficiary.address, callback: callbackAddress, volume, @@ -421,7 +421,7 @@ describe('Integration tests', function () { // Finalize each task and check balance changes. for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const { workerStakePerTask } = await iexecWrapper.contributeToTask( + const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask( dealId, taskIndex, callbackResultDigest, @@ -478,7 +478,7 @@ describe('Integration tests', function () { assets: ordersAssets, prices: ordersPrices, requester: requester.address, - tag: standardDealTag, + tag: teeDealTag, volume, trust: 1, }); @@ -497,7 +497,7 @@ describe('Integration tests', function () { const accountsInitialFrozens = await getInitialFrozens(accounts); const taskIndex = 0; const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const { workerStakePerTask } = await iexecWrapper.contributeToTask( + const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask( dealId, taskIndex, resultDigest, diff --git a/test/utils/IexecWrapper.ts b/test/utils/IexecWrapper.ts index 1db509b00..221f3181b 100644 --- a/test/utils/IexecWrapper.ts +++ b/test/utils/IexecWrapper.ts @@ -35,6 +35,7 @@ import { IexecAccounts, PocoMode, buildAndSignContributionAuthorizationMessage, + buildAndSignPocoClassicEnclaveMessage, buildResultHashAndResultSeal, getDealId, getTaskId, @@ -345,7 +346,7 @@ export class IexecWrapper { /** * Helper function to contribute to a task. The contributor's stake is * automatically deposited before contributing. - * Note: no enclave address is used. + * Note: no enclave is used. * @param contributor Signer to sign the contribution * @param dealId id of the deal * @param taskIndex index of the task. @@ -358,8 +359,60 @@ export class IexecWrapper { resultDigest: string, contributor: SignerWithAddress, ) { - const enclaveAddress = AddressZero; - const enclaveSignature = '0x'; + const { taskId, workerStakePerTask } = await this._contributeToTask( + dealId, + taskIndex, + resultDigest, + contributor, + false, // No enclave used + ); + return { taskId, workerStakePerTask }; + } + + /** + * Helper function to contribute to a task using a secure enclave. The contributor's stake is + * automatically deposited before contributing. + * This function is used for enclave-based contributions (involving a secure enclave address). + * @param contributor Signer to sign the contribution + * @param dealId id of the deal + * @param taskIndex index of the task. + * @param resultDigest hash of the result + * @returns id of the task + */ + async contributeTeeToTask( + dealId: string, + taskIndex: number, + resultDigest: string, + contributor: SignerWithAddress, + ) { + const { taskId, workerStakePerTask } = await this._contributeToTask( + dealId, + taskIndex, + resultDigest, + contributor, + true, + ); + return { taskId, workerStakePerTask }; + } + + /** + * Internal helper function to handle task contributions with optional enclave support. + * Automatically deposits the contributor's stake before contributing and handles + * enclave-related signing and validation if required. + * @param contributor Signer to sign the contribution + * @param dealId id of the deal + * @param taskIndex index of the task. + * @param resultDigest hash of the result + * @param useEnclave - Boolean flag indicating whether an enclave is used for this contribution. + * @returns id of the task + */ + async _contributeToTask( + dealId: string, + taskIndex: number, + resultDigest: string, + contributor: SignerWithAddress, + useEnclave: Boolean, + ) { const taskId = getTaskId(dealId, taskIndex); const workerStakePerTask = await IexecAccessors__factory.connect( this.proxyAddress, @@ -372,6 +425,14 @@ export class IexecWrapper { resultDigest, contributor, ); + const enclaveAddress = useEnclave ? this.accounts.enclave.address : AddressZero; + const enclaveSignature = useEnclave + ? await buildAndSignPocoClassicEnclaveMessage( + resultHash, + resultSeal, + this.accounts.enclave, + ) + : '0x'; const schedulerSignature = await buildAndSignContributionAuthorizationMessage( contributor.address, taskId, From a11d593efaaab7bd1d80f9e163ef3337c368383f Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 15:38:57 +0100 Subject: [PATCH 09/18] remove workerNumber = 1 on test 6 array --- test/000_fullchain.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index bdb645a30..3902ce7c5 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -545,8 +545,8 @@ describe('Integration tests', function () { }); describe('Integration tests array of worker', function () { - for (let workerNumber = 1; workerNumber < 6; workerNumber++) { - it(`[6.${workerNumber}] No sponsorship, no beneficiary, no callback, no BoT, up to ${workerNumber} workers`, async function () { + for (let workerNumber = 2; workerNumber < 6; workerNumber++) { + it(`[6.${workerNumber - 1}] No sponsorship, no beneficiary, no callback, no BoT, up to ${workerNumber} workers`, async function () { const volume = 1; const disposableWorkers = [worker1, worker2, worker3, worker4, worker5]; const workers = disposableWorkers.slice(0, workerNumber); From 39e4f53ed62c62df1b5e7e736a19c9a871c3a6ec Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 25 Nov 2024 15:51:45 +0100 Subject: [PATCH 10/18] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7c4d0cd1..66a2eec7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - 000_fullchain.js (#156, #157) - 00X_fullchain-Xworkers.js (#158, #159) - 000_fullchain-5workers-1error.js (#160, #162) + - Clean ToDo (#163) - Remove `smock` from unit tests: - IexecEscrow.v8 (#154, #155) - IexecPocoDelegate (#149, #151) From aeeba74c359210e08fca73f8efe80cdf2d148475 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 11:14:11 +0100 Subject: [PATCH 11/18] set workerStakePerTask outside of the loop --- test/000_fullchain.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 3902ce7c5..c149aca5d 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -131,12 +131,12 @@ describe('Integration tests', function () { const accounts = [sponsor, requester, scheduler, appProvider, datasetProvider, ...workers]; const accountsInitialFrozens = await getInitialFrozens(accounts); + const workerStakePerTask = await iexecPoco + .viewDeal(dealId) + .then((deal) => deal.workerStake.toNumber()); // Finalize each task and check balance changes. for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const workerStakePerTask = await iexecPoco - .viewDeal(dealId) - .then((deal) => deal.workerStake.toNumber()); for (const worker of workers) { await iexecWrapper.contributeToTask( dealId, From 039d5cead1674c2df85d04e328e6dfdaa511d08f Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 11:17:51 +0100 Subject: [PATCH 12/18] add await finalizeTx.wait(); --- test/000_fullchain.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index c149aca5d..1a26d6b79 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -155,6 +155,7 @@ describe('Integration tests', function () { const finalizeTx = await iexecPoco .connect(scheduler) .finalize(taskId, results, resultsCallback); + await finalizeTx.wait(); expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); // Multiply amount by the number of finalized tasks to correctly compute // stake and reward amounts. @@ -268,6 +269,7 @@ describe('Integration tests', function () { const finalizeTx = await iexecPoco .connect(scheduler) .finalize(taskId, results, resultsCallback); + await finalizeTx.wait(); expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); // Multiply amount by the number of finalized tasks to correctly compute // stake and reward amounts. @@ -354,6 +356,7 @@ describe('Integration tests', function () { const finalizeTx = await iexecPoco .connect(scheduler) .finalize(taskId, results, resultsCallback); + await finalizeTx.wait(); expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); // Multiply amount by the number of finalized tasks to correctly compute // stake and reward amounts. @@ -434,6 +437,7 @@ describe('Integration tests', function () { const finalizeTx = await iexecPoco .connect(scheduler) .finalize(taskId, results, resultsCallback); + await finalizeTx.wait(); expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); // Multiply amount by the number of finalized tasks to correctly compute // stake and reward amounts. @@ -508,6 +512,7 @@ describe('Integration tests', function () { .reveal(taskId, resultDigest) .then((tx) => tx.wait()); const finalizeTx = await iexecPoco.connect(scheduler).finalize(taskId, results, '0x'); + await finalizeTx.wait(); expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); // Multiply amount by the number of finalized tasks to correctly compute // stake and reward amounts. @@ -592,6 +597,7 @@ describe('Integration tests', function () { const finalizeTx = await iexecPoco .connect(scheduler) .finalize(taskId, results, '0x'); + await finalizeTx.wait(); expect(finalizeTx).to.changeTokenBalances( iexecPoco, [proxyAddress, requester, scheduler, appProvider, datasetProvider], @@ -696,6 +702,7 @@ describe('Integration tests', function () { .then((tx) => tx.wait()); } const finalizeTx = await iexecPoco.connect(scheduler).finalize(taskId, results, '0x'); + await finalizeTx.wait(); expect(finalizeTx).to.changeTokenBalances( iexecPoco, [proxyAddress, requester, scheduler, appProvider, datasetProvider], From 7aa37cbcf474ea39b7ff2b33bdee8064736fef5c Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 11:19:13 +0100 Subject: [PATCH 13/18] remove comment block --- test/000_fullchain.test.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 1a26d6b79..c340359ff 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -160,20 +160,6 @@ describe('Integration tests', function () { // Multiply amount by the number of finalized tasks to correctly compute // stake and reward amounts. const completedTasks = taskIndex + 1; - // For each task, balances change such as: - // - Sponsor - // - frozen: frozenBefore - taskPrice - // - Requester: no changes - // - Scheduler - // - balance: balanceBefore + taskStake + taskReward - // - frozen: frozenBefore - taskStake - // - App - // - balance: balance before + appPrice - // - Dataset - // - balance: balance before + datasetPrice - // - Worker: - // - balance: balance before + taskStake + taskReward - // - frozen: frozen before - taskStake // Verify token balance changes const expectedProxyBalanceChange = -( taskPrice * completedTasks + From 387e4a4ccf72da1c1be89d9bad674f35ce8bd139 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 11:25:15 +0100 Subject: [PATCH 14/18] push workers frozen balance in the array directly --- test/000_fullchain.test.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index c340359ff..27e6415b4 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -191,11 +191,9 @@ describe('Integration tests', function () { 0, // Requester -schedulerStakePerTask * completedTasks, // Scheduler 0, // AppProvider - 0, // DatasetProvider + 0, // DatasetProvider, + ...workers.map(() => 0), // Add 0 for each worker ]; - for (let i = 0; i < workers.length; i++) { - expectedFrozenChanges.push(0); - } await changesInFrozen({ accountsInitialFrozens, frozenChanges: expectedFrozenChanges, @@ -290,10 +288,8 @@ describe('Integration tests', function () { -schedulerStakePerTask * completedTasks, // Scheduler 0, // AppProvider 0, // DatasetProvider + ...workers.map(() => 0), // Add 0 for each worker ]; - for (let i = 0; i < workers.length; i++) { - expectedFrozenChanges.push(0); - } await changesInFrozen({ accountsInitialFrozens, frozenChanges: expectedFrozenChanges, @@ -605,10 +601,14 @@ describe('Integration tests', function () { expect((await iexecPoco.viewTask(taskId)).status).to.equal( TaskStatusEnum.COMPLETED, ); - const expectedFrozenChanges = [0, -taskPrice, -schedulerStakePerTask, 0, 0]; - for (let i = 0; i < workerNumber; i++) { - expectedFrozenChanges.push(0); - } + const expectedFrozenChanges = [ + 0, + -taskPrice, + -schedulerStakePerTask, + 0, + 0, + ...workers.map(() => 0), + ]; await changesInFrozen({ accountsInitialFrozens, frozenChanges: expectedFrozenChanges, @@ -715,10 +715,14 @@ describe('Integration tests', function () { // verify task status expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); // checks on frozen balance changes - const expectedFrozenChanges = [0, -taskPrice, -schedulerStakePerTask, 0, 0]; - for (let i = 0; i < workersAvailable.length; i++) { - expectedFrozenChanges.push(0); - } + const expectedFrozenChanges = [ + 0, + -taskPrice, + -schedulerStakePerTask, + 0, + 0, + ...workersAvailable.map(() => 0), + ]; await changesInFrozen({ accountsInitialFrozens, frozenChanges: expectedFrozenChanges, From 1cfd890aaa09ae6e75fc9418fbf1424ab02f360d Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 11:40:25 +0100 Subject: [PATCH 15/18] check all in one changeTokenBalances with workers --- test/000_fullchain.test.ts | 50 ++++++++++++++------------------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 27e6415b4..27f239c49 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -165,9 +165,11 @@ describe('Integration tests', function () { taskPrice * completedTasks + schedulerStakePerTask * completedTasks ); + const expectedWorkerBalanceChange = + workerStakePerTask + workerRewardPerTask / workers.length; expect(finalizeTx).to.changeTokenBalances( iexecPoco, - [proxyAddress, sponsor, requester, scheduler, appProvider, datasetProvider], + [proxyAddress, ...accounts], [ expectedProxyBalanceChange, // Proxy -taskPrice * completedTasks, // Sponsor @@ -175,15 +177,9 @@ describe('Integration tests', function () { schedulerStakePerTask + schedulerRewardPerTask, // Scheduler appPrice, // AppProvider datasetPrice, // DatasetProvider + ...workers.map(() => expectedWorkerBalanceChange), // Workers ], ); - for (const worker of workers) { - expect(finalizeTx).to.changeTokenBalances( - iexecPoco, - [worker], - [workerStakePerTask + workerRewardPerTask / workers.length], - ); - } // Calculate expected frozen changes const expectedFrozenChanges = [ 0, // Proxy @@ -263,24 +259,20 @@ describe('Integration tests', function () { taskPrice * completedTasks + schedulerStakePerTask * completedTasks ); + const expectedWorkerBalanceChange = + workerStakePerTask + workerRewardPerTask / workers.length; expect(finalizeTx).to.changeTokenBalances( iexecPoco, - [proxyAddress, requester, scheduler, appProvider, datasetProvider], + [proxyAddress, ...accounts], [ expectedProxyBalanceChange, // Proxy -taskPrice * completedTasks, // Requester schedulerStakePerTask + schedulerRewardPerTask, // Scheduler appPrice, // AppProvider datasetPrice, // DatasetProvider + ...workers.map(() => expectedWorkerBalanceChange), // Workers ], ); - for (const worker of workers) { - expect(finalizeTx).to.changeTokenBalances( - iexecPoco, - [worker], - [workerStakePerTask + workerRewardPerTask / workers.length], - ); - } // Calculate expected frozen changes const expectedFrozenChanges = [ 0, // Proxy @@ -563,7 +555,7 @@ describe('Integration tests', function () { } const taskId = await iexecWrapper.initializeTask(dealId, 0); // Finalize each task and check balance changes. - const workerStake = await iexecPoco + const workerStakePerTask = await iexecPoco .viewDeal(dealId) .then((deal) => deal.workerStake.toNumber()); @@ -580,24 +572,20 @@ describe('Integration tests', function () { .connect(scheduler) .finalize(taskId, results, '0x'); await finalizeTx.wait(); + const expectedWorkerBalanceChange = + workerStakePerTask + workerRewardPerTask / workerNumber; expect(finalizeTx).to.changeTokenBalances( iexecPoco, - [proxyAddress, requester, scheduler, appProvider, datasetProvider], + [proxyAddress, ...accounts], [ -(dealPrice + schedulerStakePerDeal), 0, schedulerStakePerTask + schedulerRewardPerTask, appPrice, datasetPrice, + ...workers.map(() => expectedWorkerBalanceChange), // Workers ], ); - for (let i = 0; i < workerNumber; i++) { - expect(finalizeTx).to.changeTokenBalances( - iexecPoco, - [workers[i]], - [workerStake + workerRewardPerTask / workerNumber], - ); - } expect((await iexecPoco.viewTask(taskId)).status).to.equal( TaskStatusEnum.COMPLETED, ); @@ -689,27 +677,25 @@ describe('Integration tests', function () { } const finalizeTx = await iexecPoco.connect(scheduler).finalize(taskId, results, '0x'); await finalizeTx.wait(); + const expectedWinningWorkerBalanceChange = + workerStake + workerRewardPerTask / winningWorkers.length; expect(finalizeTx).to.changeTokenBalances( iexecPoco, - [proxyAddress, requester, scheduler, appProvider, datasetProvider], + [proxyAddress, ...accounts], [ -(dealPrice + schedulerStakePerDeal), 0, schedulerStakePerTask + schedulerRewardPerTask, appPrice, datasetPrice, + 0, // losing worker + ...winningWorkers.map(() => expectedWinningWorkerBalanceChange), // winning workers ], ); // checks on losing worker - expect(finalizeTx).to.changeTokenBalances(iexecPoco, [losingWorker], [0]); expect(await iexecPoco.viewScore(losingWorker.address)).to.be.equal(0); // checks on winning workers for (const winningWorker of winningWorkers) { - expect(finalizeTx).to.changeTokenBalances( - iexecPoco, - [winningWorker.address], - [workerStake + workerRewardPerTask / winningWorkers.length], - ); expect(await iexecPoco.viewScore(winningWorker.address)).to.be.equal(1); } // verify task status From 3079c74520a2780f7b742beab7250ac009b0cf54 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 11:44:45 +0100 Subject: [PATCH 16/18] change checkFrozenChanges name and argument names --- test/000_fullchain.test.ts | 49 +++++++++++--------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 27f239c49..8bcab815c 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -190,10 +190,7 @@ describe('Integration tests', function () { 0, // DatasetProvider, ...workers.map(() => 0), // Add 0 for each worker ]; - await changesInFrozen({ - accountsInitialFrozens, - frozenChanges: expectedFrozenChanges, - }); + await checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); } }); @@ -282,10 +279,7 @@ describe('Integration tests', function () { 0, // DatasetProvider ...workers.map(() => 0), // Add 0 for each worker ]; - await changesInFrozen({ - accountsInitialFrozens, - frozenChanges: expectedFrozenChanges, - }); + await checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); } }); @@ -362,10 +356,7 @@ describe('Integration tests', function () { 0, // DatasetProvider 0, // Worker ]; - await changesInFrozen({ - accountsInitialFrozens, - frozenChanges: expectedFrozenChanges, - }); + await checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); } }); @@ -442,10 +433,7 @@ describe('Integration tests', function () { 0, // DatasetProvider 0, // Worker ]; - await changesInFrozen({ - accountsInitialFrozens, - frozenChanges: expectedFrozenChanges, - }); + await checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); } }); @@ -517,10 +505,7 @@ describe('Integration tests', function () { 0, // DatasetProvider 0, // Worker ]; - await changesInFrozen({ - accountsInitialFrozens, - frozenChanges: expectedFrozenChanges, - }); + await checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); }); describe('Integration tests array of worker', function () { @@ -597,10 +582,7 @@ describe('Integration tests', function () { 0, ...workers.map(() => 0), ]; - await changesInFrozen({ - accountsInitialFrozens, - frozenChanges: expectedFrozenChanges, - }); + await checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); for (let i = 0; i < workerNumber; i++) { expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal( workerNumber == 1 ? 0 : 1, @@ -709,10 +691,7 @@ describe('Integration tests', function () { 0, ...workersAvailable.map(() => 0), ]; - await changesInFrozen({ - accountsInitialFrozens, - frozenChanges: expectedFrozenChanges, - }); + await checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); }); async function getInitialFrozens(accounts: SignerWithAddress[]) { @@ -732,14 +711,14 @@ describe('Integration tests', function () { } }); -async function changesInFrozen(args: { - accountsInitialFrozens: { address: string; frozen: number }[]; - frozenChanges: number[]; -}) { - for (let i = 0; i < args.accountsInitialFrozens.length; i++) { +async function checkFrozenChanges( + accountsInitialFrozens: { address: string; frozen: number }[], + expectedFrozenChanges: number[], +) { + for (let i = 0; i < accountsInitialFrozens.length; i++) { const message = `Failed with account at index ${i}`; - expect(await iexecPoco.frozenOf(args.accountsInitialFrozens[i].address)).to.equal( - args.accountsInitialFrozens[i].frozen + args.frozenChanges[i], + expect(await iexecPoco.frozenOf(accountsInitialFrozens[i].address)).to.equal( + accountsInitialFrozens[i].frozen + expectedFrozenChanges[i], message, ); } From dbe737b30967b86edee2c5a0392131db42e13385 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 15:20:27 +0100 Subject: [PATCH 17/18] move workerStake compute out of the loop --- test/000_fullchain.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 8bcab815c..8bd794d65 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -223,11 +223,11 @@ describe('Integration tests', function () { const accounts = [requester, scheduler, appProvider, datasetProvider, ...workers]; const accountsInitialFrozens = await getInitialFrozens(accounts); // Finalize each task and check balance changes. + const workerStakePerTask = await iexecPoco + .viewDeal(dealId) + .then((deal) => deal.workerStake.toNumber()); for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const workerStakePerTask = await iexecPoco - .viewDeal(dealId) - .then((deal) => deal.workerStake.toNumber()); for (const worker of workers) { await iexecWrapper.contributeToTask( dealId, From 5337b7835c46a72065a7ccb4eb41bf029981dab7 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 15:21:04 +0100 Subject: [PATCH 18/18] update function tee name --- test/000_fullchain.test.ts | 6 +++--- test/utils/IexecWrapper.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 8bd794d65..ed04223f5 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -311,7 +311,7 @@ describe('Integration tests', function () { // Finalize each task and check balance changes. for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask( + const { workerStakePerTask } = await iexecWrapper.contributeToTeeTask( dealId, taskIndex, callbackResultDigest, @@ -389,7 +389,7 @@ describe('Integration tests', function () { // Finalize each task and check balance changes. for (let taskIndex = 0; taskIndex < volume; taskIndex++) { const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask( + const { workerStakePerTask } = await iexecWrapper.contributeToTeeTask( dealId, taskIndex, callbackResultDigest, @@ -463,7 +463,7 @@ describe('Integration tests', function () { const accountsInitialFrozens = await getInitialFrozens(accounts); const taskIndex = 0; const taskId = await iexecWrapper.initializeTask(dealId, taskIndex); - const { workerStakePerTask } = await iexecWrapper.contributeTeeToTask( + const { workerStakePerTask } = await iexecWrapper.contributeToTeeTask( dealId, taskIndex, resultDigest, diff --git a/test/utils/IexecWrapper.ts b/test/utils/IexecWrapper.ts index 221f3181b..c9baede00 100644 --- a/test/utils/IexecWrapper.ts +++ b/test/utils/IexecWrapper.ts @@ -379,7 +379,7 @@ export class IexecWrapper { * @param resultDigest hash of the result * @returns id of the task */ - async contributeTeeToTask( + async contributeToTeeTask( dealId: string, taskIndex: number, resultDigest: string,