Skip to content

Commit 6cdf519

Browse files
committed
test: adds checkes for no primary name set
1 parent eba6ecf commit 6cdf519

File tree

2 files changed

+155
-1
lines changed

2 files changed

+155
-1
lines changed

e2e/specs/stateless/setPrimary.spec.ts

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { expect } from '@playwright/test'
22
import { labelhash } from 'viem'
33

44
import { getResolver } from '@ensdomains/ensjs/public'
5-
import { setPrimaryName } from '@ensdomains/ensjs/wallet'
5+
import { setPrimaryName, setRecords } from '@ensdomains/ensjs/wallet'
66

77
import { test } from '../../../playwright'
88
import { createAccounts } from '../../../playwright/fixtures/accounts'
99
import {
10+
testClient,
1011
waitForTransaction,
1112
walletClient,
1213
} from '../../../playwright/fixtures/contracts/utils/addTestContracts'
@@ -487,4 +488,130 @@ test.describe('profile', () => {
487488
accounts.getAddress('user2', 5),
488489
)
489490
})
491+
492+
test('should not show primary name when ETH address record points to different address', async ({
493+
page,
494+
login,
495+
makeName,
496+
accounts,
497+
time,
498+
}) => {
499+
test.slow()
500+
501+
// Step 1: Create a name owned by user with ETH record pointing to user's own address
502+
const name = await makeName({
503+
label: 'primary-mismatch',
504+
type: 'legacy',
505+
owner: 'user',
506+
manager: 'user',
507+
addr: 'user', // Initially points to user's own address
508+
})
509+
510+
const userAddress = accounts.getAddress('user')
511+
const user2Address = accounts.getAddress('user2')
512+
513+
// Step 2: Set this name as primary name for user
514+
const tx = await setPrimaryName(walletClient, {
515+
name,
516+
account: createAccounts().getAddress('user') as `0x${string}`,
517+
})
518+
await waitForTransaction(tx)
519+
520+
await page.goto('/')
521+
await login.connect()
522+
523+
// Step 3: Verify primary name shows on user's address page
524+
await page.getByPlaceholder('Search for a name').fill(userAddress)
525+
await page.getByPlaceholder('Search for a name').press('Enter')
526+
await expect(page.getByTestId('profile-snippet')).toBeVisible({ timeout: 25000 })
527+
await expect(page.getByTestId('profile-title')).toHaveText(name)
528+
529+
// Step 4: Change the ETH address record to point to user2's address
530+
const tx2 = await setRecords(walletClient, {
531+
name,
532+
coins: [
533+
{
534+
coin: 'eth',
535+
value: user2Address,
536+
},
537+
],
538+
resolverAddress: walletClient.chain.contracts.legacyPublicResolver.address,
539+
account: accounts.getAddress('user') as `0x${string}`,
540+
})
541+
await waitForTransaction(tx2)
542+
543+
await testClient.mine({ blocks: 1 })
544+
await time.sync()
545+
546+
await page.reload()
547+
548+
// Step 5: Verify primary name NO LONGER shows on user's address page
549+
await page.getByPlaceholder('Search for a name').fill(userAddress)
550+
await page.getByPlaceholder('Search for a name').press('Enter')
551+
await expect(page.getByTestId('no-profile-snippet')).toBeVisible({ timeout: 25000 })
552+
await expect(page.getByText('No primary name set')).toBeVisible()
553+
})
554+
555+
test('name-wrapper - should not show primary name when ETH address record points to different address', async ({
556+
page,
557+
login,
558+
makeName,
559+
accounts,
560+
time,
561+
makePageObject,
562+
}) => {
563+
test.slow()
564+
565+
// Step 1: Create a name owned by user with ETH record pointing to user's own address
566+
const name = await makeName({
567+
label: 'primary-mismatch',
568+
type: 'wrapped',
569+
owner: 'user',
570+
addr: accounts.getAddress('user') as `0x${string}`,
571+
})
572+
573+
const userAddress = accounts.getAddress('user')
574+
const user2Address = accounts.getAddress('user2')
575+
576+
await page.goto('/')
577+
await login.connect()
578+
579+
const profilePage = makePageObject('ProfilePage')
580+
581+
await profilePage.goto(name)
582+
await page.getByText('Set as primary name').click()
583+
const transactionModal = makePageObject('TransactionModal')
584+
await transactionModal.autoComplete()
585+
586+
// Step 3: Verify primary name shows on user's address page
587+
await page.getByPlaceholder('Search for a name').fill(userAddress)
588+
await page.getByPlaceholder('Search for a name').press('Enter')
589+
await expect(page.getByTestId('profile-snippet')).toBeVisible({ timeout: 25000 })
590+
await expect(page.getByTestId('profile-title')).toHaveText(name)
591+
592+
// Step 4: Change the ETH address record to point to user2's address
593+
const tx2 = await setRecords(walletClient, {
594+
name,
595+
coins: [
596+
{
597+
coin: 'eth',
598+
value: user2Address,
599+
},
600+
],
601+
resolverAddress: walletClient.chain.contracts.ensPublicResolver.address as `0x${string}`,
602+
account: accounts.getAddress('user') as `0x${string}`,
603+
})
604+
await waitForTransaction(tx2)
605+
606+
await testClient.mine({ blocks: 1 })
607+
await time.sync()
608+
609+
await page.reload()
610+
611+
// Step 5: Verify primary name NO LONGER shows on user's address page
612+
await page.getByPlaceholder('Search for a name').fill(userAddress)
613+
await page.getByPlaceholder('Search for a name').press('Enter')
614+
await expect(page.getByTestId('no-profile-snippet')).toBeVisible({ timeout: 25000 })
615+
await expect(page.getByText('No primary name set')).toBeVisible()
616+
})
490617
})

src/hooks/ensjs/public/usePrimaryName.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,31 @@ describe('getPrimaryNameQueryFn', () => {
181181
}
182182
`)
183183
})
184+
185+
it('should return null when allowMismatch is true but ETH address record points to different address', async () => {
186+
const differentAddress = '0x1234567890123456789012345678901234567890'
187+
188+
mockGetName.mockImplementationOnce(() =>
189+
Promise.resolve({
190+
name: 'test.eth',
191+
match: false,
192+
resolverAddress: '0xresolver',
193+
reverseResolverAddress: '0xreverseResolver',
194+
}),
195+
)
196+
// Mock getAddressRecord to return a DIFFERENT address
197+
mockGetAddressRecord.mockImplementationOnce(() =>
198+
Promise.resolve({
199+
id: 60,
200+
name: 'eth',
201+
value: differentAddress, // ← Points to different address!
202+
}),
203+
)
204+
const result = await getPrimaryNameQueryFn(mockConfig)({
205+
queryKey: [{ address, allowMismatch: true }, chainId, address, undefined, 'getName'],
206+
meta: {} as any,
207+
signal: undefined as any,
208+
})
209+
expect(result).toBeNull() // Should return null because address doesn't match
210+
})
184211
})

0 commit comments

Comments
 (0)