From ef526905c4d2399c47c90d69c479b25b738d7f8f Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 14 Nov 2024 11:26:08 +0100 Subject: [PATCH 1/9] prepare work on migrating --- test/000_fullchain.test.ts | 237 +++++++++++++++++- ...kers.js => 001_fullchain-1workers.js.skip} | 0 ...kers.js => 002_fullchain-2workers.js.skip} | 0 ...kers.js => 003_fullchain-3workers.js.skip} | 0 ...kers.js => 004_fullchain-4workers.js.skip} | 0 ... => 100_fullchain-5workers-1error.js.skip} | 0 6 files changed, 227 insertions(+), 10 deletions(-) rename test/{001_fullchain-1workers.js => 001_fullchain-1workers.js.skip} (100%) rename test/{002_fullchain-2workers.js => 002_fullchain-2workers.js.skip} (100%) rename test/{003_fullchain-3workers.js => 003_fullchain-3workers.js.skip} (100%) rename test/{004_fullchain-4workers.js => 004_fullchain-4workers.js.skip} (100%) rename test/{100_fullchain-5workers-1error.js => 100_fullchain-5workers-1error.js.skip} (100%) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 419f444d..386a0378 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -24,6 +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 | Standard,TEE X goods | +// | [7] | x | ✔ | x | x | x | Standard,TEE goods Y 1 bad | // +---------+-------------+-------------+----------+-----+-------------+----------------+ const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000'; @@ -48,6 +50,10 @@ let [ scheduler, anyone, worker1, + worker2, + worker3, + worker4, + worker5, ]: SignerWithAddress[] = []; let ordersActors: OrdersActors; let ordersAssets: OrdersAssets; @@ -72,6 +78,10 @@ describe('Integration tests', function () { scheduler, anyone, worker1, + worker2, + worker3, + worker4, + worker5, } = accounts); iexecWrapper = new IexecWrapper(proxyAddress, accounts); ({ appAddress, datasetAddress, workerpoolAddress } = await iexecWrapper.createAssets()); @@ -166,22 +176,20 @@ describe('Integration tests', function () { // - frozen: frozen before - taskStake await checkBalancesAndFrozens({ proxyBalance: - dealPrice + - schedulerStakePerDeal - - (taskPrice + schedulerStakePerTask) * completedTasks, + dealPrice + schedulerStakePerDeal - (taskPrice + schedulerStakePerTask), accounts: [ - { signer: sponsor, balance: 0, frozen: dealPrice - taskPrice * completedTasks }, + { signer: sponsor, balance: 0, frozen: dealPrice - taskPrice }, { signer: requester, balance: 0, frozen: 0 }, { signer: scheduler, - balance: (schedulerStakePerTask + schedulerRewardPerTask) * completedTasks, - frozen: schedulerStakePerDeal - schedulerStakePerTask * completedTasks, + balance: schedulerStakePerTask + schedulerRewardPerTask, + frozen: schedulerStakePerDeal - schedulerStakePerTask, }, - { signer: appProvider, balance: appPrice * completedTasks, frozen: 0 }, - { signer: datasetProvider, balance: datasetPrice * completedTasks, frozen: 0 }, + { signer: appProvider, balance: appPrice, frozen: 0 }, + { signer: datasetProvider, balance: datasetPrice, frozen: 0 }, { signer: worker1, - balance: (workerStakePerTask + workerRewardPerTask) * completedTasks, + balance: workerStakePerTask + workerRewardPerTask, frozen: 0, }, ], @@ -191,19 +199,228 @@ describe('Integration tests', function () { // TODO implement the following tests. - it('[2] No sponsorship, beneficiary, callback, BoT, replication', async function () {}); + it('[2] No sponsorship, beneficiary, callback, BoT, 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, // TODO use 5 workers. + }); + 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; + // Check initial balances. + // TODO save initial balances and use them in for loop for comparison. + await checkBalancesAndFrozens({ + proxyBalance: dealPrice + schedulerStakePerDeal, + accounts: [ + { signer: requester, balance: 0, frozen: dealPrice }, + { signer: scheduler, balance: 0, frozen: schedulerStakePerDeal }, + { signer: appProvider, balance: 0, frozen: 0 }, + { signer: datasetProvider, balance: 0, frozen: 0 }, + { signer: worker1, balance: 0, frozen: 0 }, + ], + }); + // 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()); + await iexecPoco + .connect(scheduler) + .finalize(taskId, results, resultsCallback) + .then((tx) => tx.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. + const completedTasks = taskIndex + 1; + // For each task, balances change such as: + // - Requester + // - frozen: frozenBefore - taskPrice + // - 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 + await checkBalancesAndFrozens({ + proxyBalance: + dealPrice + schedulerStakePerDeal - (taskPrice + schedulerStakePerTask), + accounts: [ + { signer: requester, balance: 0, frozen: dealPrice - taskPrice }, + { + signer: scheduler, + balance: schedulerStakePerTask + schedulerRewardPerTask, + frozen: schedulerStakePerDeal - schedulerStakePerTask, + }, + { signer: appProvider, balance: appPrice, frozen: 0 }, + { signer: datasetProvider, balance: datasetPrice, frozen: 0 }, + { + signer: worker1, + balance: workerStakePerTask + workerRewardPerTask, + frozen: 0, + }, + ], + }); + } + }); it('[3] Sponsorship, beneficiary, callback, BoT, no replication', async function () {}); 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 () {}); + + describe.only('Integration tests array of worker', function () { + for (let workerNumber = 1; workerNumber < 5; workerNumber++) { + it(`[6.${workerNumber}] No sponsorship, no beneficiary, no callback, no BoT, up to ${workerNumber} workers`, async function () { + const volume = 1; + const disposableWokers = [worker1, worker2, worker3, worker4, worker5]; + let workers = []; + for (let i = 0; i < workerNumber; i++) { + workers.push(disposableWokers[i]); + } + // Create deal. + const orders = buildOrders({ + assets: ordersAssets, + prices: ordersPrices, + requester: requester.address, + tag: standardDealTag, + beneficiary: beneficiary.address, + callback: callbackAddress, + volume, + trust: workerNumber, + }); + 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; + // Check initial balances. + // TODO save initial balances and use them in for loop for comparison. + let accounts = [ + { signer: requester, balance: 0, frozen: dealPrice }, + { signer: scheduler, balance: 0, frozen: schedulerStakePerDeal }, + { signer: appProvider, balance: 0, frozen: 0 }, + { signer: datasetProvider, balance: 0, frozen: 0 }, + ]; + for (let i = 0; i < workerNumber; i++) { + accounts.push({ signer: workers[i], balance: 0, frozen: 0 }); + } + await checkBalancesAndFrozens({ + proxyBalance: dealPrice + schedulerStakePerDeal, + accounts, + }); + const taskId = await iexecWrapper.initializeTask(dealId, 0); + // Finalize each task and check balance changes. + let workerStake: number = 0; + for (let i = 0; i < workerNumber; i++) { + console.log('worker ' + i + ' is contributing'); + const { workerStakePerTask } = await iexecWrapper.contributeToTask( + dealId, + 0, + callbackResultDigest, + workers[i], + ); + await iexecPoco + .connect(workers[i]) + .reveal(taskId, callbackResultDigest) + .then((tx) => tx.wait()); + workerStake = workerStakePerTask; + } + await iexecPoco + .connect(scheduler) + .finalize(taskId, results, resultsCallback) + .then((tx) => tx.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. + + // For each task, balances change such as: + // - Requester + // - frozen: frozenBefore - taskPrice + // - 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 + accounts = [ + { signer: requester, balance: 0, frozen: dealPrice - taskPrice }, + { + signer: scheduler, + balance: schedulerStakePerTask + schedulerRewardPerTask, + frozen: schedulerStakePerDeal - schedulerStakePerTask, + }, + { signer: appProvider, balance: appPrice, frozen: 0 }, + { signer: datasetProvider, balance: datasetPrice, frozen: 0 }, + ]; + for (let i = 0; i < workerNumber; i++) { + accounts.push({ + signer: disposableWokers[i], + balance: workerStake + workerRewardPerTask, + frozen: 0, + }); + } + await checkBalancesAndFrozens({ + proxyBalance: 0, + accounts, + }); + }); + } + }); + + it('[6] No sponsorship, no beneficiary, no callback, no BoT, up to 5 workers', async function () { + const volume = 1; + let workers = []; + const disposableWokers = [worker1, worker2, worker3, worker4, worker5]; + + for (let workerNumber = 1; workerNumber < 3; workerNumber++) {} + }); + + it('[7] No sponsorship, no beneficiary, no callback, no BoT, up to 5 workers with 1 bad actor', async function () {}); }); async function checkBalancesAndFrozens(args: { proxyBalance: number; accounts: { signer: SignerWithAddress; balance: number; frozen: number }[]; }) { + console.log('Checking balances... => proxy first'); 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)}`; diff --git a/test/001_fullchain-1workers.js b/test/001_fullchain-1workers.js.skip similarity index 100% rename from test/001_fullchain-1workers.js rename to test/001_fullchain-1workers.js.skip diff --git a/test/002_fullchain-2workers.js b/test/002_fullchain-2workers.js.skip similarity index 100% rename from test/002_fullchain-2workers.js rename to test/002_fullchain-2workers.js.skip diff --git a/test/003_fullchain-3workers.js b/test/003_fullchain-3workers.js.skip similarity index 100% rename from test/003_fullchain-3workers.js rename to test/003_fullchain-3workers.js.skip diff --git a/test/004_fullchain-4workers.js b/test/004_fullchain-4workers.js.skip similarity index 100% rename from test/004_fullchain-4workers.js rename to test/004_fullchain-4workers.js.skip diff --git a/test/100_fullchain-5workers-1error.js b/test/100_fullchain-5workers-1error.js.skip similarity index 100% rename from test/100_fullchain-5workers-1error.js rename to test/100_fullchain-5workers-1error.js.skip From 93a3291c8849a7a7ad4a87b673afc5909f9d9024 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 15 Nov 2024 14:13:32 +0100 Subject: [PATCH 2/9] only work with array of good workers --- test/000_fullchain.test.ts | 66 +++++++------------ ....skip => 100_fullchain-5workers-1error.js} | 0 2 files changed, 22 insertions(+), 44 deletions(-) rename test/{100_fullchain-5workers-1error.js.skip => 100_fullchain-5workers-1error.js} (100%) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 386a0378..83570947 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -34,7 +34,7 @@ const appPrice = 1000; const datasetPrice = 1_000_000; const workerpoolPrice = 1_000_000_000; const callbackAddress = ethers.Wallet.createRandom().address; -const { results } = buildUtf8ResultAndDigest('result'); +const { results, resultDigest } = buildUtf8ResultAndDigest('result'); const { resultsCallback, callbackResultDigest } = buildResultCallbackAndDigest(123); let proxyAddress: string; @@ -296,8 +296,8 @@ describe('Integration tests', function () { it('[5] No sponsorship, no beneficiary, no callback, no BoT, no replication', async function () {}); - describe.only('Integration tests array of worker', function () { - for (let workerNumber = 1; workerNumber < 5; workerNumber++) { + 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 () { const volume = 1; const disposableWokers = [worker1, worker2, worker3, worker4, worker5]; @@ -312,9 +312,8 @@ describe('Integration tests', function () { requester: requester.address, tag: standardDealTag, beneficiary: beneficiary.address, - callback: callbackAddress, volume, - trust: workerNumber, + trust: workerNumber ** 2 - 1, }); const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndMatchOrders(...orders.toArray()); @@ -340,46 +339,31 @@ describe('Integration tests', function () { proxyBalance: dealPrice + schedulerStakePerDeal, accounts, }); + for (let i = 0; i < workerNumber; i++) { + expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0); + } const taskId = await iexecWrapper.initializeTask(dealId, 0); // Finalize each task and check balance changes. - let workerStake: number = 0; + const workerStake = await iexecPoco + .viewDeal(dealId) + .then((deal) => deal.workerStake.toNumber()); + + for (let i = 0; i < workerNumber; i++) { + await iexecWrapper.contributeToTask(dealId, 0, resultDigest, workers[i]); + } for (let i = 0; i < workerNumber; i++) { - console.log('worker ' + i + ' is contributing'); - const { workerStakePerTask } = await iexecWrapper.contributeToTask( - dealId, - 0, - callbackResultDigest, - workers[i], - ); await iexecPoco .connect(workers[i]) - .reveal(taskId, callbackResultDigest) + .reveal(taskId, resultDigest) .then((tx) => tx.wait()); - workerStake = workerStakePerTask; } await iexecPoco .connect(scheduler) - .finalize(taskId, results, resultsCallback) + .finalize(taskId, results, '0x') .then((tx) => tx.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. - - // For each task, balances change such as: - // - Requester - // - frozen: frozenBefore - taskPrice - // - 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 accounts = [ { signer: requester, balance: 0, frozen: dealPrice - taskPrice }, { @@ -393,7 +377,7 @@ describe('Integration tests', function () { for (let i = 0; i < workerNumber; i++) { accounts.push({ signer: disposableWokers[i], - balance: workerStake + workerRewardPerTask, + balance: workerStake + workerRewardPerTask / workerNumber, frozen: 0, }); } @@ -401,26 +385,20 @@ describe('Integration tests', function () { proxyBalance: 0, accounts, }); + for (let i = 0; i < workerNumber; i++) { + if (workerNumber == 1) { + expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0); + } + } }); } }); - - it('[6] No sponsorship, no beneficiary, no callback, no BoT, up to 5 workers', async function () { - const volume = 1; - let workers = []; - const disposableWokers = [worker1, worker2, worker3, worker4, worker5]; - - for (let workerNumber = 1; workerNumber < 3; workerNumber++) {} - }); - - it('[7] No sponsorship, no beneficiary, no callback, no BoT, up to 5 workers with 1 bad actor', async function () {}); }); async function checkBalancesAndFrozens(args: { proxyBalance: number; accounts: { signer: SignerWithAddress; balance: number; frozen: number }[]; }) { - console.log('Checking balances... => proxy first'); 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)}`; diff --git a/test/100_fullchain-5workers-1error.js.skip b/test/100_fullchain-5workers-1error.js similarity index 100% rename from test/100_fullchain-5workers-1error.js.skip rename to test/100_fullchain-5workers-1error.js From 30483115bdd6aa111d3f7e77ffb7096c739f07f3 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 15 Nov 2024 14:33:57 +0100 Subject: [PATCH 3/9] update remove test 2 --- test/000_fullchain.test.ts | 118 ++++--------------------------------- 1 file changed, 13 insertions(+), 105 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 83570947..d27f697c 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -24,8 +24,6 @@ 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 | Standard,TEE X goods | -// | [7] | x | ✔ | x | x | x | Standard,TEE goods Y 1 bad | // +---------+-------------+-------------+----------+-----+-------------+----------------+ const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000'; @@ -176,20 +174,22 @@ describe('Integration tests', function () { // - frozen: frozen before - taskStake await checkBalancesAndFrozens({ proxyBalance: - dealPrice + schedulerStakePerDeal - (taskPrice + schedulerStakePerTask), + dealPrice + + schedulerStakePerDeal - + (taskPrice + schedulerStakePerTask) * completedTasks, accounts: [ - { signer: sponsor, balance: 0, frozen: dealPrice - taskPrice }, + { signer: sponsor, balance: 0, frozen: dealPrice - taskPrice * completedTasks }, { signer: requester, balance: 0, frozen: 0 }, { signer: scheduler, - balance: schedulerStakePerTask + schedulerRewardPerTask, - frozen: schedulerStakePerDeal - schedulerStakePerTask, + balance: (schedulerStakePerTask + schedulerRewardPerTask) * completedTasks, + frozen: schedulerStakePerDeal - schedulerStakePerTask * completedTasks, }, - { signer: appProvider, balance: appPrice, frozen: 0 }, - { signer: datasetProvider, balance: datasetPrice, frozen: 0 }, + { signer: appProvider, balance: appPrice * completedTasks, frozen: 0 }, + { signer: datasetProvider, balance: datasetPrice * completedTasks, frozen: 0 }, { signer: worker1, - balance: workerStakePerTask + workerRewardPerTask, + balance: (workerStakePerTask + workerRewardPerTask) * completedTasks, frozen: 0, }, ], @@ -199,96 +199,7 @@ 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 orders = buildOrders({ - assets: ordersAssets, - prices: ordersPrices, - requester: requester.address, - tag: standardDealTag, - beneficiary: beneficiary.address, - callback: callbackAddress, - volume, - trust: 1, // TODO use 5 workers. - }); - 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; - // Check initial balances. - // TODO save initial balances and use them in for loop for comparison. - await checkBalancesAndFrozens({ - proxyBalance: dealPrice + schedulerStakePerDeal, - accounts: [ - { signer: requester, balance: 0, frozen: dealPrice }, - { signer: scheduler, balance: 0, frozen: schedulerStakePerDeal }, - { signer: appProvider, balance: 0, frozen: 0 }, - { signer: datasetProvider, balance: 0, frozen: 0 }, - { signer: worker1, balance: 0, frozen: 0 }, - ], - }); - // 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()); - await iexecPoco - .connect(scheduler) - .finalize(taskId, results, resultsCallback) - .then((tx) => tx.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. - const completedTasks = taskIndex + 1; - // For each task, balances change such as: - // - Requester - // - frozen: frozenBefore - taskPrice - // - 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 - await checkBalancesAndFrozens({ - proxyBalance: - dealPrice + schedulerStakePerDeal - (taskPrice + schedulerStakePerTask), - accounts: [ - { signer: requester, balance: 0, frozen: dealPrice - taskPrice }, - { - signer: scheduler, - balance: schedulerStakePerTask + schedulerRewardPerTask, - frozen: schedulerStakePerDeal - schedulerStakePerTask, - }, - { signer: appProvider, balance: appPrice, frozen: 0 }, - { signer: datasetProvider, balance: datasetPrice, frozen: 0 }, - { - signer: worker1, - balance: workerStakePerTask + workerRewardPerTask, - frozen: 0, - }, - ], - }); - } - }); + it('[2] No sponsorship, beneficiary, callback, BoT, replication', async function () {}); it('[3] Sponsorship, beneficiary, callback, BoT, no replication', async function () {}); @@ -300,11 +211,8 @@ describe('Integration tests', 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 () { const volume = 1; - const disposableWokers = [worker1, worker2, worker3, worker4, worker5]; - let workers = []; - for (let i = 0; i < workerNumber; i++) { - workers.push(disposableWokers[i]); - } + const disposableWorkers = [worker1, worker2, worker3, worker4, worker5]; + const workers = disposableWorkers.slice(0, workerNumber); // Create deal. const orders = buildOrders({ assets: ordersAssets, @@ -376,7 +284,7 @@ describe('Integration tests', function () { ]; for (let i = 0; i < workerNumber; i++) { accounts.push({ - signer: disposableWokers[i], + signer: disposableWorkers[i], balance: workerStake + workerRewardPerTask / workerNumber, frozen: 0, }); From 043865321f08dbcd4d1c27a92cc5eababece51fd Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 15 Nov 2024 14:37:57 +0100 Subject: [PATCH 4/9] remove comment --- test/000_fullchain.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index d27f697c..7e5daa3a 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -233,7 +233,6 @@ describe('Integration tests', function () { ); const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; // Check initial balances. - // TODO save initial balances and use them in for loop for comparison. let accounts = [ { signer: requester, balance: 0, frozen: dealPrice }, { signer: scheduler, balance: 0, frozen: schedulerStakePerDeal }, From 41e00905964982df0fdbb6b918c563db8b05d6bd Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 15 Nov 2024 15:04:29 +0100 Subject: [PATCH 5/9] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6a04e95..ddafb7b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Migrate integration test files to Typescript & Hardhat: - 000_fullchain.js (#156, #157) + - 00X_fullchain-Xworkers.js (#158) - Remove `smock` from unit tests: - IexecEscrow.v8 (#154, #155) - IexecPocoDelegate (#149, #151) From 4fc32266ddff2c8bef4b84db87b8914b57a7d267 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 18 Nov 2024 14:23:14 +0100 Subject: [PATCH 6/9] save init balances and frozen to check the diff at the end --- test/000_fullchain.test.ts | 51 ++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 7e5daa3a..090ce231 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -233,18 +233,19 @@ describe('Integration tests', function () { ); const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; // Check initial balances. - let accounts = [ + let proxyInitBalance = dealPrice + schedulerStakePerDeal; + let accountsInitBalances = [ { signer: requester, balance: 0, frozen: dealPrice }, { signer: scheduler, balance: 0, frozen: schedulerStakePerDeal }, { signer: appProvider, balance: 0, frozen: 0 }, { signer: datasetProvider, balance: 0, frozen: 0 }, ]; for (let i = 0; i < workerNumber; i++) { - accounts.push({ signer: workers[i], balance: 0, frozen: 0 }); + accountsInitBalances.push({ signer: workers[i], balance: 0, frozen: 0 }); } await checkBalancesAndFrozens({ - proxyBalance: dealPrice + schedulerStakePerDeal, - accounts, + proxyBalance: proxyInitBalance, + accounts: accountsInitBalances, }); for (let i = 0; i < workerNumber; i++) { expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0); @@ -271,26 +272,44 @@ describe('Integration tests', function () { expect((await iexecPoco.viewTask(taskId)).status).to.equal( TaskStatusEnum.COMPLETED, ); - accounts = [ - { signer: requester, balance: 0, frozen: dealPrice - taskPrice }, + let proxyFinalBalance = proxyInitBalance - (dealPrice + schedulerStakePerDeal); + let accountsFinalBalances = [ + { + signer: requester, + balance: accountsInitBalances[0].balance, + frozen: accountsInitBalances[0].frozen - taskPrice, + }, { signer: scheduler, - balance: schedulerStakePerTask + schedulerRewardPerTask, - frozen: schedulerStakePerDeal - schedulerStakePerTask, + balance: + accountsInitBalances[1].balance + + (schedulerStakePerTask + schedulerRewardPerTask), + frozen: accountsInitBalances[1].frozen - schedulerStakePerTask, + }, + { + signer: appProvider, + balance: accountsInitBalances[2].balance + appPrice, + frozen: accountsInitBalances[2].frozen, + }, + { + signer: datasetProvider, + balance: accountsInitBalances[3].balance + datasetPrice, + frozen: accountsInitBalances[3].frozen, }, - { signer: appProvider, balance: appPrice, frozen: 0 }, - { signer: datasetProvider, balance: datasetPrice, frozen: 0 }, ]; for (let i = 0; i < workerNumber; i++) { - accounts.push({ - signer: disposableWorkers[i], - balance: workerStake + workerRewardPerTask / workerNumber, - frozen: 0, + accountsFinalBalances.push({ + signer: workers[i], + balance: + accountsInitBalances[4 + i].balance + + workerStake + + workerRewardPerTask / workerNumber, + frozen: accountsInitBalances[4 + i].frozen, }); } await checkBalancesAndFrozens({ - proxyBalance: 0, - accounts, + proxyBalance: proxyFinalBalance, + accounts: accountsFinalBalances, }); for (let i = 0; i < workerNumber; i++) { if (workerNumber == 1) { From 5c10d78b0c1ae1834497a985d31ceb7e5d3d753b Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Mon, 18 Nov 2024 16:00:21 +0100 Subject: [PATCH 7/9] create changesInBalancesAndFrozens function and apply it to test --- test/000_fullchain.test.ts | 88 ++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 090ce231..d2ecb2d0 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -213,6 +213,7 @@ describe('Integration tests', function () { const volume = 1; const disposableWorkers = [worker1, worker2, worker3, worker4, worker5]; const workers = disposableWorkers.slice(0, workerNumber); + const acounts = [requester, scheduler, appProvider, datasetProvider, ...workers]; // Create deal. const orders = buildOrders({ assets: ordersAssets, @@ -233,20 +234,19 @@ describe('Integration tests', function () { ); const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask; // Check initial balances. - let proxyInitBalance = dealPrice + schedulerStakePerDeal; let accountsInitBalances = [ - { signer: requester, balance: 0, frozen: dealPrice }, - { signer: scheduler, balance: 0, frozen: schedulerStakePerDeal }, - { signer: appProvider, balance: 0, frozen: 0 }, - { signer: datasetProvider, balance: 0, frozen: 0 }, + { + address: proxyAddress, + balance: (await iexecPoco.balanceOf(proxyAddress)).toNumber(), + frozen: (await iexecPoco.frozenOf(proxyAddress)).toNumber(), + }, ]; - for (let i = 0; i < workerNumber; i++) { - accountsInitBalances.push({ signer: workers[i], balance: 0, frozen: 0 }); + for (const account of acounts) { + let address = account.address; + let balance = (await iexecPoco.balanceOf(account.address)).toNumber(); + let frozen = (await iexecPoco.frozenOf(account.address)).toNumber(); + accountsInitBalances.push({ address, balance, frozen }); } - await checkBalancesAndFrozens({ - proxyBalance: proxyInitBalance, - accounts: accountsInitBalances, - }); for (let i = 0; i < workerNumber; i++) { expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0); } @@ -272,44 +272,22 @@ describe('Integration tests', function () { expect((await iexecPoco.viewTask(taskId)).status).to.equal( TaskStatusEnum.COMPLETED, ); - let proxyFinalBalance = proxyInitBalance - (dealPrice + schedulerStakePerDeal); - let accountsFinalBalances = [ - { - signer: requester, - balance: accountsInitBalances[0].balance, - frozen: accountsInitBalances[0].frozen - taskPrice, - }, - { - signer: scheduler, - balance: - accountsInitBalances[1].balance + - (schedulerStakePerTask + schedulerRewardPerTask), - frozen: accountsInitBalances[1].frozen - schedulerStakePerTask, - }, - { - signer: appProvider, - balance: accountsInitBalances[2].balance + appPrice, - frozen: accountsInitBalances[2].frozen, - }, - { - signer: datasetProvider, - balance: accountsInitBalances[3].balance + datasetPrice, - frozen: accountsInitBalances[3].frozen, - }, + const expectedBalanceChanges = [ + -(dealPrice + schedulerStakePerDeal), + 0, + schedulerStakePerTask + schedulerRewardPerTask, + appPrice, + datasetPrice, ]; + const expectedFrozenChanges = [0, -taskPrice, -schedulerStakePerTask, 0, 0]; for (let i = 0; i < workerNumber; i++) { - accountsFinalBalances.push({ - signer: workers[i], - balance: - accountsInitBalances[4 + i].balance + - workerStake + - workerRewardPerTask / workerNumber, - frozen: accountsInitBalances[4 + i].frozen, - }); + expectedBalanceChanges.push(workerStake + workerRewardPerTask / workerNumber); + expectedFrozenChanges.push(0); } - await checkBalancesAndFrozens({ - proxyBalance: proxyFinalBalance, - accounts: accountsFinalBalances, + await changesInBalancesAndFrozens({ + accountsInitBalances, + balanceChanges: expectedBalanceChanges, + frozenChanges: expectedFrozenChanges, }); for (let i = 0; i < workerNumber; i++) { if (workerNumber == 1) { @@ -335,3 +313,21 @@ async function checkBalancesAndFrozens(args: { expect(await iexecPoco.frozenOf(account.signer.address)).to.equal(account.frozen, message); } } + +async function changesInBalancesAndFrozens(args: { + accountsInitBalances: { address: string; balance: number; frozen: number }[]; + balanceChanges: number[]; + frozenChanges: number[]; +}) { + for (let i = 0; i < args.accountsInitBalances.length; i++) { + const message = `Failed with account at index ${i}`; + expect(await iexecPoco.balanceOf(args.accountsInitBalances[i].address)).to.equal( + args.accountsInitBalances[i].balance + args.balanceChanges[i], + message, + ); + expect(await iexecPoco.frozenOf(args.accountsInitBalances[i].address)).to.equal( + args.accountsInitBalances[i].frozen + args.frozenChanges[i], + message, + ); + } +} From b864645a3351f549730ddbbf2ebfe28fff389bac Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 19 Nov 2024 09:45:25 +0100 Subject: [PATCH 8/9] use changeTokenBalances and use other function frozen --- test/000_fullchain.test.ts | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index d2ecb2d0..c923c340 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -237,15 +237,13 @@ describe('Integration tests', function () { let accountsInitBalances = [ { address: proxyAddress, - balance: (await iexecPoco.balanceOf(proxyAddress)).toNumber(), frozen: (await iexecPoco.frozenOf(proxyAddress)).toNumber(), }, ]; for (const account of acounts) { let address = account.address; - let balance = (await iexecPoco.balanceOf(account.address)).toNumber(); let frozen = (await iexecPoco.frozenOf(account.address)).toNumber(); - accountsInitBalances.push({ address, balance, frozen }); + accountsInitBalances.push({ address, frozen }); } for (let i = 0; i < workerNumber; i++) { expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0); @@ -265,28 +263,36 @@ describe('Integration tests', function () { .reveal(taskId, resultDigest) .then((tx) => tx.wait()); } - await iexecPoco + const finalizeTx = await iexecPoco .connect(scheduler) - .finalize(taskId, results, '0x') - .then((tx) => tx.wait()); + .finalize(taskId, results, '0x'); + expect(finalizeTx).to.changeTokenBalances( + iexecPoco, + [proxyAddress, requester, scheduler, appProvider, datasetProvider], + [ + -(dealPrice + schedulerStakePerDeal), + 0, + schedulerStakePerTask + schedulerRewardPerTask, + appPrice, + datasetPrice, + ], + ); + 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, ); - const expectedBalanceChanges = [ - -(dealPrice + schedulerStakePerDeal), - 0, - schedulerStakePerTask + schedulerRewardPerTask, - appPrice, - datasetPrice, - ]; const expectedFrozenChanges = [0, -taskPrice, -schedulerStakePerTask, 0, 0]; for (let i = 0; i < workerNumber; i++) { - expectedBalanceChanges.push(workerStake + workerRewardPerTask / workerNumber); expectedFrozenChanges.push(0); } - await changesInBalancesAndFrozens({ + await changesInFrozen({ accountsInitBalances, - balanceChanges: expectedBalanceChanges, frozenChanges: expectedFrozenChanges, }); for (let i = 0; i < workerNumber; i++) { @@ -314,17 +320,12 @@ async function checkBalancesAndFrozens(args: { } } -async function changesInBalancesAndFrozens(args: { - accountsInitBalances: { address: string; balance: number; frozen: number }[]; - balanceChanges: number[]; +async function changesInFrozen(args: { + accountsInitBalances: { address: string; frozen: number }[]; frozenChanges: number[]; }) { for (let i = 0; i < args.accountsInitBalances.length; i++) { const message = `Failed with account at index ${i}`; - expect(await iexecPoco.balanceOf(args.accountsInitBalances[i].address)).to.equal( - args.accountsInitBalances[i].balance + args.balanceChanges[i], - message, - ); expect(await iexecPoco.frozenOf(args.accountsInitBalances[i].address)).to.equal( args.accountsInitBalances[i].frozen + args.frozenChanges[i], message, From 2f18557bdf2ebf02870caf4ae0d520a64854a517 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 19 Nov 2024 09:55:11 +0100 Subject: [PATCH 9/9] update table --- test/000_fullchain.test.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index c923c340..33a63a3d 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -16,15 +16,16 @@ import { } from '../utils/poco-tools'; import { IexecWrapper } from './utils/IexecWrapper'; -// +---------+-------------+-------------+-------------+----------+-----+----------------+ -// | | Sponsorship | Replication | Beneficiary | Callback | BoT | Type | -// +---------+-------------+-------------+-------------+----------+-----+----------------+ -// | [1] | ✔ | ✔ | ✔ | ✔ | ✔ | Standard | -// | [2] | x | ✔ | ✔ | ✔ | ✔ | Standard | -// | [3] | ✔ | x | ✔ | ✔ | ✔ | Standard,TEE | -// | [4] | x | x | ✔ | ✔ | ✔ | Standard,TEE | -// | [5] | x | x | x | x | x | Standard,TEE | -// +---------+-------------+-------------+----------+-----+-------------+----------------+ +// +---------+-------------+-------------+-------------+----------+-----+---------------------------------+ +// | | Sponsorship | Replication | Beneficiary | Callback | BoT | Type | +// +---------+-------------+-------------+-------------+----------+-----+---------------------------------+ +// | [1] | ✔ | ✔ | ✔ | ✔ | ✔ | Standard | +// | [2] | x | ✔ | ✔ | ✔ | ✔ | Standard | +// | [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 | +// +---------+-------------+-------------+-------------+----------+-----+---------------------------------+ const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000'; const teeDealTag = '0x0000000000000000000000000000000000000000000000000000000000000001';