Skip to content

Commit 982f21c

Browse files
committed
only test one case with 5 total workers
1 parent 0764ba1 commit 982f21c

File tree

1 file changed

+102
-108
lines changed

1 file changed

+102
-108
lines changed

test/000_fullchain.test.ts

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

3131
const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000';
@@ -294,115 +294,109 @@ describe('Integration tests', function () {
294294
}
295295
});
296296
}
297-
for (let workerNumber = 4; workerNumber < 6; workerNumber++) {
298-
// Worker1 will contribute badly
299-
it(`[7.${workerNumber - 3}] No sponsorship, no beneficiary, no callback, no BoT, up to ${workerNumber} workers with 1 bad worker`, async function () {
300-
const volume = 1;
301-
const workersAvailable = [worker1, worker2, worker3, worker4, worker5];
302-
const { resultDigest: badResultDigest } = buildUtf8ResultAndDigest('bad-result');
303-
const losingWorker = worker1;
304-
const winningWorkers = workersAvailable.slice(1, workerNumber);
305-
let contributions = [{ signer: worker1, resultDigest: badResultDigest }];
306-
for (const worker of winningWorkers) {
307-
contributions.push({ signer: worker, resultDigest: resultDigest });
308-
}
309-
const accounts = [
310-
requester,
311-
scheduler,
312-
appProvider,
313-
datasetProvider,
314-
losingWorker,
315-
...winningWorkers,
316-
];
317-
// Create deal.
318-
const orders = buildOrders({
319-
assets: ordersAssets,
320-
prices: ordersPrices,
321-
requester: requester.address,
322-
tag: standardDealTag,
323-
beneficiary: beneficiary.address,
324-
volume,
325-
trust: winningWorkers.length,
326-
});
297+
});
298+
it(`[7] No sponsorship, no beneficiary, no callback, no BoT, up to 5 workers with 1 bad worker`, async function () {
299+
const volume = 1;
300+
const workersAvailable = [worker1, worker2, worker3, worker4, worker5];
301+
const { resultDigest: badResultDigest } = buildUtf8ResultAndDigest('bad-result');
302+
const losingWorker = worker1;
303+
const winningWorkers = workersAvailable.slice(1, workersAvailable.length);
304+
let contributions = [{ signer: worker1, resultDigest: badResultDigest }];
305+
for (const worker of winningWorkers) {
306+
contributions.push({ signer: worker, resultDigest: resultDigest });
307+
}
308+
const accounts = [
309+
requester,
310+
scheduler,
311+
appProvider,
312+
datasetProvider,
313+
losingWorker,
314+
...winningWorkers,
315+
];
316+
// Create deal.
317+
const orders = buildOrders({
318+
assets: ordersAssets,
319+
prices: ordersPrices,
320+
requester: requester.address,
321+
tag: standardDealTag,
322+
beneficiary: beneficiary.address,
323+
volume,
324+
trust: winningWorkers.length,
325+
});
327326

328-
const { dealId, dealPrice, schedulerStakePerDeal } =
329-
await iexecWrapper.signAndMatchOrders(...orders.toArray());
330-
const taskPrice = appPrice + datasetPrice + workerpoolPrice;
331-
const schedulerStakePerTask = schedulerStakePerDeal / volume;
332-
const workerRewardPerTask = await iexecWrapper.computeWorkerRewardPerTask(
333-
dealId,
334-
PocoMode.CLASSIC,
335-
);
336-
const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask;
337-
const accountsInitialFrozens = await getInitialFrozens(accounts);
338-
// Check initial balances.
339-
for (const contributor of contributions) {
340-
expect(await iexecPoco.viewScore(contributor.signer.address)).to.be.equal(0);
341-
}
342-
const taskId = await iexecWrapper.initializeTask(dealId, 0);
343-
// Finalize task and check balance changes.
344-
const workerStake = await iexecPoco
345-
.viewDeal(dealId)
346-
.then((deal) => deal.workerStake.toNumber());
347-
for (const contributor of contributions) {
348-
await iexecWrapper.contributeToTask(
349-
dealId,
350-
0,
351-
contributor.resultDigest,
352-
contributor.signer,
353-
);
354-
}
355-
// verify that the bad worker can't reveal.
356-
await expect(
357-
iexecPoco.connect(losingWorker).reveal(taskId, badResultDigest),
358-
).to.be.revertedWithoutReason();
359-
for (const winningWorker of winningWorkers) {
360-
await iexecPoco
361-
.connect(winningWorker)
362-
.reveal(taskId, resultDigest)
363-
.then((tx) => tx.wait());
364-
}
365-
const finalizeTx = await iexecPoco
366-
.connect(scheduler)
367-
.finalize(taskId, results, '0x');
368-
expect(finalizeTx).to.changeTokenBalances(
369-
iexecPoco,
370-
[proxyAddress, requester, scheduler, appProvider, datasetProvider],
371-
[
372-
-(dealPrice + schedulerStakePerDeal),
373-
0,
374-
schedulerStakePerTask + schedulerRewardPerTask,
375-
appPrice,
376-
datasetPrice,
377-
],
378-
);
379-
// checks on losing worker
380-
expect(finalizeTx).to.changeTokenBalances(iexecPoco, [losingWorker], [0]);
381-
expect(await iexecPoco.viewScore(losingWorker.address)).to.be.equal(0);
382-
// checks on winning workers
383-
for (const winningWorker of winningWorkers) {
384-
expect(finalizeTx).to.changeTokenBalances(
385-
iexecPoco,
386-
[winningWorker.address],
387-
[workerStake + workerRewardPerTask / winningWorkers.length],
388-
);
389-
expect(await iexecPoco.viewScore(winningWorker.address)).to.be.equal(1);
390-
}
391-
// verify task status
392-
expect((await iexecPoco.viewTask(taskId)).status).to.equal(
393-
TaskStatusEnum.COMPLETED,
394-
);
395-
// checks on frozen balance changes
396-
const expectedFrozenChanges = [0, -taskPrice, -schedulerStakePerTask, 0, 0];
397-
for (let i = 0; i < workerNumber; i++) {
398-
expectedFrozenChanges.push(0);
399-
}
400-
await changesInFrozen({
401-
accountsInitialFrozens,
402-
frozenChanges: expectedFrozenChanges,
403-
});
404-
});
327+
const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndMatchOrders(
328+
...orders.toArray(),
329+
);
330+
const taskPrice = appPrice + datasetPrice + workerpoolPrice;
331+
const schedulerStakePerTask = schedulerStakePerDeal / volume;
332+
const workerRewardPerTask = await iexecWrapper.computeWorkerRewardPerTask(
333+
dealId,
334+
PocoMode.CLASSIC,
335+
);
336+
const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask;
337+
const accountsInitialFrozens = await getInitialFrozens(accounts);
338+
// Check initial balances.
339+
for (const contributor of contributions) {
340+
expect(await iexecPoco.viewScore(contributor.signer.address)).to.be.equal(0);
405341
}
342+
const taskId = await iexecWrapper.initializeTask(dealId, 0);
343+
// Finalize task and check balance changes.
344+
const workerStake = await iexecPoco
345+
.viewDeal(dealId)
346+
.then((deal) => deal.workerStake.toNumber());
347+
for (const contributor of contributions) {
348+
await iexecWrapper.contributeToTask(
349+
dealId,
350+
0,
351+
contributor.resultDigest,
352+
contributor.signer,
353+
);
354+
}
355+
// verify that the bad worker can't reveal.
356+
await expect(
357+
iexecPoco.connect(losingWorker).reveal(taskId, badResultDigest),
358+
).to.be.revertedWithoutReason();
359+
for (const winningWorker of winningWorkers) {
360+
await iexecPoco
361+
.connect(winningWorker)
362+
.reveal(taskId, resultDigest)
363+
.then((tx) => tx.wait());
364+
}
365+
const finalizeTx = await iexecPoco.connect(scheduler).finalize(taskId, results, '0x');
366+
expect(finalizeTx).to.changeTokenBalances(
367+
iexecPoco,
368+
[proxyAddress, requester, scheduler, appProvider, datasetProvider],
369+
[
370+
-(dealPrice + schedulerStakePerDeal),
371+
0,
372+
schedulerStakePerTask + schedulerRewardPerTask,
373+
appPrice,
374+
datasetPrice,
375+
],
376+
);
377+
// checks on losing worker
378+
expect(finalizeTx).to.changeTokenBalances(iexecPoco, [losingWorker], [0]);
379+
expect(await iexecPoco.viewScore(losingWorker.address)).to.be.equal(0);
380+
// checks on winning workers
381+
for (const winningWorker of winningWorkers) {
382+
expect(finalizeTx).to.changeTokenBalances(
383+
iexecPoco,
384+
[winningWorker.address],
385+
[workerStake + workerRewardPerTask / winningWorkers.length],
386+
);
387+
expect(await iexecPoco.viewScore(winningWorker.address)).to.be.equal(1);
388+
}
389+
// verify task status
390+
expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED);
391+
// checks on frozen balance changes
392+
const expectedFrozenChanges = [0, -taskPrice, -schedulerStakePerTask, 0, 0];
393+
for (let i = 0; i < workersAvailable.length; i++) {
394+
expectedFrozenChanges.push(0);
395+
}
396+
await changesInFrozen({
397+
accountsInitialFrozens,
398+
frozenChanges: expectedFrozenChanges,
399+
});
406400
});
407401

408402
async function getInitialFrozens(accounts: SignerWithAddress[]) {

0 commit comments

Comments
 (0)