Skip to content

Commit 711c828

Browse files
authored
Migrate fullchain IT wih 1 badworker in the array (#160)
2 parents 3aa8743 + 982f21c commit 711c828

File tree

3 files changed

+142
-31
lines changed

3 files changed

+142
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Migrate integration test files to Typescript & Hardhat:
66
- 000_fullchain.js (#156, #157)
77
- 00X_fullchain-Xworkers.js (#158, #159)
8+
- 000_fullchain-5workers-1error.js (#160)
89
- Remove `smock` from unit tests:
910
- IexecEscrow.v8 (#154, #155)
1011
- IexecPocoDelegate (#149, #151)

test/000_fullchain.test.ts

Lines changed: 141 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ import {
1616
} from '../utils/poco-tools';
1717
import { IexecWrapper } from './utils/IexecWrapper';
1818

19-
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------+
20-
// | | Sponsorship | Replication | Beneficiary | Callback | BoT | Type |
21-
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------+
22-
// | [1] | ✔ | ✔ | ✔ | ✔ | ✔ | Standard |
23-
// | [2] | x | ✔ | ✔ | ✔ | ✔ | Standard |
24-
// | [3] | ✔ | x | ✔ | ✔ | ✔ | Standard,TEE |
25-
// | [4] | x | x | ✔ | ✔ | ✔ | Standard,TEE |
26-
// | [5] | x | x | x | x | x | Standard,TEE |
27-
// | [6.x] | x | ✔ | x | x | x | Standard,TEE, X good workers |
28-
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------+
19+
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------------------+
20+
// | | Sponsorship | Replication | Beneficiary | Callback | BoT | Type |
21+
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------------------+
22+
// | [1] | ✔ | ✔ | ✔ | ✔ | ✔ | Standard |
23+
// | [2] | x | ✔ | ✔ | ✔ | ✔ | Standard |
24+
// | [3] | ✔ | x | ✔ | ✔ | ✔ | Standard,TEE |
25+
// | [4] | x | x | ✔ | ✔ | ✔ | Standard,TEE |
26+
// | [5] | x | x | x | x | x | Standard,TEE |
27+
// | [6.x] | x | ✔ | x | x | x | Standard,TEE, X good workers |
28+
// | [7] | x | ✔ | x | x | x | Standard,TEE, 4 good workers 1 bad worker |
29+
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------------------+
2930

3031
const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000';
3132
const teeDealTag = '0x0000000000000000000000000000000000000000000000000000000000000001';
@@ -214,7 +215,7 @@ describe('Integration tests', function () {
214215
const volume = 1;
215216
const disposableWorkers = [worker1, worker2, worker3, worker4, worker5];
216217
const workers = disposableWorkers.slice(0, workerNumber);
217-
const acounts = [requester, scheduler, appProvider, datasetProvider, ...workers];
218+
const accounts = [requester, scheduler, appProvider, datasetProvider, ...workers];
218219
// Create deal.
219220
const orders = buildOrders({
220221
assets: ordersAssets,
@@ -234,18 +235,8 @@ describe('Integration tests', function () {
234235
PocoMode.CLASSIC,
235236
);
236237
const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask;
237-
// Check initial balances.
238-
let accountsInitBalances = [
239-
{
240-
address: proxyAddress,
241-
frozen: (await iexecPoco.frozenOf(proxyAddress)).toNumber(),
242-
},
243-
];
244-
for (const account of acounts) {
245-
let address = account.address;
246-
let frozen = (await iexecPoco.frozenOf(account.address)).toNumber();
247-
accountsInitBalances.push({ address, frozen });
248-
}
238+
const accountsInitialFrozens = await getInitialFrozens(accounts);
239+
249240
for (let i = 0; i < workerNumber; i++) {
250241
expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0);
251242
}
@@ -293,17 +284,136 @@ describe('Integration tests', function () {
293284
expectedFrozenChanges.push(0);
294285
}
295286
await changesInFrozen({
296-
accountsInitBalances,
287+
accountsInitialFrozens,
297288
frozenChanges: expectedFrozenChanges,
298289
});
299290
for (let i = 0; i < workerNumber; i++) {
300-
if (workerNumber == 1) {
301-
expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0);
302-
}
291+
expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(
292+
workerNumber == 1 ? 0 : 1,
293+
);
303294
}
304295
});
305296
}
306297
});
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+
});
326+
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);
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.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+
});
400+
});
401+
402+
async function getInitialFrozens(accounts: SignerWithAddress[]) {
403+
let initialFrozens = [
404+
{
405+
address: proxyAddress,
406+
frozen: (await iexecPoco.frozenOf(proxyAddress)).toNumber(),
407+
},
408+
];
409+
for (const account of accounts) {
410+
initialFrozens.push({
411+
address: account.address,
412+
frozen: (await iexecPoco.frozenOf(account.address)).toNumber(),
413+
});
414+
}
415+
return initialFrozens;
416+
}
307417
});
308418

309419
async function checkBalancesAndFrozens(args: {
@@ -322,13 +432,13 @@ async function checkBalancesAndFrozens(args: {
322432
}
323433

324434
async function changesInFrozen(args: {
325-
accountsInitBalances: { address: string; frozen: number }[];
435+
accountsInitialFrozens: { address: string; frozen: number }[];
326436
frozenChanges: number[];
327437
}) {
328-
for (let i = 0; i < args.accountsInitBalances.length; i++) {
438+
for (let i = 0; i < args.accountsInitialFrozens.length; i++) {
329439
const message = `Failed with account at index ${i}`;
330-
expect(await iexecPoco.frozenOf(args.accountsInitBalances[i].address)).to.equal(
331-
args.accountsInitBalances[i].frozen + args.frozenChanges[i],
440+
expect(await iexecPoco.frozenOf(args.accountsInitialFrozens[i].address)).to.equal(
441+
args.accountsInitialFrozens[i].frozen + args.frozenChanges[i],
332442
message,
333443
);
334444
}
File renamed without changes.

0 commit comments

Comments
 (0)