-
Notifications
You must be signed in to change notification settings - Fork 14
Migrate IexecMaintenance unit tests #100
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 4 commits into
develop
from
feature/migrate-maintenance-unit-tests
Aug 5, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { HashZero as hashZero } from '@ethersproject/constants'; | ||
import { loadFixture, setStorageAt } from '@nomicfoundation/hardhat-network-helpers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import { ethers, expect } from 'hardhat'; | ||
import { loadHardhatFixtureDeployment } from '../../../scripts/hardhat-fixture-deployer'; | ||
import { | ||
IexecInterfaceNative, | ||
IexecInterfaceNative__factory, | ||
IexecLibOrders_v5, | ||
IexecMaintenanceExtra, | ||
IexecMaintenanceExtra__factory, | ||
} from '../../../typechain'; | ||
import { getIexecAccounts } from '../../../utils/poco-tools'; | ||
|
||
const randomAddress = () => ethers.Wallet.createRandom().address; | ||
const configureParams = { | ||
token: randomAddress(), | ||
name: 'some name', | ||
symbol: 'some symbol', | ||
decimals: 100, | ||
appregistry: randomAddress(), | ||
datasetregistry: randomAddress(), | ||
workerpoolregistry: randomAddress(), | ||
m_v3_iexecHub: randomAddress(), | ||
}; | ||
const configureArgs = Object.values(configureParams) as [ | ||
string, | ||
string, | ||
string, | ||
number, | ||
string, | ||
string, | ||
string, | ||
string, | ||
]; | ||
const someDomainSeparator = '0x0000000000000000000000000000000000000000000000000000000000000001'; | ||
|
||
describe('Maintenance', async () => { | ||
let proxyAddress: string; | ||
let [iexecPoco, iexecPocoAsAdmin]: IexecInterfaceNative[] = []; | ||
let iexecMaintenanceExtra: IexecMaintenanceExtra; | ||
let [iexecAdmin, anyone]: SignerWithAddress[] = []; | ||
|
||
beforeEach('Deploy', async () => { | ||
proxyAddress = await loadHardhatFixtureDeployment(); | ||
await loadFixture(initFixture); | ||
}); | ||
|
||
async function initFixture() { | ||
const accounts = await getIexecAccounts(); | ||
({ iexecAdmin, anyone } = accounts); | ||
iexecPoco = IexecInterfaceNative__factory.connect(proxyAddress, anyone); | ||
iexecPocoAsAdmin = iexecPoco.connect(iexecAdmin); | ||
iexecMaintenanceExtra = IexecMaintenanceExtra__factory.connect(proxyAddress, anyone); | ||
} | ||
|
||
describe('Configure', () => { | ||
it('Should configure', async () => { | ||
await clearDomainSeparator(); | ||
await iexecPocoAsAdmin.configure(...configureArgs).then((tx) => tx.wait()); | ||
expect(await iexecPoco.eip712domain_separator()).equal( | ||
await hashDomain(await iexecPoco.domain()), | ||
); | ||
expect(await iexecPoco.token()).equal(configureParams.token); | ||
expect(await iexecPoco.name()).equal(configureParams.name); | ||
expect(await iexecPoco.symbol()).equal(configureParams.symbol); | ||
expect(await iexecPoco.decimals()).equal(configureParams.decimals); | ||
expect(await iexecPoco.appregistry()).equal(configureParams.appregistry); | ||
expect(await iexecPoco.datasetregistry()).equal(configureParams.datasetregistry); | ||
expect(await iexecPoco.workerpoolregistry()).equal(configureParams.workerpoolregistry); | ||
// no getter for m_v3_iexecHub | ||
expect(await iexecPoco.callbackgas()).equal(100000); | ||
}); | ||
it('Should not configure when sender is not owner', async () => { | ||
await expect(iexecPoco.configure(...configureArgs)).to.be.revertedWith( | ||
'Ownable: caller is not the owner', | ||
); | ||
}); | ||
it('Should not configure when already configured', async () => { | ||
await expect(iexecPocoAsAdmin.configure(...configureArgs)).to.be.revertedWith( | ||
'already-configured', | ||
); | ||
}); | ||
}); | ||
|
||
describe('Get domain', () => { | ||
it('Should get domain', async () => { | ||
const domain = await iexecPoco.domain(); | ||
expect(domain.name).equal('iExecODB'); | ||
expect(domain.version).equal('5.0.0'); | ||
expect(domain.chainId).equal((await ethers.provider.getNetwork()).chainId); | ||
expect(domain.verifyingContract).equal(proxyAddress); | ||
}); | ||
}); | ||
|
||
describe('Update domain separator', () => { | ||
it('Should update domain separator', async () => { | ||
await setDomainSeparatorInStorage(someDomainSeparator); | ||
expect(await iexecPoco.eip712domain_separator()).equal(someDomainSeparator); | ||
await iexecPoco.updateDomainSeparator().then((tx) => tx.wait()); | ||
expect(await iexecPoco.eip712domain_separator()).equal( | ||
await hashDomain(await iexecPoco.domain()), | ||
); | ||
}); | ||
it('Should not update domain separator when not configured', async () => { | ||
await clearDomainSeparator(); | ||
await expect(iexecPoco.updateDomainSeparator()).to.be.revertedWith('not-configured'); | ||
}); | ||
}); | ||
|
||
describe('Import score', () => { | ||
// Not tested | ||
}); | ||
|
||
describe('Set TEE broker', () => { | ||
it('Should set TEE broker', async () => { | ||
const teeBrokerAddress = randomAddress(); | ||
await iexecPocoAsAdmin.setTeeBroker(teeBrokerAddress).then((tx) => tx.wait()); | ||
expect(await iexecPoco.teebroker()).equal(teeBrokerAddress); | ||
}); | ||
|
||
it('Should not set TEE broker when sender is not the owner', async () => { | ||
await expect(iexecPoco.setTeeBroker(randomAddress())).to.be.revertedWith( | ||
'Ownable: caller is not the owner', | ||
); | ||
}); | ||
}); | ||
|
||
describe('Set callback gas', () => { | ||
const callbackGas = 1; | ||
|
||
it('Should set callback gas', async () => { | ||
await iexecPocoAsAdmin.setCallbackGas(callbackGas).then((tx) => tx.wait()); | ||
expect(await iexecPoco.callbackgas()).equal(callbackGas); | ||
}); | ||
|
||
it('Should not set callback gas when sender is not the owner', async () => { | ||
await expect(iexecPoco.setCallbackGas(callbackGas)).to.be.revertedWith( | ||
'Ownable: caller is not the owner', | ||
); | ||
}); | ||
}); | ||
|
||
describe('Change registries', () => { | ||
it('Should change registries', async () => { | ||
const appRegistry = randomAddress(); | ||
const datasetRegistry = randomAddress(); | ||
const workerpoolRegistry = randomAddress(); | ||
await iexecMaintenanceExtra | ||
.connect(iexecAdmin) | ||
.changeRegistries(appRegistry, datasetRegistry, workerpoolRegistry) | ||
.then((tx) => tx.wait()); | ||
expect(await iexecPoco.appregistry()).equal(appRegistry); | ||
expect(await iexecPoco.datasetregistry()).equal(datasetRegistry); | ||
expect(await iexecPoco.workerpoolregistry()).equal(workerpoolRegistry); | ||
}); | ||
|
||
it('Should not change registries when sender is not the owner', async () => { | ||
await expect( | ||
iexecMaintenanceExtra.changeRegistries( | ||
randomAddress(), | ||
randomAddress(), | ||
randomAddress(), | ||
), | ||
).to.be.revertedWith('Ownable: caller is not the owner'); | ||
}); | ||
}); | ||
|
||
async function clearDomainSeparator() { | ||
await setDomainSeparatorInStorage(hashZero); | ||
} | ||
|
||
async function setDomainSeparatorInStorage(domainSeparator: string) { | ||
await setStorageAt( | ||
proxyAddress, | ||
'0x10', // Slot index of EIP712DOMAIN_SEPARATOR in Store | ||
domainSeparator, | ||
); | ||
// Double check the update of the domain separator happened | ||
expect(await iexecPoco.eip712domain_separator()).equal(domainSeparator); | ||
} | ||
}); | ||
|
||
async function hashDomain(domain: IexecLibOrders_v5.EIP712DomainStructOutput) { | ||
return ethers.utils._TypedDataEncoder.hashDomain({ | ||
name: domain.name, | ||
version: domain.version, | ||
chainId: domain.chainId, | ||
verifyingContract: domain.verifyingContract, | ||
}); | ||
} |
This file was deleted.
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.