Skip to content

Commit

Permalink
Merge pull request #362 from ensdomains/test-improvements-improvements
Browse files Browse the repository at this point in the history
Test improvements improvements
  • Loading branch information
TateB authored Jun 13, 2024
2 parents e24d592 + 29103ab commit 3fbff99
Show file tree
Hide file tree
Showing 50 changed files with 185 additions and 227 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion deploy/dnsregistrar/00_deploy_offchain_dns_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/dnsregistrar/05_deploy_public_suffix_list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'hardhat'
import packet from 'dns-packet'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

function encodeName(name: string) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/dnsregistrar/10_deploy_dnsregistrar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/dnsregistrar/20_set_tlds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import packet from 'dns-packet'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

function encodeName(name: string) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/dnssec-oracle/00_deploy_algorithms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/dnssec-oracle/00_deploy_digests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/dnssec-oracle/10_deploy_oracle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import packet from 'dns-packet'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const realAnchors = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import namehash from 'eth-ens-namehash'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { keccak256 } from 'js-sha3'
import { namehash } from 'viem/ens'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments, network } = hre
Expand All @@ -17,7 +17,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const deployArgs = {
from: deployer,
args: [registry.address, namehash.hash('eth')],
args: [registry.address, namehash('eth')],
log: true,
}

Expand Down
1 change: 0 additions & 1 deletion deploy/ethregistrar/00_setup_base_registrar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import namehash from 'eth-ens-namehash'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/ethregistrar/03_deploy_eth_registrar_controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Interface } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const { makeInterfaceId } = require('@openzeppelin/test-helpers')
Expand Down
2 changes: 1 addition & 1 deletion deploy/ethregistrar/04_deploy_bulk_renewal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Interface } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const { makeInterfaceId } = require('@openzeppelin/test-helpers')
Expand Down
2 changes: 1 addition & 1 deletion deploy/registry/00_deploy_registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const ZERO_HASH =
Expand Down
2 changes: 1 addition & 1 deletion deploy/registry/01_deploy_reverse_registrar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { keccak256 } from 'js-sha3'

Expand Down
2 changes: 1 addition & 1 deletion deploy/resolvers/00_deploy_eth_owned_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { ethers } from 'hardhat'

