-
Notifications
You must be signed in to change notification settings - Fork 14
Migrate IexecAccessors tests to ethers v6 #189
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
Merged
james-toussaint
merged 7 commits into
feature/migration-to-ether-v6
from
feature/ethers-v6-tests-accessors
Feb 14, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
199c652
Migrate IexecAccessors tests to ethers v6
james-toussaint e9a1834
Move tmp test step
james-toussaint ce52805
Remove extractEventsFromReceipt from tools
james-toussaint 63a10f3
Re-add timeref check
james-toussaint 01a96ab
Import from ethers
james-toussaint 079fcc0
Remove missed bignumber
james-toussaint be4f838
Add domain comment
james-toussaint 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AddressZero, HashZero } from '@ethersproject/constants'; | ||
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; | ||
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import { expect } from 'chai'; | ||
import { ZeroAddress, ZeroHash } from 'ethers'; | ||
import { deployments, ethers } from 'hardhat'; | ||
import { IexecInterfaceNative, IexecInterfaceNative__factory } from '../../../typechain'; | ||
import { | ||
IexecInterfaceNative, | ||
IexecInterfaceNative__factory, | ||
IexecLibOrders_v5, | ||
} from '../../../typechain'; | ||
import { | ||
OrdersAssets, | ||
OrdersPrices, | ||
|
@@ -24,6 +28,7 @@ import { | |
} from '../../../utils/poco-tools'; | ||
import { IexecWrapper } from '../../utils/IexecWrapper'; | ||
import { loadHardhatFixtureDeployment } from '../../utils/hardhat-fixture-deployer'; | ||
import { hashDomain } from '../IexecMaintenance/IexecMaintenance.test'; | ||
|
||
/** | ||
* Test state view functions. | ||
|
@@ -136,10 +141,10 @@ describe('IexecAccessors', async () => { | |
expect(deal.workerpool.price).to.equal(workerpoolPrice); | ||
expect(deal.trust).to.equal(1); | ||
expect(deal.category).to.equal(0); | ||
expect(deal.tag).to.equal(HashZero); // Standard | ||
expect(deal.tag).to.equal(ZeroHash); // Standard | ||
expect(deal.requester).to.equal(requester.address); | ||
expect(deal.beneficiary).to.equal(AddressZero); | ||
expect(deal.callback).to.equal(AddressZero); | ||
expect(deal.beneficiary).to.equal(ZeroAddress); | ||
expect(deal.callback).to.equal(ZeroAddress); | ||
expect(deal.params).to.equal(''); | ||
expect(deal.startTime).to.be.greaterThan(0); | ||
expect(deal.botFirst).to.equal(0); | ||
|
@@ -171,10 +176,8 @@ describe('IexecAccessors', async () => { | |
const { dealId, taskId, taskIndex, startTime, timeRef } = await createDeal(); | ||
await iexecWrapper.initializeTask(dealId, taskIndex); | ||
|
||
const contributionDeadlineRatio = ( | ||
await iexecPoco.contribution_deadline_ratio() | ||
).toNumber(); | ||
const finalDeadlineRatio = (await iexecPoco.final_deadline_ratio()).toNumber(); | ||
const contributionDeadlineRatio = Number(await iexecPoco.contribution_deadline_ratio()); | ||
const finalDeadlineRatio = Number(await iexecPoco.final_deadline_ratio()); | ||
|
||
const task = await iexecPoco.viewTask(taskId); | ||
expect(task.status).to.equal(TaskStatusEnum.ACTIVE); | ||
|
@@ -184,11 +187,11 @@ describe('IexecAccessors', async () => { | |
expect(task.contributionDeadline).to.equal(startTime + timeRef * contributionDeadlineRatio); | ||
expect(task.revealDeadline).to.equal(0); | ||
expect(task.finalDeadline).to.equal(startTime + timeRef * finalDeadlineRatio); | ||
expect(task.consensusValue).to.equal(HashZero); | ||
expect(task.consensusValue).to.equal(ZeroHash); | ||
expect(task.revealCounter).to.equal(0); | ||
expect(task.winnerCounter).to.equal(0); | ||
expect(task.contributors.length).to.equal(0); | ||
expect(task.resultDigest).to.equal(HashZero); | ||
expect(task.resultDigest).to.equal(ZeroHash); | ||
expect(task.results).to.equal('0x'); | ||
expect(task.resultsTimestamp).to.equal(0); | ||
expect(task.resultsCallback).to.equal('0x'); | ||
|
@@ -202,7 +205,7 @@ describe('IexecAccessors', async () => { | |
expect(contribution.status).to.equal(ContributionStatusEnum.CONTRIBUTED); | ||
expect(contribution.resultHash.length).to.equal(66); | ||
expect(contribution.resultSeal.length).to.equal(66); | ||
expect(contribution.enclaveChallenge).to.equal(AddressZero); | ||
expect(contribution.enclaveChallenge).to.equal(ZeroAddress); | ||
expect(contribution.weight).to.equal(1); | ||
}); | ||
|
||
|
@@ -234,7 +237,7 @@ describe('IexecAccessors', async () => { | |
}); | ||
|
||
it('teeBroker', async function () { | ||
expect(await iexecPoco.teebroker()).to.equal(ethers.constants.AddressZero); | ||
expect(await iexecPoco.teebroker()).to.equal(ethers.ZeroAddress); | ||
}); | ||
|
||
it('callbackGas', async function () { | ||
|
@@ -276,8 +279,15 @@ describe('IexecAccessors', async () => { | |
}); | ||
|
||
it('eip712domainSeparator', async function () { | ||
expect(await iexecPoco.eip712domain_separator()).to.equal( | ||
'0xfc2178d8b8300e657cb9f8b5a4d1957174cf1392e294f3575b82a9cea1da1c4b', | ||
expect(await iexecPoco.eip712domain_separator()).equal( | ||
await hashDomain({ | ||
// TODO use IexecWrapper.getDomain() (with some modifications). | ||
name: 'iExecODB', | ||
version: '5.0.0', | ||
chainId: (await ethers.provider.getNetwork()).chainId, | ||
// address is different between `test` and `coverage` deployment | ||
verifyingContract: proxyAddress, | ||
} as IexecLibOrders_v5.EIP712DomainStructOutput), | ||
); | ||
}); | ||
|
||
|
@@ -300,7 +310,7 @@ describe('IexecAccessors', async () => { | |
.then((tx) => tx.wait()); | ||
const task = await iexecPoco.viewTask(taskId); | ||
expect(task.status).to.equal(TaskStatusEnum.COMPLETED); | ||
expect(await iexecPoco.callStatic.resultFor(taskId)).to.equal(resultsCallback); | ||
expect(await iexecPoco.resultFor(taskId)).to.equal(resultsCallback); | ||
}); | ||
|
||
it('Should not get result when task is not completed', async function () { | ||
|
@@ -333,7 +343,7 @@ async function createDeal(volume: number = 1) { | |
...orders.toArray(), | ||
); | ||
const dealCategory = (await iexecPoco.viewDeal(dealId)).category; | ||
const timeRef = (await iexecPoco.viewCategory(dealCategory)).workClockTimeRef.toNumber(); | ||
const timeRef = Number((await iexecPoco.viewCategory(dealCategory)).workClockTimeRef); | ||
return { dealId, taskId, taskIndex, startTime, timeRef, orders }; | ||
} | ||
|
||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <[email protected]> | ||
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AddressZero } from '@ethersproject/constants'; | ||
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; | ||
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import { expect } from 'chai'; | ||
import { ZeroAddress } from 'ethers'; | ||
import { ethers } from 'hardhat'; | ||
import { | ||
IexecInterfaceNative, | ||
|
@@ -176,7 +176,7 @@ describe('IexecAccessorsABILegacy', function () { | |
expect(contribution[0]).to.equal(ContributionStatusEnum.CONTRIBUTED); | ||
expect(contribution[1]).to.equal(resultHash); | ||
expect(contribution[2]).to.equal(resultSeal); | ||
expect(contribution[3]).to.equal(AddressZero); // enclaveChallenge | ||
expect(contribution[3]).to.equal(ZeroAddress); // enclaveChallenge | ||
}); | ||
|
||
it('[ABILegacy] Should return category', async function () { | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <[email protected]> | ||
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { HashZero as hashZero } from '@ethersproject/constants'; | ||
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; | ||
import { loadFixture, setStorageAt } from '@nomicfoundation/hardhat-network-helpers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import { expect } from 'chai'; | ||
import { TypedDataEncoder, ZeroHash } from 'ethers'; | ||
import { ethers } from 'hardhat'; | ||
import { | ||
IexecInterfaceNative, | ||
|
@@ -120,9 +120,9 @@ describe('Maintenance', async () => { | |
await expect(iexecPoco.importScore(worker.address)).to.be.revertedWithoutReason(); | ||
}); | ||
it('Should not import score when already imported', async () => { | ||
const workerScoreImportedSlot = ethers.utils.hexStripZeros( | ||
ethers.utils.keccak256( | ||
ethers.utils.defaultAbiCoder.encode( | ||
const workerScoreImportedSlot = ethers.stripZerosLeft( | ||
ethers.keccak256( | ||
ethers.AbiCoder.defaultAbiCoder().encode( | ||
['address', 'uint256'], | ||
[ | ||
worker.address, | ||
|
@@ -197,7 +197,7 @@ describe('Maintenance', async () => { | |
}); | ||
|
||
async function clearDomainSeparator() { | ||
await setDomainSeparatorInStorage(hashZero); | ||
await setDomainSeparatorInStorage(ZeroHash); | ||
} | ||
|
||
async function setDomainSeparatorInStorage(domainSeparator: string) { | ||
|
@@ -211,8 +211,9 @@ describe('Maintenance', async () => { | |
} | ||
}); | ||
|
||
async function hashDomain(domain: IexecLibOrders_v5.EIP712DomainStructOutput) { | ||
return ethers.utils._TypedDataEncoder.hashDomain({ | ||
//TODO: Move to utils | ||
export async function hashDomain(domain: IexecLibOrders_v5.EIP712DomainStructOutput) { | ||
return TypedDataEncoder.hashDomain({ | ||
name: domain.name, | ||
version: domain.version, | ||
chainId: domain.chainId, | ||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.