Skip to content

Commit

Permalink
type tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Oct 6, 2024
1 parent 6a2381f commit 6e15e59
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions test/utils/TestMigrationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { loadFixture } from '@nomicfoundation/hardhat-toolbox-viem/network-helpe
import { expect } from 'chai'
import hre from 'hardhat'
import {
Address,
encodeFunctionData,
hexToBigInt,
labelhash,
namehash,
Expand All @@ -26,7 +24,6 @@ const getAccounts = async () => {
}

async function fixture() {
const publicClient = await hre.viem.getPublicClient()
const accounts = await getAccounts()
const ensRegistry = await hre.viem.deployContract('ENSRegistry', [])
const baseRegistrar = await hre.viem.deployContract(
Expand Down Expand Up @@ -109,9 +106,15 @@ describe('MigrationHelper', () => {
it('should refuse to migrate unwrapped names to the zero address', async () => {
const { baseRegistrar, migrationHelper, registrantAccount } =
await loadFixture(fixture)
const ids = [labelhash('test'), labelhash('test2')]
const ids = [labelhash('test'), labelhash('test2')].map((v) =>
hexToBigInt(v),
)
for (let id of ids) {
await baseRegistrar.write.register([id, registrantAccount.address, 86400])
await baseRegistrar.write.register([
id,
registrantAccount.address,
86400n,
])
}
await baseRegistrar.write.setApprovalForAll(
[migrationHelper.address, true],
Expand All @@ -129,9 +132,15 @@ describe('MigrationHelper', () => {
it('should migrate unwrapped names', async () => {
const { baseRegistrar, migrationHelper, ownerAccount, registrantAccount } =
await loadFixture(fixture)
const ids = [labelhash('test'), labelhash('test2')]
const ids = [labelhash('test'), labelhash('test2')].map((v) =>
hexToBigInt(v),
)
for (let id of ids) {
await baseRegistrar.write.register([id, registrantAccount.address, 86400])
await baseRegistrar.write.register([
id,
registrantAccount.address,
86400n,
])
}
await baseRegistrar.write.setApprovalForAll(
[migrationHelper.address, true],
Expand All @@ -143,11 +152,11 @@ describe('MigrationHelper', () => {
ids,
stringToHex('test'),
])
expect(migrationHelper)
await expect(migrationHelper)
.transaction(tx)
.toEmitEventFrom(baseRegistrar, 'Transfer')
.withArgs(registrantAccount.address, ownerAccount.address, ids[0])
expect(migrationHelper)
await expect(migrationHelper)
.transaction(tx)
.toEmitEventFrom(baseRegistrar, 'Transfer')
.withArgs(registrantAccount.address, ownerAccount.address, ids[1])
Expand All @@ -156,9 +165,15 @@ describe('MigrationHelper', () => {
it('should only allow controllers to migrate unwrapped names', async () => {
const { baseRegistrar, migrationHelper, ownerAccount, registrantAccount } =
await loadFixture(fixture)
const ids = [labelhash('test'), labelhash('test2')]
const ids = [labelhash('test'), labelhash('test2')].map((v) =>
hexToBigInt(v),
)
for (let id of ids) {
await baseRegistrar.write.register([id, registrantAccount.address, 86400])
await baseRegistrar.write.register([
id,
registrantAccount.address,
86400n,
])
}
await migrationHelper.write.setMigrationTarget([ownerAccount.address])
await baseRegistrar.write.setApprovalForAll(
Expand All @@ -178,12 +193,12 @@ describe('MigrationHelper', () => {
const { nameWrapper, migrationHelper, ownerAccount, registrantAccount } =
await loadFixture(fixture)
const labels = ['test', 'test2']
const ids = labels.map((label) => namehash(label + '.eth'))
const ids = labels.map((label) => hexToBigInt(namehash(label + '.eth')))
for (let label of labels) {
await nameWrapper.write.registerAndWrapETH2LD([
label,
registrantAccount.address,
86400,
86400n,
zeroAddress,
0,
])
Expand All @@ -204,20 +219,20 @@ describe('MigrationHelper', () => {
registrantAccount.address,
ownerAccount.address,
ids,
ids.map(() => 1),
ids.map(() => 1n),
)
})

it('should refuse to migrate wrapped names to the zero address', async () => {
const { nameWrapper, migrationHelper, ownerAccount, registrantAccount } =
const { nameWrapper, migrationHelper, registrantAccount } =
await loadFixture(fixture)
const labels = ['test', 'test2']
const ids = labels.map((label) => namehash(label + '.eth'))
const ids = labels.map((label) => hexToBigInt(namehash(label + '.eth')))
for (let label of labels) {
await nameWrapper.write.registerAndWrapETH2LD([
label,
registrantAccount.address,
86400,
86400n,
zeroAddress,
0,
])
Expand All @@ -238,12 +253,12 @@ describe('MigrationHelper', () => {
const { nameWrapper, migrationHelper, ownerAccount, registrantAccount } =
await loadFixture(fixture)
const labels = ['test', 'test2']
const ids = labels.map((label) => namehash(label + '.eth'))
const ids = labels.map((label) => hexToBigInt(namehash(label + '.eth')))
for (let label of labels) {
await nameWrapper.write.registerAndWrapETH2LD([
label,
registrantAccount.address,
86400,
86400n,
zeroAddress,
0,
])
Expand Down

0 comments on commit 6e15e59

Please sign in to comment.