Skip to content

Commit

Permalink
(e2e) repair playwright fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
sugh01 committed Nov 23, 2023
1 parent 66a3ec2 commit d767ead
Show file tree
Hide file tree
Showing 11 changed files with 684 additions and 407 deletions.
474 changes: 254 additions & 220 deletions e2e/specs/stateless/createSubname.spec.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@ensdomains/content-hash": "^3.0.0-beta.5",
"@ensdomains/dnsprovejs": "0.4.1",
"@ensdomains/ens-contracts": "0.0.22",
"@ensdomains/ensjs": "3.0.0-beta.9",
"@ensdomains/ensjs": "3.0.0-beta.10",
"@ensdomains/thorin": "0.6.44",
"@metamask/inpage-provider": "^8.1.0",
"@metamask/mobile-provider": "^2.1.0",
Expand Down
45 changes: 24 additions & 21 deletions playwright/fixtures/makeName/generators/generateLegacyName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { Accounts, User } from '../../accounts'
import { Accounts, User, createAccounts } from '../../accounts'
import { Contracts } from '../../contracts'

import { namehash } from '@ensdomains/ensjs/dist/cjs/utils/normalise'

import { Provider } from '../../provider'
// import { LegacySubname, generateLegacySubname } from './generateLegacySubname'
import { registrySetOwnerSnippet} from "@ensdomains/ensjs/dist/cjs/contracts/registry.js"
import { LegacySubname, generateLegacySubname } from './generateLegacySubname'

import {
publicClient,
testClient,
waitForTransaction,
walletClient,
} from '../../contracts/utils/addTestContracts.js'
import { transferName } from '@ensdomains/ensjs/wallet'

const DEFAULT_DURATION = 31536000

Expand All @@ -30,7 +28,7 @@ export type Name = {
manager?: User
duration?: number
secret?: string
// subnames?: Omit<LegacySubname, 'name' | 'nameOwner'>[]
subnames?: Omit<LegacySubname, 'name' | 'nameOwner'>[]
}

