Skip to content

Commit

Permalink
only test one case with 5 total workers
Browse files Browse the repository at this point in the history
  • Loading branch information
gfournieriExec committed Nov 21, 2024
1 parent 0764ba1 commit 982f21c
Showing 1 changed file with 102 additions and 108 deletions.
210 changes: 102 additions & 108 deletions test/000_fullchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { IexecWrapper } from './utils/IexecWrapper';
// | [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 | x | Standard,TEE, X good workers 1 bad worker |
// | [7] | x | ✔ | x | x | x | Standard,TEE, 4 good workers 1 bad worker |
// +---------+-------------+-------------+-------------+----------+-----+---------------------------------------------+

const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000';
Expand Down Expand Up @@ -294,115 +294,109 @@ describe('Integration tests', function () {
}
});
}
for (let workerNumber = 4; workerNumber < 6; workerNumber++) {
// Worker1 will contribute badly
it(`[7.${workerNumber - 3}] No sponsorship, no beneficiary, no callback, no BoT, up to ${workerNumber} workers with 1 bad worker`, async function () {
const volume = 1;
const workersAvailable = [worker1, worker2, worker3, worker4, worker5];
const { resultDigest: badResultDigest } = buildUtf8ResultAndDigest('bad-result');
const losingWorker = worker1;
const winningWorkers = workersAvailable.slice(1, workerNumber);
let contributions = [{ signer: worker1, resultDigest: badResultDigest }];
for (const worker of winningWorkers) {
contributions.push({ signer: worker, resultDigest: resultDigest });
}
const accounts = [
requester,
scheduler,
appProvider,
datasetProvider,
losingWorker,
...winningWorkers,
];
// Create deal.
const orders = buildOrders({
assets: ordersAssets,
prices: ordersPrices,
requester: requester.address,
tag: standardDealTag,
beneficiary: beneficiary.address,
volume,
trust: winningWorkers.length,
});
});
it(`[7] No sponsorship, no beneficiary, no callback, no BoT, up to 5 workers with 1 bad worker`, async function () {
const volume = 1;
const workersAvailable = [worker1, worker2, worker3, worker4, worker5];
const { resultDigest: badResultDigest } = buildUtf8ResultAndDigest('bad-result');
const losingWorker = worker1;
const winningWorkers = workersAvailable.slice(1, workersAvailable.length);
let contributions = [{ signer: worker1, resultDigest: badResultDigest }];
for (const worker of winningWorkers) {
contributions.push({ signer: worker, resultDigest: resultDigest });
}
const accounts = [
requester,
scheduler,
appProvider,
datasetProvider,
losingWorker,
...winningWorkers,
];
// Create deal.
const orders = buildOrders({
assets: ordersAssets,
prices: ordersPrices,
requester: requester.address,
tag: standardDealTag,
beneficiary: beneficiary.address,
volume,
trust: winningWorkers.length,
});

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;
const accountsInitialFrozens = await getInitialFrozens(accounts);
// Check initial balances.
for (const contributor of contributions) {
expect(await iexecPoco.viewScore(contributor.signer.address)).to.be.equal(0);
}
const taskId = await iexecWrapper.initializeTask(dealId, 0);
// Finalize task and check balance changes.
const workerStake = await iexecPoco
.viewDeal(dealId)
.then((deal) => deal.workerStake.toNumber());
for (const contributor of contributions) {
await iexecWrapper.contributeToTask(
dealId,
0,
contributor.resultDigest,
contributor.signer,
);
}
// verify that the bad worker can't reveal.
await expect(
iexecPoco.connect(losingWorker).reveal(taskId, badResultDigest),
).to.be.revertedWithoutReason();
for (const winningWorker of winningWorkers) {
await iexecPoco
.connect(winningWorker)
.reveal(taskId, resultDigest)
.then((tx) => tx.wait());
}
const finalizeTx = await iexecPoco
.connect(scheduler)
.finalize(taskId, results, '0x');
expect(finalizeTx).to.changeTokenBalances(
iexecPoco,
[proxyAddress, requester, scheduler, appProvider, datasetProvider],
[
-(dealPrice + schedulerStakePerDeal),
0,
schedulerStakePerTask + schedulerRewardPerTask,
appPrice,
datasetPrice,
],
);
// 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
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 < workerNumber; i++) {
expectedFrozenChanges.push(0);
}
await changesInFrozen({
accountsInitialFrozens,
frozenChanges: expectedFrozenChanges,
});
});
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;
const accountsInitialFrozens = await getInitialFrozens(accounts);
// Check initial balances.
for (const contributor of contributions) {
expect(await iexecPoco.viewScore(contributor.signer.address)).to.be.equal(0);
}
const taskId = await iexecWrapper.initializeTask(dealId, 0);
// Finalize task and check balance changes.
const workerStake = await iexecPoco
.viewDeal(dealId)
.then((deal) => deal.workerStake.toNumber());
for (const contributor of contributions) {
await iexecWrapper.contributeToTask(
dealId,
0,
contributor.resultDigest,
contributor.signer,
);
}
// verify that the bad worker can't reveal.
await expect(
iexecPoco.connect(losingWorker).reveal(taskId, badResultDigest),
).to.be.revertedWithoutReason();
for (const winningWorker of winningWorkers) {
await iexecPoco
.connect(winningWorker)
.reveal(taskId, resultDigest)
.then((tx) => tx.wait());
}
const finalizeTx = await iexecPoco.connect(scheduler).finalize(taskId, results, '0x');
expect(finalizeTx).to.changeTokenBalances(
iexecPoco,
[proxyAddress, requester, scheduler, appProvider, datasetProvider],
[
-(dealPrice + schedulerStakePerDeal),
0,
schedulerStakePerTask + schedulerRewardPerTask,
appPrice,
datasetPrice,
],
);
// 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
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);
}
await changesInFrozen({
accountsInitialFrozens,
frozenChanges: expectedFrozenChanges,
});
});

async function getInitialFrozens(accounts: SignerWithAddress[]) {
Expand Down

0 comments on commit 982f21c

Please sign in to comment.