Skip to content

Commit 7ac5fa6

Browse files
committed
implement test 4
1 parent 46fa4c2 commit 7ac5fa6

File tree

1 file changed

+79
-2
lines changed

1 file changed

+79
-2
lines changed

test/000_fullchain.test.ts

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,86 @@ describe('Integration tests', function () {
392392
}
393393
});
394394

395-
// TODO implement the following tests.
396-
it('[4] No sponsorship, beneficiary, callback, BoT, no replication', async function () {});
395+
it('[4] No sponsorship, beneficiary, callback, BoT, no replication', async function () {
396+
const volume = 3;
397+
// Create deal.
398+
const orders = buildOrders({
399+
assets: ordersAssets,
400+
prices: ordersPrices,
401+
requester: requester.address,
402+
tag: standardDealTag,
403+
beneficiary: beneficiary.address,
404+
callback: callbackAddress,
405+
volume,
406+
trust: 1,
407+
});
408+
const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndMatchOrders(
409+
...orders.toArray(),
410+
);
411+
const taskPrice = appPrice + datasetPrice + workerpoolPrice;
412+
const schedulerStakePerTask = schedulerStakePerDeal / volume;
413+
const workerRewardPerTask = await iexecWrapper.computeWorkerRewardPerTask(
414+
dealId,
415+
PocoMode.CLASSIC,
416+
);
417+
const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask;
418+
// Save frozens
419+
const accounts = [requester, scheduler, appProvider, datasetProvider, worker1];
420+
const accountsInitialFrozens = await getInitialFrozens(accounts);
421+
// Finalize each task and check balance changes.
422+
for (let taskIndex = 0; taskIndex < volume; taskIndex++) {
423+
const taskId = await iexecWrapper.initializeTask(dealId, taskIndex);
424+
const { workerStakePerTask } = await iexecWrapper.contributeToTask(
425+
dealId,
426+
taskIndex,
427+
callbackResultDigest,
428+
worker1,
429+
);
430+
await iexecPoco
431+
.connect(worker1)
432+
.reveal(taskId, callbackResultDigest)
433+
.then((tx) => tx.wait());
434+
const finalizeTx = await iexecPoco
435+
.connect(scheduler)
436+
.finalize(taskId, results, resultsCallback);
437+
expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED);
438+
// Multiply amount by the number of finalized tasks to correctly compute
439+
// stake and reward amounts.
440+
const completedTasks = taskIndex + 1;
441+
// Verify token balance changes
442+
const expectedProxyBalanceChange = -(
443+
taskPrice * completedTasks +
444+
schedulerStakePerTask * completedTasks
445+
);
446+
expect(finalizeTx).to.changeTokenBalances(
447+
iexecPoco,
448+
[proxyAddress, requester, scheduler, appProvider, datasetProvider, worker1],
449+
[
450+
expectedProxyBalanceChange, // Proxy
451+
-taskPrice * completedTasks, // Requester
452+
schedulerStakePerTask + schedulerRewardPerTask, // Scheduler
453+
appPrice, // AppProvider
454+
datasetPrice, // DatasetProvider
455+
workerStakePerTask + workerRewardPerTask, // Worker
456+
],
457+
);
458+
// Calculate expected frozen changes
459+
const expectedFrozenChanges = [
460+
0, // Proxy
461+
-taskPrice * completedTasks, // Requester
462+
-schedulerStakePerTask * completedTasks, // Scheduler
463+
0, // AppProvider
464+
0, // DatasetProvider
465+
0, // Worker
466+
];
467+
await changesInFrozen({
468+
accountsInitialFrozens,
469+
frozenChanges: expectedFrozenChanges,
470+
});
471+
}
472+
});
397473

474+
// TODO implement the following tests.
398475
it('[5] No sponsorship, no beneficiary, no callback, no BoT, no replication', async function () {});
399476

400477
describe('Integration tests array of worker', function () {

0 commit comments

Comments
 (0)