Skip to content

Commit 106e67f

Browse files
Migrate IexecAccessors tests to ethers v6 (#189)
2 parents 20cd559 + be4f838 commit 106e67f

File tree

10 files changed

+175
-107
lines changed

10 files changed

+175
-107
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
run: npm run build
3333
- name: Check storage layout
3434
run: npm run test-storage-layout
35+
# TODO: Remove before merging to develop
36+
- name: Run test
37+
run: npm run test test/byContract/IexecAccessors/**
3538
- name: Run deployment
3639
# Basic deployment to make sure everything is ok.
3740
# Could be removed in the future if not relevant.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
### Features
99
- Migrate to Ethers v6:
1010
- Deployment scripts (#187)
11+
- Tests
12+
- IexecAccessors (#189)
1113
- Migrate scripts to TypeScript: (#184)
1214
- `getFunctionSignatures.js`, `common-test-snapshot.js`, `test-storage.js`, `timelock.js`
1315
- Migrated utility files to TypeScript : (#183)

test/byContract/IexecAccessors/IexecAccessors.test.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <[email protected]>
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { AddressZero, HashZero } from '@ethersproject/constants';
4+
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
55
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
6-
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
76
import { expect } from 'chai';
7+
import { ZeroAddress, ZeroHash } from 'ethers';
88
import { deployments, ethers } from 'hardhat';
9-
import { IexecInterfaceNative, IexecInterfaceNative__factory } from '../../../typechain';
9+
import {
10+
IexecInterfaceNative,
11+
IexecInterfaceNative__factory,
12+
IexecLibOrders_v5,
13+
} from '../../../typechain';
1014
import {
1115
OrdersAssets,
1216
OrdersPrices,
@@ -24,6 +28,7 @@ import {
2428
} from '../../../utils/poco-tools';
2529
import { IexecWrapper } from '../../utils/IexecWrapper';
2630
import { loadHardhatFixtureDeployment } from '../../utils/hardhat-fixture-deployer';
31+
import { hashDomain } from '../IexecMaintenance/IexecMaintenance.test';
2732

2833
/**
2934
* Test state view functions.
@@ -136,10 +141,10 @@ describe('IexecAccessors', async () => {
136141
expect(deal.workerpool.price).to.equal(workerpoolPrice);
137142
expect(deal.trust).to.equal(1);
138143
expect(deal.category).to.equal(0);
139-
expect(deal.tag).to.equal(HashZero); // Standard
144+
expect(deal.tag).to.equal(ZeroHash); // Standard
140145
expect(deal.requester).to.equal(requester.address);
141-
expect(deal.beneficiary).to.equal(AddressZero);
142-
expect(deal.callback).to.equal(AddressZero);
146+
expect(deal.beneficiary).to.equal(ZeroAddress);
147+
expect(deal.callback).to.equal(ZeroAddress);
143148
expect(deal.params).to.equal('');
144149
expect(deal.startTime).to.be.greaterThan(0);
145150
expect(deal.botFirst).to.equal(0);
@@ -171,10 +176,8 @@ describe('IexecAccessors', async () => {
171176
const { dealId, taskId, taskIndex, startTime, timeRef } = await createDeal();
172177
await iexecWrapper.initializeTask(dealId, taskIndex);
173178

174-
const contributionDeadlineRatio = (
175-
await iexecPoco.contribution_deadline_ratio()
176-
).toNumber();
177-
const finalDeadlineRatio = (await iexecPoco.final_deadline_ratio()).toNumber();
179+
const contributionDeadlineRatio = Number(await iexecPoco.contribution_deadline_ratio());
180+
const finalDeadlineRatio = Number(await iexecPoco.final_deadline_ratio());
178181

179182
const task = await iexecPoco.viewTask(taskId);
180183
expect(task.status).to.equal(TaskStatusEnum.ACTIVE);
@@ -184,11 +187,11 @@ describe('IexecAccessors', async () => {
184187
expect(task.contributionDeadline).to.equal(startTime + timeRef * contributionDeadlineRatio);
185188
expect(task.revealDeadline).to.equal(0);
186189
expect(task.finalDeadline).to.equal(startTime + timeRef * finalDeadlineRatio);
187-
expect(task.consensusValue).to.equal(HashZero);
190+
expect(task.consensusValue).to.equal(ZeroHash);
188191
expect(task.revealCounter).to.equal(0);
189192
expect(task.winnerCounter).to.equal(0);
190193
expect(task.contributors.length).to.equal(0);
191-
expect(task.resultDigest).to.equal(HashZero);
194+
expect(task.resultDigest).to.equal(ZeroHash);
192195
expect(task.results).to.equal('0x');
193196
expect(task.resultsTimestamp).to.equal(0);
194197
expect(task.resultsCallback).to.equal('0x');
@@ -202,7 +205,7 @@ describe('IexecAccessors', async () => {
202205
expect(contribution.status).to.equal(ContributionStatusEnum.CONTRIBUTED);
203206
expect(contribution.resultHash.length).to.equal(66);
204207
expect(contribution.resultSeal.length).to.equal(66);
205-
expect(contribution.enclaveChallenge).to.equal(AddressZero);
208+
expect(contribution.enclaveChallenge).to.equal(ZeroAddress);
206209
expect(contribution.weight).to.equal(1);
207210
});
208211

@@ -234,7 +237,7 @@ describe('IexecAccessors', async () => {
234237
});
235238

236239
it('teeBroker', async function () {
237-
expect(await iexecPoco.teebroker()).to.equal(ethers.constants.AddressZero);
240+
expect(await iexecPoco.teebroker()).to.equal(ethers.ZeroAddress);
238241
});
239242

240243
it('callbackGas', async function () {
@@ -276,8 +279,15 @@ describe('IexecAccessors', async () => {
276279
});
277280

278281
it('eip712domainSeparator', async function () {
279-
expect(await iexecPoco.eip712domain_separator()).to.equal(
280-
'0xfc2178d8b8300e657cb9f8b5a4d1957174cf1392e294f3575b82a9cea1da1c4b',
282+
expect(await iexecPoco.eip712domain_separator()).equal(
283+
await hashDomain({
284+
// TODO use IexecWrapper.getDomain() (with some modifications).
285+
name: 'iExecODB',
286+
version: '5.0.0',
287+
chainId: (await ethers.provider.getNetwork()).chainId,
288+
// address is different between `test` and `coverage` deployment
289+
verifyingContract: proxyAddress,
290+
} as IexecLibOrders_v5.EIP712DomainStructOutput),
281291
);
282292
});
283293

@@ -300,7 +310,7 @@ describe('IexecAccessors', async () => {
300310
.then((tx) => tx.wait());
301311
const task = await iexecPoco.viewTask(taskId);
302312
expect(task.status).to.equal(TaskStatusEnum.COMPLETED);
303-
expect(await iexecPoco.callStatic.resultFor(taskId)).to.equal(resultsCallback);
313+
expect(await iexecPoco.resultFor(taskId)).to.equal(resultsCallback);
304314
});
305315

306316
it('Should not get result when task is not completed', async function () {
@@ -333,7 +343,7 @@ async function createDeal(volume: number = 1) {
333343
...orders.toArray(),
334344
);
335345
const dealCategory = (await iexecPoco.viewDeal(dealId)).category;
336-
const timeRef = (await iexecPoco.viewCategory(dealCategory)).workClockTimeRef.toNumber();
346+
const timeRef = Number((await iexecPoco.viewCategory(dealCategory)).workClockTimeRef);
337347
return { dealId, taskId, taskIndex, startTime, timeRef, orders };
338348
}
339349

test/byContract/IexecAccessors/IexecAccessorsABILegacy.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <[email protected]>
1+
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <[email protected]>
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { AddressZero } from '@ethersproject/constants';
4+
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
55
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
6-
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
76
import { expect } from 'chai';
7+
import { ZeroAddress } from 'ethers';
88
import { ethers } from 'hardhat';
99
import {
1010
IexecInterfaceNative,
@@ -176,7 +176,7 @@ describe('IexecAccessorsABILegacy', function () {
176176
expect(contribution[0]).to.equal(ContributionStatusEnum.CONTRIBUTED);
177177
expect(contribution[1]).to.equal(resultHash);
178178
expect(contribution[2]).to.equal(resultSeal);
179-
expect(contribution[3]).to.equal(AddressZero); // enclaveChallenge
179+
expect(contribution[3]).to.equal(ZeroAddress); // enclaveChallenge
180180
});
181181

182182
it('[ABILegacy] Should return category', async function () {

test/byContract/IexecMaintenance/IexecMaintenance.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <[email protected]>
1+
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <[email protected]>
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { HashZero as hashZero } from '@ethersproject/constants';
4+
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
55
import { loadFixture, setStorageAt } from '@nomicfoundation/hardhat-network-helpers';
6-
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
76
import { expect } from 'chai';
7+
import { TypedDataEncoder, ZeroHash } from 'ethers';
88
import { ethers } from 'hardhat';
99
import {
1010
IexecInterfaceNative,
@@ -120,9 +120,9 @@ describe('Maintenance', async () => {
120120
await expect(iexecPoco.importScore(worker.address)).to.be.revertedWithoutReason();
121121
});
122122
it('Should not import score when already imported', async () => {
123-
const workerScoreImportedSlot = ethers.utils.hexStripZeros(
124-
ethers.utils.keccak256(
125-
ethers.utils.defaultAbiCoder.encode(
123+
const workerScoreImportedSlot = ethers.stripZerosLeft(
124+
ethers.keccak256(
125+
ethers.AbiCoder.defaultAbiCoder().encode(
126126
['address', 'uint256'],
127127
[
128128
worker.address,
@@ -197,7 +197,7 @@ describe('Maintenance', async () => {
197197
});
198198

199199
async function clearDomainSeparator() {
200-
await setDomainSeparatorInStorage(hashZero);
200+
await setDomainSeparatorInStorage(ZeroHash);
201201
}
202202

203203
async function setDomainSeparatorInStorage(domainSeparator: string) {
@@ -211,8 +211,9 @@ describe('Maintenance', async () => {
211211
}
212212
});
213213

214-
async function hashDomain(domain: IexecLibOrders_v5.EIP712DomainStructOutput) {
215-
return ethers.utils._TypedDataEncoder.hashDomain({
214+
//TODO: Move to utils
215+
export async function hashDomain(domain: IexecLibOrders_v5.EIP712DomainStructOutput) {
216+
return TypedDataEncoder.hashDomain({
216217
name: domain.name,
217218
version: domain.version,
218219
chainId: domain.chainId,

0 commit comments

Comments
 (0)