type Dependencies = {
Expand All @@ -48,7 +46,7 @@ export const generateLegacyName =
duration = DEFAULT_DURATION,
// eslint-disable-next-line no-restricted-syntax
secret = '0x0000000000000000000000000000000000000000000000000000000000000000',
// subnames,
subnames,
}: Name) => {
const name = `${label}.eth`
console.log('generating legacy name:', name)
Expand All @@ -71,21 +69,26 @@ export const generateLegacyName =
await registrationTx.wait()

// Create subnames
// const _subnames = (subnames || []).map((subname) => ({
// ...subname,
// name: `${label}.eth`,
// nameOwner: owner,
// }))
// for (const subname of _subnames) {
// await generateLegacySubname({ accounts, contracts })(subname)
// }
const _subnames = (subnames || []).map((subname) => ({
...subname,
name: `${label}.eth`,
nameOwner: owner,
}))
for (const subname of _subnames) {
await generateLegacySubname({ accounts, contracts })(subname)
}

// if (!!manager && manager !== owner) {
// const registry = contracts.get('ENSRegistry', { signer: owner })
// const node = namehash(`${label}.eth`)
// const _manager = accounts.getAddress(manager)
// await registry.setOwner(node, _manager)
// }
if (!!manager && manager !== owner) {
console.log('setting manager:', name, manager)
const _manager = accounts.getAddress(manager)
const tx = await transferName(walletClient, {
name: name,
newOwnerAddress: createAccounts().getAddress(manager) as `0x${string}`,
contract: 'registry',
account: createAccounts().getAddress(owner) as `0x${string}`,
})
const receipt = await waitForTransaction(tx)
}

await testClient.increaseTime({ seconds: 61 })
await testClient.mine({ blocks: 1 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import { Accounts, User, createAccounts } from '../../accounts'
import { Contracts } from '../../contracts'

import { RecordOptions } from '@ensdomains/ensjs/dist/cjs/utils/registerHelpers'
import { RecordOptions } from '@ensdomains/ensjs/utils'

// import { RESOLVER_ADDRESSES } from '@app/utils/constants'
// import { RESOLVER_ADDRESSES } from '@app/utils/constants' //Ask about this

import { Provider } from '../../provider'
// import { LegacySubname, generateLegacySubname } from './generateLegacySubname'
import { generateRecords } from './generateRecords'

import {
Expand All @@ -19,13 +18,15 @@ import {
walletClient,
} from '../../contracts/utils/addTestContracts.js'
import { setResolver } from '@ensdomains/ensjs/wallet'
import { transferName } from '@ensdomains/ensjs/wallet'
import { generateLegacySubname, LegacySubname } from './generateLegacySubname'

const DEFAULT_DURATION = 31536000
// const DEFAULT_RESOLVER = RESOLVER_ADDRESSES['1337'][2] as `0x${string}`
const DEFAULT_RESOLVER = "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB" //Not sure what resolver to use here
const DEFAULT_RESOLVER = testClient.chain.contracts.ensPublicResolver.address //Not sure what resolver to use here
// const VALID_RESOLVERS = RESOLVER_ADDRESSES['1337'].filter(
// (resolver) => resolver !== '0xd7a4F6473f32aC2Af804B3686AE8F1932bC35750',
// )
// ) //TODO SG - Remove this part after confirming

export type Name = {
label: string
Expand All @@ -36,7 +37,7 @@ export type Name = {
resolver?: `0x${string}`
addr?: User
records?: RecordOptions
// subnames?: Omit<LegacySubname, 'name'>[]
subnames?: Omit<LegacySubname, 'name'>[]
}

type Dependencies = {
Expand All @@ -57,7 +58,7 @@ export const generateLegacyNameWithConfig =
resolver = DEFAULT_RESOLVER,
addr = owner,
records,
// subnames,
subnames,
}: Name) => {
const name = `${label}.eth`
console.log('generating legacy name:', name)
Expand Down Expand Up @@ -105,39 +106,38 @@ export const generateLegacyNameWithConfig =
await generateRecords({ contracts })({ name: `${label}.eth`, owner, resolver, records })

// Create subnames
// const _subnames = (subnames || []).map((subname) => ({
// ...subname,
// name: `${label}.eth`,
// nameOwner: owner,
// resolver: subname.resolver ?? _resolver,
// }))
// for (const subname of _subnames) {
// await generateLegacySubname({ accounts, contracts })(subname)
// }
const _subnames = (subnames || []).map((subname) => ({
...subname,
name: `${label}.eth`,
nameOwner: owner,
resolver: subname.resolver ?? _resolver,
}))
for (const subname of _subnames) {
await generateLegacySubname({ accounts, contracts })(subname)
}

if (!hasValidResolver && resolver) {
console.log('setting resolver:', name, resolver)
// const registry = contracts.get('ENSRegistry', { signer: owner })
// const node = namehash(`${label}.eth`)
// await registry.setResolver(node, resolver)
const tx = await setResolver(walletClient, {
name: name,
contract: 'registry',
resolverAddress: resolver,
account: createAccounts().getAddress(owner),
account: createAccounts().getAddress(owner) as `0x${string}`,
})
expect(tx).toBeTruthy()
const receipt = await waitForTransaction(tx)
expect(receipt.status).toBe('success')
}

// if (!!manager && manager !== owner) {
// console.log('setting manager:', name, manager)
// const registry = contracts.get('ENSRegistry', { signer: owner })
// const node = namehash(`${label}.eth`)
// const _manager = accounts.getAddress(manager)
// await registry.setOwner(node, _manager)
// }
if (!!manager && manager !== owner) {
console.log('setting manager:', name, manager)
const _manager = accounts.getAddress(manager)
const tx = await transferName(walletClient, {
name: name,
newOwnerAddress: createAccounts().getAddress(manager) as `0x${string}`,
contract: 'registry',
account: createAccounts().getAddress(owner) as `0x${string}`,
})
const receipt = await waitForTransaction(tx)
}

await provider.mine()
}
107 changes: 107 additions & 0 deletions playwright/fixtures/makeName/generators/generateLegacySubname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { Accounts, createAccounts, User } from '../../accounts'
import { Contracts } from '../../contracts'
import { RecordOptions } from '@ensdomains/ensjs/utils'

// import { RESOLVER_ADDRESSES, emptyAddress } from '@app/utils/constants' //TODO (SG) - Ask about this

import { generateRecords } from './generateRecords'
import { testClient, waitForTransaction, walletClient } from '../../contracts/utils/addTestContracts'
import { createSubname, wrapName } from '@ensdomains/ensjs/wallet'
import { getChainContractAddress } from '@ensdomains/ensjs/contracts'
import { registrySetApprovalForAllSnippet } from '@ensdomains/ensjs/contracts'

export type LegacySubname = {
name: string
nameOwner: User
label: string
owner?: User
resolver?: `0x${string}`
records?: RecordOptions
duration?: number
type?: 'wrapped' | 'legacy'
subnames?: Omit<LegacySubname, 'name' | 'nameOwner'>[]
}

type Dependencies = {
accounts: Accounts
contracts: Contracts
}
// const DEFAULT_RESOLVER = RESOLVER_ADDRESSES['1337'][2] as `0x${string}`
const DEFAULT_RESOLVER = testClient.chain.contracts.ensPublicResolver.address //Not sure what resolver to use here
export const generateLegacySubname =
({ accounts, contracts }: Dependencies) =>
async ({
name,
nameOwner,
label,
owner = nameOwner,
resolver,
records,
type,
subnames,
}: LegacySubname) => {
const subname = `${label}.${name}`
console.log('generating legacy subname:', subname)

const tx = await createSubname(walletClient, {
name: `${label}.${name}`,
contract: 'registry',
owner: createAccounts().getAddress(owner) as `0x${string}`,
account: createAccounts().getAddress(nameOwner) as `0x${string}`,
})
const receipt = await waitForTransaction(tx)

// Make records
if (records && resolver) {
await generateRecords({ contracts })({
name: subname,
owner,
resolver,
records,
})
}

if (type === 'wrapped') {
const approve = async () => {
return walletClient.writeContract({
abi: registrySetApprovalForAllSnippet,
address: getChainContractAddress({
client: walletClient,
contract: 'ensRegistry',
}),
functionName: 'setApprovalForAll',
args: [
getChainContractAddress({
client: walletClient,
contract: 'ensNameWrapper',
}),
true,
],
account: createAccounts().getAddress(nameOwner) as `0x${string}`,
})
}
await approve()

console.log(`wrapping legacy subname:`, subname)
}
const wrap_tx = await wrapName(walletClient, {
name: 'test.with-subnames.eth',
newOwnerAddress: accounts.getAddress(owner) as `0x${string}`,
account: accounts.getAddress(nameOwner) as `0x${string}`,
})
await waitForTransaction(tx)

// Create subnames
const _subnames = (subnames || []).map((_subname) => ({
..._subname,
name: `${label}.${name}`,
nameOwner: owner,
resolver: _subname.resolver ?? DEFAULT_RESOLVER,
}))
for (const eachSubname of _subnames) {
await generateLegacySubname({ accounts, contracts })(eachSubname)
}
}
Loading

0 comments on commit d767ead

Please sign in to comment.