Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
run: npm run build
- name: Check storage layout
run: npm run test-storage-layout
# TODO: Remove before merging to develop
- name: Run test
run: npm run test test/byContract/IexecAccessors/**
- name: Run deployment
# Basic deployment to make sure everything is ok.
# Could be removed in the future if not relevant.
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
### Features
- Migrate to Ethers v6:
- Deployment scripts (#187)
- Tests
- IexecAccessors (#189)
- Migrate scripts to TypeScript: (#184)
- `getFunctionSignatures.js`, `common-test-snapshot.js`, `test-storage.js`, `timelock.js`
- Migrated utility files to TypeScript : (#183)
Expand Down
46 changes: 28 additions & 18 deletions test/byContract/IexecAccessors/IexecAccessors.test.ts
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,
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand All @@ -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);
});

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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),
);
});

Expand All @@ -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 () {
Expand Down Expand Up @@ -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 };
}

Expand Down
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,
Expand Down Expand Up @@ -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 () {
Expand Down
19 changes: 10 additions & 9 deletions test/byContract/IexecMaintenance/IexecMaintenance.test.ts
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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('Maintenance', async () => {
});

async function clearDomainSeparator() {
await setDomainSeparatorInStorage(hashZero);
await setDomainSeparatorInStorage(ZeroHash);
}

async function setDomainSeparatorInStorage(domainSeparator: string) {
Expand All @@ -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,
Expand Down
Loading
Loading