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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog

## vNEXT
- Migrate IexecAccessors tests Typescript & Hardhat. (#96)
- Migrate unit test files to Typescript & Hardhat:
- IexecCategoryManager (#97)
- IexecAccessors (#96)
- Wait for transactions occurring during deployment. (#95)
- Deploy and configure ENS with hardhat. (#93)
- Fix contribute & finalize with callbacks. (#92)
Expand Down
6 changes: 1 addition & 5 deletions deploy/0_deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ import {
import { Ownable__factory } from '../typechain/factories/@openzeppelin/contracts/access';
import { FactoryDeployerHelper } from '../utils/FactoryDeployerHelper';
import { getBaseNameFromContractFactory } from '../utils/deploy-tools';
interface Category {
name: string;
description: string;
workClockTimeRef: number;
}
import { Category } from '../utils/poco-tools';
const CONFIG = require('../config/config.json');

/**
Expand Down
142 changes: 0 additions & 142 deletions test/byContract/IexecCategoryManager/IexecCategoryManager.js

This file was deleted.

72 changes: 72 additions & 0 deletions test/byContract/IexecCategoryManager/IexecCategoryManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-License-Identifier: Apache-2.0

import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
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 { Category, getIexecAccounts } from '../../../utils/poco-tools';
const CONFIG = require('../../../config/config.json');

const name = 'name';
const description = 'description';
const timeRef = 100;
const args = [name, description, timeRef] as [string, string, number];

describe('CategoryManager', async () => {
let proxyAddress: string;
let [iexecPoco, iexecPocoAsAnyone]: IexecInterfaceNative[] = [];
let [iexecAdmin, anyone]: SignerWithAddress[] = [];

beforeEach('Deploy', async () => {
// Deploy all contracts
proxyAddress = await loadHardhatFixtureDeployment();
// Initialize test environment
await loadFixture(initFixture);
});

async function initFixture() {
const accounts = await getIexecAccounts();
({ iexecAdmin, anyone } = accounts);
iexecPoco = IexecInterfaceNative__factory.connect(proxyAddress, iexecAdmin);
iexecPocoAsAnyone = iexecPoco.connect(anyone);
}

it('Should view categories', async () => {
const categories = CONFIG.categories as Category[];
for (let i = 0; i < categories.length; i++) {
const expectedCategory = categories[i];
const category = await iexecPocoAsAnyone.viewCategory(i);
expect(category.name).to.equal(expectedCategory.name);
expect(category.description).to.equal(JSON.stringify(expectedCategory.description));
expect(category.workClockTimeRef).to.equal(expectedCategory.workClockTimeRef);
}
});

it('Should not view category with bad index', async () => {
const lastCategoryIndex = (await iexecPocoAsAnyone.countCategory()).toNumber() - 1;
await expect(
iexecPocoAsAnyone.viewCategory(lastCategoryIndex + 1),
).to.be.revertedWithoutReason();
});

it('Should create category', async () => {
const newCategoryIndex = 5;
expect(await iexecPoco.callStatic.createCategory(...args)).to.equal(newCategoryIndex);
await expect(iexecPoco.createCategory(...args))
.to.emit(iexecPoco, 'CreateCategory')
.withArgs(newCategoryIndex, name, description, timeRef);
expect(await iexecPocoAsAnyone.countCategory()).to.equal(6);
const category = await iexecPocoAsAnyone.viewCategory(newCategoryIndex);
expect(category.name).to.equal(name);
expect(category.description).to.equal(description);
expect(category.workClockTimeRef).to.equal(timeRef);
});

it('Should not create category when sender not authorized', async () => {
await expect(iexecPocoAsAnyone.createCategory(...args)).to.be.revertedWith(
'Ownable: caller is not the owner',
);
});
});
8 changes: 7 additions & 1 deletion utils/poco-tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-FileCopyrightText: 2023-2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-License-Identifier: Apache-2.0

import { TypedDataDomain } from '@ethersproject/abstract-signer';
Expand All @@ -8,6 +8,12 @@ import { ethers } from 'hardhat';
import { IexecLibOrders_v5 } from '../typechain';
import { hashOrder } from './createOrders';

export interface Category {
name: string;
description: string;
workClockTimeRef: number;
}

export enum TaskStatusEnum {
UNSET,
ACTIVE,
Expand Down