-
Notifications
You must be signed in to change notification settings - Fork 14
Migrate ENSIntegration unit tests to Hardhat & Typescript #105
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7b43a7e
Deploy ENS in tests
zguesmi 76cf179
Migrate ens integration tests file
zguesmi 64cb3be
Merge branch 'develop' into feature/ens-integration-tests-migration
zguesmi fb589bb
Update changelog
zguesmi 14d14b3
Clean
zguesmi 30e12b5
Rename test file
zguesmi 2cd47b3
Include review
zguesmi 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
This file was deleted.
Oops, something went wrong.
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,126 @@ | ||
// 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 { deployments, ethers, expect } from 'hardhat'; | ||
import { loadHardhatFixtureDeployment } from '../../../scripts/hardhat-fixture-deployer'; | ||
import { | ||
ENSRegistry, | ||
ENSRegistry__factory, | ||
IexecInterfaceNative, | ||
IexecInterfaceNative__factory, | ||
PublicResolver__factory, | ||
ReverseRegistrar__factory, | ||
} from '../../../typechain'; | ||
import { getIexecAccounts } from '../../../utils/poco-tools'; | ||
const CONFIG = require('../../../config/config.json'); | ||
|
||
describe('ENSIntegration', () => { | ||
let proxyAddress: string; | ||
let [iexecPoco, iexecPocoAsAdmin]: IexecInterfaceNative[] = []; | ||
let [iexecAdmin, anyone]: SignerWithAddress[] = []; | ||
let ensRegistry: ENSRegistry; | ||
|
||
beforeEach('Deploy', async () => { | ||
// Deploy all contracts | ||
proxyAddress = await loadHardhatFixtureDeployment(); | ||
// Initialize test environment | ||
await loadFixture(initFixture); | ||
}); | ||
|
||
async function initFixture() { | ||
({ iexecAdmin, anyone } = await getIexecAccounts()); | ||
const ensRegistryAddress = (await deployments.get('ENSRegistry')).address; | ||
ensRegistry = ENSRegistry__factory.connect(ensRegistryAddress, anyone); | ||
iexecPoco = IexecInterfaceNative__factory.connect(proxyAddress, anyone); | ||
iexecPocoAsAdmin = iexecPoco.connect(iexecAdmin); | ||
} | ||
|
||
describe('Forward resolution', () => { | ||
it('Should resolve initial names', async () => { | ||
gfournieriExec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (CONFIG.chains.default.asset === 'Token') { | ||
expect(await resolve('rlc.iexec.eth')).to.equal(await iexecPoco.token()); | ||
} | ||
expect(await resolve('admin.iexec.eth')).to.equal(iexecAdmin.address); | ||
expect(await resolve('core.v5.iexec.eth')).to.equal(proxyAddress); | ||
expect(await resolve('apps.v5.iexec.eth')).to.equal(await iexecPoco.appregistry()); | ||
expect(await resolve('datasets.v5.iexec.eth')).to.equal( | ||
await iexecPoco.datasetregistry(), | ||
); | ||
expect(await resolve('workerpools.v5.iexec.eth')).to.equal( | ||
await iexecPoco.workerpoolregistry(), | ||
); | ||
}); | ||
}); | ||
|
||
describe('Reverse resolution', () => { | ||
it('Should lookup initial addresses', async () => { | ||
expect(await lookup(iexecAdmin.address)).to.equal('admin.iexec.eth'); | ||
expect(await lookup(proxyAddress)).to.equal('core.v5.iexec.eth'); | ||
expect(await lookup(await iexecPoco.appregistry())).to.equal('apps.v5.iexec.eth'); | ||
expect(await lookup(await iexecPoco.datasetregistry())).to.equal( | ||
'datasets.v5.iexec.eth', | ||
); | ||
expect(await lookup(await iexecPoco.workerpoolregistry())).to.equal( | ||
'workerpools.v5.iexec.eth', | ||
); | ||
}); | ||
|
||
it('Should register reverse resolution name', async () => { | ||
const name = 'test.domain.eth'; | ||
const reverseNameHash = ethers.utils.namehash( | ||
`${proxyAddress.substring(2)}.addr.reverse`, | ||
); | ||
const reverseRootNameHash = ethers.utils.namehash('addr.reverse'); | ||
const reverseRegistrarAddress = await ensRegistry.owner(reverseRootNameHash); | ||
const reverseResolverAddress = await ReverseRegistrar__factory.connect( | ||
reverseRegistrarAddress, | ||
anyone, | ||
).defaultResolver(); | ||
const reverseResolver = PublicResolver__factory.connect(reverseResolverAddress, anyone); | ||
await expect(iexecPocoAsAdmin.setName(ensRegistry.address, name)) | ||
.to.emit(reverseResolver, 'NameChanged') | ||
.withArgs(reverseNameHash, name); | ||
expect(await lookup(proxyAddress)).to.equal(name); | ||
}); | ||
|
||
it('Should not register reverse resolution name when sender is not the owner', async () => { | ||
await expect( | ||
iexecPoco.setName(ensRegistry.address, 'some.name.eth'), | ||
).to.be.revertedWith('Ownable: caller is not the owner'); | ||
}); | ||
}); | ||
|
||
/** | ||
* Get the address associated to the given ENS name using forward resolution. | ||
* @param domain ENS domain name | ||
* @returns ETH address | ||
*/ | ||
async function resolve(domain: string) { | ||
const nameHash = ethers.utils.namehash(domain); | ||
const resolver = await getResolver(nameHash); | ||
return await resolver['addr(bytes32)'](nameHash); | ||
gfournieriExec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Get the primary ENS name associated to the given address using reverse resolution. | ||
* @param address | ||
* @returns ENS name | ||
*/ | ||
async function lookup(address: string) { | ||
const nameHash = ethers.utils.namehash(`${address.substring(2)}.addr.reverse`); | ||
const reverseResolver = await getResolver(nameHash); | ||
return await reverseResolver.name(nameHash); | ||
} | ||
|
||
/** | ||
* Get resolver contract of the given name hash. | ||
* @param nameHash namehash of the domain name | ||
* @returns PublicResolver instance | ||
*/ | ||
async function getResolver(nameHash: string) { | ||
const resolverAddress = await ensRegistry.resolver(nameHash); | ||
return PublicResolver__factory.connect(resolverAddress, anyone); | ||
} | ||
}); |
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.