Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed May 23, 2024
1 parent 2b7bae3 commit 657428a
Show file tree
Hide file tree
Showing 15 changed files with 2,747 additions and 54 deletions.
Binary file modified bun.lockb
Binary file not shown.
8 changes: 7 additions & 1 deletion hardhat.config.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import '@nomicfoundation/hardhat-toolbox-viem'
// from @nomicfoundation/hardhat-toolbox-viem to avoid module issue
import '@nomicfoundation/hardhat-ignition-viem'
import '@nomicfoundation/hardhat-verify'
import '@nomicfoundation/hardhat-viem'
import 'hardhat-gas-reporter'
import 'solidity-coverage'

import dotenv from 'dotenv'
import 'hardhat-abi-exporter'
import 'hardhat-contract-sizer'
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"compile": "NODE_OPTIONS=\"--experimental-loader ts-node/esm/transpile-only\" hardhat compile",
"test": "NODE_OPTIONS=\"--experimental-loader ts-node/esm/transpile-only\" TS_NODE_PREFER_TS_EXTS=true hardhat test ./test/ethregistrar/TestStablePriceOracle.ts",
"test": "NODE_OPTIONS=\"--experimental-loader ts-node/esm/transpile-only\" TS_NODE_PREFER_TS_EXTS=true hardhat test ./test/root/TestRoot.ts",
"test:parallel": "NODE_OPTIONS=\"--experimental-loader ts-node/esm/transpile-only\" TS_NODE_PREFER_TS_EXTS=true hardhat test ./test/**/Test*.ts --parallel",
"test:local": "hardhat --network localhost test",
"test:deploy": "hardhat --network hardhat deploy",
Expand All @@ -28,14 +28,14 @@
"main": "index.js",
"devDependencies": {
"@ensdomains/dnsprovejs": "^0.3.7",
"@ensdomains/hardhat-chai-matchers-viem": "^0.0.1",
"@ensdomains/hardhat-chai-matchers-viem": "^0.0.4",
"@ensdomains/test-utils": "^1.3.0",
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
"@openzeppelin/test-helpers": "^0.5.11",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.0",
"@vitest/expect": "^1.6.0",
"chai": "^4.3.4",
"chai": "^5.1.1",
"dotenv": "^16.4.5",
"elliptic-solidity": "^1.0.0",
"envfile": "^6.17.0",
Expand All @@ -52,7 +52,7 @@
"rfc4648": "^1.5.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"viem": "^2.10.2"
"viem": "^2.12.0"
},
"resolutions": {
"ethereum-ens": "0.8.0",
Expand Down
31 changes: 12 additions & 19 deletions test/ethregistrar/TestBaseRegistrar.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { loadFixture } from '@nomicfoundation/hardhat-toolbox-viem/network-helpers.js'
import { expect } from 'chai'
import hre from 'hardhat'
import {
getAddress,
hexToBigInt,
labelhash,
namehash,
zeroAddress,
zeroHash,
} from 'viem'
import { hexToBigInt, labelhash, namehash, zeroAddress, zeroHash } from 'viem'

const getAccounts = async () => {
const [ownerClient, controllerClient, registrantClient, otherClient] =
Expand Down Expand Up @@ -78,10 +71,10 @@ describe('BaseRegistrar', () => {

await expect(
ensRegistry.read.owner([namehash('newname.eth')]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)
await expect(
baseRegistrar.read.ownerOf([labelId('newname')]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)
await expect(
baseRegistrar.read.nameExpires([labelId('newname')]),
).resolves.toEqual(block.timestamp + 86400n)
Expand All @@ -107,10 +100,10 @@ describe('BaseRegistrar', () => {

await expect(
ensRegistry.read.owner([namehash('silentname.eth')]),
).resolves.toEqual(zeroAddress)
).resolves.toEqualAddress(zeroAddress)
await expect(
baseRegistrar.read.ownerOf([labelId('silentname')]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)
await expect(
baseRegistrar.read.nameExpires([labelId('silentname')]),
).resolves.toEqual(block.timestamp + 86400n)
Expand Down Expand Up @@ -196,7 +189,7 @@ describe('BaseRegistrar', () => {

await expect(
ensRegistry.read.owner([namehash('newname.eth')]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)
})

it('should prohibit anyone else from reclaiming a name', async () => {
Expand Down Expand Up @@ -227,10 +220,10 @@ describe('BaseRegistrar', () => {

await expect(
baseRegistrar.read.ownerOf([labelId('newname')]),
).resolves.toEqual(getAddress(otherAccount.address))
).resolves.toEqualAddress(otherAccount.address)
await expect(
ensRegistry.read.owner([namehash('newname.eth')]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)

await baseRegistrar.write.transferFrom(
[otherAccount.address, registrantAccount.address, labelId('newname')],
Expand Down Expand Up @@ -320,7 +313,7 @@ describe('BaseRegistrar', () => {

await expect(
baseRegistrar.read.ownerOf([labelId('newname')]),
).resolves.toEqual(getAddress(otherAccount.address))
).resolves.toEqualAddress(otherAccount.address)
})

it('should allow the owner to set a resolver address', async () => {
Expand All @@ -331,8 +324,8 @@ describe('BaseRegistrar', () => {
account: ownerAccount,
})

await expect(ensRegistry.read.resolver([namehash('eth')])).resolves.toEqual(
getAddress(controllerAccount.address),
)
await expect(
ensRegistry.read.resolver([namehash('eth')]),
).resolves.toEqualAddress(controllerAccount.address)
})
})
57 changes: 28 additions & 29 deletions test/ethregistrar/TestEthRegistrarController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import hre from 'hardhat'
import {
Address,
encodeFunctionData,
getAddress,
hexToBigInt,
labelhash,
namehash,
zeroAddress,
zeroHash,
} from 'viem'
import { getReverseNode } from '../fixtures/getReverseNode.js'
import {
commitName,
getDefaultRegistrationOptions,
Expand Down Expand Up @@ -51,7 +51,6 @@ const getAccounts = async () => {
}

const labelId = (label: string) => hexToBigInt(labelhash(label))
const getReverseNode = (address: Address) => `${address.slice(2)}.addr.reverse`

async function fixture() {
const publicClient = await hre.viem.getPublicClient()
Expand Down Expand Up @@ -294,24 +293,24 @@ describe('ETHRegistrarController', () => {
).resolves.toEqual(REGISTRATION_TIME)

const nodehash = namehash('newconfigname.eth')
await expect(ensRegistry.read.resolver([nodehash])).resolves.toEqual(
getAddress(publicResolver.address),
await expect(ensRegistry.read.resolver([nodehash])).resolves.toEqualAddress(
publicResolver.address,
)
await expect(ensRegistry.read.owner([nodehash])).resolves.toEqual(
getAddress(nameWrapper.address),
await expect(ensRegistry.read.owner([nodehash])).resolves.toEqualAddress(
nameWrapper.address,
)
await expect(
baseRegistrar.read.ownerOf([labelId('newconfigname')]),
).resolves.toEqual(getAddress(nameWrapper.address))
).resolves.toEqualAddress(nameWrapper.address)
await expect(
publicResolver.read.addr([nodehash]) as Promise<Address>,
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)
await expect(publicResolver.read.text([nodehash, 'url'])).resolves.toEqual(
'ethereum.com',
)
await expect(
nameWrapper.read.ownerOf([hexToBigInt(nodehash)]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)
})

it('should not permit new registrations with data and 0 resolver', async () => {
Expand Down Expand Up @@ -466,8 +465,8 @@ describe('ETHRegistrarController', () => {
)

const nodehash = namehash('newconfigname.eth')
await expect(ensRegistry.read.resolver([nodehash])).resolves.toEqual(
getAddress(publicResolver.address),
await expect(ensRegistry.read.resolver([nodehash])).resolves.toEqualAddress(
publicResolver.address,
)
await expect<Promise<Address>>(
publicResolver.read.addr([nodehash]),
Expand Down Expand Up @@ -679,8 +678,8 @@ describe('ETHRegistrarController', () => {
await expect(
nameWrapper.read.ownerOf([hexToBigInt(nodehash)]),
).resolves.toEqual(zeroAddress)
await expect(baseRegistrar.read.ownerOf([tokenId])).resolves.toEqual(
getAddress(ownerAccount.address),
await expect(baseRegistrar.read.ownerOf([tokenId])).resolves.toEqualAddress(
ownerAccount.address,
)

const expires = await baseRegistrar.read.nameExpires([tokenId])
Expand All @@ -692,8 +691,8 @@ describe('ETHRegistrarController', () => {
value: price,
})

await expect(baseRegistrar.read.ownerOf([tokenId])).resolves.toEqual(
getAddress(ownerAccount.address),
await expect(baseRegistrar.read.ownerOf([tokenId])).resolves.toEqualAddress(
ownerAccount.address,
)
await expect(
nameWrapper.read.ownerOf([hexToBigInt(nodehash)]),
Expand Down Expand Up @@ -800,14 +799,14 @@ describe('ETHRegistrarController', () => {

await expect(
nameWrapper.read.ownerOf([hexToBigInt(namehash(name))]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)

await expect(ensRegistry.read.owner([namehash(name)])).resolves.toEqual(
getAddress(nameWrapper.address),
)
await expect(baseRegistrar.read.ownerOf([labelId(label)])).resolves.toEqual(
getAddress(nameWrapper.address),
)
await expect(
ensRegistry.read.owner([namehash(name)]),
).resolves.toEqualAddress(nameWrapper.address)
await expect(
baseRegistrar.read.ownerOf([labelId(label)]),
).resolves.toEqualAddress(nameWrapper.address)
})

it('should auto wrap the name and allow fuses and expiry to be set', async () => {
Expand Down Expand Up @@ -904,16 +903,16 @@ describe('ETHRegistrarController', () => {

await expect(
nameWrapper.read.ownerOf([hexToBigInt(node)]),
).resolves.toEqual(getAddress(registrantAccount.address))
await expect(ensRegistry.read.owner([node])).resolves.toEqual(
getAddress(nameWrapper.address),
)
await expect(baseRegistrar.read.ownerOf([labelId(label)])).resolves.toEqual(
getAddress(nameWrapper.address),
).resolves.toEqualAddress(registrantAccount.address)
await expect(ensRegistry.read.owner([node])).resolves.toEqualAddress(
nameWrapper.address,
)
await expect(
baseRegistrar.read.ownerOf([labelId(label)]),
).resolves.toEqualAddress(nameWrapper.address)
await expect<Promise<Address>>(
publicResolver.read.addr([node]),
).resolves.toEqual(getAddress(registrantAccount.address))
).resolves.toEqualAddress(registrantAccount.address)
})

it('should not permit new registrations with non resolver function calls', async () => {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/getReverseNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { namehash, type Address } from 'viem'

export const getReverseNode = (address: Address) =>
`${address.slice(2)}.addr.reverse`

export const getReverseNodeHash = (address: Address) =>
namehash(getReverseNode(address))
2 changes: 1 addition & 1 deletion test/fixtures/registerName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import hre from 'hardhat'
import { Address, Hex, zeroAddress } from 'viem'
import { EnsStack } from './deployEnsFixture.js'

type Mutable<T> = {
export type Mutable<T> = {
-readonly [K in keyof T]: Mutable<T[K]>
}

Expand Down
107 changes: 107 additions & 0 deletions test/registry/TestENS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { loadFixture } from '@nomicfoundation/hardhat-toolbox-viem/network-helpers.js'
import { expect } from 'chai'
import hre from 'hardhat'
import { labelhash, namehash, padHex, zeroHash } from 'viem'

const placeholderAddr = padHex('0x1234', { size: 20 })

async function fixture() {
const accounts = await hre.viem
.getWalletClients()
.then((clients) => clients.map((c) => c.account))
const ensRegistry = await hre.viem.deployContract('ENSRegistry', [])

return { ensRegistry, accounts }
}

describe('ENSRegistry', () => {
it('should allow ownership transfers', async () => {
const { ensRegistry } = await loadFixture(fixture)

await expect(ensRegistry)
.write('setOwner', [zeroHash, placeholderAddr])
.toEmitEvent('Transfer')
.withArgs(zeroHash, placeholderAddr)

await expect(ensRegistry.read.owner([zeroHash])).resolves.toEqual(
placeholderAddr,
)
})

it('should prohibit transfers by non-owners', async () => {
const { ensRegistry } = await loadFixture(fixture)

await expect(ensRegistry)
.write('setOwner', [padHex('0x01', { size: 32 }), placeholderAddr])
.toBeRevertedWithoutReason()
})

it('should allow setting resolvers', async () => {
const { ensRegistry } = await loadFixture(fixture)

await expect(ensRegistry)
.write('setResolver', [zeroHash, placeholderAddr])
.toEmitEvent('NewResolver')
.withArgs(zeroHash, placeholderAddr)

await expect(ensRegistry.read.resolver([zeroHash])).resolves.toEqual(
placeholderAddr,
)
})

it('should prevent setting resolvers by non-owners', async () => {
const { ensRegistry } = await loadFixture(fixture)

await expect(ensRegistry)
.write('setResolver', [padHex('0x01', { size: 32 }), placeholderAddr])
.toBeRevertedWithoutReason()
})

it('should allow setting the TTL', async () => {
const { ensRegistry } = await loadFixture(fixture)

await expect(ensRegistry)
.write('setTTL', [zeroHash, 3600n])
.toEmitEvent('NewTTL')
.withArgs(zeroHash, 3600n)

await expect(ensRegistry.read.ttl([zeroHash])).resolves.toEqual(3600n)
})

it('should prevent setting the TTL by non-owners', async () => {
const { ensRegistry } = await loadFixture(fixture)

await expect(ensRegistry)
.write('setTTL', [padHex('0x01', { size: 32 }), 3600n])
.toBeRevertedWithoutReason()
})

it('should allow the creation of subnodes', async () => {
const { ensRegistry, accounts } = await loadFixture(fixture)

await expect(ensRegistry)
.write('setSubnodeOwner', [
zeroHash,
labelhash('eth'),
accounts[1].address,
])
.toEmitEvent('NewOwner')
.withArgs(zeroHash, labelhash('eth'), accounts[1].address)

await expect(
ensRegistry.read.owner([namehash('eth')]),
).resolves.toEqualAddress(accounts[1].address)
})

it('should prohibit subnode creation by non-owners', async () => {
const { ensRegistry, accounts } = await loadFixture(fixture)

await expect(ensRegistry)
.write(
'setSubnodeOwner',
[zeroHash, labelhash('eth'), accounts[1].address],
{ account: accounts[1] },
)
.toBeRevertedWithoutReason()
})
})
Loading

0 comments on commit 657428a

Please sign in to comment.