Expand Down
2 changes: 1 addition & 1 deletion deploy/resolvers/00_deploy_extended_dns_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/resolvers/00_deploy_legacy_public_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, network } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/resolvers/00_deploy_public_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/root/00_deploy_root.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/root/00_setup_root.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const ZERO_HASH =
Expand Down
2 changes: 1 addition & 1 deletion deploy/utils/00_deploy_universal_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/wrapper/00_deploy_static_metadata_service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/wrapper/01_deploy_name_wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Interface } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const { makeInterfaceId } = require('@openzeppelin/test-helpers')
Expand Down
2 changes: 1 addition & 1 deletion deploy/wrapper/02_deploy_test_unwrap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import type { DeployFunction } from 'hardhat-deploy/types.js'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const TESTNET_WRAPPER_ADDRESSES = {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@
"chai": "^5.1.1",
"dotenv": "^16.4.5",
"elliptic-solidity": "^1.0.0",
"envfile": "^6.17.0",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.6.1",
"hardhat": "^2.22.2",
"hardhat-abi-exporter": "^2.9.0",
"hardhat-contract-sizer": "^2.6.1",
"hardhat-deploy": "^0.11.10",
"hardhat-deploy": "^0.12.4",
"hardhat-gas-reporter": "^1.0.4",
"husky": "^8.0.0",
"prettier": "^2.6.2",
Expand Down Expand Up @@ -79,5 +78,6 @@
"homepage": "https://github.com/ensdomains/ens-contracts#readme",
"volta": {
"node": "16.20.2"
}
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
26 changes: 9 additions & 17 deletions tasks/seed.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fs from 'fs'

import * as envfile from 'envfile'
import n from 'eth-ens-namehash'
import { namehash } from 'viem/ens'
import * as dotenv from 'dotenv'
import { task } from 'hardhat/config'

const namehash = n.hash
const labelhash = (utils: any, label: string) =>
utils.keccak256(utils.toUtf8Bytes(label))

Expand All @@ -16,18 +13,13 @@ function getOpenSeaUrl(ethers: any, contract: string, namehashedname: string) {
task('seed', 'Creates test subbdomains and wraps them with Namewrapper')
.addPositionalParam('name', 'The ENS label to seed subdomains')
.setAction(async ({ name }, hre) => {
let parsedFile
try {
parsedFile = envfile.parse(fs.readFileSync('./.env', 'utf8'))
} catch (error: any) {
if (error.code !== 'ENOENT') {
throw error
}
console.warn(
'.env file is empty, fill as in README to complete seed action',
)
return
}
const { parsed: parsedFile, error } = dotenv.config({
path: './.env',
encoding: 'utf8',
})

if (error) throw error

const ethers = hre.ethers
const [deployer] = await ethers.getSigners()
const CAN_DO_EVERYTHING = 0
Expand Down
32 changes: 16 additions & 16 deletions test/dnsregistrar/TestDNSRegistrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SimplePublixSuffixList = artifacts.require('./SimplePublicSuffixList.sol')
const DNSRegistrarContract = artifacts.require('./DNSRegistrar.sol')
const PublicResolver = artifacts.require('./PublicResolver.sol')
const DNSSECImpl = artifacts.require('./DNSSECImpl')
const namehash = require('eth-ens-namehash')
const { namehash } = require('viem/ens')
const utils = require('./Helpers/Utils')
const { exceptions } = require('@ensdomains/test-utils')
const { assert } = require('chai')
Expand Down Expand Up @@ -61,7 +61,7 @@ contract('DNSRegistrar', function (accounts) {
const ReverseRegistrar = await deploy('ReverseRegistrar', ens.address)
await ens.setSubnodeOwner(EMPTY_BYTES32, labelhash('reverse'), accounts[0])
await ens.setSubnodeOwner(
namehash.hash('reverse'),
namehash('reverse'),
labelhash('addr'),
ReverseRegistrar.address,
)
Expand Down Expand Up @@ -100,7 +100,7 @@ contract('DNSRegistrar', function (accounts) {
from: accounts[1],
})

assert.equal(await ens.owner(namehash.hash('foo.test')), accounts[0])
assert.equal(await ens.owner(namehash('foo.test')), accounts[0])
})

it('allows claims on names that are not TLDs', async function () {
Expand All @@ -111,7 +111,7 @@ contract('DNSRegistrar', function (accounts) {

await registrar.proveAndClaim(utils.hexEncodeName('foo.co.nz'), proof)

assert.equal(await ens.owner(namehash.hash('foo.co.nz')), accounts[0])
assert.equal(await ens.owner(namehash('foo.co.nz')), accounts[0])
})

it('allows anyone to update a DNSSEC referenced name', async function () {
Expand All @@ -126,7 +126,7 @@ contract('DNSRegistrar', function (accounts) {

await registrar.proveAndClaim(utils.hexEncodeName('foo.test'), proof)

assert.equal(await ens.owner(namehash.hash('foo.test')), accounts[1])
assert.equal(await ens.owner(namehash('foo.test')), accounts[1])
})

it('rejects proofs with earlier inceptions', async function () {
Expand Down Expand Up @@ -173,8 +173,8 @@ contract('DNSRegistrar', function (accounts) {
ZERO_ADDRESS,
)

assert.equal(await ens.owner(namehash.hash('foo.test')), accounts[0])
assert.equal(await ens.resolver(namehash.hash('foo.test')), accounts[1])
assert.equal(await ens.owner(namehash('foo.test')), accounts[0])
assert.equal(await ens.resolver(namehash('foo.test')), accounts[1])
})

it('does not allow anyone else to claim and set a resolver', async () => {
Expand Down Expand Up @@ -214,7 +214,7 @@ contract('DNSRegistrar', function (accounts) {
accounts[0],
)

assert.equal(await resolver.addr(namehash.hash('foo.test')), accounts[0])
assert.equal(await resolver.addr(namehash('foo.test')), accounts[0])
})

it('forbids setting an address if the resolver is not also set', async () => {
Expand Down Expand Up @@ -309,22 +309,22 @@ contract('DNSRegistrar', function (accounts) {

// This is the expected use case.
// Using the proof for `alice.test`, can claim `alice.test`
assert.equal(await ens.owner(namehash.hash('alice.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('alice.test')), ZERO_ADDRESS)
await registrar.proveAndClaim(
utils.hexEncodeName('alice.test'),
proofForAliceDotTest,
)
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)

// Now using the same proof for `alice.test`, alice can also claim `foo.test`. Without a proof involving `foo.test`
assert.equal(await ens.owner(namehash.hash('foo.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('foo.test')), ZERO_ADDRESS)
await expect(
registrar.proveAndClaim(
utils.hexEncodeName('foo.test'),
proofForAliceDotTest,
),
).to.be.revertedWith('NoOwnerRecordFound')
assert.equal(await ens.owner(namehash.hash('foo.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('foo.test')), ZERO_ADDRESS)
})

it('cannot takeover claimed DNS domains using unrelated proof', async function () {
Expand All @@ -338,12 +338,12 @@ contract('DNSRegistrar', function (accounts) {
]

// Alice claims her domain
assert.equal(await ens.owner(namehash.hash('alice.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('alice.test')), ZERO_ADDRESS)
await registrar.proveAndClaim(
utils.hexEncodeName('alice.test'),
proofForAliceDotTest,
)
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)

// Build sample proof for a DNS record with name `bob.test` that bob owns
const proofForBobDotTest = [
Expand All @@ -352,13 +352,13 @@ contract('DNSRegistrar', function (accounts) {
]

// Bob claims alice's domain
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)
await expect(
registrar.proveAndClaim(
utils.hexEncodeName('alice.test'),
proofForBobDotTest,
),
).to.be.revertedWith('NoOwnerRecordFound')
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)
})
})
Loading

0 comments on commit 3fbff99

Please sign in to comment.