From 92688ad24b301f6b6911a0e74c5e1a75a0f57f08 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 12 Sep 2024 08:36:31 +0200 Subject: [PATCH 1/5] remove skip file --- test/byContract/registries/registies.js.skip | 460 ------------------- 1 file changed, 460 deletions(-) delete mode 100644 test/byContract/registries/registies.js.skip diff --git a/test/byContract/registries/registies.js.skip b/test/byContract/registries/registies.js.skip deleted file mode 100644 index 94cf8d15b..000000000 --- a/test/byContract/registries/registies.js.skip +++ /dev/null @@ -1,460 +0,0 @@ -// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -const loadTruffleFixtureDeployment = require('../../../scripts/truffle-fixture-deployer'); -// Config -var DEPLOYMENT = require('../../../config/config.json').chains.default; -// Artefacts -var RLC = artifacts.require('rlc-faucet-contract/contracts/RLC'); -var ERC1538Proxy = artifacts.require('iexec-solidity/ERC1538Proxy'); -var IexecInterface = artifacts.require(`IexecInterface${DEPLOYMENT.asset}`); -var AppRegistry = artifacts.require('AppRegistry'); -var DatasetRegistry = artifacts.require('DatasetRegistry'); -var WorkerpoolRegistry = artifacts.require('WorkerpoolRegistry'); -var App = artifacts.require('App'); -var Dataset = artifacts.require('Dataset'); -var Workerpool = artifacts.require('Workerpool'); - -const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers'); -const tools = require('../../../utils/tools'); -const enstools = require('../../../utils/ens-tools'); -const odbtools = require('../../../utils/odb-tools'); -const constants = require('../../../utils/constants'); - -Object.extract = (obj, keys) => keys.map((key) => obj[key]); - -contract('Registries', async (accounts) => { - assert.isAtLeast(accounts.length, 10, 'should have at least 10 accounts'); - let iexecAdmin = null; - let appProvider = null; - let datasetProvider = null; - let scheduler = null; - let worker1 = null; - let worker2 = null; - let worker3 = null; - let worker4 = null; - let worker5 = null; - let user = null; - - var RLCInstance = null; - var IexecInstance = null; - var AppRegistryInstance = null; - var DatasetRegistryInstance = null; - var WorkerpoolRegistryInstance = null; - - var AppInstances = {}; - var DatasetInstances = {}; - var WorkerpoolInstances = {}; - - /*************************************************************************** - * Environment configuration * - ***************************************************************************/ - before('configure', async () => { - await loadTruffleFixtureDeployment(); - console.log('# web3 version:', web3.version); - - /** - * Retreive deployed contracts - */ - IexecInstance = await IexecInterface.at((await ERC1538Proxy.deployed()).address); - AppRegistryInstance = await AppRegistry.deployed(); - DatasetRegistryInstance = await DatasetRegistry.deployed(); - WorkerpoolRegistryInstance = await WorkerpoolRegistry.deployed(); - ERC712_domain = await IexecInstance.domain(); - RLCInstance = - DEPLOYMENT.asset == 'Native' - ? { address: constants.NULL.ADDRESS } - : await RLC.at(await IexecInstance.token()); - - broker = new odbtools.Broker(IexecInstance); - iexecAdmin = new odbtools.iExecAgent(IexecInstance, accounts[0]); - appProvider = new odbtools.iExecAgent(IexecInstance, accounts[1]); - datasetProvider = new odbtools.iExecAgent(IexecInstance, accounts[2]); - scheduler = new odbtools.Scheduler(IexecInstance, accounts[3]); - worker1 = new odbtools.Worker(IexecInstance, accounts[4]); - worker2 = new odbtools.Worker(IexecInstance, accounts[5]); - worker3 = new odbtools.Worker(IexecInstance, accounts[6]); - worker4 = new odbtools.Worker(IexecInstance, accounts[7]); - worker5 = new odbtools.Worker(IexecInstance, accounts[8]); - user = new odbtools.iExecAgent(IexecInstance, accounts[9]); - await broker.initialize(); - }); - - describe('Registry', async () => { - it('cannot reinitialize', async () => { - await expectRevert.unspecified(AppRegistryInstance.initialize(constants.NULL.ADDRESS)); - await expectRevert.unspecified( - DatasetRegistryInstance.initialize(constants.NULL.ADDRESS), - ); - await expectRevert.unspecified( - WorkerpoolRegistryInstance.initialize(constants.NULL.ADDRESS), - ); - }); - it('baseURI', async () => { - const chainid = await web3.eth.net.getId(); - assert.equal( - await AppRegistryInstance.baseURI(), - `https://nfts-metadata.iex.ec/app/${chainid}/`, - ); - assert.equal( - await DatasetRegistryInstance.baseURI(), - `https://nfts-metadata.iex.ec/dataset/${chainid}/`, - ); - assert.equal( - await WorkerpoolRegistryInstance.baseURI(), - `https://nfts-metadata.iex.ec/workerpool/${chainid}/`, - ); - }); - }); - - /*************************************************************************** - * TEST: App creation (by appProvider) * - ***************************************************************************/ - describe('Apps', async () => { - Array(8) - .fill() - .map((_, i) => { - describe(`app #${i}`, async () => { - it('creation', async () => { - const code = await AppRegistryInstance.proxyCode(); - const args = web3.eth.abi.encodeFunctionCall( - App.abi.find((e) => e.name == 'initialize'), - [ - 'App #' + i, - 'DOCKER', - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of app #' + i), - '0x1234', - ], - ); - const salt = web3.utils.soliditySha3( - { t: 'bytes', v: args }, - { t: 'address', v: appProvider.address }, - ); - const predictedAddress = tools.create2( - AppRegistryInstance.address, - code, - salt, - ); - - assert.equal( - await AppRegistryInstance.predictApp( - appProvider.address, - 'App #' + i, - 'DOCKER', - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of app #' + i), - '0x1234', - ), - predictedAddress, - ); - - txMined = await AppRegistryInstance.createApp( - appProvider.address, - 'App #' + i, - 'DOCKER', - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of app #' + i), - '0x1234', - { from: appProvider.address }, - ); - - events = tools.extractEvents( - txMined, - AppRegistryInstance.address, - 'Transfer', - ); - assert.equal(events[0].args.from, constants.NULL.ADDRESS); - assert.equal(events[0].args.to, appProvider.address); - assert.deepEqual(events[0].args.tokenId, web3.utils.toBN(predictedAddress)); - AppInstances[i] = await App.at(predictedAddress); - }); - - it('content', async () => { - assert.equal(await AppInstances[i].registry(), AppRegistryInstance.address); - assert.equal(await AppInstances[i].owner(), appProvider.address); - assert.equal(await AppInstances[i].m_appName(), 'App #' + i); - assert.equal(await AppInstances[i].m_appType(), 'DOCKER'); - assert.equal( - await AppInstances[i].m_appMultiaddr(), - constants.MULTIADDR_BYTES, - ); - assert.equal( - await AppInstances[i].m_appChecksum(), - web3.utils.keccak256('Content of app #' + i), - ); - assert.equal(await AppInstances[i].m_appMREnclave(), '0x1234'); - }); - - it('token details', async () => { - assert.equal( - await AppRegistryInstance.ownerOf(AppInstances[i].address), - appProvider.address, - ); - assert.equal( - await AppRegistryInstance.balanceOf(appProvider.address), - i + 1, - ); - assert.isTrue( - await AppRegistryInstance.isRegistered(AppInstances[i].address), - ); - assert.equal( - tools.BN2Address( - await AppRegistryInstance.tokenOfOwnerByIndex( - appProvider.address, - i, - ), - ), - AppInstances[i].address, - ); - assert.equal( - await AppRegistryInstance.tokenURI(AppInstances[i].address), - (await AppRegistryInstance.baseURI()) + - web3.utils.toBN(AppInstances[i].address), - ); - }); - - it('duplicate protection', async () => { - await expectRevert.unspecified( - AppRegistryInstance.createApp( - appProvider.address, - 'App #' + i, - 'DOCKER', - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of app #' + i), - '0x1234', - ), - ); - }); - }); - }); - }); - - /*************************************************************************** - * TEST: Dataset creation (by datasetProvider) * - ***************************************************************************/ - describe('Datasets', async () => { - Array(8) - .fill() - .map((_, i) => { - describe(`dataset #${i}`, async () => { - it('creation', async () => { - const code = await AppRegistryInstance.proxyCode(); - const args = web3.eth.abi.encodeFunctionCall( - Dataset.abi.find((e) => e.name == 'initialize'), - [ - 'Dataset #' + i, - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of dataset #' + i), - ], - ); - const salt = web3.utils.soliditySha3( - { t: 'bytes', v: args }, - { t: 'address', v: datasetProvider.address }, - ); - const predictedAddress = tools.create2( - DatasetRegistryInstance.address, - code, - salt, - ); - - assert.equal( - await DatasetRegistryInstance.predictDataset( - datasetProvider.address, - 'Dataset #' + i, - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of dataset #' + i), - ), - predictedAddress, - ); - - txMined = await DatasetRegistryInstance.createDataset( - datasetProvider.address, - 'Dataset #' + i, - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of dataset #' + i), - { from: datasetProvider.address }, - ); - - events = tools.extractEvents( - txMined, - DatasetRegistryInstance.address, - 'Transfer', - ); - assert.equal(events[0].args.from, constants.NULL.ADDRESS); - assert.equal(events[0].args.to, datasetProvider.address); - assert.deepEqual(events[0].args.tokenId, web3.utils.toBN(predictedAddress)); - DatasetInstances[i] = await Dataset.at(predictedAddress); - }); - - it('content', async () => { - assert.equal( - await DatasetInstances[i].registry(), - DatasetRegistryInstance.address, - ); - assert.equal(await DatasetInstances[i].owner(), datasetProvider.address); - assert.equal(await DatasetInstances[i].m_datasetName(), 'Dataset #' + i); - assert.equal( - await DatasetInstances[i].m_datasetMultiaddr(), - constants.MULTIADDR_BYTES, - ); - assert.equal( - await DatasetInstances[i].m_datasetChecksum(), - web3.utils.keccak256('Content of dataset #' + i), - ); - }); - - it('token details', async () => { - assert.equal( - await DatasetRegistryInstance.ownerOf(DatasetInstances[i].address), - datasetProvider.address, - ); - assert.equal( - await DatasetRegistryInstance.balanceOf(datasetProvider.address), - i + 1, - ); - assert.isTrue( - await DatasetRegistryInstance.isRegistered(DatasetInstances[i].address), - ); - assert.equal( - tools.BN2Address( - await DatasetRegistryInstance.tokenOfOwnerByIndex( - datasetProvider.address, - i, - ), - ), - DatasetInstances[i].address, - ); - assert.equal( - await DatasetRegistryInstance.tokenURI(DatasetInstances[i].address), - (await DatasetRegistryInstance.baseURI()) + - web3.utils.toBN(DatasetInstances[i].address), - ); - }); - - it('duplicate protection', async () => { - await expectRevert.unspecified( - DatasetRegistryInstance.createDataset( - datasetProvider.address, - 'Dataset #' + i, - constants.MULTIADDR_BYTES, - web3.utils.keccak256('Content of dataset #' + i), - ), - ); - }); - }); - }); - }); - - /*************************************************************************** - * TEST: Workerpool creation (by scheduler) * - ***************************************************************************/ - describe('Workerpools', async () => { - Array(8) - .fill() - .map((_, i) => { - describe(`workerpool #${i}`, async () => { - it('creation', async () => { - const code = await AppRegistryInstance.proxyCode(); - const args = web3.eth.abi.encodeFunctionCall( - Workerpool.abi.find((e) => e.name == 'initialize'), - ['Workerpool #' + i], - ); - const salt = web3.utils.soliditySha3( - { t: 'bytes', v: args }, - { t: 'address', v: scheduler.address }, - ); - const predictedAddress = tools.create2( - WorkerpoolRegistryInstance.address, - code, - salt, - ); - - assert.equal( - await WorkerpoolRegistryInstance.predictWorkerpool( - scheduler.address, - 'Workerpool #' + i, - ), - predictedAddress, - ); - - txMined = await WorkerpoolRegistryInstance.createWorkerpool( - scheduler.address, - 'Workerpool #' + i, - { from: scheduler.address }, - ); - - events = tools.extractEvents( - txMined, - WorkerpoolRegistryInstance.address, - 'Transfer', - ); - assert.equal(events[0].args.from, constants.NULL.ADDRESS); - assert.equal(events[0].args.to, scheduler.address); - assert.deepEqual(events[0].args.tokenId, web3.utils.toBN(predictedAddress)); - WorkerpoolInstances[i] = await Workerpool.at(predictedAddress); - }); - - it('content', async () => { - assert.equal( - await WorkerpoolInstances[i].registry(), - WorkerpoolRegistryInstance.address, - ); - assert.equal(await WorkerpoolInstances[i].owner(), scheduler.address); - assert.equal( - await WorkerpoolInstances[i].m_workerpoolDescription(), - 'Workerpool #' + i, - ); - assert.equal(await WorkerpoolInstances[i].m_workerStakeRatioPolicy(), 30); - assert.equal( - await WorkerpoolInstances[i].m_schedulerRewardRatioPolicy(), - 1, - ); - }); - - it('token details', async () => { - assert.equal( - await WorkerpoolRegistryInstance.ownerOf( - WorkerpoolInstances[i].address, - ), - scheduler.address, - ); - assert.equal( - await WorkerpoolRegistryInstance.balanceOf(scheduler.address), - i + 1, - ); - assert.isTrue( - await WorkerpoolRegistryInstance.isRegistered( - WorkerpoolInstances[i].address, - ), - ); - assert.equal( - tools.BN2Address( - await WorkerpoolRegistryInstance.tokenOfOwnerByIndex( - scheduler.address, - i, - ), - ), - WorkerpoolInstances[i].address, - ); - assert.equal( - await WorkerpoolRegistryInstance.tokenURI( - WorkerpoolInstances[i].address, - ), - (await WorkerpoolRegistryInstance.baseURI()) + - web3.utils.toBN(WorkerpoolInstances[i].address), - ); - }); - - it('duplicate protection', async () => { - await expectRevert.unspecified( - WorkerpoolRegistryInstance.createWorkerpool( - scheduler.address, - 'Workerpool #' + i, - ), - ); - }); - }); - }); - }); -}); From 94574b9a93bbf61c5724020d659d84ee9b2785c8 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 12 Sep 2024 08:38:52 +0200 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb86dff95..b8f9ea0f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Update UML class diagrams. (#112) - Generate Solidity documentation. (#111) - Migrate unit test files to Typescript & Hardhat: - - Registries (#122) + - Registries (#122, #124) - IexecPoco2 - finalize (#79, #117, #119) - reveal (#114, #118) From 29701ec3a54bc3bb23e1b5d70b7ce5a9d63532ea Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 12 Sep 2024 09:50:56 +0200 Subject: [PATCH 3/5] add check on tokenOfOwnerByIndex and tokenURI --- test/byContract/registries/registries.test.ts | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/test/byContract/registries/registries.test.ts b/test/byContract/registries/registries.test.ts index d5dbf62d8..7470ad317 100644 --- a/test/byContract/registries/registries.test.ts +++ b/test/byContract/registries/registries.test.ts @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 +import { BigNumber } from '@ethersproject/bignumber'; import { BytesLike } from '@ethersproject/bytes'; import { AddressZero } from '@ethersproject/constants'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; @@ -304,7 +305,7 @@ describe('Registries', () => { ); }); - it('Should create the app', async () => { + it('Should create the app and check token details', async () => { const initialAppBalance = await appRegistry.balanceOf(appProvider.address); expect(initialAppBalance).to.equal(0); @@ -312,7 +313,7 @@ describe('Registries', () => { appProvider.address, ...createAppArgs, ); - await expect(await appRegistry.createApp(appProvider.address, ...createAppArgs)) + await expect(appRegistry.createApp(appProvider.address, ...createAppArgs)) .to.emit(appRegistry, 'Transfer') .withArgs( AddressZero, @@ -323,6 +324,15 @@ describe('Registries', () => { initialAppBalance.add(1), ); expect(await appRegistry.ownerOf(predictedAddress)).to.equal(appProvider.address); + + const tokenAtIndex = await appRegistry.tokenOfOwnerByIndex(appProvider.address, 0); + expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( + ethers.utils.getAddress(predictedAddress), + ); + + const tokenURI = await appRegistry.tokenURI(predictedAddress); + const baseURI = await appRegistry.baseURI(); + expect(tokenURI).to.equal(baseURI + ethers.BigNumber.from(predictedAddress).toString()); }); it('Should check that a new app is well registered', async () => { @@ -399,7 +409,7 @@ describe('Registries', () => { ).to.equal(predictedAddress); }); - it('Should create the dataset', async () => { + it('Should create the dataset and check token details', async () => { const initialDatasetBalance = await datasetRegistry.balanceOf(datasetProvider.address); expect(initialDatasetBalance).to.equal(0); @@ -422,6 +432,18 @@ describe('Registries', () => { expect(await datasetRegistry.ownerOf(predictedAddress)).to.equal( datasetProvider.address, ); + + const tokenAtIndex = await datasetRegistry.tokenOfOwnerByIndex( + datasetProvider.address, + 0, + ); + expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( + ethers.utils.getAddress(predictedAddress), + ); + + const tokenURI = await datasetRegistry.tokenURI(predictedAddress); + const baseURI = await datasetRegistry.baseURI(); + expect(tokenURI).to.equal(baseURI + ethers.BigNumber.from(predictedAddress).toString()); }); it('Should check that a new dataset is well registered', async () => { @@ -479,7 +501,7 @@ describe('Registries', () => { expect(predictedAddress).to.equal(expectedAddress); }); - it('Should create the workerpool', async () => { + it('Should create the workerpool and check token details', async () => { const initialWorkerpoolBalance = await workerpoolRegistry.balanceOf(scheduler.address); expect(initialWorkerpoolBalance).to.equal(0); @@ -503,6 +525,15 @@ describe('Registries', () => { initialWorkerpoolBalance.add(1), ); expect(await workerpoolRegistry.ownerOf(predictedAddress)).to.equal(scheduler.address); + + const tokenAtIndex = await workerpoolRegistry.tokenOfOwnerByIndex(scheduler.address, 0); + expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( + ethers.utils.getAddress(predictedAddress), + ); + + const tokenURI = await workerpoolRegistry.tokenURI(predictedAddress); + const baseURI = await workerpoolRegistry.baseURI(); + expect(tokenURI).to.equal(baseURI + ethers.BigNumber.from(predictedAddress).toString()); }); it('Should check that a new workerpool is well registered', async () => { @@ -534,4 +565,10 @@ describe('Registries', () => { const computeNameHash = (address: string) => ethers.utils.namehash(`${address.substring(2)}.addr.reverse`); + + function BN2Address(n: BigNumber): string { + const hexValue = ethers.utils.hexlify(n); + const paddedHex = ethers.utils.hexZeroPad(hexValue, 20); + return ethers.utils.getAddress(paddedHex); + } }); From 1851d8ed557785efab666e4b3f124307b6f6ea54 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 12 Sep 2024 15:44:30 +0200 Subject: [PATCH 4/5] remove created BN2Address and import tools instead --- test/byContract/registries/registries.test.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/byContract/registries/registries.test.ts b/test/byContract/registries/registries.test.ts index 7470ad317..7358bfc9d 100644 --- a/test/byContract/registries/registries.test.ts +++ b/test/byContract/registries/registries.test.ts @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 -import { BigNumber } from '@ethersproject/bignumber'; import { BytesLike } from '@ethersproject/bytes'; import { AddressZero } from '@ethersproject/constants'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; @@ -29,6 +28,7 @@ import { } from '../../../typechain'; import { getIexecAccounts } from '../../../utils/poco-tools'; const constants = require('../../../utils/constants'); +const tools = require('../../../utils/tools'); const randomAddress = () => ethers.Wallet.createRandom().address; const CONFIG = require('../../../config/config.json'); @@ -326,7 +326,7 @@ describe('Registries', () => { expect(await appRegistry.ownerOf(predictedAddress)).to.equal(appProvider.address); const tokenAtIndex = await appRegistry.tokenOfOwnerByIndex(appProvider.address, 0); - expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( + expect(ethers.utils.getAddress(tools.BN2Address(tokenAtIndex))).to.equal( ethers.utils.getAddress(predictedAddress), ); @@ -437,7 +437,7 @@ describe('Registries', () => { datasetProvider.address, 0, ); - expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( + expect(ethers.utils.getAddress(tools.BN2Address(tokenAtIndex))).to.equal( ethers.utils.getAddress(predictedAddress), ); @@ -527,7 +527,7 @@ describe('Registries', () => { expect(await workerpoolRegistry.ownerOf(predictedAddress)).to.equal(scheduler.address); const tokenAtIndex = await workerpoolRegistry.tokenOfOwnerByIndex(scheduler.address, 0); - expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( + expect(ethers.utils.getAddress(tools.BN2Address(tokenAtIndex))).to.equal( ethers.utils.getAddress(predictedAddress), ); @@ -565,10 +565,4 @@ describe('Registries', () => { const computeNameHash = (address: string) => ethers.utils.namehash(`${address.substring(2)}.addr.reverse`); - - function BN2Address(n: BigNumber): string { - const hexValue = ethers.utils.hexlify(n); - const paddedHex = ethers.utils.hexZeroPad(hexValue, 20); - return ethers.utils.getAddress(paddedHex); - } }); From 291ecdb8b810b70f8bae5c3b3fadf1b52676c7ca Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 12 Sep 2024 16:41:45 +0200 Subject: [PATCH 5/5] switch from require to import and export types --- test/byContract/registries/registries.test.ts | 16 ++++++++-------- utils/constants.d.ts | 2 ++ utils/tools.d.ts | 2 ++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/byContract/registries/registries.test.ts b/test/byContract/registries/registries.test.ts index 7358bfc9d..19dca204e 100644 --- a/test/byContract/registries/registries.test.ts +++ b/test/byContract/registries/registries.test.ts @@ -6,6 +6,7 @@ import { AddressZero } from '@ethersproject/constants'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import hre, { deployments, ethers, expect } from 'hardhat'; +import CONFIG from '../../../config/config.json'; import { loadHardhatFixtureDeployment } from '../../../scripts/hardhat-fixture-deployer'; import { AppRegistry, @@ -26,11 +27,10 @@ import { WorkerpoolRegistry__factory, Workerpool__factory, } from '../../../typechain'; +import { MULTIADDR_BYTES } from '../../../utils/constants'; import { getIexecAccounts } from '../../../utils/poco-tools'; -const constants = require('../../../utils/constants'); -const tools = require('../../../utils/tools'); +import { BN2Address } from '../../../utils/tools'; const randomAddress = () => ethers.Wallet.createRandom().address; -const CONFIG = require('../../../config/config.json'); describe('Registries', () => { let proxyAddress: string; @@ -279,7 +279,7 @@ describe('Registries', () => { const createAppArgs = [ `App`, 'DOCKER', - constants.MULTIADDR_BYTES, + MULTIADDR_BYTES, ethers.utils.id(`Content of my app`), '0x1234', ] as [string, string, BytesLike, BytesLike, BytesLike]; @@ -326,7 +326,7 @@ describe('Registries', () => { expect(await appRegistry.ownerOf(predictedAddress)).to.equal(appProvider.address); const tokenAtIndex = await appRegistry.tokenOfOwnerByIndex(appProvider.address, 0); - expect(ethers.utils.getAddress(tools.BN2Address(tokenAtIndex))).to.equal( + expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( ethers.utils.getAddress(predictedAddress), ); @@ -384,7 +384,7 @@ describe('Registries', () => { describe('Dataset Registry', () => { const createDatasetArgs = [ `Dataset`, - constants.MULTIADDR_BYTES, + MULTIADDR_BYTES, ethers.utils.id(`Content of my dataset`), ] as [string, BytesLike, BytesLike]; it('Should predict the correct address for future dataset creation', async () => { @@ -437,7 +437,7 @@ describe('Registries', () => { datasetProvider.address, 0, ); - expect(ethers.utils.getAddress(tools.BN2Address(tokenAtIndex))).to.equal( + expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( ethers.utils.getAddress(predictedAddress), ); @@ -527,7 +527,7 @@ describe('Registries', () => { expect(await workerpoolRegistry.ownerOf(predictedAddress)).to.equal(scheduler.address); const tokenAtIndex = await workerpoolRegistry.tokenOfOwnerByIndex(scheduler.address, 0); - expect(ethers.utils.getAddress(tools.BN2Address(tokenAtIndex))).to.equal( + expect(ethers.utils.getAddress(BN2Address(tokenAtIndex))).to.equal( ethers.utils.getAddress(predictedAddress), ); diff --git a/utils/constants.d.ts b/utils/constants.d.ts index 3c7068c88..37441f3b4 100644 --- a/utils/constants.d.ts +++ b/utils/constants.d.ts @@ -6,3 +6,5 @@ export declare const NULL: { BYTES32: string; SIGNATURE: string; }; + +export declare const MULTIADDR_BYTES: string; diff --git a/utils/tools.d.ts b/utils/tools.d.ts index d66a35b64..81a29e778 100644 --- a/utils/tools.d.ts +++ b/utils/tools.d.ts @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2023 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 +import { BigNumber } from '@ethersproject/bignumber'; import { ContractReceipt, Event } from '@ethersproject/contracts'; export function extractEventsFromReceipt( @@ -10,3 +11,4 @@ export function extractEventsFromReceipt( ): Event[]; export function compactSignature(signature: string): string; +export function BN2Address(n: BigNumber): string;