-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate 300 fullchain reopen file #170
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6b7109d
init file
gfournieriExec 1c123f0
skip old file
gfournieriExec 8ece78f
Merge branch 'develop' into feature/migrate-300-fullchain-old-IT
gfournieriExec b2cf6b2
update test IT
gfournieriExec 0487d62
remove tee
gfournieriExec 866cf26
update changelog
gfournieriExec 2c2aeb3
modifiy changelog PR number
gfournieriExec af16acb
Merge branch 'develop' into feature/migrate-300-fullchain-old-IT
zguesmi a41e8bb
apply suggestions
gfournieriExec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,222 @@ | ||||||
// SPDX-FileCopyrightText: 2024 IEXEC BLOCKCHAIN TECH <[email protected]> | ||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||
|
||||||
import { AddressZero } from '@ethersproject/constants'; | ||||||
import { loadFixture, mine } from '@nomicfoundation/hardhat-network-helpers'; | ||||||
import { setNextBlockTimestamp } from '@nomicfoundation/hardhat-network-helpers/dist/src/helpers/time'; | ||||||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||||||
import { expect } from 'hardhat'; | ||||||
import { loadHardhatFixtureDeployment } from '../scripts/hardhat-fixture-deployer'; | ||||||
import { IexecInterfaceNative, IexecInterfaceNative__factory } from '../typechain'; | ||||||
import { OrdersActors, OrdersAssets, OrdersPrices, buildOrders } from '../utils/createOrders'; | ||||||
|
||||||
import { | ||||||
TaskStatusEnum, | ||||||
buildAndSignContributionAuthorizationMessage, | ||||||
buildResultHashAndResultSeal, | ||||||
buildUtf8ResultAndDigest, | ||||||
getIexecAccounts, | ||||||
} from '../utils/poco-tools'; | ||||||
import { IexecWrapper } from './utils/IexecWrapper'; | ||||||
|
||||||
const standardDealTag = '0x0000000000000000000000000000000000000000000000000000000000000000'; | ||||||
const appPrice = 1000; | ||||||
const datasetPrice = 1_000_000; | ||||||
const workerpoolPrice = 1_000_000_000; | ||||||
const { results, resultDigest } = buildUtf8ResultAndDigest('result'); | ||||||
|
||||||
let proxyAddress: string; | ||||||
let [iexecPoco, iexecPocoAsScheduler]: IexecInterfaceNative[] = []; | ||||||
let iexecWrapper: IexecWrapper; | ||||||
let [appAddress, workerpoolAddress, datasetAddress]: string[] = []; | ||||||
let [ | ||||||
requester, | ||||||
appProvider, | ||||||
datasetProvider, | ||||||
scheduler, | ||||||
anyone, | ||||||
worker1, | ||||||
worker2, | ||||||
worker3, | ||||||
worker4, | ||||||
]: SignerWithAddress[] = []; | ||||||
let ordersActors: OrdersActors; | ||||||
let ordersAssets: OrdersAssets; | ||||||
let ordersPrices: OrdersPrices; | ||||||
|
||||||
describe('Integration tests', function () { | ||||||
beforeEach('Deploy', async () => { | ||||||
// Deploy all contracts | ||||||
proxyAddress = await loadHardhatFixtureDeployment(); | ||||||
// Initialize test environment | ||||||
await loadFixture(initFixture); | ||||||
}); | ||||||
|
||||||
async function initFixture() { | ||||||
const accounts = await getIexecAccounts(); | ||||||
({ | ||||||
requester, | ||||||
appProvider, | ||||||
datasetProvider, | ||||||
scheduler, | ||||||
anyone, | ||||||
worker1, | ||||||
worker2, | ||||||
worker3, | ||||||
worker4, | ||||||
} = accounts); | ||||||
iexecWrapper = new IexecWrapper(proxyAddress, accounts); | ||||||
({ appAddress, datasetAddress, workerpoolAddress } = await iexecWrapper.createAssets()); | ||||||
iexecPoco = IexecInterfaceNative__factory.connect(proxyAddress, anyone); | ||||||
iexecPocoAsScheduler = iexecPoco.connect(scheduler); | ||||||
ordersActors = { | ||||||
appOwner: appProvider, | ||||||
datasetOwner: datasetProvider, | ||||||
workerpoolOwner: scheduler, | ||||||
requester: requester, | ||||||
}; | ||||||
ordersAssets = { | ||||||
app: appAddress, | ||||||
dataset: datasetAddress, | ||||||
workerpool: workerpoolAddress, | ||||||
}; | ||||||
ordersPrices = { | ||||||
app: appPrice, | ||||||
dataset: datasetPrice, | ||||||
workerpool: workerpoolPrice, | ||||||
}; | ||||||
} | ||||||
|
||||||
/* | ||||||
This test simulates the full lifecycle of a task in iExec: | ||||||
- Creates a deal with specific orders and initializes a task. | ||||||
- Tests worker contributions: | ||||||
- The first group of workers contributes, triggering the reveal phase. | ||||||
- Task is reopened after the reveal deadline passes. | ||||||
- Ensures that workers who already contributed cannot contribute again. | ||||||
- The second group of workers contributes and reveals successfully. | ||||||
- Finalizes the task, distributing rewards among workers and the scheduler. | ||||||
- Validates token balance changes for all participants. | ||||||
- Verifies that winning workers receive a positive score, while losing workers do not. | ||||||
*/ | ||||||
it(`[1] Task lifecycle with contributions and reopening`, async function () { | ||||||
const volume = 1; | ||||||
const workers = [worker1, worker2, worker3, worker4]; | ||||||
const firstContribution = workers.slice(0, 2); | ||||||
const secondContribution = workers.slice(2, 4); | ||||||
const accounts = [requester, scheduler, appProvider, datasetProvider, ...workers]; | ||||||
|
||||||
// Create deal. | ||||||
const orders = buildOrders({ | ||||||
assets: ordersAssets, | ||||||
prices: ordersPrices, | ||||||
requester: requester.address, | ||||||
tag: standardDealTag, | ||||||
volume, | ||||||
trust: 4, | ||||||
}); | ||||||
const { dealId, dealPrice, schedulerStakePerDeal } = await iexecWrapper.signAndMatchOrders( | ||||||
...orders.toArray(), | ||||||
); | ||||||
const taskPrice = appPrice + datasetPrice + workerpoolPrice; | ||||||
const schedulerStakePerTask = schedulerStakePerDeal / volume; | ||||||
const accountsInitialFrozens = await iexecWrapper.getInitialFrozens(accounts); | ||||||
|
||||||
for (let i = 0; i < 4; i++) { | ||||||
expect(await iexecPoco.viewScore(workers[i].address)).to.be.equal(0); | ||||||
} | ||||||
const taskId = await iexecWrapper.initializeTask(dealId, 0); | ||||||
const workerStakePerTask = await iexecPoco | ||||||
.viewDeal(dealId) | ||||||
.then((deal) => deal.workerStake.toNumber()); | ||||||
for (const contributor of firstContribution) { | ||||||
await iexecWrapper.contributeToTask(dealId, 0, resultDigest, contributor); | ||||||
} | ||||||
const task = await iexecPoco.viewTask(taskId); | ||||||
expect(task.status).to.equal(TaskStatusEnum.REVEALING); | ||||||
await setNextBlockTimestamp(task.revealDeadline).then(() => mine()); | ||||||
await expect(iexecPocoAsScheduler.reopen(taskId)) | ||||||
.to.emit(iexecPoco, 'TaskReopen') | ||||||
.withArgs(taskId); | ||||||
expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.ACTIVE); | ||||||
// test that the already contributed worker 1 can't contribute anymore | ||||||
const { resultHash, resultSeal } = buildResultHashAndResultSeal( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
taskId, | ||||||
resultDigest, | ||||||
worker1, | ||||||
); | ||||||
const schedulerSignature = await buildAndSignContributionAuthorizationMessage( | ||||||
worker1.address, | ||||||
taskId, | ||||||
AddressZero, | ||||||
scheduler, | ||||||
); | ||||||
await expect( | ||||||
iexecPoco | ||||||
.connect(worker1) | ||||||
.contribute(taskId, resultHash, resultSeal, AddressZero, '0x', schedulerSignature), | ||||||
).to.revertedWithoutReason(); | ||||||
|
||||||
for (const contributor of secondContribution) { | ||||||
await iexecWrapper.contributeToTask(dealId, 0, resultDigest, contributor); | ||||||
} | ||||||
for (const contributor of secondContribution) { | ||||||
await iexecPoco | ||||||
.connect(contributor) | ||||||
.reveal(taskId, resultDigest) | ||||||
.then((tx) => tx.wait()); | ||||||
} | ||||||
const finalizeTx = await iexecPocoAsScheduler.finalize(taskId, results, '0x'); | ||||||
await finalizeTx.wait(); | ||||||
const totalWorkerPoolReward = | ||||||
workerpoolPrice + workerStakePerTask * firstContribution.length; // bad wrokers lose their stake and add it to the pool price | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
const workersRewardPerTask = await iexecWrapper.computeWorkersRewardForCurrentTask( | ||||||
totalWorkerPoolReward, | ||||||
dealId, | ||||||
); | ||||||
const expectedWinningWorkerBalanceChange = | ||||||
workerStakePerTask + workersRewardPerTask / secondContribution.length; | ||||||
// compute expected scheduler reward for current task | ||||||
const schedulerRewardPerTask = totalWorkerPoolReward - workersRewardPerTask; | ||||||
const expectedSchedulerBalanceChange = schedulerStakePerTask + schedulerRewardPerTask; | ||||||
|
||||||
const expectedProxyBalanceChange = -( | ||||||
dealPrice + | ||||||
workerStakePerTask * workers.length + | ||||||
schedulerStakePerTask | ||||||
); | ||||||
await expect(finalizeTx).to.changeTokenBalances( | ||||||
iexecPoco, | ||||||
[proxyAddress, ...accounts], | ||||||
[ | ||||||
expectedProxyBalanceChange, | ||||||
0, | ||||||
expectedSchedulerBalanceChange, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
appPrice, | ||||||
datasetPrice, | ||||||
...firstContribution.map(() => 0), // Workers | ||||||
...secondContribution.map(() => expectedWinningWorkerBalanceChange), // Workers | ||||||
], | ||||||
); | ||||||
expect((await iexecPoco.viewTask(taskId)).status).to.equal(TaskStatusEnum.COMPLETED); | ||||||
const expectedFrozenChanges = [ | ||||||
0, | ||||||
-taskPrice, | ||||||
-schedulerStakePerTask, | ||||||
0, | ||||||
0, | ||||||
...workers.map(() => 0), | ||||||
]; | ||||||
await iexecWrapper.checkFrozenChanges(accountsInitialFrozens, expectedFrozenChanges); | ||||||
|
||||||
// checks on losing worker | ||||||
for (const contributor of firstContribution) { | ||||||
expect(await iexecPoco.viewScore(contributor.address)).to.be.equal(0); | ||||||
} | ||||||
// checks on winning workers | ||||||
for (const contributor of secondContribution) { | ||||||
expect(await iexecPoco.viewScore(contributor.address)).to.be.equal(1); | ||||||
} | ||||||
}); | ||||||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.