Skip to content

Commit

Permalink
merge + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Aug 9, 2023
2 parents 07164d7 + 1f14a39 commit d222bb7
Show file tree
Hide file tree
Showing 80 changed files with 1,652 additions and 680 deletions.
Binary file modified packages/ensjs/archive.tar.lz4
Binary file not shown.
11 changes: 11 additions & 0 deletions packages/ensjs/deploy/00_register_legacy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ const names = [
namedAddr: 'owner',
duration: 2419200,
},
{
label: 'deletable',
namedOwner: 'owner',
namedAddr: 'owner',
subnames: [
{ label: 'xyz', namedOwner: 'owner2' },
{ label: 'test', namedOwner: 'owner' },
{ label: 'unwrapped-deleted', namedOwner: 'owner' },
{ label: 'wrapped-deleted', namedOwner: 'owner' },
],
},
...Array.from({ length: 34 }, (_, i) => ({
label: `${i}-dummy`,
namedOwner: 'owner2',
Expand Down
14 changes: 10 additions & 4 deletions packages/ensjs/deploy/00_register_wrapped.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ const names = [
label: 'wrapped-with-expiring-subnames',
namedOwner: 'owner',
fuses: encodeFuses({
child: {
named: ['CANNOT_UNWRAP'],
input: {
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
subnames: [
Expand All @@ -79,15 +81,19 @@ const names = [
namedOwner: 'owner2',
expiry: Math.floor(Date.now() / 1000),
fuses: encodeFuses({
parent: { named: ['PARENT_CANNOT_CONTROL'] },
input: {
parent: { named: ['PARENT_CANNOT_CONTROL'] },
},
}),
},
{
label: 'pcc',
namedOwner: 'owner2',
expiry: MAX_DATE_INT,
fuses: encodeFuses({
parent: { named: ['PARENT_CANNOT_CONTROL'] },
input: {
parent: { named: ['PARENT_CANNOT_CONTROL'] },
},
}),
},
],
Expand Down
65 changes: 65 additions & 0 deletions packages/ensjs/deploy/01_delete_names.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-await-in-loop */
const { ethers } = require('hardhat')
const { namehash, toHex, labelhash } = require('viem')
const { EMPTY_ADDRESS } = require('../dist/cjs/utils/consts')
const { packetToBytes } = require('../dist/cjs/utils/hexEncodedName')

/**
* @type {import('hardhat-deploy/types').DeployFunction}
*/
const func = async function (hre) {
const { getNamedAccounts } = hre
const allNamedAccts = await getNamedAccounts()

const nameWrapper = await ethers.getContract(
'NameWrapper',
await ethers.getSigner(allNamedAccts.owner),
)
const registry = await ethers.getContract(
'ENSRegistry',
await ethers.getSigner(allNamedAccts.owner),
)

/**
* @param {string} name
*/
const deleteName = async (name) => {
const labels = name.split('.')
const label = labelhash(labels.shift())
const node = namehash(labels.join('.'))

const tx = await registry.setSubnodeRecord(
node,
label,
EMPTY_ADDRESS,
EMPTY_ADDRESS,
0,
)
await tx.wait()
}

const name1 = 'wrapped-deleted.deletable.eth'
const name2 = 'unwrapped-deleted.deletable.eth'

// wrap wrapped-deleted.deletable.eth
const approveTx = await registry.setApprovalForAll(nameWrapper.address, true)
await approveTx.wait()
const wrapTx = await nameWrapper.wrap(
toHex(packetToBytes(name1)),
allNamedAccts.owner,
EMPTY_ADDRESS,
)
await wrapTx.wait()

await deleteName(name1)
await deleteName(name2)

return true
}

func.id = 'delete-names'
func.tags = ['delete-names']
func.runAtTheEnd = true

module.exports = func
2 changes: 1 addition & 1 deletion packages/ensjs/hardhat.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('@nomiclabs/hardhat-ethers')
require('dotenv/config')
require('@nomiclabs/hardhat-ethers')
require('hardhat-deploy')
const { resolve } = require('path')

Expand Down
5 changes: 3 additions & 2 deletions packages/ensjs/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* eslint-disable @typescript-eslint/naming-convention */
const config = {
verbose: true,
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
transformIgnorePatterns: [],
moduleNameMapper: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^(\\.{1,2}/.*)\\.js$': '$1',
'^multiformats$': '<rootDir>/node_modules/multiformats/src/index.js',
'^multiformats/(.*)$': '<rootDir>/node_modules/multiformats/src/$1',
},
}

Expand Down
6 changes: 4 additions & 2 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"files": [
"dist/",
"src/",
"!src/tests"
"!src/**/*.test.ts",
"!src/test"
],
"repository": "[email protected]:ensdomains/ensjs-v3.git",
"author": "TateB <[email protected]>",
Expand Down Expand Up @@ -99,7 +100,7 @@
"dependencies": {
"@adraffy/ens-normalize": "1.9.0",
"@ensdomains/address-encoder": "^0.2.18",
"@ensdomains/content-hash": "^2.5.7",
"@ensdomains/content-hash": "^3.0.0-beta.5",
"@ensdomains/dnsprovejs": "^0.4.1",
"abitype": "^0.8.0",
"cbor": "^8.1.0",
Expand Down Expand Up @@ -136,6 +137,7 @@
"jest": "^29.5.0",
"jest-environment-node": "^29.5.0",
"jest-localstorage-mock": "^2.4.21",
"multiformats": "^12.0.1",
"solc": "^0.8.13",
"ts-jest": "^29.1.1",
"ts-node": "^10.7.0",
Expand Down
1 change: 0 additions & 1 deletion packages/ensjs/src/@types/@ensdomains/content-hash.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/ensjs/src/clients/decorators/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export type EnsSubgraphActions = {
name,
searchString,
allowExpired,
allowDeleted,
orderBy,
orderDirection,
pageSize,
Expand Down
6 changes: 6 additions & 0 deletions packages/ensjs/src/contracts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const addresses = {
ensDnssecImpl: {
address: '0x21745FF62108968fBf5aB1E07961CC0FCBeB2364',
},
ensUniversalResolver: {
address: '0x9380F1974D2B7064eA0c0EC251968D8c69f0Ae31',
},
},
goerli: {
ensBaseRegistrarImplementation: {
Expand All @@ -79,6 +82,9 @@ export const addresses = {
ensDnssecImpl: {
address: '0xF427c4AdED8B6dfde604865c1a7E953B160C26f0',
},
ensUniversalResolver: {
address: '0x3952Be0b2186f8B113193a84b69bD71ad3fc1ae3',
},
},
} as const

Expand Down
39 changes: 21 additions & 18 deletions packages/ensjs/src/errors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export class FusesOutOfRangeError extends BaseError {

constructor({
fuses,
minimum = 1,
maximum = 2 ** 32,
minimum = 0n,
maximum = 2n ** 32n,
details,
}: {
fuses: number
minimum?: number
maximum?: number
fuses: bigint
minimum?: bigint
maximum?: bigint
details?: string
}) {
super('Fuse value out of range', {
Expand All @@ -24,21 +24,16 @@ export class FusesOutOfRangeError extends BaseError {
}
}

export class FusesNonIntegerError extends BaseError {
override name = 'FusesNonIntegerError'

constructor({ fuses, details }: { fuses: number; details?: string }) {
super('Fuse was not an integer, which is required', {
metaMessages: [`- Fuse value: ${fuses}`],
details,
})
}
}

export class FusesRestrictionNotAllowedError extends BaseError {
override name = 'FusesRestrictionNotAllowed'

constructor({ fuses, details }: { fuses: object; details?: string }) {
constructor({
fuses,
details,
}: {
fuses: object | bigint
details?: string
}) {
super('Restriction not allowed', {
metaMessages: [`- Fuse value: ${fuses}`],
details,
Expand Down Expand Up @@ -76,7 +71,7 @@ export class FusesInvalidNamedFuseError extends BaseError {
export class FusesFuseNotAllowedError extends BaseError {
override name = 'FusesFuseNotAllowedError'

constructor({ fuse }: { fuse: string | number }) {
constructor({ fuse }: { fuse: string | bigint }) {
super(`${fuse} is not allowed for this operation`)
}
}
Expand Down Expand Up @@ -159,3 +154,11 @@ export class CampaignReferenceTooLargeError extends BaseError {
})
}
}

export class InvalidContentHashError extends BaseError {
override name = 'InvalidContentHashError'

constructor() {
super('Invalid content hash')
}
}
3 changes: 2 additions & 1 deletion packages/ensjs/src/functions/dns/getDnsImportData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
testClient,
waitForTransaction,
walletClient,
} from '../../tests/addTestContracts.js'
} from '../../test/addTestContracts.js'
import getDnsImportData, { type RrSetWithSig } from './getDnsImportData.js'
import importDnsName from './importDnsName.js'

Expand All @@ -30,6 +30,7 @@ const decodeProofs = (proofs: RrSetWithSig[]) =>
)

jest.setTimeout(10000)
jest.retryTimes(2)

const wait = async (ms: number) =>
// eslint-disable-next-line no-promise-executor-return
Expand Down
5 changes: 4 additions & 1 deletion packages/ensjs/src/functions/dns/getDnsOwner.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { RequestListener } from 'http'
import { getVersion } from '../../errors/error-utils.js'
import { createHttpServer } from '../../tests/createHttpServer.js'
import { createHttpServer } from '../../test/createHttpServer.js'
import getDnsOwner from './getDnsOwner.js'

const handler: jest.MockedFunction<RequestListener> = jest.fn()
Expand All @@ -22,6 +22,9 @@ beforeEach(() => {
handler.mockReset()
})

jest.setTimeout(10000)
jest.retryTimes(2)

it('returns valid address from valid domain and record', async () => {
let name
let type
Expand Down
5 changes: 4 additions & 1 deletion packages/ensjs/src/functions/dns/importDnsName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
testClient,
waitForTransaction,
walletClient,
} from '../../tests/addTestContracts.js'
} from '../../test/addTestContracts.js'
import getOwner from '../public/getOwner.js'
import getResolver from '../public/getResolver.js'
import getDnsImportData from './getDnsImportData.js'
Expand All @@ -30,6 +30,9 @@ afterEach(async () => {
await testClient.revert({ id: snapshot })
})

jest.setTimeout(10000)
jest.retryTimes(2)

it('should import a DNS name with no address', async () => {
const tx = await importDnsName(walletClient, {
name,
Expand Down
4 changes: 2 additions & 2 deletions packages/ensjs/src/functions/public/_getContentHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { publicResolverContenthashSnippet } from '../../contracts/publicResolver
import type { Prettify, SimpleTransactionRequest } from '../../types.js'
import { EMPTY_ADDRESS } from '../../utils/consts.js'
import {
decodeContenthash,
decodeContentHash,
type DecodedContentHash,
} from '../../utils/contentHash.js'
import { generateFunction } from '../../utils/generateFunction.js'
Expand Down Expand Up @@ -44,7 +44,7 @@ const decode = async (
data,
})

return decodeContenthash(response)
return decodeContentHash(response)
}

const _getContentHash = generateFunction({ encode, decode })
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { addEnsContracts } from '../../contracts/addEnsContracts.js'
import {
deploymentAddresses,
publicClient,
} from '../../tests/addTestContracts.js'
} from '../../test/addTestContracts.js'
import batch from './batch.js'
import getAddressRecord from './getAddressRecord.js'
import getName from './getName.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getAbiRecord.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { publicClient } from '../../tests/addTestContracts.js'
import { publicClient } from '../../test/addTestContracts.js'
import getAbiRecord from './getAbiRecord.js'

const dummyABI = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { addEnsContracts } from '../../contracts/addEnsContracts.js'
import { publicClient } from '../../tests/addTestContracts.js'
import { publicClient } from '../../test/addTestContracts.js'
import getAddressRecord from './getAddressRecord.js'

const mainnetPublicClient = createPublicClient({
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getAvailable.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { publicClient } from '../../tests/addTestContracts.js'
import { publicClient } from '../../test/addTestContracts.js'
import getAvailable from './getAvailable.js'

describe('getAvailable', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { publicClient } from '../../tests/addTestContracts.js'
import { publicClient } from '../../test/addTestContracts.js'
import getContentHashRecord from './getContentHashRecord.js'

describe('getContentHashRecord', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getExpiry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { publicClient } from '../../tests/addTestContracts.js'
import { publicClient } from '../../test/addTestContracts.js'
import getExpiry from './getExpiry.js'

describe('getExpiry', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
testClient,
waitForTransaction,
walletClient,
} from '../../tests/addTestContracts.js'
} from '../../test/addTestContracts.js'
import setPrimaryName from '../wallet/setPrimaryName.js'
import getName from './getName.js'

Expand Down
Loading

0 comments on commit d222bb7

Please sign in to comment.