Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register unwrapped names #925

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
199 changes: 178 additions & 21 deletions e2e/specs/stateless/registerName.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { expect } from '@playwright/test'
import { Hash, isHash } from 'viem'
import { Hash } from 'viem'

import { ethRegistrarControllerCommitSnippet } from '@ensdomains/ensjs/contracts'
import {
ethRegistrarControllerCommitSnippet,
legacyEthRegistrarControllerCommitSnippet,
} from '@ensdomains/ensjs/contracts'
import { setPrimaryName } from '@ensdomains/ensjs/wallet'
import { Web3RequestKind } from '@ensdomains/headless-web3-provider'

Expand Down Expand Up @@ -60,6 +63,8 @@ test.describe.serial('normal registration', () => {
await homePage.goto()
await login.connect()

await page.pause()

await test.step('should redirect to registration page', async () => {
await homePage.searchInput.fill(name)
await page.locator(`[data-testid="search-result-name"]`, { hasText: name }).waitFor()
Expand Down Expand Up @@ -233,8 +238,11 @@ test.describe.serial('normal registration', () => {
await expect(page.getByText(`You are now the owner of ${name}`)).toBeVisible()

// calculate date one year from now
const date = new Date()
date.setFullYear(date.getFullYear() + 1)
const date = await page.evaluate(() => {
const _date = new Date()
_date.setFullYear(_date.getFullYear() + 1)
return _date
})
const formattedDate = date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
Expand All @@ -255,6 +263,10 @@ test.describe.serial('normal registration', () => {
accounts.getAddress('user', 5),
)
})

await test.step('confirm name is wrapped', async () => {
await expect(page.getByTestId('permissions-tab')).toBeVisible()
})
})

test('should not direct to the registration page on search, and show all records from registration', async ({
Expand Down Expand Up @@ -326,6 +338,11 @@ test.describe.serial('normal registration', () => {
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
new RegExp(accounts.getAddress('user', 5)),
)

await test.step('confirm name is unwrapped', async () => {
await page.pause()
await expect(page.getByTestId('permissions-tab')).not.toBeVisible()
})
})
})

Expand Down Expand Up @@ -370,6 +387,10 @@ test('should allow registering a premium name', async ({
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
new RegExp(accounts.getAddress('user', 5)),
)

await test.step('confirm name is unwrapped', async () => {
await expect(page.getByTestId('permissions-tab')).not.toBeVisible()
})
})

test('should allow registering a name and resuming from the commit toast', async ({
Expand Down Expand Up @@ -458,9 +479,9 @@ test('should allow registering with a specific date', async ({ page, login, make
await expect(page.getByTestId('payment-choice-ethereum')).toBeChecked()
await expect(registrationPage.primaryNameToggle).not.toBeChecked()

await test.step('should show correct price data (for 2.5 years)', async () => {
await expect(registrationPage.yearMarker(0)).toHaveText(/11% gas/)
await expect(registrationPage.yearMarker(1)).toHaveText(/6% gas/)
await test.step('should show correct price marker data for unwrapped registration (for 2.5 years)', async () => {
await expect(registrationPage.yearMarker(0)).toHaveText(/9% gas/)
await expect(registrationPage.yearMarker(1)).toHaveText(/5% gas/)
await expect(registrationPage.yearMarker(2)).toHaveText(/2% gas/)
})
})
Expand Down Expand Up @@ -515,6 +536,8 @@ test('should allow registering a premium name with a specific date', async ({
})

await page.getByTestId('payment-choice-ethereum').click()
await page.getByTestId('primary-name-toggle').check()

await expect(page.getByTestId('invoice-item-2-amount')).toBeVisible()
await page.getByTestId('next-button').click()
if (await page.getByTestId('profile-submit-button').isVisible()) {
Expand All @@ -533,6 +556,10 @@ test('should allow registering a premium name with a specific date', async ({
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
new RegExp(accounts.getAddress('user', 5)),
)

await test.step('confirm name is wrapped', async () => {
await expect(page.getByTestId('permissions-tab')).toBeVisible()
})
})

test('should allow registering a premium name for two months', async ({
Expand Down Expand Up @@ -601,6 +628,11 @@ test('should allow registering a premium name for two months', async ({
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
new RegExp(accounts.getAddress('user', 5)),
)

await test.step('confirm name is unwrapped', async () => {
await page.pause()
await expect(page.getByTestId('permissions-tab')).not.toBeVisible()
})
})

test('should not allow registering a premium name for less than 28 days', async ({
Expand Down Expand Up @@ -661,6 +693,7 @@ test('should not allow registering a premium name for less than 28 days', async
expect(page.getByText('28 days registration', { exact: true })).toBeVisible()
})

await page.pause()
await page.getByTestId('payment-choice-ethereum').click()
await expect(page.getByTestId('invoice-item-2-amount')).toBeVisible()
await page.getByTestId('next-button').click()
Expand All @@ -680,6 +713,11 @@ test('should not allow registering a premium name for less than 28 days', async
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
new RegExp(accounts.getAddress('user', 5)),
)

await test.step('confirm name is unwrapped', async () => {
await page.pause()
await expect(page.getByTestId('permissions-tab')).not.toBeVisible()
})
})

test('should allow normal registration for a month', async ({
Expand Down Expand Up @@ -800,6 +838,11 @@ test('should allow normal registration for a month', async ({
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
accounts.getAddress('user', 5),
)

await test.step('confirm name is wrapped', async () => {
await page.pause()
await expect(page.getByTestId('permissions-tab')).toBeVisible()
})
})

test('should not allow normal registration less than 28 days', async ({
Expand Down Expand Up @@ -931,14 +974,20 @@ test('should not allow normal registration less than 28 days', async ({
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
accounts.getAddress('user', 5),
)

await test.step('confirm name is wrapped (set primary name)', async () => {
await page.pause()
await expect(page.getByTestId('permissions-tab')).toBeVisible()
})
})

test('should be able to detect an existing commit created on a private mempool', async ({
test('should be able to detect an existing commit created on a private mempool for a wrapped registration', async ({
page,
login,
accounts,
time,
wallet,
consoleListener,
makePageObject,
}) => {
test.slow()
Expand All @@ -947,6 +996,9 @@ test('should be able to detect an existing commit created on a private mempool',
const homePage = makePageObject('HomePage')
const registrationPage = makePageObject('RegistrationPage')
const transactionModal = makePageObject('TransactionModal')
await consoleListener.initialize({
regex: /commit is:/,
})

await time.sync(500)

Expand All @@ -958,28 +1010,23 @@ test('should be able to detect an existing commit created on a private mempool',
await homePage.searchInput.press('Enter')
await expect(page.getByRole('heading', { name: `Register ${name}` })).toBeVisible()

await registrationPage.primaryNameToggle.uncheck()
await registrationPage.primaryNameToggle.check()

// should go to profile editor step
await page.getByTestId('next-button').click()

await page.getByTestId('profile-submit-button').click()

await test.step('should be able to find an existing commit', async () => {
await page.getByTestId('next-button').click()

await transactionModal.closeButton.click()

let commitHash: Hash | undefined
let attempts = 0
while (!commitHash && attempts < 4) {
// eslint-disable-next-line no-await-in-loop
const message = await page.waitForEvent('console')
// eslint-disable-next-line no-await-in-loop
const txt = await message.text()
const hash = txt.split(':')[1]?.trim() as Hash
if (isHash(hash)) commitHash = hash
attempts += 1
}
expect(commitHash!).toBeDefined()
await page.pause()

await expect(consoleListener.getMessages().length).toBeGreaterThan(0)
const commitHash = consoleListener.getMessages()[0].split(':')[1]?.trim() as Hash
console.log('>>>>>', commitHash)
storywithoutend marked this conversation as resolved.
Show resolved Hide resolved

const approveTx = await walletClient.writeContract({
abi: ethRegistrarControllerCommitSnippet,
Expand Down Expand Up @@ -1031,9 +1078,118 @@ test('should be able to detect an existing commit created on a private mempool',
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
accounts.getAddress('user', 5),
)

await test.step('confirm name is unwrapped', async () => {
await page.pause()
await expect(page.getByTestId('permissions-tab')).toBeVisible()
})
})
})

test('should be able to detect an existing commit created on a private mempool for a legacy registration', async ({
page,
login,
accounts,
time,
wallet,
consoleListener,
makePageObject,
}) => {
test.slow()

const name = `registration-normal-${Date.now()}.eth`
const homePage = makePageObject('HomePage')
const registrationPage = makePageObject('RegistrationPage')
const transactionModal = makePageObject('TransactionModal')
await consoleListener.initialize({
regex: /commit is:/,
})

await time.sync(500)

await homePage.goto()
await login.connect()

// should redirect to registration page
await homePage.searchInput.fill(name)
await homePage.searchInput.press('Enter')
await expect(page.getByRole('heading', { name: `Register ${name}` })).toBeVisible()

await registrationPage.primaryNameToggle.uncheck()

// should go to profile editor step
await page.getByTestId('next-button').click()

// await page.getByTestId('profile-submit-button').click()
storywithoutend marked this conversation as resolved.
Show resolved Hide resolved

await test.step('should be able to find an existing commit', async () => {
await page.getByTestId('next-button').click()

await transactionModal.closeButton.click()

await expect(consoleListener.getMessages().length).toBeGreaterThan(0)
const commitHash = consoleListener.getMessages()[0].split(':')[1]?.trim() as Hash
console.log('>>>>>', commitHash)
storywithoutend marked this conversation as resolved.
Show resolved Hide resolved

const approveTx = await walletClient.writeContract({
abi: legacyEthRegistrarControllerCommitSnippet,
address: testClient.chain.contracts.legacyEthRegistrarController.address,
args: [commitHash!],
functionName: 'commit',
account: createAccounts().getAddress('user') as `0x${string}`,
})
await waitForTransaction(approveTx)

await page.route('https://api.findblock.xyz/**/*', async (route) => {
await route.fulfill({
json: {
ok: true,
data: {
hash: approveTx,
},
},
})
})

// should show countdown
await expect(page.getByTestId('countdown-circle')).toBeVisible()
await expect(page.getByTestId('countdown-circle')).toContainText(/^[0-6]?[0-9]$/)
await testClient.increaseTime({ seconds: 60 })

await page.pause()
await expect(page.getByTestId('countdown-complete-check')).toBeVisible({ timeout: 10000 })
})

await test.step('should be able to complete registration when modal is closed', async () => {
await expect(page.getByTestId('finish-button')).toBeEnabled()

// should save the registration state and the transaction status
await page.reload()
await expect(page.getByTestId('finish-button')).toBeEnabled()

// should allow finalising registration and automatically go to the complete step
await page.getByTestId('finish-button').click()
await expect(page.getByText('Open Wallet')).toBeVisible()
await transactionModal.confirmButton.click()

await transactionModal.closeButton.click()

await expect(transactionModal.transactionModal).toHaveCount(0)

await wallet.authorize(Web3RequestKind.SendTransaction)
// await transactionModal.confirm()
storywithoutend marked this conversation as resolved.
Show resolved Hide resolved

await page.getByTestId('view-name').click()
await expect(page.getByTestId('address-profile-button-eth')).toHaveText(
accounts.getAddress('user', 5),
)

await test.step('confirm name is unwrapped', async () => {
await page.pause()
await expect(page.getByTestId('permissions-tab')).not.toBeVisible()
})
})
})
test.describe('Error handling', () => {
test('should be able to detect an existing commit created on a private mempool', async ({
page,
Expand Down Expand Up @@ -1124,6 +1280,7 @@ test.describe('Error handling', () => {
})

await test.step('transaction: commit', async () => {
await page.pause()
await expect(page.getByText('Open Wallet')).toBeVisible()
await transactionModal.confirm()
await expect(page.getByText(`Your "Start timer" transaction was successful`)).toBeVisible()
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@ensdomains/address-encoder": "1.1.1",
"@ensdomains/content-hash": "^3.0.0-beta.5",
"@ensdomains/ens-contracts": "1.2.0-beta.0",
"@ensdomains/ensjs": "4.0.2",
"@ensdomains/ensjs": "4.0.3-alpha.12",
"@ensdomains/thorin": "0.6.50",
"@metamask/post-message-stream": "^6.1.2",
"@metamask/providers": "^14.0.2",
Expand Down Expand Up @@ -280,4 +280,4 @@
}
},
"packageManager": "[email protected]"
}
}
Loading
Loading